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 | |
| 17 | class JobContinue(SystemExit): |
| 18 | """Allow us to bail out requesting continuance.""" |
| 19 | pass |
| 20 | |
| 21 | class JobComplete(SystemExit): |
| 22 | """Allow us to bail out indicating continuation not required.""" |
| 23 | pass |
| 24 | |
| 25 | class AutotestError(Exception): |
| 26 | """The parent of all errors deliberatly thrown within the client code.""" |
| 27 | pass |
| 28 | |
| 29 | class JobError(AutotestError): |
| 30 | """Indicates an error which terminates and fails the whole job.""" |
| 31 | pass |
| 32 | |
| 33 | class TestError(AutotestError): |
| 34 | """Indicates an error which terminates and fails the test.""" |
| 35 | pass |
| 36 | |
mbligh | 302482e | 2008-05-01 20:06:16 +0000 | [diff] [blame] | 37 | class TestNAError(AutotestError): |
| 38 | """Indictates that the test is Not Applicable. Should be thrown |
| 39 | when various conditions are such that the test is inappropriate""" |
| 40 | pass |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame] | 41 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 42 | class CmdError(TestError): |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame] | 43 | """\ |
| 44 | Indicates that a command failed, is fatal to the test unless caught. |
| 45 | """ |
mbligh | 8ea61e2 | 2008-05-09 18:09:37 +0000 | [diff] [blame] | 46 | def __init__(self, command, result_obj): |
| 47 | TestError.__init__(self, command, result_obj) |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame] | 48 | |
| 49 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 50 | def __str__(self): |
mbligh | 8ea61e2 | 2008-05-09 18:09:37 +0000 | [diff] [blame] | 51 | return "Command <" + self.args[0] + "> failed, rc=%d" % (self.args[1].exit_status) |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 52 | |
| 53 | class PackageError(TestError): |
mbligh | 642b03e | 2008-01-14 16:53:15 +0000 | [diff] [blame] | 54 | """Indicates an error trying to perform a package operation.""" |
| 55 | pass |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 56 | |
| 57 | class UnhandledError(TestError): |
| 58 | """Indicates an unhandled exception in a test.""" |
| 59 | def __init__(self, prefix): |
| 60 | msg = prefix + format_error() |
| 61 | TestError.__init__(self, msg) |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 62 | |
mbligh | 5deff3d | 2008-01-04 21:21:28 +0000 | [diff] [blame] | 63 | class InstallError(JobError): |
| 64 | """Indicates an installation error which Terminates and fails the job.""" |
| 65 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 66 | |
mbligh | 6f015c4 | 2008-02-12 20:55:03 +0000 | [diff] [blame] | 67 | class AutotestRunError(AutotestError): |
| 68 | pass |
| 69 | |
| 70 | class AutotestTimeoutError(AutotestError): |
| 71 | """This exception is raised when an autotest test exceeds the timeout |
| 72 | parameter passed to run_timed_test and is killed. |
| 73 | """ |
| 74 | |
| 75 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 76 | # server-specific errors |
| 77 | |
| 78 | class AutoservError(Exception): |
| 79 | pass |
| 80 | |
| 81 | |
mbligh | 34faa28 | 2008-01-16 17:44:49 +0000 | [diff] [blame] | 82 | class AutoservSSHTimeout(AutoservError): |
| 83 | """SSH experienced a connection timeout""" |
| 84 | pass |
| 85 | |
| 86 | |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 87 | class AutoservRunError(AutoservError): |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame] | 88 | """\ |
| 89 | Errors raised by one of the run functions. Should always be |
| 90 | constructed with a tuple of two args (error description (str), |
| 91 | run result object). |
| 92 | """ |
| 93 | def __init__(self, description, result_obj): |
| 94 | AutoservError.__init__(self, description, result_obj) |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 95 | |
| 96 | |
| 97 | class AutoservVirtError(AutoservError): |
| 98 | """Vitualization related error""" |
| 99 | pass |
| 100 | |
| 101 | |
| 102 | class AutoservUnsupportedError(AutoservError): |
| 103 | """Error raised when you try to use an unsupported optional feature""" |
| 104 | pass |
| 105 | |
| 106 | class AutoservHostError(AutoservError): |
| 107 | """Error reaching a host""" |
| 108 | pass |
| 109 | |
| 110 | class AutoservRebootError(AutoservError): |
| 111 | """Error occured while rebooting a machine""" |
| 112 | pass |
mbligh | 6e2ffec | 2008-03-05 16:08:34 +0000 | [diff] [blame] | 113 | |
| 114 | class AutoservSubcommandError(AutoservError): |
| 115 | """Indicates an error while executing a (forked) subcommand""" |
| 116 | def __init__(self, func, exit_code): |
| 117 | AutoservError.__init__(self, func, exit_code) |
| 118 | self.func = func |
| 119 | self.exit_code = exit_code |
| 120 | def __str__(self): |
| 121 | return ("Subcommand %s failed with exit code %d" % |
mbligh | 158ba7b | 2008-03-07 18:29:12 +0000 | [diff] [blame] | 122 | (self.func, self.exit_code)) |