mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 1 | """ |
| 2 | Internal global error types |
| 3 | """ |
| 4 | |
jadmanski | 6f73136 | 2008-06-17 16:47:06 +0000 | [diff] [blame] | 5 | import sys, traceback |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 6 | from traceback import format_exception |
| 7 | |
mbligh | 9167225 | 2008-10-16 22:28:34 +0000 | [diff] [blame] | 8 | # Add names you want to be imported by 'from errors import *' to this list. |
| 9 | # This must be list not a tuple as we modify it to include all of our |
| 10 | # the Exception classes we define below at the end of this file. |
| 11 | __all__ = ['format_error'] |
| 12 | |
| 13 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 14 | def format_error(): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 15 | t, o, tb = sys.exc_info() |
| 16 | trace = format_exception(t, o, tb) |
| 17 | # Clear the backtrace to prevent a circular reference |
| 18 | # in the heap -- as per tutorial |
| 19 | tb = '' |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 20 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 21 | return ''.join(trace) |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 22 | |
mbligh | 4f40746 | 2008-12-03 15:22:39 +0000 | [diff] [blame] | 23 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 24 | class JobContinue(SystemExit): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 25 | """Allow us to bail out requesting continuance.""" |
| 26 | pass |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 27 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 28 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 29 | class JobComplete(SystemExit): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 30 | """Allow us to bail out indicating continuation not required.""" |
| 31 | pass |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 32 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 33 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 34 | class AutotestError(Exception): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 35 | """The parent of all errors deliberatly thrown within the client code.""" |
| 36 | pass |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 37 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 38 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 39 | class JobError(AutotestError): |
mbligh | 4f40746 | 2008-12-03 15:22:39 +0000 | [diff] [blame] | 40 | """Indicates an error which terminates and fails the whole job (ABORT).""" |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 41 | pass |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 42 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 43 | |
mbligh | 4f40746 | 2008-12-03 15:22:39 +0000 | [diff] [blame] | 44 | class UnhandledJobError(JobError): |
| 45 | """Indicates an unhandled error in a job.""" |
| 46 | def __init__(self, unhandled_exception): |
| 47 | if isinstance(unhandled_exception, JobError): |
mbligh | 1ca1c2c | 2008-12-09 23:38:25 +0000 | [diff] [blame] | 48 | JobError.__init__(self, *unhandled_exception.args) |
mbligh | 4f40746 | 2008-12-03 15:22:39 +0000 | [diff] [blame] | 49 | else: |
| 50 | msg = "Unhandled %s: %s" |
| 51 | msg %= (unhandled_exception.__class__.__name__, |
| 52 | unhandled_exception) |
| 53 | msg += "\n" + traceback.format_exc() |
| 54 | JobError.__init__(self, msg) |
| 55 | |
| 56 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 57 | class TestBaseException(AutotestError): |
| 58 | """The parent of all test exceptions.""" |
mbligh | 021679f | 2008-11-27 00:43:19 +0000 | [diff] [blame] | 59 | # Children are required to override this. Never instantiate directly. |
| 60 | exit_status="NEVER_RAISE_THIS" |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 61 | |
| 62 | |
| 63 | class TestError(TestBaseException): |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 64 | """Indicates that something went wrong with the test harness itself.""" |
| 65 | exit_status="ERROR" |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 66 | |
jadmanski | 8d01bfe | 2008-06-23 18:13:24 +0000 | [diff] [blame] | 67 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 68 | class TestNAError(TestBaseException): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 69 | """Indictates that the test is Not Applicable. Should be thrown |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 70 | when various conditions are such that the test is inappropriate.""" |
| 71 | exit_status="TEST_NA" |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 72 | |
jadmanski | 8d01bfe | 2008-06-23 18:13:24 +0000 | [diff] [blame] | 73 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 74 | class TestFail(TestBaseException): |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 75 | """Indicates that the test failed, but the job will not continue.""" |
| 76 | exit_status="FAIL" |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 77 | |
jadmanski | 8d01bfe | 2008-06-23 18:13:24 +0000 | [diff] [blame] | 78 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 79 | class TestWarn(TestBaseException): |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 80 | """Indicates that bad things (may) have happened, but not an explicit |
| 81 | failure.""" |
| 82 | exit_status="WARN" |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame] | 83 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 84 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 85 | class UnhandledTestError(TestError): |
| 86 | """Indicates an unhandled error in a test.""" |
| 87 | def __init__(self, unhandled_exception): |
| 88 | if isinstance(unhandled_exception, TestError): |
| 89 | TestError.__init__(self, *unhandled_exception.args) |
| 90 | else: |
| 91 | msg = "Unhandled %s: %s" |
| 92 | msg %= (unhandled_exception.__class__.__name__, |
| 93 | unhandled_exception) |
| 94 | msg += "\n" + traceback.format_exc() |
| 95 | TestError.__init__(self, msg) |
| 96 | |
| 97 | |
| 98 | class UnhandledTestFail(TestFail): |
| 99 | """Indicates an unhandled fail in a test.""" |
| 100 | def __init__(self, unhandled_exception): |
| 101 | if isinstance(unhandled_exception, TestFail): |
| 102 | TestFail.__init__(self, *unhandled_exception.args) |
| 103 | else: |
| 104 | msg = "Unhandled %s: %s" |
| 105 | msg %= (unhandled_exception.__class__.__name__, |
| 106 | unhandled_exception) |
| 107 | msg += "\n" + traceback.format_exc() |
| 108 | TestFail.__init__(self, msg) |
| 109 | |
| 110 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 111 | class CmdError(TestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 112 | """\ |
| 113 | Indicates that a command failed, is fatal to the test unless caught. |
| 114 | """ |
| 115 | def __init__(self, command, result_obj, additional_text=None): |
| 116 | TestError.__init__(self, command, result_obj, additional_text) |
mbligh | c23051c | 2008-06-27 19:26:46 +0000 | [diff] [blame] | 117 | self.command = command |
| 118 | self.result_obj = result_obj |
| 119 | self.additional_text = additional_text |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame] | 120 | |
| 121 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 122 | def __str__(self): |
jadmanski | 6ef0b67 | 2008-09-30 22:50:19 +0000 | [diff] [blame] | 123 | if self.result_obj.exit_status is None: |
| 124 | msg = "Command <%s> failed and is not responding to signals" |
| 125 | msg %= self.command |
| 126 | else: |
| 127 | msg = "Command <%s> failed, rc=%d" |
| 128 | msg %= (self.command, self.result_obj.exit_status) |
| 129 | |
mbligh | c23051c | 2008-06-27 19:26:46 +0000 | [diff] [blame] | 130 | if self.additional_text: |
| 131 | msg += ", " + self.additional_text |
showard | 6d7e94f | 2008-08-20 20:53:34 +0000 | [diff] [blame] | 132 | msg += '\n' + repr(self.result_obj) |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 133 | return msg |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 134 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 135 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 136 | class PackageError(TestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 137 | """Indicates an error trying to perform a package operation.""" |
| 138 | pass |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 139 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 140 | |
mbligh | e867310 | 2008-07-16 14:09:03 +0000 | [diff] [blame] | 141 | class BarrierError(JobError): |
| 142 | """Indicates an error happened during a barrier operation.""" |
| 143 | pass |
| 144 | |
| 145 | |
mbligh | 5deff3d | 2008-01-04 21:21:28 +0000 | [diff] [blame] | 146 | class InstallError(JobError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 147 | """Indicates an installation error which Terminates and fails the job.""" |
| 148 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 149 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 150 | |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 151 | class AutotestRunError(AutotestError): |
mbligh | 021679f | 2008-11-27 00:43:19 +0000 | [diff] [blame] | 152 | """Indicates a problem running server side control files.""" |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 153 | pass |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 154 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 155 | |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 156 | class AutotestTimeoutError(AutotestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 157 | """This exception is raised when an autotest test exceeds the timeout |
| 158 | parameter passed to run_timed_test and is killed. |
| 159 | """ |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 160 | |
| 161 | |
mbligh | ce955fc | 2009-08-24 21:59:02 +0000 | [diff] [blame] | 162 | class HostRunErrorMixIn(Exception): |
| 163 | """ |
| 164 | Indicates a problem in the host run() function raised from client code. |
| 165 | Should always be constructed with a tuple of two args (error description |
| 166 | (str), run result object). This is a common class mixed in to create the |
| 167 | client and server side versions of it. |
| 168 | """ |
| 169 | def __init__(self, description, result_obj): |
| 170 | self.description = description |
| 171 | self.result_obj = result_obj |
| 172 | Exception.__init__(self, description, result_obj) |
| 173 | |
| 174 | def __str__(self): |
| 175 | return self.description + '\n' + repr(self.result_obj) |
| 176 | |
| 177 | |
| 178 | class AutotestHostRunError(HostRunErrorMixIn, AutotestError): |
| 179 | pass |
| 180 | |
| 181 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 182 | # server-specific errors |
| 183 | |
| 184 | class AutoservError(Exception): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 185 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 186 | |
| 187 | |
mbligh | 34faa28 | 2008-01-16 17:44:49 +0000 | [diff] [blame] | 188 | class AutoservSSHTimeout(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 189 | """SSH experienced a connection timeout""" |
| 190 | pass |
mbligh | 34faa28 | 2008-01-16 17:44:49 +0000 | [diff] [blame] | 191 | |
| 192 | |
mbligh | ce955fc | 2009-08-24 21:59:02 +0000 | [diff] [blame] | 193 | class AutoservRunError(HostRunErrorMixIn, AutoservError): |
| 194 | pass |
showard | 6d7e94f | 2008-08-20 20:53:34 +0000 | [diff] [blame] | 195 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 196 | |
mbligh | 9d738d6 | 2009-03-09 21:17:10 +0000 | [diff] [blame] | 197 | class AutoservSshPermissionDeniedError(AutoservRunError): |
| 198 | """Indicates that a SSH permission denied error was encountered.""" |
| 199 | pass |
| 200 | |
| 201 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 202 | class AutoservVirtError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 203 | """Vitualization related error""" |
| 204 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 205 | |
| 206 | |
| 207 | class AutoservUnsupportedError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 208 | """Error raised when you try to use an unsupported optional feature""" |
| 209 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 210 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 211 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 212 | class AutoservHostError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 213 | """Error reaching a host""" |
| 214 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 215 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 216 | |
mbligh | c971c5f | 2009-06-08 16:48:54 +0000 | [diff] [blame] | 217 | class AutoservHostIsShuttingDownError(AutoservHostError): |
| 218 | """Host is shutting down""" |
| 219 | pass |
| 220 | |
| 221 | |
| 222 | class AutoservNotMountedHostError(AutoservHostError): |
| 223 | """Found unmounted partitions that should be mounted""" |
| 224 | pass |
| 225 | |
| 226 | |
| 227 | class AutoservSshPingHostError(AutoservHostError): |
| 228 | """SSH ping failed""" |
| 229 | pass |
| 230 | |
| 231 | |
| 232 | class AutoservDiskFullHostError(AutoservHostError): |
| 233 | """Not enough free disk space on host""" |
| 234 | def __init__(self, path, want_gb, free_space_gb): |
| 235 | AutoservHostError.__init__(self, |
| 236 | 'Not enough free space on %s - %.3fGB free, want %.3fGB' % |
| 237 | (path, free_space_gb, want_gb)) |
| 238 | |
| 239 | self.path = path |
| 240 | self.want_gb = want_gb |
| 241 | self.free_space_gb = free_space_gb |
| 242 | |
| 243 | |
| 244 | class AutoservHardwareHostError(AutoservHostError): |
| 245 | """Found hardware problems with the host""" |
| 246 | pass |
| 247 | |
| 248 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 249 | class AutoservRebootError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 250 | """Error occured while rebooting a machine""" |
| 251 | pass |
mbligh | 6e2ffec | 2008-03-05 16:08:34 +0000 | [diff] [blame] | 252 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 253 | |
jadmanski | 65eb8f5 | 2009-07-24 18:34:43 +0000 | [diff] [blame] | 254 | class AutoservShutdownError(AutoservRebootError): |
| 255 | """Error occured during shutdown of machine""" |
| 256 | pass |
| 257 | |
| 258 | |
mbligh | 6e2ffec | 2008-03-05 16:08:34 +0000 | [diff] [blame] | 259 | class AutoservSubcommandError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 260 | """Indicates an error while executing a (forked) subcommand""" |
| 261 | def __init__(self, func, exit_code): |
| 262 | AutoservError.__init__(self, func, exit_code) |
| 263 | self.func = func |
| 264 | self.exit_code = exit_code |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 265 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 266 | def __str__(self): |
| 267 | return ("Subcommand %s failed with exit code %d" % |
| 268 | (self.func, self.exit_code)) |
mbligh | 9167225 | 2008-10-16 22:28:34 +0000 | [diff] [blame] | 269 | |
| 270 | |
mbligh | 25c0b8c | 2009-01-24 01:44:17 +0000 | [diff] [blame] | 271 | class AutoservHardwareRepairRequestedError(AutoservError): |
| 272 | """ |
| 273 | Exception class raised from Host.repair_full() (or overrides) when software |
| 274 | repair fails but it successfully managed to request a hardware repair (by |
| 275 | notifying the staff, sending mail, etc) |
| 276 | """ |
| 277 | pass |
| 278 | |
| 279 | |
jadmanski | c1dda21 | 2009-11-18 19:22:00 +0000 | [diff] [blame^] | 280 | class AutoservInstallError(AutoservError): |
| 281 | """Error occured while installing autotest on a host""" |
| 282 | pass |
| 283 | |
| 284 | |
jadmanski | c27c231 | 2009-08-05 20:58:51 +0000 | [diff] [blame] | 285 | # packaging system errors |
| 286 | |
| 287 | class PackagingError(AutotestError): |
| 288 | 'Abstract error class for all packaging related errors.' |
| 289 | |
| 290 | |
| 291 | class PackageUploadError(PackagingError): |
| 292 | 'Raised when there is an error uploading the package' |
| 293 | |
| 294 | |
| 295 | class PackageFetchError(PackagingError): |
| 296 | 'Raised when there is an error fetching the package' |
| 297 | |
| 298 | |
| 299 | class PackageRemoveError(PackagingError): |
| 300 | 'Raised when there is an error removing the package' |
| 301 | |
| 302 | |
| 303 | class PackageInstallError(PackagingError): |
| 304 | 'Raised when there is an error installing the package' |
| 305 | |
| 306 | |
| 307 | class RepoDiskFullError(PackagingError): |
| 308 | 'Raised when the destination for packages is full' |
| 309 | |
| 310 | |
| 311 | class RepoWriteError(PackagingError): |
| 312 | "Raised when packager cannot write to a repo's desitnation" |
| 313 | |
| 314 | |
| 315 | class RepoUnknownError(PackagingError): |
| 316 | "Raised when packager cannot write to a repo's desitnation" |
| 317 | |
| 318 | |
| 319 | class RepoError(PackagingError): |
| 320 | "Raised when a repo isn't working in some way" |
| 321 | |
| 322 | |
mbligh | 9167225 | 2008-10-16 22:28:34 +0000 | [diff] [blame] | 323 | # This MUST remain at the end of the file. |
| 324 | # Limit 'from error import *' to only import the exception instances. |
| 325 | for _name, _thing in locals().items(): |
| 326 | try: |
| 327 | if issubclass(_thing, Exception): |
| 328 | __all__.append(_name) |
| 329 | except TypeError: |
| 330 | pass # _thing not a class |
| 331 | __all__ = tuple(__all__) |