blob: 642860b23beb5d7651d91f009bdb43cb4e610644 [file] [log] [blame]
mbligh906b9f72007-11-29 18:56:17 +00001"""
2Internal global error types
3"""
4
jadmanski6f731362008-06-17 16:47:06 +00005import sys, traceback
mbligh906b9f72007-11-29 18:56:17 +00006from traceback import format_exception
7
8def format_error():
jadmanski0afbb632008-06-06 21:10:57 +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
jadmanski0afbb632008-06-06 21:10:57 +000015 return ''.join(trace)
mbligh906b9f72007-11-29 18:56:17 +000016
17class JobContinue(SystemExit):
jadmanski0afbb632008-06-06 21:10:57 +000018 """Allow us to bail out requesting continuance."""
19 pass
mbligh906b9f72007-11-29 18:56:17 +000020
mbligh7e1b1502008-06-06 15:05:41 +000021
mbligh906b9f72007-11-29 18:56:17 +000022class JobComplete(SystemExit):
jadmanski0afbb632008-06-06 21:10:57 +000023 """Allow us to bail out indicating continuation not required."""
24 pass
mbligh906b9f72007-11-29 18:56:17 +000025
mbligh7e1b1502008-06-06 15:05:41 +000026
mbligh906b9f72007-11-29 18:56:17 +000027class AutotestError(Exception):
jadmanski0afbb632008-06-06 21:10:57 +000028 """The parent of all errors deliberatly thrown within the client code."""
29 pass
mbligh906b9f72007-11-29 18:56:17 +000030
mbligh7e1b1502008-06-06 15:05:41 +000031
mbligh906b9f72007-11-29 18:56:17 +000032class JobError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +000033 """Indicates an error which terminates and fails the whole job."""
34 pass
mbligh906b9f72007-11-29 18:56:17 +000035
mbligh7e1b1502008-06-06 15:05:41 +000036
mblighc2180832008-07-25 03:26:12 +000037class TestBaseException(AutotestError):
38 """The parent of all test exceptions."""
39
40
41class TestError(TestBaseException):
mblighb48fa562008-06-23 17:29:40 +000042 """Indicates that something went wrong with the test harness itself."""
43 exit_status="ERROR"
44 pass
45
jadmanski8d01bfe2008-06-23 18:13:24 +000046
mblighc2180832008-07-25 03:26:12 +000047class TestNAError(TestBaseException):
jadmanski0afbb632008-06-06 21:10:57 +000048 """Indictates that the test is Not Applicable. Should be thrown
mblighb48fa562008-06-23 17:29:40 +000049 when various conditions are such that the test is inappropriate."""
50 exit_status="TEST_NA"
51 pass
52
jadmanski8d01bfe2008-06-23 18:13:24 +000053
mblighc2180832008-07-25 03:26:12 +000054class TestFail(TestBaseException):
mblighb48fa562008-06-23 17:29:40 +000055 """Indicates that the test failed, but the job will not continue."""
56 exit_status="FAIL"
57 pass
58
jadmanski8d01bfe2008-06-23 18:13:24 +000059
mblighc2180832008-07-25 03:26:12 +000060class TestWarn(TestBaseException):
mblighb48fa562008-06-23 17:29:40 +000061 """Indicates that bad things (may) have happened, but not an explicit
62 failure."""
63 exit_status="WARN"
jadmanski0afbb632008-06-06 21:10:57 +000064 pass
mbligh6a2a2df2008-01-16 17:41:55 +000065
mbligh7e1b1502008-06-06 15:05:41 +000066
mblighc2180832008-07-25 03:26:12 +000067class UnhandledTestError(TestError):
68 """Indicates an unhandled error in a test."""
69 def __init__(self, unhandled_exception):
70 if isinstance(unhandled_exception, TestError):
71 TestError.__init__(self, *unhandled_exception.args)
72 else:
73 msg = "Unhandled %s: %s"
74 msg %= (unhandled_exception.__class__.__name__,
75 unhandled_exception)
76 msg += "\n" + traceback.format_exc()
77 TestError.__init__(self, msg)
78
79
80class UnhandledTestFail(TestFail):
81 """Indicates an unhandled fail in a test."""
82 def __init__(self, unhandled_exception):
83 if isinstance(unhandled_exception, TestFail):
84 TestFail.__init__(self, *unhandled_exception.args)
85 else:
86 msg = "Unhandled %s: %s"
87 msg %= (unhandled_exception.__class__.__name__,
88 unhandled_exception)
89 msg += "\n" + traceback.format_exc()
90 TestFail.__init__(self, msg)
91
92
mbligh906b9f72007-11-29 18:56:17 +000093class CmdError(TestError):
jadmanski0afbb632008-06-06 21:10:57 +000094 """\
95 Indicates that a command failed, is fatal to the test unless caught.
96 """
97 def __init__(self, command, result_obj, additional_text=None):
98 TestError.__init__(self, command, result_obj, additional_text)
mblighc23051c2008-06-27 19:26:46 +000099 self.command = command
100 self.result_obj = result_obj
101 self.additional_text = additional_text
mbligh6a2a2df2008-01-16 17:41:55 +0000102
103
jadmanski0afbb632008-06-06 21:10:57 +0000104 def __str__(self):
mblighc23051c2008-06-27 19:26:46 +0000105 msg = "Command <%s> failed, rc=%d" % (self.command,
106 self.result_obj.exit_status)
107 if self.additional_text:
108 msg += ", " + self.additional_text
jadmanski0afbb632008-06-06 21:10:57 +0000109 return msg
mbligh906b9f72007-11-29 18:56:17 +0000110
mbligh7e1b1502008-06-06 15:05:41 +0000111
mbligh906b9f72007-11-29 18:56:17 +0000112class PackageError(TestError):
jadmanski0afbb632008-06-06 21:10:57 +0000113 """Indicates an error trying to perform a package operation."""
114 pass
mbligh906b9f72007-11-29 18:56:17 +0000115
mbligh7e1b1502008-06-06 15:05:41 +0000116
mblighe8673102008-07-16 14:09:03 +0000117class BarrierError(JobError):
118 """Indicates an error happened during a barrier operation."""
119 pass
120
121
mbligh5deff3d2008-01-04 21:21:28 +0000122class InstallError(JobError):
jadmanski0afbb632008-06-06 21:10:57 +0000123 """Indicates an installation error which Terminates and fails the job."""
124 pass
mbligh03f4fc72007-11-29 20:56:14 +0000125
mbligh7e1b1502008-06-06 15:05:41 +0000126
mbligh6f015c42008-02-12 20:55:03 +0000127class AutotestRunError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +0000128 pass
mbligh6f015c42008-02-12 20:55:03 +0000129
mbligh7e1b1502008-06-06 15:05:41 +0000130
mbligh6f015c42008-02-12 20:55:03 +0000131class AutotestTimeoutError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +0000132 """This exception is raised when an autotest test exceeds the timeout
133 parameter passed to run_timed_test and is killed.
134 """
mbligh6f015c42008-02-12 20:55:03 +0000135
136
mbligh03f4fc72007-11-29 20:56:14 +0000137# server-specific errors
138
139class AutoservError(Exception):
jadmanski0afbb632008-06-06 21:10:57 +0000140 pass
mbligh03f4fc72007-11-29 20:56:14 +0000141
142
mbligh34faa282008-01-16 17:44:49 +0000143class AutoservSSHTimeout(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000144 """SSH experienced a connection timeout"""
145 pass
mbligh34faa282008-01-16 17:44:49 +0000146
147
mbligh03f4fc72007-11-29 20:56:14 +0000148class AutoservRunError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000149 """\
150 Errors raised by one of the run functions. Should always be
151 constructed with a tuple of two args (error description (str),
152 run result object).
153 """
154 def __init__(self, description, result_obj):
155 AutoservError.__init__(self, description, result_obj)
mbligh03f4fc72007-11-29 20:56:14 +0000156
157
158class AutoservVirtError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000159 """Vitualization related error"""
160 pass
mbligh03f4fc72007-11-29 20:56:14 +0000161
162
163class AutoservUnsupportedError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000164 """Error raised when you try to use an unsupported optional feature"""
165 pass
mbligh03f4fc72007-11-29 20:56:14 +0000166
mbligh7e1b1502008-06-06 15:05:41 +0000167
mbligh03f4fc72007-11-29 20:56:14 +0000168class AutoservHostError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000169 """Error reaching a host"""
170 pass
mbligh03f4fc72007-11-29 20:56:14 +0000171
mbligh7e1b1502008-06-06 15:05:41 +0000172
mbligh03f4fc72007-11-29 20:56:14 +0000173class AutoservRebootError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000174 """Error occured while rebooting a machine"""
175 pass
mbligh6e2ffec2008-03-05 16:08:34 +0000176
mbligh7e1b1502008-06-06 15:05:41 +0000177
mbligh6e2ffec2008-03-05 16:08:34 +0000178class AutoservSubcommandError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000179 """Indicates an error while executing a (forked) subcommand"""
180 def __init__(self, func, exit_code):
181 AutoservError.__init__(self, func, exit_code)
182 self.func = func
183 self.exit_code = exit_code
mbligh7e1b1502008-06-06 15:05:41 +0000184
jadmanski0afbb632008-06-06 21:10:57 +0000185 def __str__(self):
186 return ("Subcommand %s failed with exit code %d" %
187 (self.func, self.exit_code))