error.py revision d93d7d2a9728bbed6d125a6d8a9f61bb3f2b6718
1""" 2Internal global error types 3""" 4 5import sys 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 17class JobContinue(SystemExit): 18 """Allow us to bail out requesting continuance.""" 19 pass 20 21class JobComplete(SystemExit): 22 """Allow us to bail out indicating continuation not required.""" 23 pass 24 25class AutotestError(Exception): 26 """The parent of all errors deliberatly thrown within the client code.""" 27 pass 28 29class JobError(AutotestError): 30 """Indicates an error which terminates and fails the whole job.""" 31 pass 32 33class TestError(AutotestError): 34 """Indicates an error which terminates and fails the test.""" 35 pass 36 37class 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 41 42class CmdError(TestError): 43 """\ 44 Indicates that a command failed, is fatal to the test unless caught. 45 """ 46 def __init__(self, command, result_obj, additional_text=None): 47 TestError.__init__(self, command, result_obj, additional_text) 48 49 50 def __str__(self): 51 msg = "Command <%s> failed, rc=%d" % (self.args[0], 52 self.args[1]) 53 if self.args[2]: 54 msg += ", " + self.args[2] 55 return msg 56 57class PackageError(TestError): 58 """Indicates an error trying to perform a package operation.""" 59 pass 60 61class UnhandledError(TestError): 62 """Indicates an unhandled exception in a test.""" 63 def __init__(self, prefix): 64 msg = prefix + format_error() 65 TestError.__init__(self, msg) 66 67class InstallError(JobError): 68 """Indicates an installation error which Terminates and fails the job.""" 69 pass 70 71class AutotestRunError(AutotestError): 72 pass 73 74class AutotestTimeoutError(AutotestError): 75 """This exception is raised when an autotest test exceeds the timeout 76 parameter passed to run_timed_test and is killed. 77 """ 78 79 80# server-specific errors 81 82class AutoservError(Exception): 83 pass 84 85 86class AutoservSSHTimeout(AutoservError): 87 """SSH experienced a connection timeout""" 88 pass 89 90 91class AutoservRunError(AutoservError): 92 """\ 93 Errors raised by one of the run functions. Should always be 94 constructed with a tuple of two args (error description (str), 95 run result object). 96 """ 97 def __init__(self, description, result_obj): 98 AutoservError.__init__(self, description, result_obj) 99 100 101class AutoservVirtError(AutoservError): 102 """Vitualization related error""" 103 pass 104 105 106class AutoservUnsupportedError(AutoservError): 107 """Error raised when you try to use an unsupported optional feature""" 108 pass 109 110class AutoservHostError(AutoservError): 111 """Error reaching a host""" 112 pass 113 114class AutoservRebootError(AutoservError): 115 """Error occured while rebooting a machine""" 116 pass 117 118class AutoservSubcommandError(AutoservError): 119 """Indicates an error while executing a (forked) subcommand""" 120 def __init__(self, func, exit_code): 121 AutoservError.__init__(self, func, exit_code) 122 self.func = func 123 self.exit_code = exit_code 124 def __str__(self): 125 return ("Subcommand %s failed with exit code %d" % 126 (self.func, self.exit_code)) 127