error.py revision 6e2ffec8a247d84271dc86a1551c3ad543475d0f
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 37 38class CmdError(TestError): 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 46 def __str__(self): 47 return "Command <" + self.args[0] + "> failed, rc=%d" % (self.args[1]) 48 49class PackageError(TestError): 50 """Indicates an error trying to perform a package operation.""" 51 pass 52 53class 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) 58 59class InstallError(JobError): 60 """Indicates an installation error which Terminates and fails the job.""" 61 pass 62 63class AutotestRunError(AutotestError): 64 pass 65 66class AutotestTimeoutError(AutotestError): 67 """This exception is raised when an autotest test exceeds the timeout 68 parameter passed to run_timed_test and is killed. 69 """ 70 71 72# server-specific errors 73 74class AutoservError(Exception): 75 pass 76 77 78class AutoservSSHTimeout(AutoservError): 79 """SSH experienced a connection timeout""" 80 pass 81 82 83class AutoservRunError(AutoservError): 84 """\ 85 Errors raised by one of the run functions. Should always be 86 constructed with a tuple of two args (error description (str), 87 run result object). 88 """ 89 def __init__(self, description, result_obj): 90 AutoservError.__init__(self, description, result_obj) 91 92 93class AutoservVirtError(AutoservError): 94 """Vitualization related error""" 95 pass 96 97 98class AutoservUnsupportedError(AutoservError): 99 """Error raised when you try to use an unsupported optional feature""" 100 pass 101 102class AutoservHostError(AutoservError): 103 """Error reaching a host""" 104 pass 105 106class AutoservRebootError(AutoservError): 107 """Error occured while rebooting a machine""" 108 pass 109 110class AutoservSubcommandError(AutoservError): 111 """Indicates an error while executing a (forked) subcommand""" 112 def __init__(self, func, exit_code): 113 AutoservError.__init__(self, func, exit_code) 114 self.func = func 115 self.exit_code = exit_code 116 def __str__(self): 117 return ("Subcommand %s failed with exit code %d" % 118 self.func, self.exit_code) 119