blob: 14e253f41c3a6dbf49bd53f607126f57d8efa3db [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):
mblighc23051c2008-06-27 19:26:46 +0000106 msg = "Command <%s> failed, rc=%d" % (self.command,
107 self.result_obj.exit_status)
108 if self.additional_text:
109 msg += ", " + self.additional_text
jadmanski0afbb632008-06-06 21:10:57 +0000110 return msg
mbligh906b9f72007-11-29 18:56:17 +0000111
mbligh7e1b1502008-06-06 15:05:41 +0000112
mbligh906b9f72007-11-29 18:56:17 +0000113class PackageError(TestError):
jadmanski0afbb632008-06-06 21:10:57 +0000114 """Indicates an error trying to perform a package operation."""
115 pass
mbligh906b9f72007-11-29 18:56:17 +0000116
mbligh7e1b1502008-06-06 15:05:41 +0000117
mblighe8673102008-07-16 14:09:03 +0000118class BarrierError(JobError):
119 """Indicates an error happened during a barrier operation."""
120 pass
121
122
mbligh5deff3d2008-01-04 21:21:28 +0000123class InstallError(JobError):
jadmanski0afbb632008-06-06 21:10:57 +0000124 """Indicates an installation error which Terminates and fails the job."""
125 pass
mbligh03f4fc72007-11-29 20:56:14 +0000126
mbligh7e1b1502008-06-06 15:05:41 +0000127
mbligh6f015c42008-02-12 20:55:03 +0000128class AutotestRunError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +0000129 pass
mbligh6f015c42008-02-12 20:55:03 +0000130
mbligh7e1b1502008-06-06 15:05:41 +0000131
mbligh6f015c42008-02-12 20:55:03 +0000132class AutotestTimeoutError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +0000133 """This exception is raised when an autotest test exceeds the timeout
134 parameter passed to run_timed_test and is killed.
135 """
mbligh6f015c42008-02-12 20:55:03 +0000136
137
mbligh03f4fc72007-11-29 20:56:14 +0000138# server-specific errors
139
140class AutoservError(Exception):
jadmanski0afbb632008-06-06 21:10:57 +0000141 pass
mbligh03f4fc72007-11-29 20:56:14 +0000142
143
mbligh34faa282008-01-16 17:44:49 +0000144class AutoservSSHTimeout(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000145 """SSH experienced a connection timeout"""
146 pass
mbligh34faa282008-01-16 17:44:49 +0000147
148
mbligh03f4fc72007-11-29 20:56:14 +0000149class AutoservRunError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000150 """\
151 Errors raised by one of the run functions. Should always be
152 constructed with a tuple of two args (error description (str),
153 run result object).
154 """
155 def __init__(self, description, result_obj):
156 AutoservError.__init__(self, description, result_obj)
mbligh03f4fc72007-11-29 20:56:14 +0000157
158
159class AutoservVirtError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000160 """Vitualization related error"""
161 pass
mbligh03f4fc72007-11-29 20:56:14 +0000162
163
164class AutoservUnsupportedError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000165 """Error raised when you try to use an unsupported optional feature"""
166 pass
mbligh03f4fc72007-11-29 20:56:14 +0000167
mbligh7e1b1502008-06-06 15:05:41 +0000168
mbligh03f4fc72007-11-29 20:56:14 +0000169class AutoservHostError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000170 """Error reaching a host"""
171 pass
mbligh03f4fc72007-11-29 20:56:14 +0000172
mbligh7e1b1502008-06-06 15:05:41 +0000173
mbligh03f4fc72007-11-29 20:56:14 +0000174class AutoservRebootError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000175 """Error occured while rebooting a machine"""
176 pass
mbligh6e2ffec2008-03-05 16:08:34 +0000177
mbligh7e1b1502008-06-06 15:05:41 +0000178
mbligh6e2ffec2008-03-05 16:08:34 +0000179class AutoservSubcommandError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000180 """Indicates an error while executing a (forked) subcommand"""
181 def __init__(self, func, exit_code):
182 AutoservError.__init__(self, func, exit_code)
183 self.func = func
184 self.exit_code = exit_code
mbligh7e1b1502008-06-06 15:05:41 +0000185
jadmanski0afbb632008-06-06 21:10:57 +0000186 def __str__(self):
187 return ("Subcommand %s failed with exit code %d" %
188 (self.func, self.exit_code))