mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 1 | """ |
| 2 | Internal global error types |
| 3 | """ |
| 4 | |
| 5 | import sys |
| 6 | from traceback import format_exception |
| 7 | |
| 8 | def format_error(): |
mbligh | 642b03e | 2008-01-14 16:53:15 +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 | |
mbligh | 642b03e | 2008-01-14 16:53:15 +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): |
| 19 | """Allow us to bail out requesting continuance.""" |
| 20 | pass |
| 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): |
| 24 | """Allow us to bail out indicating continuation not required.""" |
| 25 | pass |
| 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): |
| 29 | """The parent of all errors deliberatly thrown within the client code.""" |
| 30 | pass |
| 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): |
| 34 | """Indicates an error which terminates and fails the whole job.""" |
| 35 | pass |
| 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): |
| 39 | """Indicates an error which terminates and fails the test.""" |
| 40 | pass |
| 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): |
| 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): |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame] | 50 | """\ |
| 51 | Indicates that a command failed, is fatal to the test unless caught. |
| 52 | """ |
jadmanski | d93d7d2 | 2008-05-29 21:37:29 +0000 | [diff] [blame] | 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 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 57 | def __str__(self): |
jadmanski | d93d7d2 | 2008-05-29 21:37:29 +0000 | [diff] [blame] | 58 | msg = "Command <%s> failed, rc=%d" % (self.args[0], |
mbligh | 7aff6bd | 2008-06-06 15:06:29 +0000 | [diff] [blame] | 59 | self.args[1].exit_status) |
jadmanski | d93d7d2 | 2008-05-29 21:37:29 +0000 | [diff] [blame] | 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): |
mbligh | 642b03e | 2008-01-14 16:53:15 +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): |
| 71 | """Indicates an unhandled exception in a test.""" |
| 72 | def __init__(self, prefix): |
| 73 | msg = prefix + format_error() |
| 74 | TestError.__init__(self, msg) |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 75 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 76 | |
mbligh | 5deff3d | 2008-01-04 21:21:28 +0000 | [diff] [blame] | 77 | class InstallError(JobError): |
| 78 | """Indicates an installation error which Terminates and fails the job.""" |
| 79 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 80 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 81 | |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 82 | class AutotestRunError(AutotestError): |
| 83 | pass |
| 84 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 85 | |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 86 | class AutotestTimeoutError(AutotestError): |
| 87 | """This exception is raised when an autotest test exceeds the timeout |
| 88 | parameter passed to run_timed_test and is killed. |
| 89 | """ |
| 90 | |
| 91 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 92 | # server-specific errors |
| 93 | |
| 94 | class AutoservError(Exception): |
| 95 | pass |
| 96 | |
| 97 | |
mbligh | 34faa28 | 2008-01-16 17:44:49 +0000 | [diff] [blame] | 98 | class AutoservSSHTimeout(AutoservError): |
| 99 | """SSH experienced a connection timeout""" |
| 100 | pass |
| 101 | |
| 102 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 103 | class AutoservRunError(AutoservError): |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame] | 104 | """\ |
| 105 | Errors raised by one of the run functions. Should always be |
| 106 | constructed with a tuple of two args (error description (str), |
| 107 | run result object). |
| 108 | """ |
| 109 | def __init__(self, description, result_obj): |
| 110 | AutoservError.__init__(self, description, result_obj) |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 111 | |
| 112 | |
| 113 | class AutoservVirtError(AutoservError): |
| 114 | """Vitualization related error""" |
| 115 | pass |
| 116 | |
| 117 | |
| 118 | class AutoservUnsupportedError(AutoservError): |
| 119 | """Error raised when you try to use an unsupported optional feature""" |
| 120 | pass |
| 121 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 122 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 123 | class AutoservHostError(AutoservError): |
| 124 | """Error reaching a host""" |
| 125 | pass |
| 126 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 127 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 128 | class AutoservRebootError(AutoservError): |
| 129 | """Error occured while rebooting a machine""" |
| 130 | pass |
mbligh | 6e2ffec | 2008-03-05 16:08:34 +0000 | [diff] [blame] | 131 | |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 132 | |
mbligh | 6e2ffec | 2008-03-05 16:08:34 +0000 | [diff] [blame] | 133 | class AutoservSubcommandError(AutoservError): |
| 134 | """Indicates an error while executing a (forked) subcommand""" |
| 135 | def __init__(self, func, exit_code): |
| 136 | AutoservError.__init__(self, func, exit_code) |
| 137 | self.func = func |
| 138 | self.exit_code = exit_code |
mbligh | 7e1b150 | 2008-06-06 15:05:41 +0000 | [diff] [blame] | 139 | |
mbligh | 6e2ffec | 2008-03-05 16:08:34 +0000 | [diff] [blame] | 140 | def __str__(self): |
| 141 | return ("Subcommand %s failed with exit code %d" % |
mbligh | 158ba7b | 2008-03-07 18:29:12 +0000 | [diff] [blame] | 142 | (self.func, self.exit_code)) |