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): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 39 | """Indicates an error which terminates and fails the test.""" |
| 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 | 302482e | 2008-05-01 20:06:16 +0000 | [diff] [blame] | 43 | class TestNAError(AutotestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 44 | """Indictates that the test is Not Applicable. Should be thrown |
| 45 | when various conditions are such that the test is inappropriate""" |
| 46 | pass |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame] | 47 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 48 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 49 | class CmdError(TestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 50 | """\ |
| 51 | Indicates that a command failed, is fatal to the test unless caught. |
| 52 | """ |
| 53 | def __init__(self, command, result_obj, additional_text=None): |
| 54 | TestError.__init__(self, command, result_obj, additional_text) |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame] | 55 | |
| 56 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 57 | def __str__(self): |
| 58 | msg = "Command <%s> failed, rc=%d" % (self.args[0], |
| 59 | self.args[1].exit_status) |
| 60 | if self.args[2]: |
| 61 | msg += ", " + self.args[2] |
| 62 | return msg |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 63 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 64 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 65 | class PackageError(TestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 66 | """Indicates an error trying to perform a package operation.""" |
| 67 | pass |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +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 UnhandledError(TestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 71 | """Indicates an unhandled exception in a test.""" |
jadmanski | 6f73136 | 2008-06-17 16:47:06 +0000 | [diff] [blame] | 72 | def __init__(self, unhandled_exception): |
| 73 | if isinstance(unhandled_exception, TestError): |
| 74 | TestError.__init__(self, *unhandled_exception.args) |
| 75 | else: |
| 76 | msg = "Unhandled %s: %s" |
| 77 | msg %= (unhandled_exception.__class__.__name__, |
| 78 | unhandled_exception) |
jadmanski | e01c2e5 | 2008-06-18 20:25:26 +0000 | [diff] [blame] | 79 | msg += "\n" + traceback.format_exc() |
jadmanski | 6f73136 | 2008-06-17 16:47:06 +0000 | [diff] [blame] | 80 | TestError.__init__(self, msg) |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 81 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 82 | |
mbligh | 5deff3d | 2008-01-04 21:21:28 +0000 | [diff] [blame] | 83 | class InstallError(JobError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 84 | """Indicates an installation error which Terminates and fails the job.""" |
| 85 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 86 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 87 | |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 88 | class AutotestRunError(AutotestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 89 | pass |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 90 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 91 | |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 92 | class AutotestTimeoutError(AutotestError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 93 | """This exception is raised when an autotest test exceeds the timeout |
| 94 | parameter passed to run_timed_test and is killed. |
| 95 | """ |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 96 | |
| 97 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 98 | # server-specific errors |
| 99 | |
| 100 | class AutoservError(Exception): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 101 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 102 | |
| 103 | |
mbligh | 34faa28 | 2008-01-16 17:44:49 +0000 | [diff] [blame] | 104 | class AutoservSSHTimeout(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 105 | """SSH experienced a connection timeout""" |
| 106 | pass |
mbligh | 34faa28 | 2008-01-16 17:44:49 +0000 | [diff] [blame] | 107 | |
| 108 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 109 | class AutoservRunError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 110 | """\ |
| 111 | Errors raised by one of the run functions. Should always be |
| 112 | constructed with a tuple of two args (error description (str), |
| 113 | run result object). |
| 114 | """ |
| 115 | def __init__(self, description, result_obj): |
| 116 | AutoservError.__init__(self, description, result_obj) |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 117 | |
| 118 | |
| 119 | class AutoservVirtError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 120 | """Vitualization related error""" |
| 121 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 122 | |
| 123 | |
| 124 | class AutoservUnsupportedError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 125 | """Error raised when you try to use an unsupported optional feature""" |
| 126 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 127 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 128 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 129 | class AutoservHostError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 130 | """Error reaching a host""" |
| 131 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 132 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 133 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 134 | class AutoservRebootError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 135 | """Error occured while rebooting a machine""" |
| 136 | pass |
mbligh | 6e2ffec | 2008-03-05 16:08:34 +0000 | [diff] [blame] | 137 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 138 | |
mbligh | 6e2ffec | 2008-03-05 16:08:34 +0000 | [diff] [blame] | 139 | class AutoservSubcommandError(AutoservError): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 140 | """Indicates an error while executing a (forked) subcommand""" |
| 141 | def __init__(self, func, exit_code): |
| 142 | AutoservError.__init__(self, func, exit_code) |
| 143 | self.func = func |
| 144 | self.exit_code = exit_code |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 145 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 146 | def __str__(self): |
| 147 | return ("Subcommand %s failed with exit code %d" % |
| 148 | (self.func, self.exit_code)) |