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 JobNAError(JobError): |
| 45 | """Indicates an error to skip this part of the whole job or fail it if |
| 46 | this was not a multi-step job.""" |
| 47 | pass |
| 48 | |
| 49 | |
| 50 | class UnhandledJobError(JobError): |
| 51 | """Indicates an unhandled error in a job.""" |
| 52 | def __init__(self, unhandled_exception): |
| 53 | if isinstance(unhandled_exception, JobError): |
| 54 | TestError.__init__(self, *unhandled_exception.args) |
| 55 | else: |
| 56 | msg = "Unhandled %s: %s" |
| 57 | msg %= (unhandled_exception.__class__.__name__, |
| 58 | unhandled_exception) |
| 59 | msg += "\n" + traceback.format_exc() |
| 60 | JobError.__init__(self, msg) |
| 61 | |
| 62 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 63 | class TestBaseException(AutotestError): |
| 64 | """The parent of all test exceptions.""" |
mbligh | 021679f | 2008-11-27 00:43:19 +0000 | [diff] [blame] | 65 | # Children are required to override this. Never instantiate directly. |
| 66 | exit_status="NEVER_RAISE_THIS" |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 67 | |
| 68 | |
| 69 | class TestError(TestBaseException): |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 70 | """Indicates that something went wrong with the test harness itself.""" |
| 71 | exit_status="ERROR" |
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 TestNAError(TestBaseException): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 75 | """Indictates that the test is Not Applicable. Should be thrown |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 76 | when various conditions are such that the test is inappropriate.""" |
| 77 | exit_status="TEST_NA" |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 78 | |
jadmanski | 8d01bfe | 2008-06-23 18:13:24 +0000 | [diff] [blame] | 79 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 80 | class TestFail(TestBaseException): |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 81 | """Indicates that the test failed, but the job will not continue.""" |
| 82 | exit_status="FAIL" |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 83 | |
jadmanski | 8d01bfe | 2008-06-23 18:13:24 +0000 | [diff] [blame] | 84 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 85 | class TestWarn(TestBaseException): |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 86 | """Indicates that bad things (may) have happened, but not an explicit |
| 87 | failure.""" |
| 88 | exit_status="WARN" |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame] | 89 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 90 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 91 | class UnhandledTestError(TestError): |
| 92 | """Indicates an unhandled error in a test.""" |
| 93 | def __init__(self, unhandled_exception): |
| 94 | if isinstance(unhandled_exception, TestError): |
| 95 | TestError.__init__(self, *unhandled_exception.args) |
| 96 | else: |
| 97 | msg = "Unhandled %s: %s" |
| 98 | msg %= (unhandled_exception.__class__.__name__, |
| 99 | unhandled_exception) |
| 100 | msg += "\n" + traceback.format_exc() |
| 101 | TestError.__init__(self, msg) |
| 102 | |
| 103 | |
| 104 | class UnhandledTestFail(TestFail): |
| 105 | """Indicates an unhandled fail in a test.""" |
| 106 | def __init__(self, unhandled_exception): |
| 107 | if isinstance(unhandled_exception, TestFail): |
| 108 | TestFail.__init__(self, *unhandled_exception.args) |
| 109 | else: |
| 110 | msg = "Unhandled %s: %s" |
| 111 | msg %= (unhandled_exception.__class__.__name__, |
| 112 | unhandled_exception) |
| 113 | msg += "\n" + traceback.format_exc() |
| 114 | TestFail.__init__(self, msg) |
| 115 | |
| 116 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 117 | class CmdError(TestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 118 | """\ |
| 119 | Indicates that a command failed, is fatal to the test unless caught. |
| 120 | """ |
| 121 | def __init__(self, command, result_obj, additional_text=None): |
| 122 | TestError.__init__(self, command, result_obj, additional_text) |
mbligh | c23051c | 2008-06-27 19:26:46 +0000 | [diff] [blame] | 123 | self.command = command |
| 124 | self.result_obj = result_obj |
| 125 | self.additional_text = additional_text |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame] | 126 | |
| 127 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 128 | def __str__(self): |
jadmanski | 6ef0b67 | 2008-09-30 22:50:19 +0000 | [diff] [blame] | 129 | if self.result_obj.exit_status is None: |
| 130 | msg = "Command <%s> failed and is not responding to signals" |
| 131 | msg %= self.command |
| 132 | else: |
| 133 | msg = "Command <%s> failed, rc=%d" |
| 134 | msg %= (self.command, self.result_obj.exit_status) |
| 135 | |
mbligh | c23051c | 2008-06-27 19:26:46 +0000 | [diff] [blame] | 136 | if self.additional_text: |
| 137 | msg += ", " + self.additional_text |
showard | 6d7e94f | 2008-08-20 20:53:34 +0000 | [diff] [blame] | 138 | msg += '\n' + repr(self.result_obj) |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 139 | return msg |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 140 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 141 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 142 | class PackageError(TestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 143 | """Indicates an error trying to perform a package operation.""" |
| 144 | pass |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 145 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 146 | |
mbligh | e867310 | 2008-07-16 14:09:03 +0000 | [diff] [blame] | 147 | class BarrierError(JobError): |
| 148 | """Indicates an error happened during a barrier operation.""" |
| 149 | pass |
| 150 | |
| 151 | |
mbligh | 5deff3d | 2008-01-04 21:21:28 +0000 | [diff] [blame] | 152 | class InstallError(JobError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 153 | """Indicates an installation error which Terminates and fails the job.""" |
| 154 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 155 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 156 | |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 157 | class AutotestRunError(AutotestError): |
mbligh | 021679f | 2008-11-27 00:43:19 +0000 | [diff] [blame] | 158 | """Indicates a problem running server side control files.""" |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 159 | pass |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 160 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 161 | |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 162 | class AutotestTimeoutError(AutotestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 163 | """This exception is raised when an autotest test exceeds the timeout |
| 164 | parameter passed to run_timed_test and is killed. |
| 165 | """ |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 166 | |
| 167 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 168 | # server-specific errors |
| 169 | |
| 170 | class AutoservError(Exception): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 171 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 172 | |
| 173 | |
mbligh | 34faa28 | 2008-01-16 17:44:49 +0000 | [diff] [blame] | 174 | class AutoservSSHTimeout(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 175 | """SSH experienced a connection timeout""" |
| 176 | pass |
mbligh | 34faa28 | 2008-01-16 17:44:49 +0000 | [diff] [blame] | 177 | |
| 178 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 179 | class AutoservRunError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 180 | """\ |
| 181 | Errors raised by one of the run functions. Should always be |
| 182 | constructed with a tuple of two args (error description (str), |
| 183 | run result object). |
| 184 | """ |
| 185 | def __init__(self, description, result_obj): |
showard | 6d7e94f | 2008-08-20 20:53:34 +0000 | [diff] [blame] | 186 | self.description = description |
| 187 | self.result_obj = result_obj |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 188 | AutoservError.__init__(self, description, result_obj) |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 189 | |
showard | 6d7e94f | 2008-08-20 20:53:34 +0000 | [diff] [blame] | 190 | def __str__(self): |
| 191 | return self.description + '\n' + repr(self.result_obj) |
| 192 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 193 | |
| 194 | class AutoservVirtError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 195 | """Vitualization related error""" |
| 196 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 197 | |
| 198 | |
| 199 | class AutoservUnsupportedError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 200 | """Error raised when you try to use an unsupported optional feature""" |
| 201 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 202 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 203 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 204 | class AutoservHostError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 205 | """Error reaching a host""" |
| 206 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 207 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 208 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 209 | class AutoservRebootError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 210 | """Error occured while rebooting a machine""" |
| 211 | pass |
mbligh | 6e2ffec | 2008-03-05 16:08:34 +0000 | [diff] [blame] | 212 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 213 | |
mbligh | 6e2ffec | 2008-03-05 16:08:34 +0000 | [diff] [blame] | 214 | class AutoservSubcommandError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 215 | """Indicates an error while executing a (forked) subcommand""" |
| 216 | def __init__(self, func, exit_code): |
| 217 | AutoservError.__init__(self, func, exit_code) |
| 218 | self.func = func |
| 219 | self.exit_code = exit_code |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 220 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 221 | def __str__(self): |
| 222 | return ("Subcommand %s failed with exit code %d" % |
| 223 | (self.func, self.exit_code)) |
mbligh | 9167225 | 2008-10-16 22:28:34 +0000 | [diff] [blame] | 224 | |
| 225 | |
| 226 | # This MUST remain at the end of the file. |
| 227 | # Limit 'from error import *' to only import the exception instances. |
| 228 | for _name, _thing in locals().items(): |
| 229 | try: |
| 230 | if issubclass(_thing, Exception): |
| 231 | __all__.append(_name) |
| 232 | except TypeError: |
| 233 | pass # _thing not a class |
| 234 | __all__ = tuple(__all__) |