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 | |
| 8 | def format_error(): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 9 | t, o, tb = sys.exc_info() |
| 10 | trace = format_exception(t, o, tb) |
| 11 | # Clear the backtrace to prevent a circular reference |
| 12 | # in the heap -- as per tutorial |
| 13 | tb = '' |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 14 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 15 | return ''.join(trace) |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 16 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 17 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 18 | class JobContinue(SystemExit): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 19 | """Allow us to bail out requesting continuance.""" |
| 20 | pass |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 21 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 22 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 23 | class JobComplete(SystemExit): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 24 | """Allow us to bail out indicating continuation not required.""" |
| 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 AutotestError(Exception): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 29 | """The parent of all errors deliberatly thrown within the client code.""" |
| 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 JobError(AutotestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 34 | """Indicates an error which terminates and fails the whole job.""" |
| 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 TestError(AutotestError): |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 39 | """Indicates that something went wrong with the test harness itself.""" |
| 40 | exit_status="ERROR" |
| 41 | pass |
| 42 | |
jadmanski | 8d01bfe | 2008-06-23 18:13:24 +0000 | [diff] [blame^] | 43 | |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 44 | class TestUnknownError(AutotestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 45 | """Indicates an error which terminates and fails the test.""" |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 46 | exit_status="FAIL" |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 47 | pass |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 48 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 49 | |
mbligh | 302482e | 2008-05-01 20:06:16 +0000 | [diff] [blame] | 50 | class TestNAError(AutotestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 51 | """Indictates that the test is Not Applicable. Should be thrown |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 52 | when various conditions are such that the test is inappropriate.""" |
| 53 | exit_status="TEST_NA" |
| 54 | pass |
| 55 | |
jadmanski | 8d01bfe | 2008-06-23 18:13:24 +0000 | [diff] [blame^] | 56 | |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 57 | class TestFail(AutotestError): |
| 58 | """Indicates that the test failed, but the job will not continue.""" |
| 59 | exit_status="FAIL" |
| 60 | pass |
| 61 | |
jadmanski | 8d01bfe | 2008-06-23 18:13:24 +0000 | [diff] [blame^] | 62 | |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 63 | class TestWarn(AutotestError): |
| 64 | """Indicates that bad things (may) have happened, but not an explicit |
| 65 | failure.""" |
| 66 | exit_status="WARN" |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 67 | pass |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame] | 68 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 69 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 70 | class CmdError(TestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 71 | """\ |
| 72 | Indicates that a command failed, is fatal to the test unless caught. |
| 73 | """ |
| 74 | def __init__(self, command, result_obj, additional_text=None): |
| 75 | TestError.__init__(self, command, result_obj, additional_text) |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame] | 76 | |
| 77 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 78 | def __str__(self): |
| 79 | msg = "Command <%s> failed, rc=%d" % (self.args[0], |
| 80 | self.args[1].exit_status) |
| 81 | if self.args[2]: |
| 82 | msg += ", " + self.args[2] |
| 83 | return msg |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 84 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 85 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 86 | class PackageError(TestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 87 | """Indicates an error trying to perform a package operation.""" |
| 88 | pass |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 89 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 90 | |
mbligh | b48fa56 | 2008-06-23 17:29:40 +0000 | [diff] [blame] | 91 | class UnhandledError(TestUnknownError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 92 | """Indicates an unhandled exception in a test.""" |
jadmanski | 6f73136 | 2008-06-17 16:47:06 +0000 | [diff] [blame] | 93 | def __init__(self, unhandled_exception): |
jadmanski | 8d01bfe | 2008-06-23 18:13:24 +0000 | [diff] [blame^] | 94 | if isinstance(unhandled_exception, AutotestError): |
| 95 | TestUnknownError.__init__(self, *unhandled_exception.args) |
jadmanski | 6f73136 | 2008-06-17 16:47:06 +0000 | [diff] [blame] | 96 | else: |
| 97 | msg = "Unhandled %s: %s" |
| 98 | msg %= (unhandled_exception.__class__.__name__, |
| 99 | unhandled_exception) |
jadmanski | e01c2e5 | 2008-06-18 20:25:26 +0000 | [diff] [blame] | 100 | msg += "\n" + traceback.format_exc() |
jadmanski | 8d01bfe | 2008-06-23 18:13:24 +0000 | [diff] [blame^] | 101 | TestUnknownError.__init__(self, msg) |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 102 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 103 | |
mbligh | 5deff3d | 2008-01-04 21:21:28 +0000 | [diff] [blame] | 104 | class InstallError(JobError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 105 | """Indicates an installation error which Terminates and fails the job.""" |
| 106 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 107 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 108 | |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 109 | class AutotestRunError(AutotestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 110 | pass |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 111 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 112 | |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 113 | class AutotestTimeoutError(AutotestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 114 | """This exception is raised when an autotest test exceeds the timeout |
| 115 | parameter passed to run_timed_test and is killed. |
| 116 | """ |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 117 | |
| 118 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 119 | # server-specific errors |
| 120 | |
| 121 | class AutoservError(Exception): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 122 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 123 | |
| 124 | |
mbligh | 34faa28 | 2008-01-16 17:44:49 +0000 | [diff] [blame] | 125 | class AutoservSSHTimeout(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 126 | """SSH experienced a connection timeout""" |
| 127 | pass |
mbligh | 34faa28 | 2008-01-16 17:44:49 +0000 | [diff] [blame] | 128 | |
| 129 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 130 | class AutoservRunError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 131 | """\ |
| 132 | Errors raised by one of the run functions. Should always be |
| 133 | constructed with a tuple of two args (error description (str), |
| 134 | run result object). |
| 135 | """ |
| 136 | def __init__(self, description, result_obj): |
| 137 | AutoservError.__init__(self, description, result_obj) |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 138 | |
| 139 | |
| 140 | class AutoservVirtError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 141 | """Vitualization related error""" |
| 142 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 143 | |
| 144 | |
| 145 | class AutoservUnsupportedError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 146 | """Error raised when you try to use an unsupported optional feature""" |
| 147 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 148 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 149 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 150 | class AutoservHostError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 151 | """Error reaching a host""" |
| 152 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 153 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 154 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 155 | class AutoservRebootError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 156 | """Error occured while rebooting a machine""" |
| 157 | pass |
mbligh | 6e2ffec | 2008-03-05 16:08:34 +0000 | [diff] [blame] | 158 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 159 | |
mbligh | 6e2ffec | 2008-03-05 16:08:34 +0000 | [diff] [blame] | 160 | class AutoservSubcommandError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 161 | """Indicates an error while executing a (forked) subcommand""" |
| 162 | def __init__(self, func, exit_code): |
| 163 | AutoservError.__init__(self, func, exit_code) |
| 164 | self.func = func |
| 165 | self.exit_code = exit_code |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 166 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 167 | def __str__(self): |
| 168 | return ("Subcommand %s failed with exit code %d" % |
| 169 | (self.func, self.exit_code)) |