blob: 242344225089b5a5600a5b9535c7eee2ae33e007 [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
mbligh7e1b1502008-06-06 15:05:41 +000017
mbligh906b9f72007-11-29 18:56:17 +000018class JobContinue(SystemExit):
jadmanski0afbb632008-06-06 21:10:57 +000019 """Allow us to bail out requesting continuance."""
20 pass
mbligh906b9f72007-11-29 18:56:17 +000021
mbligh7e1b1502008-06-06 15:05:41 +000022
mbligh906b9f72007-11-29 18:56:17 +000023class JobComplete(SystemExit):
jadmanski0afbb632008-06-06 21:10:57 +000024 """Allow us to bail out indicating continuation not required."""
25 pass
mbligh906b9f72007-11-29 18:56:17 +000026
mbligh7e1b1502008-06-06 15:05:41 +000027
mbligh906b9f72007-11-29 18:56:17 +000028class AutotestError(Exception):
jadmanski0afbb632008-06-06 21:10:57 +000029 """The parent of all errors deliberatly thrown within the client code."""
30 pass
mbligh906b9f72007-11-29 18:56:17 +000031
mbligh7e1b1502008-06-06 15:05:41 +000032
mbligh906b9f72007-11-29 18:56:17 +000033class JobError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +000034 """Indicates an error which terminates and fails the whole job."""
35 pass
mbligh906b9f72007-11-29 18:56:17 +000036
mbligh7e1b1502008-06-06 15:05:41 +000037
mbligh906b9f72007-11-29 18:56:17 +000038class TestError(AutotestError):
mblighb48fa562008-06-23 17:29:40 +000039 """Indicates that something went wrong with the test harness itself."""
40 exit_status="ERROR"
41 pass
42
jadmanski8d01bfe2008-06-23 18:13:24 +000043
mblighb48fa562008-06-23 17:29:40 +000044class TestUnknownError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +000045 """Indicates an error which terminates and fails the test."""
mblighb48fa562008-06-23 17:29:40 +000046 exit_status="FAIL"
jadmanski0afbb632008-06-06 21:10:57 +000047 pass
mbligh906b9f72007-11-29 18:56:17 +000048
mbligh7e1b1502008-06-06 15:05:41 +000049
mbligh302482e2008-05-01 20:06:16 +000050class TestNAError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +000051 """Indictates that the test is Not Applicable. Should be thrown
mblighb48fa562008-06-23 17:29:40 +000052 when various conditions are such that the test is inappropriate."""
53 exit_status="TEST_NA"
54 pass
55
jadmanski8d01bfe2008-06-23 18:13:24 +000056
mblighb48fa562008-06-23 17:29:40 +000057class TestFail(AutotestError):
58 """Indicates that the test failed, but the job will not continue."""
59 exit_status="FAIL"
60 pass
61
jadmanski8d01bfe2008-06-23 18:13:24 +000062
mblighb48fa562008-06-23 17:29:40 +000063class TestWarn(AutotestError):
64 """Indicates that bad things (may) have happened, but not an explicit
65 failure."""
66 exit_status="WARN"
jadmanski0afbb632008-06-06 21:10:57 +000067 pass
mbligh6a2a2df2008-01-16 17:41:55 +000068
mbligh7e1b1502008-06-06 15:05:41 +000069
mbligh906b9f72007-11-29 18:56:17 +000070class CmdError(TestError):
jadmanski0afbb632008-06-06 21:10:57 +000071 """\
72 Indicates that a command failed, is fatal to the test unless caught.
73 """
74 def __init__(self, command, result_obj, additional_text=None):
75 TestError.__init__(self, command, result_obj, additional_text)
mblighc23051c2008-06-27 19:26:46 +000076 self.command = command
77 self.result_obj = result_obj
78 self.additional_text = additional_text
mbligh6a2a2df2008-01-16 17:41:55 +000079
80
jadmanski0afbb632008-06-06 21:10:57 +000081 def __str__(self):
mblighc23051c2008-06-27 19:26:46 +000082 msg = "Command <%s> failed, rc=%d" % (self.command,
83 self.result_obj.exit_status)
84 if self.additional_text:
85 msg += ", " + self.additional_text
jadmanski0afbb632008-06-06 21:10:57 +000086 return msg
mbligh906b9f72007-11-29 18:56:17 +000087
mbligh7e1b1502008-06-06 15:05:41 +000088
mbligh906b9f72007-11-29 18:56:17 +000089class PackageError(TestError):
jadmanski0afbb632008-06-06 21:10:57 +000090 """Indicates an error trying to perform a package operation."""
91 pass
mbligh906b9f72007-11-29 18:56:17 +000092
mbligh7e1b1502008-06-06 15:05:41 +000093
mblighb48fa562008-06-23 17:29:40 +000094class UnhandledError(TestUnknownError):
jadmanski0afbb632008-06-06 21:10:57 +000095 """Indicates an unhandled exception in a test."""
jadmanski6f731362008-06-17 16:47:06 +000096 def __init__(self, unhandled_exception):
jadmanski8d01bfe2008-06-23 18:13:24 +000097 if isinstance(unhandled_exception, AutotestError):
98 TestUnknownError.__init__(self, *unhandled_exception.args)
jadmanski6f731362008-06-17 16:47:06 +000099 else:
100 msg = "Unhandled %s: %s"
101 msg %= (unhandled_exception.__class__.__name__,
102 unhandled_exception)
jadmanskie01c2e52008-06-18 20:25:26 +0000103 msg += "\n" + traceback.format_exc()
jadmanski8d01bfe2008-06-23 18:13:24 +0000104 TestUnknownError.__init__(self, msg)
mbligh03f4fc72007-11-29 20:56:14 +0000105
mbligh7e1b1502008-06-06 15:05:41 +0000106
mbligh5deff3d2008-01-04 21:21:28 +0000107class InstallError(JobError):
jadmanski0afbb632008-06-06 21:10:57 +0000108 """Indicates an installation error which Terminates and fails the job."""
109 pass
mbligh03f4fc72007-11-29 20:56:14 +0000110
mbligh7e1b1502008-06-06 15:05:41 +0000111
mbligh6f015c42008-02-12 20:55:03 +0000112class AutotestRunError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +0000113 pass
mbligh6f015c42008-02-12 20:55:03 +0000114
mbligh7e1b1502008-06-06 15:05:41 +0000115
mbligh6f015c42008-02-12 20:55:03 +0000116class AutotestTimeoutError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +0000117 """This exception is raised when an autotest test exceeds the timeout
118 parameter passed to run_timed_test and is killed.
119 """
mbligh6f015c42008-02-12 20:55:03 +0000120
121
mbligh03f4fc72007-11-29 20:56:14 +0000122# server-specific errors
123
124class AutoservError(Exception):
jadmanski0afbb632008-06-06 21:10:57 +0000125 pass
mbligh03f4fc72007-11-29 20:56:14 +0000126
127
mbligh34faa282008-01-16 17:44:49 +0000128class AutoservSSHTimeout(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000129 """SSH experienced a connection timeout"""
130 pass
mbligh34faa282008-01-16 17:44:49 +0000131
132
mbligh03f4fc72007-11-29 20:56:14 +0000133class AutoservRunError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000134 """\
135 Errors raised by one of the run functions. Should always be
136 constructed with a tuple of two args (error description (str),
137 run result object).
138 """
139 def __init__(self, description, result_obj):
140 AutoservError.__init__(self, description, result_obj)
mbligh03f4fc72007-11-29 20:56:14 +0000141
142
143class AutoservVirtError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000144 """Vitualization related error"""
145 pass
mbligh03f4fc72007-11-29 20:56:14 +0000146
147
148class AutoservUnsupportedError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000149 """Error raised when you try to use an unsupported optional feature"""
150 pass
mbligh03f4fc72007-11-29 20:56:14 +0000151
mbligh7e1b1502008-06-06 15:05:41 +0000152
mbligh03f4fc72007-11-29 20:56:14 +0000153class AutoservHostError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000154 """Error reaching a host"""
155 pass
mbligh03f4fc72007-11-29 20:56:14 +0000156
mbligh7e1b1502008-06-06 15:05:41 +0000157
mbligh03f4fc72007-11-29 20:56:14 +0000158class AutoservRebootError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000159 """Error occured while rebooting a machine"""
160 pass
mbligh6e2ffec2008-03-05 16:08:34 +0000161
mbligh7e1b1502008-06-06 15:05:41 +0000162
mbligh6e2ffec2008-03-05 16:08:34 +0000163class AutoservSubcommandError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000164 """Indicates an error while executing a (forked) subcommand"""
165 def __init__(self, func, exit_code):
166 AutoservError.__init__(self, func, exit_code)
167 self.func = func
168 self.exit_code = exit_code
mbligh7e1b1502008-06-06 15:05:41 +0000169
jadmanski0afbb632008-06-06 21:10:57 +0000170 def __str__(self):
171 return ("Subcommand %s failed with exit code %d" %
172 (self.func, self.exit_code))