blob: 582810d0228f2aa8d2b5432e3580cbb8edccecc9 [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
mbligh906b9f72007-11-29 18:56:17 +000037class TestError(AutotestError):
mblighb48fa562008-06-23 17:29:40 +000038 """Indicates that something went wrong with the test harness itself."""
39 exit_status="ERROR"
40 pass
41
jadmanski8d01bfe2008-06-23 18:13:24 +000042
mblighb48fa562008-06-23 17:29:40 +000043class TestUnknownError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +000044 """Indicates an error which terminates and fails the test."""
mblighb48fa562008-06-23 17:29:40 +000045 exit_status="FAIL"
jadmanski0afbb632008-06-06 21:10:57 +000046 pass
mbligh906b9f72007-11-29 18:56:17 +000047
mbligh7e1b1502008-06-06 15:05:41 +000048
mbligh302482e2008-05-01 20:06:16 +000049class TestNAError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +000050 """Indictates that the test is Not Applicable. Should be thrown
mblighb48fa562008-06-23 17:29:40 +000051 when various conditions are such that the test is inappropriate."""
52 exit_status="TEST_NA"
53 pass
54
jadmanski8d01bfe2008-06-23 18:13:24 +000055
mblighb48fa562008-06-23 17:29:40 +000056class TestFail(AutotestError):
57 """Indicates that the test failed, but the job will not continue."""
58 exit_status="FAIL"
59 pass
60
jadmanski8d01bfe2008-06-23 18:13:24 +000061
mblighb48fa562008-06-23 17:29:40 +000062class TestWarn(AutotestError):
63 """Indicates that bad things (may) have happened, but not an explicit
64 failure."""
65 exit_status="WARN"
jadmanski0afbb632008-06-06 21:10:57 +000066 pass
mbligh6a2a2df2008-01-16 17:41:55 +000067
mbligh7e1b1502008-06-06 15:05:41 +000068
mbligh906b9f72007-11-29 18:56:17 +000069class CmdError(TestError):
jadmanski0afbb632008-06-06 21:10:57 +000070 """\
71 Indicates that a command failed, is fatal to the test unless caught.
72 """
73 def __init__(self, command, result_obj, additional_text=None):
74 TestError.__init__(self, command, result_obj, additional_text)
mblighc23051c2008-06-27 19:26:46 +000075 self.command = command
76 self.result_obj = result_obj
77 self.additional_text = additional_text
mbligh6a2a2df2008-01-16 17:41:55 +000078
79
jadmanski0afbb632008-06-06 21:10:57 +000080 def __str__(self):
mblighc23051c2008-06-27 19:26:46 +000081 msg = "Command <%s> failed, rc=%d" % (self.command,
82 self.result_obj.exit_status)
83 if self.additional_text:
84 msg += ", " + self.additional_text
jadmanski0afbb632008-06-06 21:10:57 +000085 return msg
mbligh906b9f72007-11-29 18:56:17 +000086
mbligh7e1b1502008-06-06 15:05:41 +000087
mbligh906b9f72007-11-29 18:56:17 +000088class PackageError(TestError):
jadmanski0afbb632008-06-06 21:10:57 +000089 """Indicates an error trying to perform a package operation."""
90 pass
mbligh906b9f72007-11-29 18:56:17 +000091
mbligh7e1b1502008-06-06 15:05:41 +000092
mblighe8673102008-07-16 14:09:03 +000093class BarrierError(JobError):
94 """Indicates an error happened during a barrier operation."""
95 pass
96
97
mblighb48fa562008-06-23 17:29:40 +000098class UnhandledError(TestUnknownError):
jadmanski0afbb632008-06-06 21:10:57 +000099 """Indicates an unhandled exception in a test."""
jadmanski6f731362008-06-17 16:47:06 +0000100 def __init__(self, unhandled_exception):
jadmanski8d01bfe2008-06-23 18:13:24 +0000101 if isinstance(unhandled_exception, AutotestError):
102 TestUnknownError.__init__(self, *unhandled_exception.args)
jadmanski6f731362008-06-17 16:47:06 +0000103 else:
104 msg = "Unhandled %s: %s"
105 msg %= (unhandled_exception.__class__.__name__,
106 unhandled_exception)
jadmanskie01c2e52008-06-18 20:25:26 +0000107 msg += "\n" + traceback.format_exc()
jadmanski8d01bfe2008-06-23 18:13:24 +0000108 TestUnknownError.__init__(self, msg)
mbligh03f4fc72007-11-29 20:56:14 +0000109
mbligh7e1b1502008-06-06 15:05:41 +0000110
mbligh5deff3d2008-01-04 21:21:28 +0000111class InstallError(JobError):
jadmanski0afbb632008-06-06 21:10:57 +0000112 """Indicates an installation error which Terminates and fails the job."""
113 pass
mbligh03f4fc72007-11-29 20:56:14 +0000114
mbligh7e1b1502008-06-06 15:05:41 +0000115
mbligh6f015c42008-02-12 20:55:03 +0000116class AutotestRunError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +0000117 pass
mbligh6f015c42008-02-12 20:55:03 +0000118
mbligh7e1b1502008-06-06 15:05:41 +0000119
mbligh6f015c42008-02-12 20:55:03 +0000120class AutotestTimeoutError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +0000121 """This exception is raised when an autotest test exceeds the timeout
122 parameter passed to run_timed_test and is killed.
123 """
mbligh6f015c42008-02-12 20:55:03 +0000124
125
mbligh03f4fc72007-11-29 20:56:14 +0000126# server-specific errors
127
128class AutoservError(Exception):
jadmanski0afbb632008-06-06 21:10:57 +0000129 pass
mbligh03f4fc72007-11-29 20:56:14 +0000130
131
mbligh34faa282008-01-16 17:44:49 +0000132class AutoservSSHTimeout(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000133 """SSH experienced a connection timeout"""
134 pass
mbligh34faa282008-01-16 17:44:49 +0000135
136
mbligh03f4fc72007-11-29 20:56:14 +0000137class AutoservRunError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000138 """\
139 Errors raised by one of the run functions. Should always be
140 constructed with a tuple of two args (error description (str),
141 run result object).
142 """
143 def __init__(self, description, result_obj):
144 AutoservError.__init__(self, description, result_obj)
mbligh03f4fc72007-11-29 20:56:14 +0000145
146
147class AutoservVirtError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000148 """Vitualization related error"""
149 pass
mbligh03f4fc72007-11-29 20:56:14 +0000150
151
152class AutoservUnsupportedError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000153 """Error raised when you try to use an unsupported optional feature"""
154 pass
mbligh03f4fc72007-11-29 20:56:14 +0000155
mbligh7e1b1502008-06-06 15:05:41 +0000156
mbligh03f4fc72007-11-29 20:56:14 +0000157class AutoservHostError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000158 """Error reaching a host"""
159 pass
mbligh03f4fc72007-11-29 20:56:14 +0000160
mbligh7e1b1502008-06-06 15:05:41 +0000161
mbligh03f4fc72007-11-29 20:56:14 +0000162class AutoservRebootError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000163 """Error occured while rebooting a machine"""
164 pass
mbligh6e2ffec2008-03-05 16:08:34 +0000165
mbligh7e1b1502008-06-06 15:05:41 +0000166
mbligh6e2ffec2008-03-05 16:08:34 +0000167class AutoservSubcommandError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000168 """Indicates an error while executing a (forked) subcommand"""
169 def __init__(self, func, exit_code):
170 AutoservError.__init__(self, func, exit_code)
171 self.func = func
172 self.exit_code = exit_code
mbligh7e1b1502008-06-06 15:05:41 +0000173
jadmanski0afbb632008-06-06 21:10:57 +0000174 def __str__(self):
175 return ("Subcommand %s failed with exit code %d" %
176 (self.func, self.exit_code))