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 | |
Richard Barnette | c32ef4d | 2016-04-21 12:31:05 -0700 | [diff] [blame] | 7 | import sys, traceback |
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. |
Richard Barnette | c32ef4d | 2016-04-21 12:31:05 -0700 | [diff] [blame] | 13 | __all__ = ['format_error'] |
mbligh | 9167225 | 2008-10-16 22:28:34 +0000 | [diff] [blame] | 14 | |
| 15 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 16 | def format_error(): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 17 | t, o, tb = sys.exc_info() |
| 18 | trace = format_exception(t, o, tb) |
| 19 | # Clear the backtrace to prevent a circular reference |
| 20 | # in the heap -- as per tutorial |
| 21 | tb = '' |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 22 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 23 | return ''.join(trace) |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 24 | |
mbligh | 4f40746 | 2008-12-03 15:22:39 +0000 | [diff] [blame] | 25 | |
beeps | 60aec24 | 2013-06-26 14:47:48 -0700 | [diff] [blame] | 26 | class TimeoutException(Exception): |
Aviv Keshet | 6dec0e1 | 2017-04-17 15:23:33 -0700 | [diff] [blame] | 27 | """Generic exception raised on retry timeouts.""" |
beeps | 60aec24 | 2013-06-26 14:47:48 -0700 | [diff] [blame] | 28 | |
| 29 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 30 | class JobContinue(SystemExit): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 31 | """Allow us to bail out requesting continuance.""" |
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 JobComplete(SystemExit): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 35 | """Allow us to bail out indicating continuation not required.""" |
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 AutotestError(Exception): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 39 | """The parent of all errors deliberatly thrown within the client code.""" |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 40 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 41 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 42 | class JobError(AutotestError): |
mbligh | 4f40746 | 2008-12-03 15:22:39 +0000 | [diff] [blame] | 43 | """Indicates an error which terminates and fails the whole job (ABORT).""" |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 44 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 45 | |
mbligh | 4f40746 | 2008-12-03 15:22:39 +0000 | [diff] [blame] | 46 | class UnhandledJobError(JobError): |
| 47 | """Indicates an unhandled error in a job.""" |
| 48 | def __init__(self, unhandled_exception): |
| 49 | if isinstance(unhandled_exception, JobError): |
mbligh | 1ca1c2c | 2008-12-09 23:38:25 +0000 | [diff] [blame] | 50 | JobError.__init__(self, *unhandled_exception.args) |
Luis Hector Chavez | 9c4a433 | 2017-03-30 13:12:28 -0700 | [diff] [blame] | 51 | elif isinstance(unhandled_exception, basestring): |
Eric Li | 861b2d5 | 2011-02-04 14:50:35 -0800 | [diff] [blame] | 52 | JobError.__init__(self, unhandled_exception) |
mbligh | 4f40746 | 2008-12-03 15:22:39 +0000 | [diff] [blame] | 53 | else: |
| 54 | msg = "Unhandled %s: %s" |
| 55 | msg %= (unhandled_exception.__class__.__name__, |
| 56 | unhandled_exception) |
mbligh | 4f40746 | 2008-12-03 15:22:39 +0000 | [diff] [blame] | 57 | msg += "\n" + traceback.format_exc() |
| 58 | JobError.__init__(self, msg) |
| 59 | |
| 60 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 61 | class TestBaseException(AutotestError): |
| 62 | """The parent of all test exceptions.""" |
mbligh | 021679f | 2008-11-27 00:43:19 +0000 | [diff] [blame] | 63 | # Children are required to override this. Never instantiate directly. |
Alex Miller | 3083790 | 2013-02-02 15:52:43 -0800 | [diff] [blame] | 64 | exit_status = "NEVER_RAISE_THIS" |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 65 | |
| 66 | |
| 67 | class TestError(TestBaseException): |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 68 | """Indicates that something went wrong with the test harness itself.""" |
Alex Miller | 3083790 | 2013-02-02 15:52:43 -0800 | [diff] [blame] | 69 | exit_status = "ERROR" |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 70 | |
jadmanski | 8d01bfe | 2008-06-23 18:13:24 +0000 | [diff] [blame] | 71 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 72 | class TestNAError(TestBaseException): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 73 | """Indictates that the test is Not Applicable. Should be thrown |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 74 | when various conditions are such that the test is inappropriate.""" |
Alex Miller | 3083790 | 2013-02-02 15:52:43 -0800 | [diff] [blame] | 75 | exit_status = "TEST_NA" |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 76 | |
jadmanski | 8d01bfe | 2008-06-23 18:13:24 +0000 | [diff] [blame] | 77 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 78 | class TestFail(TestBaseException): |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 79 | """Indicates that the test failed, but the job will not continue.""" |
Alex Miller | 3083790 | 2013-02-02 15:52:43 -0800 | [diff] [blame] | 80 | exit_status = "FAIL" |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 81 | |
jadmanski | 8d01bfe | 2008-06-23 18:13:24 +0000 | [diff] [blame] | 82 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 83 | class TestWarn(TestBaseException): |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 84 | """Indicates that bad things (may) have happened, but not an explicit |
| 85 | failure.""" |
Alex Miller | 3083790 | 2013-02-02 15:52:43 -0800 | [diff] [blame] | 86 | exit_status = "WARN" |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame] | 87 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 88 | |
Aviv Keshet | 39164ca | 2013-03-27 15:08:33 -0700 | [diff] [blame] | 89 | class TestFailRetry(TestFail): |
| 90 | """Indicates that the test failed, but in a manner that may be retried |
| 91 | if test retries are enabled for this test.""" |
| 92 | exit_status = "FAIL" |
| 93 | |
| 94 | |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 95 | class UnhandledTestError(TestError): |
| 96 | """Indicates an unhandled error in a test.""" |
| 97 | def __init__(self, unhandled_exception): |
| 98 | if isinstance(unhandled_exception, TestError): |
| 99 | TestError.__init__(self, *unhandled_exception.args) |
Luis Hector Chavez | 9c4a433 | 2017-03-30 13:12:28 -0700 | [diff] [blame] | 100 | elif isinstance(unhandled_exception, basestring): |
Eric Li | 861b2d5 | 2011-02-04 14:50:35 -0800 | [diff] [blame] | 101 | TestError.__init__(self, unhandled_exception) |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 102 | else: |
| 103 | msg = "Unhandled %s: %s" |
| 104 | msg %= (unhandled_exception.__class__.__name__, |
| 105 | unhandled_exception) |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 106 | msg += "\n" + traceback.format_exc() |
| 107 | TestError.__init__(self, msg) |
| 108 | |
| 109 | |
| 110 | class UnhandledTestFail(TestFail): |
| 111 | """Indicates an unhandled fail in a test.""" |
| 112 | def __init__(self, unhandled_exception): |
| 113 | if isinstance(unhandled_exception, TestFail): |
| 114 | TestFail.__init__(self, *unhandled_exception.args) |
Luis Hector Chavez | 9c4a433 | 2017-03-30 13:12:28 -0700 | [diff] [blame] | 115 | elif isinstance(unhandled_exception, basestring): |
Eric Li | 861b2d5 | 2011-02-04 14:50:35 -0800 | [diff] [blame] | 116 | TestFail.__init__(self, unhandled_exception) |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 117 | else: |
| 118 | msg = "Unhandled %s: %s" |
| 119 | msg %= (unhandled_exception.__class__.__name__, |
| 120 | unhandled_exception) |
mbligh | c218083 | 2008-07-25 03:26:12 +0000 | [diff] [blame] | 121 | msg += "\n" + traceback.format_exc() |
| 122 | TestFail.__init__(self, msg) |
| 123 | |
| 124 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 125 | class CmdError(TestError): |
Christopher Wiley | cd69dc0 | 2013-09-09 13:48:58 -0700 | [diff] [blame] | 126 | """Indicates that a command failed, is fatal to the test unless caught.""" |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 127 | def __init__(self, command, result_obj, additional_text=None): |
| 128 | TestError.__init__(self, command, result_obj, additional_text) |
mbligh | c23051c | 2008-06-27 19:26:46 +0000 | [diff] [blame] | 129 | self.command = command |
| 130 | self.result_obj = result_obj |
| 131 | self.additional_text = additional_text |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame] | 132 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 133 | def __str__(self): |
jadmanski | 6ef0b67 | 2008-09-30 22:50:19 +0000 | [diff] [blame] | 134 | if self.result_obj.exit_status is None: |
| 135 | msg = "Command <%s> failed and is not responding to signals" |
| 136 | msg %= self.command |
| 137 | else: |
| 138 | msg = "Command <%s> failed, rc=%d" |
| 139 | msg %= (self.command, self.result_obj.exit_status) |
| 140 | |
mbligh | c23051c | 2008-06-27 19:26:46 +0000 | [diff] [blame] | 141 | if self.additional_text: |
| 142 | msg += ", " + self.additional_text |
showard | 6d7e94f | 2008-08-20 20:53:34 +0000 | [diff] [blame] | 143 | msg += '\n' + repr(self.result_obj) |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 144 | return msg |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 145 | |
Prathmesh Prabhu | 5490541 | 2017-07-11 17:08:38 -0700 | [diff] [blame] | 146 | def __eq__(self, other): |
| 147 | if type(self) == type(other): |
| 148 | return (self.command == other.command |
| 149 | and self.result_obj == other.result_obj |
| 150 | and self.additional_text == other.additional_text) |
| 151 | else: |
| 152 | return NotImplemented |
| 153 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 154 | |
Christopher Wiley | cd69dc0 | 2013-09-09 13:48:58 -0700 | [diff] [blame] | 155 | class CmdTimeoutError(CmdError): |
| 156 | """Indicates that a command timed out.""" |
Christopher Wiley | cd69dc0 | 2013-09-09 13:48:58 -0700 | [diff] [blame] | 157 | |
| 158 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 159 | class PackageError(TestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 160 | """Indicates an error trying to perform a package operation.""" |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 161 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 162 | |
mbligh | e867310 | 2008-07-16 14:09:03 +0000 | [diff] [blame] | 163 | class BarrierError(JobError): |
| 164 | """Indicates an error happened during a barrier operation.""" |
mbligh | e867310 | 2008-07-16 14:09:03 +0000 | [diff] [blame] | 165 | |
| 166 | |
mbligh | 999fb13 | 2010-04-23 17:22:03 +0000 | [diff] [blame] | 167 | class BarrierAbortError(BarrierError): |
| 168 | """Indicate that the barrier was explicitly aborted by a member.""" |
mbligh | 999fb13 | 2010-04-23 17:22:03 +0000 | [diff] [blame] | 169 | |
| 170 | |
mbligh | 5deff3d | 2008-01-04 21:21:28 +0000 | [diff] [blame] | 171 | class InstallError(JobError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 172 | """Indicates an installation error which Terminates and fails the job.""" |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 173 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 174 | |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 175 | class AutotestRunError(AutotestError): |
mbligh | 021679f | 2008-11-27 00:43:19 +0000 | [diff] [blame] | 176 | """Indicates a problem running server side control files.""" |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 177 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 178 | |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 179 | class AutotestTimeoutError(AutotestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 180 | """This exception is raised when an autotest test exceeds the timeout |
| 181 | parameter passed to run_timed_test and is killed. |
| 182 | """ |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 183 | |
| 184 | |
Justin Giorgi | 6ee6453 | 2016-08-10 11:32:04 -0700 | [diff] [blame] | 185 | class GenericHostRunError(Exception): |
| 186 | """Indicates a problem in the host run() function running in either client |
| 187 | or server code. |
| 188 | |
mbligh | ce955fc | 2009-08-24 21:59:02 +0000 | [diff] [blame] | 189 | Should always be constructed with a tuple of two args (error description |
Justin Giorgi | 6ee6453 | 2016-08-10 11:32:04 -0700 | [diff] [blame] | 190 | (str), run result object). This is a common class used to create the client |
| 191 | and server side versions of it when the distinction is useful. |
mbligh | ce955fc | 2009-08-24 21:59:02 +0000 | [diff] [blame] | 192 | """ |
| 193 | def __init__(self, description, result_obj): |
| 194 | self.description = description |
| 195 | self.result_obj = result_obj |
| 196 | Exception.__init__(self, description, result_obj) |
| 197 | |
| 198 | def __str__(self): |
| 199 | return self.description + '\n' + repr(self.result_obj) |
| 200 | |
| 201 | |
Dale Curtis | 8adf789 | 2011-09-08 16:13:36 -0700 | [diff] [blame] | 202 | class HostInstallTimeoutError(JobError): |
| 203 | """ |
| 204 | Indicates the machine failed to be installed after the predetermined |
| 205 | timeout. |
| 206 | """ |
Dale Curtis | 8adf789 | 2011-09-08 16:13:36 -0700 | [diff] [blame] | 207 | |
| 208 | |
Justin Giorgi | 6ee6453 | 2016-08-10 11:32:04 -0700 | [diff] [blame] | 209 | class AutotestHostRunError(GenericHostRunError, AutotestError): |
mbligh | ce955fc | 2009-08-24 21:59:02 +0000 | [diff] [blame] | 210 | pass |
| 211 | |
| 212 | |
Prathmesh Prabhu | dd53f71 | 2017-07-11 12:22:06 -0700 | [diff] [blame] | 213 | class AutotestHostRunCmdError(AutotestHostRunError): |
| 214 | """Indicates that the command run via Host.run failed. |
| 215 | |
| 216 | This is equivalent to CmdError when raised from a Host object instead of |
| 217 | directly on the DUT using utils.run |
| 218 | """ |
| 219 | |
| 220 | def __init__(self, command, result_obj, additional_text=''): |
| 221 | description = command |
| 222 | if additional_text: |
| 223 | description += ' (%s)' % additional_text |
| 224 | super(AutotestHostRunCmdError, self).__init__(description, result_obj) |
| 225 | self.command = command |
| 226 | self.additional_text = additional_text |
| 227 | |
| 228 | |
| 229 | class AutotestHostRunTimeoutError(AutotestHostRunCmdError): |
| 230 | """Indicates that a command run via Host.run timed out. |
| 231 | |
| 232 | This is equivalent to CmdTimeoutError when raised from a Host object instead |
| 233 | of directly on the DUT using utils.run |
| 234 | """ |
| 235 | |
| 236 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 237 | # server-specific errors |
| 238 | |
| 239 | class AutoservError(Exception): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 240 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 241 | |
| 242 | |
Richard Barnette | 83e6b54 | 2013-12-13 21:38:03 +0000 | [diff] [blame] | 243 | class AutoservSSHTimeout(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 244 | """SSH experienced a connection timeout""" |
mbligh | 34faa28 | 2008-01-16 17:44:49 +0000 | [diff] [blame] | 245 | |
| 246 | |
Justin Giorgi | 6ee6453 | 2016-08-10 11:32:04 -0700 | [diff] [blame] | 247 | class AutoservRunError(GenericHostRunError, AutoservError): |
mbligh | ce955fc | 2009-08-24 21:59:02 +0000 | [diff] [blame] | 248 | pass |
showard | 6d7e94f | 2008-08-20 20:53:34 +0000 | [diff] [blame] | 249 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 250 | |
mbligh | 9d738d6 | 2009-03-09 21:17:10 +0000 | [diff] [blame] | 251 | class AutoservSshPermissionDeniedError(AutoservRunError): |
| 252 | """Indicates that a SSH permission denied error was encountered.""" |
mbligh | 9d738d6 | 2009-03-09 21:17:10 +0000 | [diff] [blame] | 253 | |
| 254 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 255 | class AutoservUnsupportedError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 256 | """Error raised when you try to use an unsupported optional feature""" |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 257 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 258 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 259 | class AutoservHostError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 260 | """Error reaching a host""" |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 261 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 262 | |
mbligh | c971c5f | 2009-06-08 16:48:54 +0000 | [diff] [blame] | 263 | class AutoservHostIsShuttingDownError(AutoservHostError): |
| 264 | """Host is shutting down""" |
mbligh | c971c5f | 2009-06-08 16:48:54 +0000 | [diff] [blame] | 265 | |
| 266 | |
| 267 | class AutoservNotMountedHostError(AutoservHostError): |
| 268 | """Found unmounted partitions that should be mounted""" |
mbligh | c971c5f | 2009-06-08 16:48:54 +0000 | [diff] [blame] | 269 | |
| 270 | |
| 271 | class AutoservSshPingHostError(AutoservHostError): |
| 272 | """SSH ping failed""" |
mbligh | c971c5f | 2009-06-08 16:48:54 +0000 | [diff] [blame] | 273 | |
| 274 | |
| 275 | class AutoservDiskFullHostError(AutoservHostError): |
| 276 | """Not enough free disk space on host""" |
mbligh | c971c5f | 2009-06-08 16:48:54 +0000 | [diff] [blame] | 277 | |
J. Richard Barnette | 4164d1d | 2014-12-02 17:52:33 -0800 | [diff] [blame] | 278 | def __init__(self, path, want_gb, free_space_gb): |
| 279 | super(AutoservDiskFullHostError, self).__init__( |
| 280 | 'Not enough free space on %s - %.3fGB free, want %.3fGB' % |
| 281 | (path, free_space_gb, want_gb)) |
mbligh | c971c5f | 2009-06-08 16:48:54 +0000 | [diff] [blame] | 282 | self.path = path |
| 283 | self.want_gb = want_gb |
| 284 | self.free_space_gb = free_space_gb |
| 285 | |
| 286 | |
J. Richard Barnette | 4164d1d | 2014-12-02 17:52:33 -0800 | [diff] [blame] | 287 | class AutoservNoFreeInodesError(AutoservHostError): |
| 288 | """Not enough free i-nodes on host""" |
| 289 | |
| 290 | def __init__(self, path, want_inodes, free_inodes): |
| 291 | super(AutoservNoFreeInodesError, self).__init__( |
| 292 | 'Not enough free inodes on %s - %d free, want %d' % |
| 293 | (path, free_inodes, want_inodes)) |
| 294 | self.path = path |
| 295 | self.want_inodes = want_inodes |
| 296 | self.free_inodes = free_inodes |
| 297 | |
| 298 | |
mbligh | c971c5f | 2009-06-08 16:48:54 +0000 | [diff] [blame] | 299 | class AutoservHardwareHostError(AutoservHostError): |
| 300 | """Found hardware problems with the host""" |
mbligh | c971c5f | 2009-06-08 16:48:54 +0000 | [diff] [blame] | 301 | |
| 302 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 303 | class AutoservRebootError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 304 | """Error occured while rebooting a machine""" |
mbligh | 6e2ffec | 2008-03-05 16:08:34 +0000 | [diff] [blame] | 305 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 306 | |
jadmanski | 65eb8f5 | 2009-07-24 18:34:43 +0000 | [diff] [blame] | 307 | class AutoservShutdownError(AutoservRebootError): |
| 308 | """Error occured during shutdown of machine""" |
jadmanski | 65eb8f5 | 2009-07-24 18:34:43 +0000 | [diff] [blame] | 309 | |
| 310 | |
Gwendal Grignou | 7a61d2f | 2014-05-23 11:05:51 -0700 | [diff] [blame] | 311 | class AutoservSuspendError(AutoservRebootError): |
| 312 | """Error occured while suspending a machine""" |
Gwendal Grignou | 7a61d2f | 2014-05-23 11:05:51 -0700 | [diff] [blame] | 313 | |
| 314 | |
mbligh | 6e2ffec | 2008-03-05 16:08:34 +0000 | [diff] [blame] | 315 | class AutoservSubcommandError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 316 | """Indicates an error while executing a (forked) subcommand""" |
| 317 | def __init__(self, func, exit_code): |
| 318 | AutoservError.__init__(self, func, exit_code) |
| 319 | self.func = func |
| 320 | self.exit_code = exit_code |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 321 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 322 | def __str__(self): |
| 323 | return ("Subcommand %s failed with exit code %d" % |
| 324 | (self.func, self.exit_code)) |
mbligh | 9167225 | 2008-10-16 22:28:34 +0000 | [diff] [blame] | 325 | |
| 326 | |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 327 | class AutoservRepairTotalFailure(AutoservError): |
| 328 | """Raised if all attempts to repair the DUT failed.""" |
Scott Zawalski | 62bacae | 2013-03-05 10:40:32 -0500 | [diff] [blame] | 329 | |
| 330 | |
jadmanski | c1dda21 | 2009-11-18 19:22:00 +0000 | [diff] [blame] | 331 | class AutoservInstallError(AutoservError): |
| 332 | """Error occured while installing autotest on a host""" |
jadmanski | c1dda21 | 2009-11-18 19:22:00 +0000 | [diff] [blame] | 333 | |
| 334 | |
Simran Basi | 31cf2bd | 2012-08-14 16:51:54 -0700 | [diff] [blame] | 335 | class AutoservPidAlreadyDeadError(AutoservError): |
| 336 | """Error occured by trying to kill a nonexistant PID""" |
Simran Basi | 31cf2bd | 2012-08-14 16:51:54 -0700 | [diff] [blame] | 337 | |
| 338 | |
jadmanski | c27c231 | 2009-08-05 20:58:51 +0000 | [diff] [blame] | 339 | # packaging system errors |
| 340 | |
| 341 | class PackagingError(AutotestError): |
| 342 | 'Abstract error class for all packaging related errors.' |
| 343 | |
| 344 | |
| 345 | class PackageUploadError(PackagingError): |
| 346 | 'Raised when there is an error uploading the package' |
| 347 | |
| 348 | |
| 349 | class PackageFetchError(PackagingError): |
| 350 | 'Raised when there is an error fetching the package' |
| 351 | |
| 352 | |
| 353 | class PackageRemoveError(PackagingError): |
| 354 | 'Raised when there is an error removing the package' |
| 355 | |
| 356 | |
| 357 | class PackageInstallError(PackagingError): |
| 358 | 'Raised when there is an error installing the package' |
| 359 | |
| 360 | |
| 361 | class RepoDiskFullError(PackagingError): |
| 362 | 'Raised when the destination for packages is full' |
| 363 | |
| 364 | |
| 365 | class RepoWriteError(PackagingError): |
| 366 | "Raised when packager cannot write to a repo's desitnation" |
| 367 | |
| 368 | |
| 369 | class RepoUnknownError(PackagingError): |
| 370 | "Raised when packager cannot write to a repo's desitnation" |
| 371 | |
| 372 | |
| 373 | class RepoError(PackagingError): |
| 374 | "Raised when a repo isn't working in some way" |
| 375 | |
| 376 | |
Prashanth B | 6285f6a | 2014-05-08 18:01:27 -0700 | [diff] [blame] | 377 | class StageControlFileFailure(Exception): |
| 378 | """Exceptions encountered staging control files.""" |
Prashanth B | 6285f6a | 2014-05-08 18:01:27 -0700 | [diff] [blame] | 379 | |
| 380 | |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 381 | class CrosDynamicSuiteException(Exception): |
| 382 | """ |
Chris Masone | b493555 | 2012-08-14 12:05:54 -0700 | [diff] [blame] | 383 | Base class for exceptions coming from dynamic suite code in |
| 384 | server/cros/dynamic_suite/*. |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 385 | """ |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 386 | |
| 387 | |
| 388 | class StageBuildFailure(CrosDynamicSuiteException): |
| 389 | """Raised when the dev server throws 500 while staging a build.""" |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 390 | |
| 391 | |
| 392 | class ControlFileEmpty(CrosDynamicSuiteException): |
| 393 | """Raised when the control file exists on the server, but can't be read.""" |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 394 | |
| 395 | |
Alex Miller | a713e25 | 2013-03-01 10:45:44 -0800 | [diff] [blame] | 396 | class ControlFileMalformed(CrosDynamicSuiteException): |
| 397 | """Raised when an invalid control file is read.""" |
Alex Miller | a713e25 | 2013-03-01 10:45:44 -0800 | [diff] [blame] | 398 | |
| 399 | |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 400 | class AsynchronousBuildFailure(CrosDynamicSuiteException): |
| 401 | """Raised when the dev server throws 500 while finishing staging of a build. |
| 402 | """ |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 403 | |
| 404 | |
| 405 | class SuiteArgumentException(CrosDynamicSuiteException): |
| 406 | """Raised when improper arguments are used to run a suite.""" |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 407 | |
| 408 | |
Chris Masone | 8906ab1 | 2012-07-23 15:37:56 -0700 | [diff] [blame] | 409 | class MalformedDependenciesException(CrosDynamicSuiteException): |
| 410 | """Raised when a build has a malformed dependency_info file.""" |
Chris Masone | 8906ab1 | 2012-07-23 15:37:56 -0700 | [diff] [blame] | 411 | |
| 412 | |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 413 | class InadequateHostsException(CrosDynamicSuiteException): |
| 414 | """Raised when there are too few hosts to run a suite.""" |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 415 | |
| 416 | |
| 417 | class NoHostsException(CrosDynamicSuiteException): |
| 418 | """Raised when there are no healthy hosts to run a suite.""" |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 419 | |
| 420 | |
| 421 | class ControlFileNotFound(CrosDynamicSuiteException): |
| 422 | """Raised when a control file cannot be found and/or read.""" |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 423 | |
| 424 | |
| 425 | class NoControlFileList(CrosDynamicSuiteException): |
Chris Masone | 9807bd6 | 2012-07-11 14:44:17 -0700 | [diff] [blame] | 426 | """Raised to indicate that a listing can't be done.""" |
Chris Masone | 9807bd6 | 2012-07-11 14:44:17 -0700 | [diff] [blame] | 427 | |
| 428 | |
xixuan | 0f7755d | 2016-04-18 14:49:12 -0700 | [diff] [blame] | 429 | class SuiteControlFileException(CrosDynamicSuiteException): |
| 430 | """Raised when failing to list the contents of all control file.""" |
xixuan | 0f7755d | 2016-04-18 14:49:12 -0700 | [diff] [blame] | 431 | |
| 432 | |
Chris Masone | 9807bd6 | 2012-07-11 14:44:17 -0700 | [diff] [blame] | 433 | class HostLockManagerReuse(CrosDynamicSuiteException): |
| 434 | """Raised when a caller tries to re-use a HostLockManager instance.""" |
Chris Masone | f8b5306 | 2012-05-08 22:14:18 -0700 | [diff] [blame] | 435 | |
| 436 | |
Simran Basi | 94d9bd0 | 2012-11-12 15:13:59 -0800 | [diff] [blame] | 437 | class ReimageAbortedException(CrosDynamicSuiteException): |
| 438 | """Raised when a Reimage job is aborted""" |
Simran Basi | 94d9bd0 | 2012-11-12 15:13:59 -0800 | [diff] [blame] | 439 | |
| 440 | |
Alex Miller | 3083790 | 2013-02-02 15:52:43 -0800 | [diff] [blame] | 441 | class UnknownReimageType(CrosDynamicSuiteException): |
| 442 | """Raised when a suite passes in an invalid reimage type""" |
Alex Miller | 3083790 | 2013-02-02 15:52:43 -0800 | [diff] [blame] | 443 | |
| 444 | |
Alex Miller | 24c27c1 | 2012-08-09 10:24:24 -0700 | [diff] [blame] | 445 | class NoUniquePackageFound(Exception): |
| 446 | """Raised when an executable cannot be mapped back to a single package.""" |
Alex Miller | 24c27c1 | 2012-08-09 10:24:24 -0700 | [diff] [blame] | 447 | |
| 448 | |
Alex Miller | 4a19369 | 2013-08-21 13:59:01 -0700 | [diff] [blame] | 449 | class RPCException(Exception): |
| 450 | """Raised when an RPC encounters an error that a client might wish to |
| 451 | handle specially.""" |
Alex Miller | 4a19369 | 2013-08-21 13:59:01 -0700 | [diff] [blame] | 452 | |
| 453 | |
| 454 | class NoEligibleHostException(RPCException): |
| 455 | """Raised when no host could satisfy the requirements of a job.""" |
Alex Miller | 4a19369 | 2013-08-21 13:59:01 -0700 | [diff] [blame] | 456 | |
| 457 | |
Xixuan Wu | 76cd058 | 2017-12-21 13:23:28 -0800 | [diff] [blame] | 458 | class UnmodifiableLabelException(RPCException): |
| 459 | """Raised when an RPC tries to modify static labels.""" |
| 460 | |
| 461 | |
Aviv Keshet | 4625075 | 2013-08-27 15:52:06 -0700 | [diff] [blame] | 462 | class InvalidBgJobCall(Exception): |
| 463 | """Raised when an invalid call is made to a BgJob object.""" |
Aviv Keshet | 4625075 | 2013-08-27 15:52:06 -0700 | [diff] [blame] | 464 | |
| 465 | |
Jakob Juelich | 3b27dbc | 2014-09-03 18:05:37 -0700 | [diff] [blame] | 466 | class HeartbeatOnlyAllowedInShardModeException(Exception): |
| 467 | """Raised when a heartbeat is attempted but not allowed.""" |
Jakob Juelich | 3b27dbc | 2014-09-03 18:05:37 -0700 | [diff] [blame] | 468 | |
| 469 | |
Jakob Juelich | a94efe6 | 2014-09-18 16:02:49 -0700 | [diff] [blame] | 470 | class UnallowedRecordsSentToMaster(Exception): |
Aviv Keshet | 6dec0e1 | 2017-04-17 15:23:33 -0700 | [diff] [blame] | 471 | """Raised when an illegal record was sent from shard to master.""" |
| 472 | |
| 473 | |
| 474 | class IgnorableUnallowedRecordsSentToMaster(UnallowedRecordsSentToMaster): |
| 475 | """Raised when non-fatal illegal record was sent from shard. |
| 476 | |
| 477 | This exception may be raised by rpc model logic on master, but will |
| 478 | not be returned back to heartbeat client. It indicates that some records |
| 479 | may have been illegal, but the master is ignoring those records and |
| 480 | proceeding with the rest of the heartbeat handling. |
| 481 | """ |
Jakob Juelich | a94efe6 | 2014-09-18 16:02:49 -0700 | [diff] [blame] | 482 | |
| 483 | |
Dan Shi | 9a535c9 | 2014-11-24 08:52:40 -0800 | [diff] [blame] | 484 | class InvalidDataError(Exception): |
Aviv Keshet | 6dec0e1 | 2017-04-17 15:23:33 -0700 | [diff] [blame] | 485 | """Exception raised when invalid data provided for database operation.""" |
Dan Shi | 9a535c9 | 2014-11-24 08:52:40 -0800 | [diff] [blame] | 486 | |
| 487 | |
Dan Shi | 767dced | 2015-02-01 00:21:07 -0800 | [diff] [blame] | 488 | class ContainerError(Exception): |
Aviv Keshet | 6dec0e1 | 2017-04-17 15:23:33 -0700 | [diff] [blame] | 489 | """Exception raised when program runs into error using container.""" |
Dan Shi | 767dced | 2015-02-01 00:21:07 -0800 | [diff] [blame] | 490 | |
| 491 | |
Simran Basi | 9f364a6 | 2015-12-07 14:15:19 -0800 | [diff] [blame] | 492 | class IllegalUser(Exception): |
| 493 | """Exception raise when a program runs as an illegal user.""" |
| 494 | |
| 495 | |
Keith Haddow | 07f1d3e | 2017-08-03 17:40:41 -0700 | [diff] [blame] | 496 | class AutoservDirectoryNotFoundError(AutoservHostError): |
| 497 | """Exception raised when an expected directory is not found.""" |
| 498 | |
| 499 | |
| 500 | class AutoservDiskSizeUnknownError(AutoservHostError): |
| 501 | """Exception raised when the disk space could not be determined.""" |
| 502 | |
| 503 | |
mbligh | 9167225 | 2008-10-16 22:28:34 +0000 | [diff] [blame] | 504 | # This MUST remain at the end of the file. |
| 505 | # Limit 'from error import *' to only import the exception instances. |
| 506 | for _name, _thing in locals().items(): |
| 507 | try: |
| 508 | if issubclass(_thing, Exception): |
| 509 | __all__.append(_name) |
| 510 | except TypeError: |
| 511 | pass # _thing not a class |
| 512 | __all__ = tuple(__all__) |