Aviv Keshet | 39164ca | 2013-03-27 15:08:33 -0700 | [diff] [blame] | 1 | #pylint: disable-msg=C0111 |
| 2 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 3 | """ |
| 4 | Internal global error types |
| 5 | """ |
| 6 | |
Alex Miller | 3083790 | 2013-02-02 15:52:43 -0800 | [diff] [blame] | 7 | import sys, traceback, threading |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 8 | from traceback import format_exception |
| 9 | |
mbligh | 9167225 | 2008-10-16 22:28:34 +0000 | [diff] [blame] | 10 | # Add names you want to be imported by 'from errors import *' to this list. |
| 11 | # This must be list not a tuple as we modify it to include all of our |
| 12 | # the Exception classes we define below at the end of this file. |
Eric Li | 861b2d5 | 2011-02-04 14:50:35 -0800 | [diff] [blame] | 13 | __all__ = ['format_error', 'context_aware', 'context', 'get_context', |
| 14 | 'exception_context'] |
mbligh | 9167225 | 2008-10-16 22:28:34 +0000 | [diff] [blame] | 15 | |
| 16 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 17 | def format_error(): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 18 | t, o, tb = sys.exc_info() |
| 19 | trace = format_exception(t, o, tb) |
| 20 | # Clear the backtrace to prevent a circular reference |
| 21 | # in the heap -- as per tutorial |
| 22 | tb = '' |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 23 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 24 | return ''.join(trace) |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 25 | |
mbligh | 4f40746 | 2008-12-03 15:22:39 +0000 | [diff] [blame] | 26 | |
Eric Li | 861b2d5 | 2011-02-04 14:50:35 -0800 | [diff] [blame] | 27 | # Exception context information: |
| 28 | # ------------------------------ |
| 29 | # Every function can have some context string associated with it. |
| 30 | # The context string can be changed by calling context(str) and cleared by |
| 31 | # calling context() with no parameters. |
| 32 | # get_context() joins the current context strings of all functions in the |
| 33 | # provided traceback. The result is a brief description of what the test was |
| 34 | # doing in the provided traceback (which should be the traceback of a caught |
| 35 | # exception). |
| 36 | # |
| 37 | # For example: assume a() calls b() and b() calls c(). |
| 38 | # |
| 39 | # @error.context_aware |
| 40 | # def a(): |
| 41 | # error.context("hello") |
| 42 | # b() |
| 43 | # error.context("world") |
| 44 | # error.get_context() ----> 'world' |
| 45 | # |
| 46 | # @error.context_aware |
| 47 | # def b(): |
| 48 | # error.context("foo") |
| 49 | # c() |
| 50 | # |
| 51 | # @error.context_aware |
| 52 | # def c(): |
| 53 | # error.context("bar") |
| 54 | # error.get_context() ----> 'hello --> foo --> bar' |
| 55 | # |
| 56 | # The current context is automatically inserted into exceptions raised in |
| 57 | # context_aware functions, so usually test code doesn't need to call |
| 58 | # error.get_context(). |
| 59 | |
| 60 | ctx = threading.local() |
| 61 | |
| 62 | |
| 63 | def _new_context(s=""): |
| 64 | if not hasattr(ctx, "contexts"): |
| 65 | ctx.contexts = [] |
| 66 | ctx.contexts.append(s) |
| 67 | |
| 68 | |
| 69 | def _pop_context(): |
| 70 | ctx.contexts.pop() |
| 71 | |
| 72 | |
| 73 | def context(s="", log=None): |
| 74 | """ |
| 75 | Set the context for the currently executing function and optionally log it. |
| 76 | |
| 77 | @param s: A string. If not provided, the context for the current function |
| 78 | will be cleared. |
| 79 | @param log: A logging function to pass the context message to. If None, no |
| 80 | function will be called. |
| 81 | """ |
| 82 | ctx.contexts[-1] = s |
| 83 | if s and log: |
| 84 | log("Context: %s" % get_context()) |
| 85 | |
| 86 | |
| 87 | def base_context(s="", log=None): |
| 88 | """ |
| 89 | Set the base context for the currently executing function and optionally |
| 90 | log it. The base context is just another context level that is hidden by |
| 91 | default. Functions that require a single context level should not use |
| 92 | base_context(). |
| 93 | |
| 94 | @param s: A string. If not provided, the base context for the current |
| 95 | function will be cleared. |
| 96 | @param log: A logging function to pass the context message to. If None, no |
| 97 | function will be called. |
| 98 | """ |
| 99 | ctx.contexts[-1] = "" |
| 100 | ctx.contexts[-2] = s |
| 101 | if s and log: |
| 102 | log("Context: %s" % get_context()) |
| 103 | |
| 104 | |
| 105 | def get_context(): |
| 106 | """Return the current context (or None if none is defined).""" |
| 107 | if hasattr(ctx, "contexts"): |
| 108 | return " --> ".join([s for s in ctx.contexts if s]) |
| 109 | |
| 110 | |
| 111 | def exception_context(e): |
| 112 | """Return the context of a given exception (or None if none is defined).""" |
| 113 | if hasattr(e, "_context"): |
Alex Miller | 3083790 | 2013-02-02 15:52:43 -0800 | [diff] [blame] | 114 | return e._context # pylint: disable=W0212 |
Eric Li | 861b2d5 | 2011-02-04 14:50:35 -0800 | [diff] [blame] | 115 | |
| 116 | |
| 117 | def set_exception_context(e, s): |
| 118 | """Set the context of a given exception.""" |
| 119 | e._context = s |
| 120 | |
| 121 | |
| 122 | def join_contexts(s1, s2): |
| 123 | """Join two context strings.""" |
| 124 | if s1: |
| 125 | if s2: |
| 126 | return "%s --> %s" % (s1, s2) |
| 127 | else: |
| 128 | return s1 |
| 129 | else: |
| 130 | return s2 |
| 131 | |
| 132 | |
| 133 | def context_aware(fn): |
| 134 | """A decorator that must be applied to functions that call context().""" |
| 135 | def new_fn(*args, **kwargs): |
| 136 | _new_context() |
| 137 | _new_context("(%s)" % fn.__name__) |
| 138 | try: |
| 139 | try: |
| 140 | return fn(*args, **kwargs) |
| 141 | except Exception, e: |
| 142 | if not exception_context(e): |
| 143 | set_exception_context(e, get_context()) |
| 144 | raise |
| 145 | finally: |
| 146 | _pop_context() |
| 147 | _pop_context() |
| 148 | new_fn.__name__ = fn.__name__ |
| 149 | new_fn.__doc__ = fn.__doc__ |
| 150 | new_fn.__dict__.update(fn.__dict__) |
| 151 | return new_fn |
| 152 | |
| 153 | |
| 154 | def _context_message(e): |
| 155 | s = exception_context(e) |
| 156 | if s: |
| 157 | return " [context: %s]" % s |
| 158 | else: |
| 159 | return "" |
| 160 | |
| 161 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 162 | class JobContinue(SystemExit): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 163 | """Allow us to bail out requesting continuance.""" |
| 164 | pass |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 165 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 166 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 167 | class JobComplete(SystemExit): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 168 | """Allow us to bail out indicating continuation not required.""" |
| 169 | pass |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 170 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 171 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 172 | class AutotestError(Exception): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 173 | """The parent of all errors deliberatly thrown within the client code.""" |
Eric Li | 861b2d5 | 2011-02-04 14:50:35 -0800 | [diff] [blame] | 174 | def __str__(self): |
| 175 | return Exception.__str__(self) + _context_message(self) |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 176 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 177 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 178 | class JobError(AutotestError): |
mbligh | 4f40746 | 2008-12-03 15:22:39 +0000 | [diff] [blame] | 179 | """Indicates an error which terminates and fails the whole job (ABORT).""" |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 180 | pass |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 181 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 182 | |
mbligh | 4f40746 | 2008-12-03 15:22:39 +0000 | [diff] [blame] | 183 | class UnhandledJobError(JobError): |
| 184 | """Indicates an unhandled error in a job.""" |
| 185 | def __init__(self, unhandled_exception): |
| 186 | if isinstance(unhandled_exception, JobError): |
mbligh | 1ca1c2c | 2008-12-09 23:38:25 +0000 | [diff] [blame] | 187 | JobError.__init__(self, *unhandled_exception.args) |
Eric Li | 861b2d5 | 2011-02-04 14:50:35 -0800 | [diff] [blame] | 188 | elif isinstance(unhandled_exception, str): |
| 189 | JobError.__init__(self, unhandled_exception) |
mbligh | 4f40746 | 2008-12-03 15:22:39 +0000 | [diff] [blame] | 190 | else: |
| 191 | msg = "Unhandled %s: %s" |
| 192 | msg %= (unhandled_exception.__class__.__name__, |
| 193 | unhandled_exception) |
Eric Li | 861b2d5 | 2011-02-04 14:50:35 -0800 | [diff] [blame] | 194 | if not isinstance(unhandled_exception, AutotestError): |
| 195 | msg += _context_message(unhandled_exception) |
mbligh | 4f40746 | 2008-12-03 15:22:39 +0000 | [diff] [blame] | 196 | msg += "\n" + traceback.format_exc() |
| 197 | JobError.__init__(self, msg) |
| 198 | |
| 199 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 200 | class TestBaseException(AutotestError): |
| 201 | """The parent of all test exceptions.""" |
mbligh | 021679f | 2008-11-27 00:43:19 +0000 | [diff] [blame] | 202 | # Children are required to override this. Never instantiate directly. |
Alex Miller | 3083790 | 2013-02-02 15:52:43 -0800 | [diff] [blame] | 203 | exit_status = "NEVER_RAISE_THIS" |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 204 | |
| 205 | |
| 206 | class TestError(TestBaseException): |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 207 | """Indicates that something went wrong with the test harness itself.""" |
Alex Miller | 3083790 | 2013-02-02 15:52:43 -0800 | [diff] [blame] | 208 | exit_status = "ERROR" |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 209 | |
jadmanski | 8d01bfe | 2008-06-23 18:13:24 +0000 | [diff] [blame] | 210 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 211 | class TestNAError(TestBaseException): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 212 | """Indictates that the test is Not Applicable. Should be thrown |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 213 | when various conditions are such that the test is inappropriate.""" |
Alex Miller | 3083790 | 2013-02-02 15:52:43 -0800 | [diff] [blame] | 214 | exit_status = "TEST_NA" |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 215 | |
jadmanski | 8d01bfe | 2008-06-23 18:13:24 +0000 | [diff] [blame] | 216 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 217 | class TestFail(TestBaseException): |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 218 | """Indicates that the test failed, but the job will not continue.""" |
Alex Miller | 3083790 | 2013-02-02 15:52:43 -0800 | [diff] [blame] | 219 | exit_status = "FAIL" |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 220 | |
jadmanski | 8d01bfe | 2008-06-23 18:13:24 +0000 | [diff] [blame] | 221 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 222 | class TestWarn(TestBaseException): |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 223 | """Indicates that bad things (may) have happened, but not an explicit |
| 224 | failure.""" |
Alex Miller | 3083790 | 2013-02-02 15:52:43 -0800 | [diff] [blame] | 225 | exit_status = "WARN" |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame] | 226 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 227 | |
Aviv Keshet | 39164ca | 2013-03-27 15:08:33 -0700 | [diff] [blame] | 228 | class TestFailRetry(TestFail): |
| 229 | """Indicates that the test failed, but in a manner that may be retried |
| 230 | if test retries are enabled for this test.""" |
| 231 | exit_status = "FAIL" |
| 232 | |
| 233 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 234 | class UnhandledTestError(TestError): |
| 235 | """Indicates an unhandled error in a test.""" |
| 236 | def __init__(self, unhandled_exception): |
| 237 | if isinstance(unhandled_exception, TestError): |
| 238 | TestError.__init__(self, *unhandled_exception.args) |
Eric Li | 861b2d5 | 2011-02-04 14:50:35 -0800 | [diff] [blame] | 239 | elif isinstance(unhandled_exception, str): |
| 240 | TestError.__init__(self, unhandled_exception) |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 241 | else: |
| 242 | msg = "Unhandled %s: %s" |
| 243 | msg %= (unhandled_exception.__class__.__name__, |
| 244 | unhandled_exception) |
Eric Li | 861b2d5 | 2011-02-04 14:50:35 -0800 | [diff] [blame] | 245 | if not isinstance(unhandled_exception, AutotestError): |
| 246 | msg += _context_message(unhandled_exception) |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 247 | msg += "\n" + traceback.format_exc() |
| 248 | TestError.__init__(self, msg) |
| 249 | |
| 250 | |
| 251 | class UnhandledTestFail(TestFail): |
| 252 | """Indicates an unhandled fail in a test.""" |
| 253 | def __init__(self, unhandled_exception): |
| 254 | if isinstance(unhandled_exception, TestFail): |
| 255 | TestFail.__init__(self, *unhandled_exception.args) |
Eric Li | 861b2d5 | 2011-02-04 14:50:35 -0800 | [diff] [blame] | 256 | elif isinstance(unhandled_exception, str): |
| 257 | TestFail.__init__(self, unhandled_exception) |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 258 | else: |
| 259 | msg = "Unhandled %s: %s" |
| 260 | msg %= (unhandled_exception.__class__.__name__, |
| 261 | unhandled_exception) |
Eric Li | 861b2d5 | 2011-02-04 14:50:35 -0800 | [diff] [blame] | 262 | if not isinstance(unhandled_exception, AutotestError): |
| 263 | msg += _context_message(unhandled_exception) |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 264 | msg += "\n" + traceback.format_exc() |
| 265 | TestFail.__init__(self, msg) |
| 266 | |
| 267 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 268 | class CmdError(TestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 269 | """\ |
| 270 | Indicates that a command failed, is fatal to the test unless caught. |
| 271 | """ |
| 272 | def __init__(self, command, result_obj, additional_text=None): |
| 273 | TestError.__init__(self, command, result_obj, additional_text) |
mbligh | c23051c | 2008-06-27 19:26:46 +0000 | [diff] [blame] | 274 | self.command = command |
| 275 | self.result_obj = result_obj |
| 276 | self.additional_text = additional_text |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame] | 277 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 278 | def __str__(self): |
jadmanski | 6ef0b67 | 2008-09-30 22:50:19 +0000 | [diff] [blame] | 279 | if self.result_obj.exit_status is None: |
| 280 | msg = "Command <%s> failed and is not responding to signals" |
| 281 | msg %= self.command |
| 282 | else: |
| 283 | msg = "Command <%s> failed, rc=%d" |
| 284 | msg %= (self.command, self.result_obj.exit_status) |
| 285 | |
mbligh | c23051c | 2008-06-27 19:26:46 +0000 | [diff] [blame] | 286 | if self.additional_text: |
| 287 | msg += ", " + self.additional_text |
Eric Li | 861b2d5 | 2011-02-04 14:50:35 -0800 | [diff] [blame] | 288 | msg += _context_message(self) |
showard | 6d7e94f | 2008-08-20 20:53:34 +0000 | [diff] [blame] | 289 | msg += '\n' + repr(self.result_obj) |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 290 | return msg |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 291 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 292 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 293 | class PackageError(TestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 294 | """Indicates an error trying to perform a package operation.""" |
| 295 | pass |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 296 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 297 | |
mbligh | e867310 | 2008-07-16 14:09:03 +0000 | [diff] [blame] | 298 | class BarrierError(JobError): |
| 299 | """Indicates an error happened during a barrier operation.""" |
| 300 | pass |
| 301 | |
| 302 | |
mbligh | 999fb13 | 2010-04-23 17:22:03 +0000 | [diff] [blame] | 303 | class BarrierAbortError(BarrierError): |
| 304 | """Indicate that the barrier was explicitly aborted by a member.""" |
| 305 | pass |
| 306 | |
| 307 | |
mbligh | 5deff3d | 2008-01-04 21:21:28 +0000 | [diff] [blame] | 308 | class InstallError(JobError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 309 | """Indicates an installation error which Terminates and fails the job.""" |
| 310 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 311 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 312 | |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 313 | class AutotestRunError(AutotestError): |
mbligh | 021679f | 2008-11-27 00:43:19 +0000 | [diff] [blame] | 314 | """Indicates a problem running server side control files.""" |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 315 | pass |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 316 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 317 | |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 318 | class AutotestTimeoutError(AutotestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 319 | """This exception is raised when an autotest test exceeds the timeout |
| 320 | parameter passed to run_timed_test and is killed. |
| 321 | """ |
Dale Curtis | 8adf789 | 2011-09-08 16:13:36 -0700 | [diff] [blame] | 322 | pass |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 323 | |
| 324 | |
mbligh | ce955fc | 2009-08-24 21:59:02 +0000 | [diff] [blame] | 325 | class HostRunErrorMixIn(Exception): |
| 326 | """ |
| 327 | Indicates a problem in the host run() function raised from client code. |
| 328 | Should always be constructed with a tuple of two args (error description |
| 329 | (str), run result object). This is a common class mixed in to create the |
| 330 | client and server side versions of it. |
| 331 | """ |
| 332 | def __init__(self, description, result_obj): |
| 333 | self.description = description |
| 334 | self.result_obj = result_obj |
| 335 | Exception.__init__(self, description, result_obj) |
| 336 | |
| 337 | def __str__(self): |
| 338 | return self.description + '\n' + repr(self.result_obj) |
| 339 | |
| 340 | |
Dale Curtis | 8adf789 | 2011-09-08 16:13:36 -0700 | [diff] [blame] | 341 | class HostInstallTimeoutError(JobError): |
| 342 | """ |
| 343 | Indicates the machine failed to be installed after the predetermined |
| 344 | timeout. |
| 345 | """ |
| 346 | pass |
| 347 | |
| 348 | |
mbligh | ce955fc | 2009-08-24 21:59:02 +0000 | [diff] [blame] | 349 | class AutotestHostRunError(HostRunErrorMixIn, AutotestError): |
| 350 | pass |
| 351 | |
| 352 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 353 | # server-specific errors |
| 354 | |
| 355 | class AutoservError(Exception): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 356 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 357 | |
| 358 | |
mbligh | 34faa28 | 2008-01-16 17:44:49 +0000 | [diff] [blame] | 359 | class AutoservSSHTimeout(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 360 | """SSH experienced a connection timeout""" |
| 361 | pass |
mbligh | 34faa28 | 2008-01-16 17:44:49 +0000 | [diff] [blame] | 362 | |
| 363 | |
mbligh | ce955fc | 2009-08-24 21:59:02 +0000 | [diff] [blame] | 364 | class AutoservRunError(HostRunErrorMixIn, AutoservError): |
| 365 | pass |
showard | 6d7e94f | 2008-08-20 20:53:34 +0000 | [diff] [blame] | 366 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 367 | |
mbligh | 9d738d6 | 2009-03-09 21:17:10 +0000 | [diff] [blame] | 368 | class AutoservSshPermissionDeniedError(AutoservRunError): |
| 369 | """Indicates that a SSH permission denied error was encountered.""" |
| 370 | pass |
| 371 | |
| 372 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 373 | class AutoservVirtError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 374 | """Vitualization related error""" |
| 375 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 376 | |
| 377 | |
| 378 | class AutoservUnsupportedError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 379 | """Error raised when you try to use an unsupported optional feature""" |
| 380 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 381 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 382 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 383 | class AutoservHostError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 384 | """Error reaching a host""" |
| 385 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 386 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 387 | |
mbligh | c971c5f | 2009-06-08 16:48:54 +0000 | [diff] [blame] | 388 | class AutoservHostIsShuttingDownError(AutoservHostError): |
| 389 | """Host is shutting down""" |
| 390 | pass |
| 391 | |
| 392 | |
| 393 | class AutoservNotMountedHostError(AutoservHostError): |
| 394 | """Found unmounted partitions that should be mounted""" |
| 395 | pass |
| 396 | |
| 397 | |
| 398 | class AutoservSshPingHostError(AutoservHostError): |
| 399 | """SSH ping failed""" |
| 400 | pass |
| 401 | |
| 402 | |
| 403 | class AutoservDiskFullHostError(AutoservHostError): |
| 404 | """Not enough free disk space on host""" |
| 405 | def __init__(self, path, want_gb, free_space_gb): |
| 406 | AutoservHostError.__init__(self, |
| 407 | 'Not enough free space on %s - %.3fGB free, want %.3fGB' % |
| 408 | (path, free_space_gb, want_gb)) |
| 409 | |
| 410 | self.path = path |
| 411 | self.want_gb = want_gb |
| 412 | self.free_space_gb = free_space_gb |
| 413 | |
| 414 | |
| 415 | class AutoservHardwareHostError(AutoservHostError): |
| 416 | """Found hardware problems with the host""" |
| 417 | pass |
| 418 | |
| 419 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 420 | class AutoservRebootError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 421 | """Error occured while rebooting a machine""" |
| 422 | pass |
mbligh | 6e2ffec | 2008-03-05 16:08:34 +0000 | [diff] [blame] | 423 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 424 | |
jadmanski | 65eb8f5 | 2009-07-24 18:34:43 +0000 | [diff] [blame] | 425 | class AutoservShutdownError(AutoservRebootError): |
| 426 | """Error occured during shutdown of machine""" |
| 427 | pass |
| 428 | |
| 429 | |
mbligh | 6e2ffec | 2008-03-05 16:08:34 +0000 | [diff] [blame] | 430 | class AutoservSubcommandError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 431 | """Indicates an error while executing a (forked) subcommand""" |
| 432 | def __init__(self, func, exit_code): |
| 433 | AutoservError.__init__(self, func, exit_code) |
| 434 | self.func = func |
| 435 | self.exit_code = exit_code |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 436 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 437 | def __str__(self): |
| 438 | return ("Subcommand %s failed with exit code %d" % |
| 439 | (self.func, self.exit_code)) |
mbligh | 9167225 | 2008-10-16 22:28:34 +0000 | [diff] [blame] | 440 | |
| 441 | |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 442 | class AutoservRepairTotalFailure(AutoservError): |
| 443 | """Raised if all attempts to repair the DUT failed.""" |
| 444 | pass |
| 445 | |
| 446 | |
| 447 | class AutoservRepairFailure(AutoservError): |
| 448 | """Raised by a repair method if it is unable to repair a DUT.""" |
| 449 | pass |
| 450 | |
| 451 | |
| 452 | class AutoservRepairMethodNA(AutoservError): |
| 453 | """Raised when for any reason a praticular repair method is NA.""" |
| 454 | pass |
| 455 | |
| 456 | |
mbligh | 25c0b8c | 2009-01-24 01:44:17 +0000 | [diff] [blame] | 457 | class AutoservHardwareRepairRequestedError(AutoservError): |
| 458 | """ |
| 459 | Exception class raised from Host.repair_full() (or overrides) when software |
| 460 | repair fails but it successfully managed to request a hardware repair (by |
| 461 | notifying the staff, sending mail, etc) |
| 462 | """ |
| 463 | pass |
| 464 | |
| 465 | |
jadmanski | 2615f4a | 2010-07-19 16:39:56 +0000 | [diff] [blame] | 466 | class AutoservHardwareRepairRequiredError(AutoservError): |
| 467 | """ |
| 468 | Exception class raised during repairs to indicate that a hardware repair |
| 469 | is going to be necessary. |
| 470 | """ |
| 471 | pass |
| 472 | |
| 473 | |
jadmanski | c1dda21 | 2009-11-18 19:22:00 +0000 | [diff] [blame] | 474 | class AutoservInstallError(AutoservError): |
| 475 | """Error occured while installing autotest on a host""" |
| 476 | pass |
| 477 | |
| 478 | |
Simran Basi | 31cf2bd | 2012-08-14 16:51:54 -0700 | [diff] [blame] | 479 | class AutoservPidAlreadyDeadError(AutoservError): |
| 480 | """Error occured by trying to kill a nonexistant PID""" |
| 481 | pass |
| 482 | |
| 483 | |
jadmanski | c27c231 | 2009-08-05 20:58:51 +0000 | [diff] [blame] | 484 | # packaging system errors |
| 485 | |
| 486 | class PackagingError(AutotestError): |
| 487 | 'Abstract error class for all packaging related errors.' |
| 488 | |
| 489 | |
| 490 | class PackageUploadError(PackagingError): |
| 491 | 'Raised when there is an error uploading the package' |
| 492 | |
| 493 | |
| 494 | class PackageFetchError(PackagingError): |
| 495 | 'Raised when there is an error fetching the package' |
| 496 | |
| 497 | |
| 498 | class PackageRemoveError(PackagingError): |
| 499 | 'Raised when there is an error removing the package' |
| 500 | |
| 501 | |
| 502 | class PackageInstallError(PackagingError): |
| 503 | 'Raised when there is an error installing the package' |
| 504 | |
| 505 | |
| 506 | class RepoDiskFullError(PackagingError): |
| 507 | 'Raised when the destination for packages is full' |
| 508 | |
| 509 | |
| 510 | class RepoWriteError(PackagingError): |
| 511 | "Raised when packager cannot write to a repo's desitnation" |
| 512 | |
| 513 | |
| 514 | class RepoUnknownError(PackagingError): |
| 515 | "Raised when packager cannot write to a repo's desitnation" |
| 516 | |
| 517 | |
| 518 | class RepoError(PackagingError): |
| 519 | "Raised when a repo isn't working in some way" |
| 520 | |
| 521 | |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 522 | class CrosDynamicSuiteException(Exception): |
| 523 | """ |
Chris Masone | b493555 | 2012-08-14 12:05:54 -0700 | [diff] [blame] | 524 | Base class for exceptions coming from dynamic suite code in |
| 525 | server/cros/dynamic_suite/*. |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 526 | """ |
| 527 | pass |
| 528 | |
| 529 | |
| 530 | class StageBuildFailure(CrosDynamicSuiteException): |
| 531 | """Raised when the dev server throws 500 while staging a build.""" |
| 532 | pass |
| 533 | |
| 534 | |
| 535 | class ControlFileEmpty(CrosDynamicSuiteException): |
| 536 | """Raised when the control file exists on the server, but can't be read.""" |
| 537 | pass |
| 538 | |
| 539 | |
Alex Miller | a713e25 | 2013-03-01 10:45:44 -0800 | [diff] [blame] | 540 | class ControlFileMalformed(CrosDynamicSuiteException): |
| 541 | """Raised when an invalid control file is read.""" |
| 542 | pass |
| 543 | |
| 544 | |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 545 | class AsynchronousBuildFailure(CrosDynamicSuiteException): |
| 546 | """Raised when the dev server throws 500 while finishing staging of a build. |
| 547 | """ |
| 548 | pass |
| 549 | |
| 550 | |
| 551 | class SuiteArgumentException(CrosDynamicSuiteException): |
| 552 | """Raised when improper arguments are used to run a suite.""" |
| 553 | pass |
| 554 | |
| 555 | |
Chris Masone | 8906ab1 | 2012-07-23 15:37:56 -0700 | [diff] [blame] | 556 | class MalformedDependenciesException(CrosDynamicSuiteException): |
| 557 | """Raised when a build has a malformed dependency_info file.""" |
| 558 | pass |
| 559 | |
| 560 | |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 561 | class InadequateHostsException(CrosDynamicSuiteException): |
| 562 | """Raised when there are too few hosts to run a suite.""" |
| 563 | pass |
| 564 | |
| 565 | |
| 566 | class NoHostsException(CrosDynamicSuiteException): |
| 567 | """Raised when there are no healthy hosts to run a suite.""" |
| 568 | pass |
| 569 | |
| 570 | |
| 571 | class ControlFileNotFound(CrosDynamicSuiteException): |
| 572 | """Raised when a control file cannot be found and/or read.""" |
| 573 | pass |
| 574 | |
| 575 | |
| 576 | class NoControlFileList(CrosDynamicSuiteException): |
Chris Masone | 9807bd6 | 2012-07-11 14:44:17 -0700 | [diff] [blame] | 577 | """Raised to indicate that a listing can't be done.""" |
| 578 | pass |
| 579 | |
| 580 | |
| 581 | class HostLockManagerReuse(CrosDynamicSuiteException): |
| 582 | """Raised when a caller tries to re-use a HostLockManager instance.""" |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 583 | pass |
| 584 | |
| 585 | |
Simran Basi | 94d9bd0 | 2012-11-12 15:13:59 -0800 | [diff] [blame] | 586 | class ReimageAbortedException(CrosDynamicSuiteException): |
| 587 | """Raised when a Reimage job is aborted""" |
| 588 | pass |
| 589 | |
| 590 | |
Alex Miller | 3083790 | 2013-02-02 15:52:43 -0800 | [diff] [blame] | 591 | class UnknownReimageType(CrosDynamicSuiteException): |
| 592 | """Raised when a suite passes in an invalid reimage type""" |
| 593 | pass |
| 594 | |
| 595 | |
Simran Basi | 22aa9fe | 2012-12-07 16:37:09 -0800 | [diff] [blame] | 596 | class LabIsDownException(Exception): |
| 597 | """Raised when the Lab is Down""" |
| 598 | pass |
| 599 | |
| 600 | |
Simran Basi | 41bfae4 | 2013-01-09 10:50:47 -0800 | [diff] [blame] | 601 | class BoardIsDisabledException(Exception): |
| 602 | """Raised when a certain board is disabled in the Lab""" |
| 603 | pass |
| 604 | |
| 605 | |
Alex Miller | 24c27c1 | 2012-08-09 10:24:24 -0700 | [diff] [blame] | 606 | class NoUniquePackageFound(Exception): |
| 607 | """Raised when an executable cannot be mapped back to a single package.""" |
| 608 | pass |
| 609 | |
| 610 | |
mbligh | 9167225 | 2008-10-16 22:28:34 +0000 | [diff] [blame] | 611 | # This MUST remain at the end of the file. |
| 612 | # Limit 'from error import *' to only import the exception instances. |
| 613 | for _name, _thing in locals().items(): |
| 614 | try: |
| 615 | if issubclass(_thing, Exception): |
| 616 | __all__.append(_name) |
| 617 | except TypeError: |
| 618 | pass # _thing not a class |
| 619 | __all__ = tuple(__all__) |