blob: b5148ec67a60f92a6d2f7de8766e9fdae415cefa [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."""
jadmanskif2171e22008-07-28 17:23:49 +000039 pass
mblighc2180832008-07-25 03:26:12 +000040
41
42class TestError(TestBaseException):
mblighb48fa562008-06-23 17:29:40 +000043 """Indicates that something went wrong with the test harness itself."""
44 exit_status="ERROR"
45 pass
46
jadmanski8d01bfe2008-06-23 18:13:24 +000047
mblighc2180832008-07-25 03:26:12 +000048class TestNAError(TestBaseException):
jadmanski0afbb632008-06-06 21:10:57 +000049 """Indictates that the test is Not Applicable. Should be thrown
mblighb48fa562008-06-23 17:29:40 +000050 when various conditions are such that the test is inappropriate."""
51 exit_status="TEST_NA"
52 pass
53
jadmanski8d01bfe2008-06-23 18:13:24 +000054
mblighc2180832008-07-25 03:26:12 +000055class TestFail(TestBaseException):
mblighb48fa562008-06-23 17:29:40 +000056 """Indicates that the test failed, but the job will not continue."""
57 exit_status="FAIL"
58 pass
59
jadmanski8d01bfe2008-06-23 18:13:24 +000060
mblighc2180832008-07-25 03:26:12 +000061class TestWarn(TestBaseException):
mblighb48fa562008-06-23 17:29:40 +000062 """Indicates that bad things (may) have happened, but not an explicit
63 failure."""
64 exit_status="WARN"
jadmanski0afbb632008-06-06 21:10:57 +000065 pass
mbligh6a2a2df2008-01-16 17:41:55 +000066
mbligh7e1b1502008-06-06 15:05:41 +000067
mblighc2180832008-07-25 03:26:12 +000068class UnhandledTestError(TestError):
69 """Indicates an unhandled error in a test."""
70 def __init__(self, unhandled_exception):
71 if isinstance(unhandled_exception, TestError):
72 TestError.__init__(self, *unhandled_exception.args)
73 else:
74 msg = "Unhandled %s: %s"
75 msg %= (unhandled_exception.__class__.__name__,
76 unhandled_exception)
77 msg += "\n" + traceback.format_exc()
78 TestError.__init__(self, msg)
79
80
81class UnhandledTestFail(TestFail):
82 """Indicates an unhandled fail in a test."""
83 def __init__(self, unhandled_exception):
84 if isinstance(unhandled_exception, TestFail):
85 TestFail.__init__(self, *unhandled_exception.args)
86 else:
87 msg = "Unhandled %s: %s"
88 msg %= (unhandled_exception.__class__.__name__,
89 unhandled_exception)
90 msg += "\n" + traceback.format_exc()
91 TestFail.__init__(self, msg)
92
93
mbligh906b9f72007-11-29 18:56:17 +000094class CmdError(TestError):
jadmanski0afbb632008-06-06 21:10:57 +000095 """\
96 Indicates that a command failed, is fatal to the test unless caught.
97 """
98 def __init__(self, command, result_obj, additional_text=None):
99 TestError.__init__(self, command, result_obj, additional_text)
mblighc23051c2008-06-27 19:26:46 +0000100 self.command = command
101 self.result_obj = result_obj
102 self.additional_text = additional_text
mbligh6a2a2df2008-01-16 17:41:55 +0000103
104
jadmanski0afbb632008-06-06 21:10:57 +0000105 def __str__(self):
jadmanski6ef0b672008-09-30 22:50:19 +0000106 if self.result_obj.exit_status is None:
107 msg = "Command <%s> failed and is not responding to signals"
108 msg %= self.command
109 else:
110 msg = "Command <%s> failed, rc=%d"
111 msg %= (self.command, self.result_obj.exit_status)
112
mblighc23051c2008-06-27 19:26:46 +0000113 if self.additional_text:
114 msg += ", " + self.additional_text
showard6d7e94f2008-08-20 20:53:34 +0000115 msg += '\n' + repr(self.result_obj)
jadmanski0afbb632008-06-06 21:10:57 +0000116 return msg
mbligh906b9f72007-11-29 18:56:17 +0000117
mbligh7e1b1502008-06-06 15:05:41 +0000118
mbligh906b9f72007-11-29 18:56:17 +0000119class PackageError(TestError):
jadmanski0afbb632008-06-06 21:10:57 +0000120 """Indicates an error trying to perform a package operation."""
121 pass
mbligh906b9f72007-11-29 18:56:17 +0000122
mbligh7e1b1502008-06-06 15:05:41 +0000123
mblighe8673102008-07-16 14:09:03 +0000124class BarrierError(JobError):
125 """Indicates an error happened during a barrier operation."""
126 pass
127
128
mbligh5deff3d2008-01-04 21:21:28 +0000129class InstallError(JobError):
jadmanski0afbb632008-06-06 21:10:57 +0000130 """Indicates an installation error which Terminates and fails the job."""
131 pass
mbligh03f4fc72007-11-29 20:56:14 +0000132
mbligh7e1b1502008-06-06 15:05:41 +0000133
mbligh6f015c42008-02-12 20:55:03 +0000134class AutotestRunError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +0000135 pass
mbligh6f015c42008-02-12 20:55:03 +0000136
mbligh7e1b1502008-06-06 15:05:41 +0000137
mbligh6f015c42008-02-12 20:55:03 +0000138class AutotestTimeoutError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +0000139 """This exception is raised when an autotest test exceeds the timeout
140 parameter passed to run_timed_test and is killed.
141 """
mbligh6f015c42008-02-12 20:55:03 +0000142
143
mbligh03f4fc72007-11-29 20:56:14 +0000144# server-specific errors
145
146class AutoservError(Exception):
jadmanski0afbb632008-06-06 21:10:57 +0000147 pass
mbligh03f4fc72007-11-29 20:56:14 +0000148
149
mbligh34faa282008-01-16 17:44:49 +0000150class AutoservSSHTimeout(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000151 """SSH experienced a connection timeout"""
152 pass
mbligh34faa282008-01-16 17:44:49 +0000153
154
mbligh03f4fc72007-11-29 20:56:14 +0000155class AutoservRunError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000156 """\
157 Errors raised by one of the run functions. Should always be
158 constructed with a tuple of two args (error description (str),
159 run result object).
160 """
161 def __init__(self, description, result_obj):
showard6d7e94f2008-08-20 20:53:34 +0000162 self.description = description
163 self.result_obj = result_obj
jadmanski0afbb632008-06-06 21:10:57 +0000164 AutoservError.__init__(self, description, result_obj)
mbligh03f4fc72007-11-29 20:56:14 +0000165
showard6d7e94f2008-08-20 20:53:34 +0000166 def __str__(self):
167 return self.description + '\n' + repr(self.result_obj)
168
mbligh03f4fc72007-11-29 20:56:14 +0000169
170class AutoservVirtError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000171 """Vitualization related error"""
172 pass
mbligh03f4fc72007-11-29 20:56:14 +0000173
174
175class AutoservUnsupportedError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000176 """Error raised when you try to use an unsupported optional feature"""
177 pass
mbligh03f4fc72007-11-29 20:56:14 +0000178
mbligh7e1b1502008-06-06 15:05:41 +0000179
mbligh03f4fc72007-11-29 20:56:14 +0000180class AutoservHostError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000181 """Error reaching a host"""
182 pass
mbligh03f4fc72007-11-29 20:56:14 +0000183
mbligh7e1b1502008-06-06 15:05:41 +0000184
mbligh03f4fc72007-11-29 20:56:14 +0000185class AutoservRebootError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000186 """Error occured while rebooting a machine"""
187 pass
mbligh6e2ffec2008-03-05 16:08:34 +0000188
mbligh7e1b1502008-06-06 15:05:41 +0000189
mbligh6e2ffec2008-03-05 16:08:34 +0000190class AutoservSubcommandError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000191 """Indicates an error while executing a (forked) subcommand"""
192 def __init__(self, func, exit_code):
193 AutoservError.__init__(self, func, exit_code)
194 self.func = func
195 self.exit_code = exit_code
mbligh7e1b1502008-06-06 15:05:41 +0000196
jadmanski0afbb632008-06-06 21:10:57 +0000197 def __str__(self):
198 return ("Subcommand %s failed with exit code %d" %
199 (self.func, self.exit_code))