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