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 | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame^] | 37 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 38 | class CmdError(TestError): |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame^] | 39 | """\ |
| 40 | Indicates that a command failed, is fatal to the test unless caught. |
| 41 | """ |
| 42 | def __init__(self, command, result_code): |
| 43 | TestError.__init__(self, command, result_code) |
| 44 | |
| 45 | |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 46 | def __str__(self): |
| 47 | return "Command <" + self.args[0] + "> failed, rc=%d" % (self.args[1]) |
| 48 | |
| 49 | class PackageError(TestError): |
mbligh | 642b03e | 2008-01-14 16:53:15 +0000 | [diff] [blame] | 50 | """Indicates an error trying to perform a package operation.""" |
| 51 | pass |
mbligh | 906b9f7 | 2007-11-29 18:56:17 +0000 | [diff] [blame] | 52 | |
| 53 | class UnhandledError(TestError): |
| 54 | """Indicates an unhandled exception in a test.""" |
| 55 | def __init__(self, prefix): |
| 56 | msg = prefix + format_error() |
| 57 | TestError.__init__(self, msg) |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 58 | |
mbligh | 5deff3d | 2008-01-04 21:21:28 +0000 | [diff] [blame] | 59 | class InstallError(JobError): |
| 60 | """Indicates an installation error which Terminates and fails the job.""" |
| 61 | pass |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 62 | |
| 63 | # server-specific errors |
| 64 | |
| 65 | class AutoservError(Exception): |
| 66 | pass |
| 67 | |
| 68 | |
| 69 | class AutoservRunError(AutoservError): |
mbligh | 6a2a2df | 2008-01-16 17:41:55 +0000 | [diff] [blame^] | 70 | """\ |
| 71 | Errors raised by one of the run functions. Should always be |
| 72 | constructed with a tuple of two args (error description (str), |
| 73 | run result object). |
| 74 | """ |
| 75 | def __init__(self, description, result_obj): |
| 76 | AutoservError.__init__(self, description, result_obj) |
mbligh | 03f4fc7 | 2007-11-29 20:56:14 +0000 | [diff] [blame] | 77 | |
| 78 | |
| 79 | class AutoservVirtError(AutoservError): |
| 80 | """Vitualization related error""" |
| 81 | pass |
| 82 | |
| 83 | |
| 84 | class AutoservUnsupportedError(AutoservError): |
| 85 | """Error raised when you try to use an unsupported optional feature""" |
| 86 | pass |
| 87 | |
| 88 | class AutoservHostError(AutoservError): |
| 89 | """Error reaching a host""" |
| 90 | pass |
| 91 | |
| 92 | class AutoservRebootError(AutoservError): |
| 93 | """Error occured while rebooting a machine""" |
| 94 | pass |