blob: 94ac4761042bda42980d9add45937e7a2fb07684 [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
mbligh91672252008-10-16 22:28:34 +00008# Add names you want to be imported by 'from errors import *' to this list.
9# This must be list not a tuple as we modify it to include all of our
10# the Exception classes we define below at the end of this file.
11__all__ = ['format_error']
12
13
mbligh906b9f72007-11-29 18:56:17 +000014def format_error():
jadmanski0afbb632008-06-06 21:10:57 +000015 t, o, tb = sys.exc_info()
16 trace = format_exception(t, o, tb)
17 # Clear the backtrace to prevent a circular reference
18 # in the heap -- as per tutorial
19 tb = ''
mbligh906b9f72007-11-29 18:56:17 +000020
jadmanski0afbb632008-06-06 21:10:57 +000021 return ''.join(trace)
mbligh906b9f72007-11-29 18:56:17 +000022
mbligh4f407462008-12-03 15:22:39 +000023
mbligh906b9f72007-11-29 18:56:17 +000024class JobContinue(SystemExit):
jadmanski0afbb632008-06-06 21:10:57 +000025 """Allow us to bail out requesting continuance."""
26 pass
mbligh906b9f72007-11-29 18:56:17 +000027
mbligh7e1b1502008-06-06 15:05:41 +000028
mbligh906b9f72007-11-29 18:56:17 +000029class JobComplete(SystemExit):
jadmanski0afbb632008-06-06 21:10:57 +000030 """Allow us to bail out indicating continuation not required."""
31 pass
mbligh906b9f72007-11-29 18:56:17 +000032
mbligh7e1b1502008-06-06 15:05:41 +000033
mbligh906b9f72007-11-29 18:56:17 +000034class AutotestError(Exception):
jadmanski0afbb632008-06-06 21:10:57 +000035 """The parent of all errors deliberatly thrown within the client code."""
36 pass
mbligh906b9f72007-11-29 18:56:17 +000037
mbligh7e1b1502008-06-06 15:05:41 +000038
mbligh906b9f72007-11-29 18:56:17 +000039class JobError(AutotestError):
mbligh4f407462008-12-03 15:22:39 +000040 """Indicates an error which terminates and fails the whole job (ABORT)."""
jadmanski0afbb632008-06-06 21:10:57 +000041 pass
mbligh906b9f72007-11-29 18:56:17 +000042
mbligh7e1b1502008-06-06 15:05:41 +000043
mbligh4f407462008-12-03 15:22:39 +000044class UnhandledJobError(JobError):
45 """Indicates an unhandled error in a job."""
46 def __init__(self, unhandled_exception):
47 if isinstance(unhandled_exception, JobError):
mbligh1ca1c2c2008-12-09 23:38:25 +000048 JobError.__init__(self, *unhandled_exception.args)
mbligh4f407462008-12-03 15:22:39 +000049 else:
50 msg = "Unhandled %s: %s"
51 msg %= (unhandled_exception.__class__.__name__,
52 unhandled_exception)
53 msg += "\n" + traceback.format_exc()
54 JobError.__init__(self, msg)
55
56
mblighc2180832008-07-25 03:26:12 +000057class TestBaseException(AutotestError):
58 """The parent of all test exceptions."""
mbligh021679f2008-11-27 00:43:19 +000059 # Children are required to override this. Never instantiate directly.
60 exit_status="NEVER_RAISE_THIS"
mblighc2180832008-07-25 03:26:12 +000061
62
63class TestError(TestBaseException):
mblighb48fa562008-06-23 17:29:40 +000064 """Indicates that something went wrong with the test harness itself."""
65 exit_status="ERROR"
mblighb48fa562008-06-23 17:29:40 +000066
jadmanski8d01bfe2008-06-23 18:13:24 +000067
mblighc2180832008-07-25 03:26:12 +000068class TestNAError(TestBaseException):
jadmanski0afbb632008-06-06 21:10:57 +000069 """Indictates that the test is Not Applicable. Should be thrown
mblighb48fa562008-06-23 17:29:40 +000070 when various conditions are such that the test is inappropriate."""
71 exit_status="TEST_NA"
mblighb48fa562008-06-23 17:29:40 +000072
jadmanski8d01bfe2008-06-23 18:13:24 +000073
mblighc2180832008-07-25 03:26:12 +000074class TestFail(TestBaseException):
mblighb48fa562008-06-23 17:29:40 +000075 """Indicates that the test failed, but the job will not continue."""
76 exit_status="FAIL"
mblighb48fa562008-06-23 17:29:40 +000077
jadmanski8d01bfe2008-06-23 18:13:24 +000078
mblighc2180832008-07-25 03:26:12 +000079class TestWarn(TestBaseException):
mblighb48fa562008-06-23 17:29:40 +000080 """Indicates that bad things (may) have happened, but not an explicit
81 failure."""
82 exit_status="WARN"
mbligh6a2a2df2008-01-16 17:41:55 +000083
mbligh7e1b1502008-06-06 15:05:41 +000084
mblighc2180832008-07-25 03:26:12 +000085class UnhandledTestError(TestError):
86 """Indicates an unhandled error in a test."""
87 def __init__(self, unhandled_exception):
88 if isinstance(unhandled_exception, TestError):
89 TestError.__init__(self, *unhandled_exception.args)
90 else:
91 msg = "Unhandled %s: %s"
92 msg %= (unhandled_exception.__class__.__name__,
93 unhandled_exception)
94 msg += "\n" + traceback.format_exc()
95 TestError.__init__(self, msg)
96
97
98class UnhandledTestFail(TestFail):
99 """Indicates an unhandled fail in a test."""
100 def __init__(self, unhandled_exception):
101 if isinstance(unhandled_exception, TestFail):
102 TestFail.__init__(self, *unhandled_exception.args)
103 else:
104 msg = "Unhandled %s: %s"
105 msg %= (unhandled_exception.__class__.__name__,
106 unhandled_exception)
107 msg += "\n" + traceback.format_exc()
108 TestFail.__init__(self, msg)
109
110
mbligh906b9f72007-11-29 18:56:17 +0000111class CmdError(TestError):
jadmanski0afbb632008-06-06 21:10:57 +0000112 """\
113 Indicates that a command failed, is fatal to the test unless caught.
114 """
115 def __init__(self, command, result_obj, additional_text=None):
116 TestError.__init__(self, command, result_obj, additional_text)
mblighc23051c2008-06-27 19:26:46 +0000117 self.command = command
118 self.result_obj = result_obj
119 self.additional_text = additional_text
mbligh6a2a2df2008-01-16 17:41:55 +0000120
121
jadmanski0afbb632008-06-06 21:10:57 +0000122 def __str__(self):
jadmanski6ef0b672008-09-30 22:50:19 +0000123 if self.result_obj.exit_status is None:
124 msg = "Command <%s> failed and is not responding to signals"
125 msg %= self.command
126 else:
127 msg = "Command <%s> failed, rc=%d"
128 msg %= (self.command, self.result_obj.exit_status)
129
mblighc23051c2008-06-27 19:26:46 +0000130 if self.additional_text:
131 msg += ", " + self.additional_text
showard6d7e94f2008-08-20 20:53:34 +0000132 msg += '\n' + repr(self.result_obj)
jadmanski0afbb632008-06-06 21:10:57 +0000133 return msg
mbligh906b9f72007-11-29 18:56:17 +0000134
mbligh7e1b1502008-06-06 15:05:41 +0000135
mbligh906b9f72007-11-29 18:56:17 +0000136class PackageError(TestError):
jadmanski0afbb632008-06-06 21:10:57 +0000137 """Indicates an error trying to perform a package operation."""
138 pass
mbligh906b9f72007-11-29 18:56:17 +0000139
mbligh7e1b1502008-06-06 15:05:41 +0000140
mblighe8673102008-07-16 14:09:03 +0000141class BarrierError(JobError):
142 """Indicates an error happened during a barrier operation."""
143 pass
144
145
mbligh999fb132010-04-23 17:22:03 +0000146class BarrierAbortError(BarrierError):
147 """Indicate that the barrier was explicitly aborted by a member."""
148 pass
149
150
mbligh5deff3d2008-01-04 21:21:28 +0000151class InstallError(JobError):
jadmanski0afbb632008-06-06 21:10:57 +0000152 """Indicates an installation error which Terminates and fails the job."""
153 pass
mbligh03f4fc72007-11-29 20:56:14 +0000154
mbligh7e1b1502008-06-06 15:05:41 +0000155
mbligh6f015c42008-02-12 20:55:03 +0000156class AutotestRunError(AutotestError):
mbligh021679f2008-11-27 00:43:19 +0000157 """Indicates a problem running server side control files."""
jadmanski0afbb632008-06-06 21:10:57 +0000158 pass
mbligh6f015c42008-02-12 20:55:03 +0000159
mbligh7e1b1502008-06-06 15:05:41 +0000160
mbligh6f015c42008-02-12 20:55:03 +0000161class AutotestTimeoutError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +0000162 """This exception is raised when an autotest test exceeds the timeout
163 parameter passed to run_timed_test and is killed.
164 """
mbligh6f015c42008-02-12 20:55:03 +0000165
166
mblighce955fc2009-08-24 21:59:02 +0000167class HostRunErrorMixIn(Exception):
168 """
169 Indicates a problem in the host run() function raised from client code.
170 Should always be constructed with a tuple of two args (error description
171 (str), run result object). This is a common class mixed in to create the
172 client and server side versions of it.
173 """
174 def __init__(self, description, result_obj):
175 self.description = description
176 self.result_obj = result_obj
177 Exception.__init__(self, description, result_obj)
178
179 def __str__(self):
180 return self.description + '\n' + repr(self.result_obj)
181
182
183class AutotestHostRunError(HostRunErrorMixIn, AutotestError):
184 pass
185
186
mbligh03f4fc72007-11-29 20:56:14 +0000187# server-specific errors
188
189class AutoservError(Exception):
jadmanski0afbb632008-06-06 21:10:57 +0000190 pass
mbligh03f4fc72007-11-29 20:56:14 +0000191
192
mbligh34faa282008-01-16 17:44:49 +0000193class AutoservSSHTimeout(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000194 """SSH experienced a connection timeout"""
195 pass
mbligh34faa282008-01-16 17:44:49 +0000196
197
mblighce955fc2009-08-24 21:59:02 +0000198class AutoservRunError(HostRunErrorMixIn, AutoservError):
199 pass
showard6d7e94f2008-08-20 20:53:34 +0000200
mbligh03f4fc72007-11-29 20:56:14 +0000201
mbligh9d738d62009-03-09 21:17:10 +0000202class AutoservSshPermissionDeniedError(AutoservRunError):
203 """Indicates that a SSH permission denied error was encountered."""
204 pass
205
206
mbligh03f4fc72007-11-29 20:56:14 +0000207class AutoservVirtError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000208 """Vitualization related error"""
209 pass
mbligh03f4fc72007-11-29 20:56:14 +0000210
211
212class AutoservUnsupportedError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000213 """Error raised when you try to use an unsupported optional feature"""
214 pass
mbligh03f4fc72007-11-29 20:56:14 +0000215
mbligh7e1b1502008-06-06 15:05:41 +0000216
mbligh03f4fc72007-11-29 20:56:14 +0000217class AutoservHostError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000218 """Error reaching a host"""
219 pass
mbligh03f4fc72007-11-29 20:56:14 +0000220
mbligh7e1b1502008-06-06 15:05:41 +0000221
mblighc971c5f2009-06-08 16:48:54 +0000222class AutoservHostIsShuttingDownError(AutoservHostError):
223 """Host is shutting down"""
224 pass
225
226
227class AutoservNotMountedHostError(AutoservHostError):
228 """Found unmounted partitions that should be mounted"""
229 pass
230
231
232class AutoservSshPingHostError(AutoservHostError):
233 """SSH ping failed"""
234 pass
235
236
237class AutoservDiskFullHostError(AutoservHostError):
238 """Not enough free disk space on host"""
239 def __init__(self, path, want_gb, free_space_gb):
240 AutoservHostError.__init__(self,
241 'Not enough free space on %s - %.3fGB free, want %.3fGB' %
242 (path, free_space_gb, want_gb))
243
244 self.path = path
245 self.want_gb = want_gb
246 self.free_space_gb = free_space_gb
247
248
249class AutoservHardwareHostError(AutoservHostError):
250 """Found hardware problems with the host"""
251 pass
252
253
mbligh03f4fc72007-11-29 20:56:14 +0000254class AutoservRebootError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000255 """Error occured while rebooting a machine"""
256 pass
mbligh6e2ffec2008-03-05 16:08:34 +0000257
mbligh7e1b1502008-06-06 15:05:41 +0000258
jadmanski65eb8f52009-07-24 18:34:43 +0000259class AutoservShutdownError(AutoservRebootError):
260 """Error occured during shutdown of machine"""
261 pass
262
263
mbligh6e2ffec2008-03-05 16:08:34 +0000264class AutoservSubcommandError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000265 """Indicates an error while executing a (forked) subcommand"""
266 def __init__(self, func, exit_code):
267 AutoservError.__init__(self, func, exit_code)
268 self.func = func
269 self.exit_code = exit_code
mbligh7e1b1502008-06-06 15:05:41 +0000270
jadmanski0afbb632008-06-06 21:10:57 +0000271 def __str__(self):
272 return ("Subcommand %s failed with exit code %d" %
273 (self.func, self.exit_code))
mbligh91672252008-10-16 22:28:34 +0000274
275
mbligh25c0b8c2009-01-24 01:44:17 +0000276class AutoservHardwareRepairRequestedError(AutoservError):
277 """
278 Exception class raised from Host.repair_full() (or overrides) when software
279 repair fails but it successfully managed to request a hardware repair (by
280 notifying the staff, sending mail, etc)
281 """
282 pass
283
284
jadmanskic1dda212009-11-18 19:22:00 +0000285class AutoservInstallError(AutoservError):
286 """Error occured while installing autotest on a host"""
287 pass
288
289
jadmanskic27c2312009-08-05 20:58:51 +0000290# packaging system errors
291
292class PackagingError(AutotestError):
293 'Abstract error class for all packaging related errors.'
294
295
296class PackageUploadError(PackagingError):
297 'Raised when there is an error uploading the package'
298
299
300class PackageFetchError(PackagingError):
301 'Raised when there is an error fetching the package'
302
303
304class PackageRemoveError(PackagingError):
305 'Raised when there is an error removing the package'
306
307
308class PackageInstallError(PackagingError):
309 'Raised when there is an error installing the package'
310
311
312class RepoDiskFullError(PackagingError):
313 'Raised when the destination for packages is full'
314
315
316class RepoWriteError(PackagingError):
317 "Raised when packager cannot write to a repo's desitnation"
318
319
320class RepoUnknownError(PackagingError):
321 "Raised when packager cannot write to a repo's desitnation"
322
323
324class RepoError(PackagingError):
325 "Raised when a repo isn't working in some way"
326
327
mbligh91672252008-10-16 22:28:34 +0000328# This MUST remain at the end of the file.
329# Limit 'from error import *' to only import the exception instances.
330for _name, _thing in locals().items():
331 try:
332 if issubclass(_thing, Exception):
333 __all__.append(_name)
334 except TypeError:
335 pass # _thing not a class
336__all__ = tuple(__all__)