blob: 25a9e9a835bd075a7c68e97c1aa60f618997d862 [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
43class 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
55class TestFail(AutotestError):
56 """Indicates that the test failed, but the job will not continue."""
57 exit_status="FAIL"
58 pass
59
60class TestWarn(AutotestError):
61 """Indicates that bad things (may) have happened, but not an explicit
62 failure."""
63 exit_status="WARN"
jadmanski0afbb632008-06-06 21:10:57 +000064 pass
mbligh6a2a2df2008-01-16 17:41:55 +000065
mbligh7e1b1502008-06-06 15:05:41 +000066
mbligh906b9f72007-11-29 18:56:17 +000067class CmdError(TestError):
jadmanski0afbb632008-06-06 21:10:57 +000068 """\
69 Indicates that a command failed, is fatal to the test unless caught.
70 """
71 def __init__(self, command, result_obj, additional_text=None):
72 TestError.__init__(self, command, result_obj, additional_text)
mbligh6a2a2df2008-01-16 17:41:55 +000073
74
jadmanski0afbb632008-06-06 21:10:57 +000075 def __str__(self):
76 msg = "Command <%s> failed, rc=%d" % (self.args[0],
77 self.args[1].exit_status)
78 if self.args[2]:
79 msg += ", " + self.args[2]
80 return msg
mbligh906b9f72007-11-29 18:56:17 +000081
mbligh7e1b1502008-06-06 15:05:41 +000082
mbligh906b9f72007-11-29 18:56:17 +000083class PackageError(TestError):
jadmanski0afbb632008-06-06 21:10:57 +000084 """Indicates an error trying to perform a package operation."""
85 pass
mbligh906b9f72007-11-29 18:56:17 +000086
mbligh7e1b1502008-06-06 15:05:41 +000087
mblighb48fa562008-06-23 17:29:40 +000088class UnhandledError(TestUnknownError):
jadmanski0afbb632008-06-06 21:10:57 +000089 """Indicates an unhandled exception in a test."""
jadmanski6f731362008-06-17 16:47:06 +000090 def __init__(self, unhandled_exception):
91 if isinstance(unhandled_exception, TestError):
92 TestError.__init__(self, *unhandled_exception.args)
93 else:
94 msg = "Unhandled %s: %s"
95 msg %= (unhandled_exception.__class__.__name__,
96 unhandled_exception)
jadmanskie01c2e52008-06-18 20:25:26 +000097 msg += "\n" + traceback.format_exc()
jadmanski6f731362008-06-17 16:47:06 +000098 TestError.__init__(self, msg)
mbligh03f4fc72007-11-29 20:56:14 +000099
mbligh7e1b1502008-06-06 15:05:41 +0000100
mbligh5deff3d2008-01-04 21:21:28 +0000101class InstallError(JobError):
jadmanski0afbb632008-06-06 21:10:57 +0000102 """Indicates an installation error which Terminates and fails the job."""
103 pass
mbligh03f4fc72007-11-29 20:56:14 +0000104
mbligh7e1b1502008-06-06 15:05:41 +0000105
mbligh6f015c42008-02-12 20:55:03 +0000106class AutotestRunError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +0000107 pass
mbligh6f015c42008-02-12 20:55:03 +0000108
mbligh7e1b1502008-06-06 15:05:41 +0000109
mbligh6f015c42008-02-12 20:55:03 +0000110class AutotestTimeoutError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +0000111 """This exception is raised when an autotest test exceeds the timeout
112 parameter passed to run_timed_test and is killed.
113 """
mbligh6f015c42008-02-12 20:55:03 +0000114
115
mbligh03f4fc72007-11-29 20:56:14 +0000116# server-specific errors
117
118class AutoservError(Exception):
jadmanski0afbb632008-06-06 21:10:57 +0000119 pass
mbligh03f4fc72007-11-29 20:56:14 +0000120
121
mbligh34faa282008-01-16 17:44:49 +0000122class AutoservSSHTimeout(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000123 """SSH experienced a connection timeout"""
124 pass
mbligh34faa282008-01-16 17:44:49 +0000125
126
mbligh03f4fc72007-11-29 20:56:14 +0000127class AutoservRunError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000128 """\
129 Errors raised by one of the run functions. Should always be
130 constructed with a tuple of two args (error description (str),
131 run result object).
132 """
133 def __init__(self, description, result_obj):
134 AutoservError.__init__(self, description, result_obj)
mbligh03f4fc72007-11-29 20:56:14 +0000135
136
137class AutoservVirtError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000138 """Vitualization related error"""
139 pass
mbligh03f4fc72007-11-29 20:56:14 +0000140
141
142class AutoservUnsupportedError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000143 """Error raised when you try to use an unsupported optional feature"""
144 pass
mbligh03f4fc72007-11-29 20:56:14 +0000145
mbligh7e1b1502008-06-06 15:05:41 +0000146
mbligh03f4fc72007-11-29 20:56:14 +0000147class AutoservHostError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000148 """Error reaching a host"""
149 pass
mbligh03f4fc72007-11-29 20:56:14 +0000150
mbligh7e1b1502008-06-06 15:05:41 +0000151
mbligh03f4fc72007-11-29 20:56:14 +0000152class AutoservRebootError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000153 """Error occured while rebooting a machine"""
154 pass
mbligh6e2ffec2008-03-05 16:08:34 +0000155
mbligh7e1b1502008-06-06 15:05:41 +0000156
mbligh6e2ffec2008-03-05 16:08:34 +0000157class AutoservSubcommandError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000158 """Indicates an error while executing a (forked) subcommand"""
159 def __init__(self, func, exit_code):
160 AutoservError.__init__(self, func, exit_code)
161 self.func = func
162 self.exit_code = exit_code
mbligh7e1b1502008-06-06 15:05:41 +0000163
jadmanski0afbb632008-06-06 21:10:57 +0000164 def __str__(self):
165 return ("Subcommand %s failed with exit code %d" %
166 (self.func, self.exit_code))