blob: f4be0001b46e8187014868553799da151d7a6328 [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 JobNAError(JobError):
45 """Indicates an error to skip this part of the whole job or fail it if
46 this was not a multi-step job."""
47 pass
48
49
50class UnhandledJobError(JobError):
51 """Indicates an unhandled error in a job."""
52 def __init__(self, unhandled_exception):
53 if isinstance(unhandled_exception, JobError):
54 TestError.__init__(self, *unhandled_exception.args)
55 else:
56 msg = "Unhandled %s: %s"
57 msg %= (unhandled_exception.__class__.__name__,
58 unhandled_exception)
59 msg += "\n" + traceback.format_exc()
60 JobError.__init__(self, msg)
61
62
mblighc2180832008-07-25 03:26:12 +000063class TestBaseException(AutotestError):
64 """The parent of all test exceptions."""
mbligh021679f2008-11-27 00:43:19 +000065 # Children are required to override this. Never instantiate directly.
66 exit_status="NEVER_RAISE_THIS"
mblighc2180832008-07-25 03:26:12 +000067
68
69class TestError(TestBaseException):
mblighb48fa562008-06-23 17:29:40 +000070 """Indicates that something went wrong with the test harness itself."""
71 exit_status="ERROR"
mblighb48fa562008-06-23 17:29:40 +000072
jadmanski8d01bfe2008-06-23 18:13:24 +000073
mblighc2180832008-07-25 03:26:12 +000074class TestNAError(TestBaseException):
jadmanski0afbb632008-06-06 21:10:57 +000075 """Indictates that the test is Not Applicable. Should be thrown
mblighb48fa562008-06-23 17:29:40 +000076 when various conditions are such that the test is inappropriate."""
77 exit_status="TEST_NA"
mblighb48fa562008-06-23 17:29:40 +000078
jadmanski8d01bfe2008-06-23 18:13:24 +000079
mblighc2180832008-07-25 03:26:12 +000080class TestFail(TestBaseException):
mblighb48fa562008-06-23 17:29:40 +000081 """Indicates that the test failed, but the job will not continue."""
82 exit_status="FAIL"
mblighb48fa562008-06-23 17:29:40 +000083
jadmanski8d01bfe2008-06-23 18:13:24 +000084
mblighc2180832008-07-25 03:26:12 +000085class TestWarn(TestBaseException):
mblighb48fa562008-06-23 17:29:40 +000086 """Indicates that bad things (may) have happened, but not an explicit
87 failure."""
88 exit_status="WARN"
mbligh6a2a2df2008-01-16 17:41:55 +000089
mbligh7e1b1502008-06-06 15:05:41 +000090
mblighc2180832008-07-25 03:26:12 +000091class UnhandledTestError(TestError):
92 """Indicates an unhandled error in a test."""
93 def __init__(self, unhandled_exception):
94 if isinstance(unhandled_exception, TestError):
95 TestError.__init__(self, *unhandled_exception.args)
96 else:
97 msg = "Unhandled %s: %s"
98 msg %= (unhandled_exception.__class__.__name__,
99 unhandled_exception)
100 msg += "\n" + traceback.format_exc()
101 TestError.__init__(self, msg)
102
103
104class UnhandledTestFail(TestFail):
105 """Indicates an unhandled fail in a test."""
106 def __init__(self, unhandled_exception):
107 if isinstance(unhandled_exception, TestFail):
108 TestFail.__init__(self, *unhandled_exception.args)
109 else:
110 msg = "Unhandled %s: %s"
111 msg %= (unhandled_exception.__class__.__name__,
112 unhandled_exception)
113 msg += "\n" + traceback.format_exc()
114 TestFail.__init__(self, msg)
115
116
mbligh906b9f72007-11-29 18:56:17 +0000117class CmdError(TestError):
jadmanski0afbb632008-06-06 21:10:57 +0000118 """\
119 Indicates that a command failed, is fatal to the test unless caught.
120 """
121 def __init__(self, command, result_obj, additional_text=None):
122 TestError.__init__(self, command, result_obj, additional_text)
mblighc23051c2008-06-27 19:26:46 +0000123 self.command = command
124 self.result_obj = result_obj
125 self.additional_text = additional_text
mbligh6a2a2df2008-01-16 17:41:55 +0000126
127
jadmanski0afbb632008-06-06 21:10:57 +0000128 def __str__(self):
jadmanski6ef0b672008-09-30 22:50:19 +0000129 if self.result_obj.exit_status is None:
130 msg = "Command <%s> failed and is not responding to signals"
131 msg %= self.command
132 else:
133 msg = "Command <%s> failed, rc=%d"
134 msg %= (self.command, self.result_obj.exit_status)
135
mblighc23051c2008-06-27 19:26:46 +0000136 if self.additional_text:
137 msg += ", " + self.additional_text
showard6d7e94f2008-08-20 20:53:34 +0000138 msg += '\n' + repr(self.result_obj)
jadmanski0afbb632008-06-06 21:10:57 +0000139 return msg
mbligh906b9f72007-11-29 18:56:17 +0000140
mbligh7e1b1502008-06-06 15:05:41 +0000141
mbligh906b9f72007-11-29 18:56:17 +0000142class PackageError(TestError):
jadmanski0afbb632008-06-06 21:10:57 +0000143 """Indicates an error trying to perform a package operation."""
144 pass
mbligh906b9f72007-11-29 18:56:17 +0000145
mbligh7e1b1502008-06-06 15:05:41 +0000146
mblighe8673102008-07-16 14:09:03 +0000147class BarrierError(JobError):
148 """Indicates an error happened during a barrier operation."""
149 pass
150
151
mbligh5deff3d2008-01-04 21:21:28 +0000152class InstallError(JobError):
jadmanski0afbb632008-06-06 21:10:57 +0000153 """Indicates an installation error which Terminates and fails the job."""
154 pass
mbligh03f4fc72007-11-29 20:56:14 +0000155
mbligh7e1b1502008-06-06 15:05:41 +0000156
mbligh6f015c42008-02-12 20:55:03 +0000157class AutotestRunError(AutotestError):
mbligh021679f2008-11-27 00:43:19 +0000158 """Indicates a problem running server side control files."""
jadmanski0afbb632008-06-06 21:10:57 +0000159 pass
mbligh6f015c42008-02-12 20:55:03 +0000160
mbligh7e1b1502008-06-06 15:05:41 +0000161
mbligh6f015c42008-02-12 20:55:03 +0000162class AutotestTimeoutError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +0000163 """This exception is raised when an autotest test exceeds the timeout
164 parameter passed to run_timed_test and is killed.
165 """
mbligh6f015c42008-02-12 20:55:03 +0000166
167
mbligh03f4fc72007-11-29 20:56:14 +0000168# server-specific errors
169
170class AutoservError(Exception):
jadmanski0afbb632008-06-06 21:10:57 +0000171 pass
mbligh03f4fc72007-11-29 20:56:14 +0000172
173
mbligh34faa282008-01-16 17:44:49 +0000174class AutoservSSHTimeout(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000175 """SSH experienced a connection timeout"""
176 pass
mbligh34faa282008-01-16 17:44:49 +0000177
178
mbligh03f4fc72007-11-29 20:56:14 +0000179class AutoservRunError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000180 """\
181 Errors raised by one of the run functions. Should always be
182 constructed with a tuple of two args (error description (str),
183 run result object).
184 """
185 def __init__(self, description, result_obj):
showard6d7e94f2008-08-20 20:53:34 +0000186 self.description = description
187 self.result_obj = result_obj
jadmanski0afbb632008-06-06 21:10:57 +0000188 AutoservError.__init__(self, description, result_obj)
mbligh03f4fc72007-11-29 20:56:14 +0000189
showard6d7e94f2008-08-20 20:53:34 +0000190 def __str__(self):
191 return self.description + '\n' + repr(self.result_obj)
192
mbligh03f4fc72007-11-29 20:56:14 +0000193
194class AutoservVirtError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000195 """Vitualization related error"""
196 pass
mbligh03f4fc72007-11-29 20:56:14 +0000197
198
199class AutoservUnsupportedError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000200 """Error raised when you try to use an unsupported optional feature"""
201 pass
mbligh03f4fc72007-11-29 20:56:14 +0000202
mbligh7e1b1502008-06-06 15:05:41 +0000203
mbligh03f4fc72007-11-29 20:56:14 +0000204class AutoservHostError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000205 """Error reaching a host"""
206 pass
mbligh03f4fc72007-11-29 20:56:14 +0000207
mbligh7e1b1502008-06-06 15:05:41 +0000208
mbligh03f4fc72007-11-29 20:56:14 +0000209class AutoservRebootError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000210 """Error occured while rebooting a machine"""
211 pass
mbligh6e2ffec2008-03-05 16:08:34 +0000212
mbligh7e1b1502008-06-06 15:05:41 +0000213
mbligh6e2ffec2008-03-05 16:08:34 +0000214class AutoservSubcommandError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000215 """Indicates an error while executing a (forked) subcommand"""
216 def __init__(self, func, exit_code):
217 AutoservError.__init__(self, func, exit_code)
218 self.func = func
219 self.exit_code = exit_code
mbligh7e1b1502008-06-06 15:05:41 +0000220
jadmanski0afbb632008-06-06 21:10:57 +0000221 def __str__(self):
222 return ("Subcommand %s failed with exit code %d" %
223 (self.func, self.exit_code))
mbligh91672252008-10-16 22:28:34 +0000224
225
226# This MUST remain at the end of the file.
227# Limit 'from error import *' to only import the exception instances.
228for _name, _thing in locals().items():
229 try:
230 if issubclass(_thing, Exception):
231 __all__.append(_name)
232 except TypeError:
233 pass # _thing not a class
234__all__ = tuple(__all__)