blob: 60425af9ced1db478f76450ecb11a182114dd7d6 [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
mbligh5deff3d2008-01-04 21:21:28 +0000146class InstallError(JobError):
jadmanski0afbb632008-06-06 21:10:57 +0000147 """Indicates an installation error which Terminates and fails the job."""
148 pass
mbligh03f4fc72007-11-29 20:56:14 +0000149
mbligh7e1b1502008-06-06 15:05:41 +0000150
mbligh6f015c42008-02-12 20:55:03 +0000151class AutotestRunError(AutotestError):
mbligh021679f2008-11-27 00:43:19 +0000152 """Indicates a problem running server side control files."""
jadmanski0afbb632008-06-06 21:10:57 +0000153 pass
mbligh6f015c42008-02-12 20:55:03 +0000154
mbligh7e1b1502008-06-06 15:05:41 +0000155
mbligh6f015c42008-02-12 20:55:03 +0000156class AutotestTimeoutError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +0000157 """This exception is raised when an autotest test exceeds the timeout
158 parameter passed to run_timed_test and is killed.
159 """
mbligh6f015c42008-02-12 20:55:03 +0000160
161
mbligh03f4fc72007-11-29 20:56:14 +0000162# server-specific errors
163
164class AutoservError(Exception):
jadmanski0afbb632008-06-06 21:10:57 +0000165 pass
mbligh03f4fc72007-11-29 20:56:14 +0000166
167
mbligh34faa282008-01-16 17:44:49 +0000168class AutoservSSHTimeout(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000169 """SSH experienced a connection timeout"""
170 pass
mbligh34faa282008-01-16 17:44:49 +0000171
172
mbligh03f4fc72007-11-29 20:56:14 +0000173class AutoservRunError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000174 """\
175 Errors raised by one of the run functions. Should always be
176 constructed with a tuple of two args (error description (str),
177 run result object).
178 """
179 def __init__(self, description, result_obj):
showard6d7e94f2008-08-20 20:53:34 +0000180 self.description = description
181 self.result_obj = result_obj
jadmanski0afbb632008-06-06 21:10:57 +0000182 AutoservError.__init__(self, description, result_obj)
mbligh03f4fc72007-11-29 20:56:14 +0000183
showard6d7e94f2008-08-20 20:53:34 +0000184 def __str__(self):
185 return self.description + '\n' + repr(self.result_obj)
186
mbligh03f4fc72007-11-29 20:56:14 +0000187
mbligh9d738d62009-03-09 21:17:10 +0000188class AutoservSshPermissionDeniedError(AutoservRunError):
189 """Indicates that a SSH permission denied error was encountered."""
190 pass
191
192
mbligh03f4fc72007-11-29 20:56:14 +0000193class AutoservVirtError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000194 """Vitualization related error"""
195 pass
mbligh03f4fc72007-11-29 20:56:14 +0000196
197
198class AutoservUnsupportedError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000199 """Error raised when you try to use an unsupported optional feature"""
200 pass
mbligh03f4fc72007-11-29 20:56:14 +0000201
mbligh7e1b1502008-06-06 15:05:41 +0000202
mbligh03f4fc72007-11-29 20:56:14 +0000203class AutoservHostError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000204 """Error reaching a host"""
205 pass
mbligh03f4fc72007-11-29 20:56:14 +0000206
mbligh7e1b1502008-06-06 15:05:41 +0000207
mblighc971c5f2009-06-08 16:48:54 +0000208class AutoservHostIsShuttingDownError(AutoservHostError):
209 """Host is shutting down"""
210 pass
211
212
213class AutoservNotMountedHostError(AutoservHostError):
214 """Found unmounted partitions that should be mounted"""
215 pass
216
217
218class AutoservSshPingHostError(AutoservHostError):
219 """SSH ping failed"""
220 pass
221
222
223class AutoservDiskFullHostError(AutoservHostError):
224 """Not enough free disk space on host"""
225 def __init__(self, path, want_gb, free_space_gb):
226 AutoservHostError.__init__(self,
227 'Not enough free space on %s - %.3fGB free, want %.3fGB' %
228 (path, free_space_gb, want_gb))
229
230 self.path = path
231 self.want_gb = want_gb
232 self.free_space_gb = free_space_gb
233
234
235class AutoservHardwareHostError(AutoservHostError):
236 """Found hardware problems with the host"""
237 pass
238
239
mbligh03f4fc72007-11-29 20:56:14 +0000240class AutoservRebootError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000241 """Error occured while rebooting a machine"""
242 pass
mbligh6e2ffec2008-03-05 16:08:34 +0000243
mbligh7e1b1502008-06-06 15:05:41 +0000244
jadmanski65eb8f52009-07-24 18:34:43 +0000245class AutoservShutdownError(AutoservRebootError):
246 """Error occured during shutdown of machine"""
247 pass
248
249
mbligh6e2ffec2008-03-05 16:08:34 +0000250class AutoservSubcommandError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000251 """Indicates an error while executing a (forked) subcommand"""
252 def __init__(self, func, exit_code):
253 AutoservError.__init__(self, func, exit_code)
254 self.func = func
255 self.exit_code = exit_code
mbligh7e1b1502008-06-06 15:05:41 +0000256
jadmanski0afbb632008-06-06 21:10:57 +0000257 def __str__(self):
258 return ("Subcommand %s failed with exit code %d" %
259 (self.func, self.exit_code))
mbligh91672252008-10-16 22:28:34 +0000260
261
mbligh25c0b8c2009-01-24 01:44:17 +0000262class AutoservHardwareRepairRequestedError(AutoservError):
263 """
264 Exception class raised from Host.repair_full() (or overrides) when software
265 repair fails but it successfully managed to request a hardware repair (by
266 notifying the staff, sending mail, etc)
267 """
268 pass
269
270
mbligh91672252008-10-16 22:28:34 +0000271# This MUST remain at the end of the file.
272# Limit 'from error import *' to only import the exception instances.
273for _name, _thing in locals().items():
274 try:
275 if issubclass(_thing, Exception):
276 __all__.append(_name)
277 except TypeError:
278 pass # _thing not a class
279__all__ = tuple(__all__)