blob: 09502323662aa30176b567a872912173bb90368a [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)
mbligh6a2a2df2008-01-16 17:41:55 +000076
77
jadmanski0afbb632008-06-06 21:10:57 +000078 def __str__(self):
79 msg = "Command <%s> failed, rc=%d" % (self.args[0],
80 self.args[1].exit_status)
81 if self.args[2]:
82 msg += ", " + self.args[2]
83 return msg
mbligh906b9f72007-11-29 18:56:17 +000084
mbligh7e1b1502008-06-06 15:05:41 +000085
mbligh906b9f72007-11-29 18:56:17 +000086class PackageError(TestError):
jadmanski0afbb632008-06-06 21:10:57 +000087 """Indicates an error trying to perform a package operation."""
88 pass
mbligh906b9f72007-11-29 18:56:17 +000089
mbligh7e1b1502008-06-06 15:05:41 +000090
mblighb48fa562008-06-23 17:29:40 +000091class UnhandledError(TestUnknownError):
jadmanski0afbb632008-06-06 21:10:57 +000092 """Indicates an unhandled exception in a test."""
jadmanski6f731362008-06-17 16:47:06 +000093 def __init__(self, unhandled_exception):
jadmanski8d01bfe2008-06-23 18:13:24 +000094 if isinstance(unhandled_exception, AutotestError):
95 TestUnknownError.__init__(self, *unhandled_exception.args)
jadmanski6f731362008-06-17 16:47:06 +000096 else:
97 msg = "Unhandled %s: %s"
98 msg %= (unhandled_exception.__class__.__name__,
99 unhandled_exception)
jadmanskie01c2e52008-06-18 20:25:26 +0000100 msg += "\n" + traceback.format_exc()
jadmanski8d01bfe2008-06-23 18:13:24 +0000101 TestUnknownError.__init__(self, msg)
mbligh03f4fc72007-11-29 20:56:14 +0000102
mbligh7e1b1502008-06-06 15:05:41 +0000103
mbligh5deff3d2008-01-04 21:21:28 +0000104class InstallError(JobError):
jadmanski0afbb632008-06-06 21:10:57 +0000105 """Indicates an installation error which Terminates and fails the job."""
106 pass
mbligh03f4fc72007-11-29 20:56:14 +0000107
mbligh7e1b1502008-06-06 15:05:41 +0000108
mbligh6f015c42008-02-12 20:55:03 +0000109class AutotestRunError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +0000110 pass
mbligh6f015c42008-02-12 20:55:03 +0000111
mbligh7e1b1502008-06-06 15:05:41 +0000112
mbligh6f015c42008-02-12 20:55:03 +0000113class AutotestTimeoutError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +0000114 """This exception is raised when an autotest test exceeds the timeout
115 parameter passed to run_timed_test and is killed.
116 """
mbligh6f015c42008-02-12 20:55:03 +0000117
118
mbligh03f4fc72007-11-29 20:56:14 +0000119# server-specific errors
120
121class AutoservError(Exception):
jadmanski0afbb632008-06-06 21:10:57 +0000122 pass
mbligh03f4fc72007-11-29 20:56:14 +0000123
124
mbligh34faa282008-01-16 17:44:49 +0000125class AutoservSSHTimeout(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000126 """SSH experienced a connection timeout"""
127 pass
mbligh34faa282008-01-16 17:44:49 +0000128
129
mbligh03f4fc72007-11-29 20:56:14 +0000130class AutoservRunError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000131 """\
132 Errors raised by one of the run functions. Should always be
133 constructed with a tuple of two args (error description (str),
134 run result object).
135 """
136 def __init__(self, description, result_obj):
137 AutoservError.__init__(self, description, result_obj)
mbligh03f4fc72007-11-29 20:56:14 +0000138
139
140class AutoservVirtError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000141 """Vitualization related error"""
142 pass
mbligh03f4fc72007-11-29 20:56:14 +0000143
144
145class AutoservUnsupportedError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000146 """Error raised when you try to use an unsupported optional feature"""
147 pass
mbligh03f4fc72007-11-29 20:56:14 +0000148
mbligh7e1b1502008-06-06 15:05:41 +0000149
mbligh03f4fc72007-11-29 20:56:14 +0000150class AutoservHostError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000151 """Error reaching a host"""
152 pass
mbligh03f4fc72007-11-29 20:56:14 +0000153
mbligh7e1b1502008-06-06 15:05:41 +0000154
mbligh03f4fc72007-11-29 20:56:14 +0000155class AutoservRebootError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000156 """Error occured while rebooting a machine"""
157 pass
mbligh6e2ffec2008-03-05 16:08:34 +0000158
mbligh7e1b1502008-06-06 15:05:41 +0000159
mbligh6e2ffec2008-03-05 16:08:34 +0000160class AutoservSubcommandError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000161 """Indicates an error while executing a (forked) subcommand"""
162 def __init__(self, func, exit_code):
163 AutoservError.__init__(self, func, exit_code)
164 self.func = func
165 self.exit_code = exit_code
mbligh7e1b1502008-06-06 15:05:41 +0000166
jadmanski0afbb632008-06-06 21:10:57 +0000167 def __str__(self):
168 return ("Subcommand %s failed with exit code %d" %
169 (self.func, self.exit_code))