blob: 0051cdb1783c2476da3a64885f3cb4a3c3be0399 [file] [log] [blame]
mbligh906b9f72007-11-29 18:56:17 +00001"""
2Internal global error types
3"""
4
5import sys
6from traceback import format_exception
7
8def format_error():
mbligh642b03e2008-01-14 16:53:15 +00009 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 = ''
mbligh906b9f72007-11-29 18:56:17 +000014
mbligh642b03e2008-01-14 16:53:15 +000015 return ''.join(trace)
mbligh906b9f72007-11-29 18:56:17 +000016
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
mbligh302482e2008-05-01 20:06:16 +000037class 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
mbligh6a2a2df2008-01-16 17:41:55 +000041
mbligh906b9f72007-11-29 18:56:17 +000042class CmdError(TestError):
mbligh6a2a2df2008-01-16 17:41:55 +000043 """\
44 Indicates that a command failed, is fatal to the test unless caught.
45 """
jadmanskid93d7d22008-05-29 21:37:29 +000046 def __init__(self, command, result_obj, additional_text=None):
47 TestError.__init__(self, command, result_obj, additional_text)
mbligh6a2a2df2008-01-16 17:41:55 +000048
49
mbligh906b9f72007-11-29 18:56:17 +000050 def __str__(self):
jadmanskid93d7d22008-05-29 21:37:29 +000051 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
mbligh906b9f72007-11-29 18:56:17 +000056
57class PackageError(TestError):
mbligh642b03e2008-01-14 16:53:15 +000058 """Indicates an error trying to perform a package operation."""
59 pass
mbligh906b9f72007-11-29 18:56:17 +000060
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)
mbligh03f4fc72007-11-29 20:56:14 +000066
mbligh5deff3d2008-01-04 21:21:28 +000067class InstallError(JobError):
68 """Indicates an installation error which Terminates and fails the job."""
69 pass
mbligh03f4fc72007-11-29 20:56:14 +000070
mbligh6f015c42008-02-12 20:55:03 +000071class 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
mbligh03f4fc72007-11-29 20:56:14 +000080# server-specific errors
81
82class AutoservError(Exception):
83 pass
84
85
mbligh34faa282008-01-16 17:44:49 +000086class AutoservSSHTimeout(AutoservError):
87 """SSH experienced a connection timeout"""
88 pass
89
90
mbligh03f4fc72007-11-29 20:56:14 +000091class AutoservRunError(AutoservError):
mbligh6a2a2df2008-01-16 17:41:55 +000092 """\
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)
mbligh03f4fc72007-11-29 20:56:14 +000099
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
mbligh6e2ffec2008-03-05 16:08:34 +0000117
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" %
mbligh158ba7b2008-03-07 18:29:12 +0000126 (self.func, self.exit_code))