error.py revision 6f731364e6207c198ac8de748a043eba1e9223b3
1""" 2Internal global error types 3""" 4 5import sys, traceback 6from traceback import format_exception 7 8def format_error(): 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 = '' 14 15 return ''.join(trace) 16 17 18class JobContinue(SystemExit): 19 """Allow us to bail out requesting continuance.""" 20 pass 21 22 23class JobComplete(SystemExit): 24 """Allow us to bail out indicating continuation not required.""" 25 pass 26 27 28class AutotestError(Exception): 29 """The parent of all errors deliberatly thrown within the client code.""" 30 pass 31 32 33class JobError(AutotestError): 34 """Indicates an error which terminates and fails the whole job.""" 35 pass 36 37 38class TestError(AutotestError): 39 """Indicates an error which terminates and fails the test.""" 40 pass 41 42 43class 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 47 48 49class CmdError(TestError): 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) 55 56 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 63 64 65class PackageError(TestError): 66 """Indicates an error trying to perform a package operation.""" 67 pass 68 69 70class UnhandledError(TestError): 71 """Indicates an unhandled exception in a test.""" 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) 79 msg += "\n" + "\n".join(traceback.format_exc()) 80 TestError.__init__(self, msg) 81 82 83class InstallError(JobError): 84 """Indicates an installation error which Terminates and fails the job.""" 85 pass 86 87 88class AutotestRunError(AutotestError): 89 pass 90 91 92class AutotestTimeoutError(AutotestError): 93 """This exception is raised when an autotest test exceeds the timeout 94 parameter passed to run_timed_test and is killed. 95 """ 96 97 98# server-specific errors 99 100class AutoservError(Exception): 101 pass 102 103 104class AutoservSSHTimeout(AutoservError): 105 """SSH experienced a connection timeout""" 106 pass 107 108 109class AutoservRunError(AutoservError): 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) 117 118 119class AutoservVirtError(AutoservError): 120 """Vitualization related error""" 121 pass 122 123 124class AutoservUnsupportedError(AutoservError): 125 """Error raised when you try to use an unsupported optional feature""" 126 pass 127 128 129class AutoservHostError(AutoservError): 130 """Error reaching a host""" 131 pass 132 133 134class AutoservRebootError(AutoservError): 135 """Error occured while rebooting a machine""" 136 pass 137 138 139class AutoservSubcommandError(AutoservError): 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 145 146 def __str__(self): 147 return ("Subcommand %s failed with exit code %d" % 148 (self.func, self.exit_code)) 149