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 | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 162 | # server-specific errors |
| 163 | |
| 164 | class AutoservError(Exception): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 165 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 166 | |
| 167 | |
mbligh | 34faa28 | 2008-01-16 17:44:49 +0000 | [diff] [blame] | 168 | class AutoservSSHTimeout(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 169 | """SSH experienced a connection timeout""" |
| 170 | pass |
mbligh | 34faa28 | 2008-01-16 17:44:49 +0000 | [diff] [blame] | 171 | |
| 172 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 173 | class AutoservRunError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 174 | """\ |
| 175 | Errors raised by one of the run functions. Should always be |
| 176 | constructed with a tuple of two args (error description (str), |
| 177 | run result object). |
| 178 | """ |
| 179 | def __init__(self, description, result_obj): |
showard | 6d7e94f | 2008-08-20 20:53:34 +0000 | [diff] [blame] | 180 | self.description = description |
| 181 | self.result_obj = result_obj |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 182 | AutoservError.__init__(self, description, result_obj) |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 183 | |
showard | 6d7e94f | 2008-08-20 20:53:34 +0000 | [diff] [blame] | 184 | def __str__(self): |
| 185 | return self.description + '\n' + repr(self.result_obj) |
| 186 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 187 | |
| 188 | class AutoservVirtError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 189 | """Vitualization related error""" |
| 190 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 191 | |
| 192 | |
| 193 | class AutoservUnsupportedError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 194 | """Error raised when you try to use an unsupported optional feature""" |
| 195 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 196 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 197 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 198 | class AutoservHostError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 199 | """Error reaching a host""" |
| 200 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 201 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 202 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 203 | class AutoservRebootError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 204 | """Error occured while rebooting a machine""" |
| 205 | pass |
mbligh | 6e2ffec | 2008-03-05 16:08:34 +0000 | [diff] [blame] | 206 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 207 | |
mbligh | 6e2ffec | 2008-03-05 16:08:34 +0000 | [diff] [blame] | 208 | class AutoservSubcommandError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 209 | """Indicates an error while executing a (forked) subcommand""" |
| 210 | def __init__(self, func, exit_code): |
| 211 | AutoservError.__init__(self, func, exit_code) |
| 212 | self.func = func |
| 213 | self.exit_code = exit_code |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 214 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 215 | def __str__(self): |
| 216 | return ("Subcommand %s failed with exit code %d" % |
| 217 | (self.func, self.exit_code)) |
mbligh | 9167225 | 2008-10-16 22:28:34 +0000 | [diff] [blame] | 218 | |
| 219 | |
mbligh | 25c0b8c | 2009-01-24 01:44:17 +0000 | [diff] [blame] | 220 | class AutoservHardwareRepairRequestedError(AutoservError): |
| 221 | """ |
| 222 | Exception class raised from Host.repair_full() (or overrides) when software |
| 223 | repair fails but it successfully managed to request a hardware repair (by |
| 224 | notifying the staff, sending mail, etc) |
| 225 | """ |
| 226 | pass |
| 227 | |
| 228 | |
mbligh | 9167225 | 2008-10-16 22:28:34 +0000 | [diff] [blame] | 229 | # This MUST remain at the end of the file. |
| 230 | # Limit 'from error import *' to only import the exception instances. |
| 231 | for _name, _thing in locals().items(): |
| 232 | try: |
| 233 | if issubclass(_thing, Exception): |
| 234 | __all__.append(_name) |
| 235 | except TypeError: |
| 236 | pass # _thing not a class |
| 237 | __all__ = tuple(__all__) |