blob: 6eeb3fede6633ef9127f54a339602722a0c57430 [file] [log] [blame]
mbligh906b9f72007-11-29 18:56:17 +00001"""
2Internal global error types
3"""
4
5import sys
6from traceback import format_exception
7
8def format_error():
mbligh642b03e2008-01-14 16:53:15 +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
mbligh642b03e2008-01-14 16:53:15 +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):
19 """Allow us to bail out requesting continuance."""
20 pass
21
mbligh7e1b1502008-06-06 15:05:41 +000022
mbligh906b9f72007-11-29 18:56:17 +000023class JobComplete(SystemExit):
24 """Allow us to bail out indicating continuation not required."""
25 pass
26
mbligh7e1b1502008-06-06 15:05:41 +000027
mbligh906b9f72007-11-29 18:56:17 +000028class AutotestError(Exception):
29 """The parent of all errors deliberatly thrown within the client code."""
30 pass
31
mbligh7e1b1502008-06-06 15:05:41 +000032
mbligh906b9f72007-11-29 18:56:17 +000033class JobError(AutotestError):
34 """Indicates an error which terminates and fails the whole job."""
35 pass
36
mbligh7e1b1502008-06-06 15:05:41 +000037
mbligh906b9f72007-11-29 18:56:17 +000038class TestError(AutotestError):
39 """Indicates an error which terminates and fails the test."""
40 pass
41
mbligh7e1b1502008-06-06 15:05:41 +000042
mbligh302482e2008-05-01 20:06:16 +000043class TestNAError(AutotestError):
44 """Indictates that the test is Not Applicable. Should be thrown
45 when various conditions are such that the test is inappropriate"""
46 pass
mbligh6a2a2df2008-01-16 17:41:55 +000047
mbligh7e1b1502008-06-06 15:05:41 +000048
mbligh906b9f72007-11-29 18:56:17 +000049class CmdError(TestError):
mbligh6a2a2df2008-01-16 17:41:55 +000050 """\
51 Indicates that a command failed, is fatal to the test unless caught.
52 """
jadmanskid93d7d22008-05-29 21:37:29 +000053 def __init__(self, command, result_obj, additional_text=None):
54 TestError.__init__(self, command, result_obj, additional_text)
mbligh6a2a2df2008-01-16 17:41:55 +000055
56
mbligh906b9f72007-11-29 18:56:17 +000057 def __str__(self):
jadmanskid93d7d22008-05-29 21:37:29 +000058 msg = "Command <%s> failed, rc=%d" % (self.args[0],
mbligh7aff6bd2008-06-06 15:06:29 +000059 self.args[1].exit_status)
jadmanskid93d7d22008-05-29 21:37:29 +000060 if self.args[2]:
61 msg += ", " + self.args[2]
62 return msg
mbligh906b9f72007-11-29 18:56:17 +000063
mbligh7e1b1502008-06-06 15:05:41 +000064
mbligh906b9f72007-11-29 18:56:17 +000065class PackageError(TestError):
mbligh642b03e2008-01-14 16:53:15 +000066 """Indicates an error trying to perform a package operation."""
67 pass
mbligh906b9f72007-11-29 18:56:17 +000068
mbligh7e1b1502008-06-06 15:05:41 +000069
mbligh906b9f72007-11-29 18:56:17 +000070class UnhandledError(TestError):
71 """Indicates an unhandled exception in a test."""
72 def __init__(self, prefix):
73 msg = prefix + format_error()
74 TestError.__init__(self, msg)
mbligh03f4fc72007-11-29 20:56:14 +000075
mbligh7e1b1502008-06-06 15:05:41 +000076
mbligh5deff3d2008-01-04 21:21:28 +000077class InstallError(JobError):
78 """Indicates an installation error which Terminates and fails the job."""
79 pass
mbligh03f4fc72007-11-29 20:56:14 +000080
mbligh7e1b1502008-06-06 15:05:41 +000081
mbligh6f015c42008-02-12 20:55:03 +000082class AutotestRunError(AutotestError):
83 pass
84
mbligh7e1b1502008-06-06 15:05:41 +000085
mbligh6f015c42008-02-12 20:55:03 +000086class AutotestTimeoutError(AutotestError):
87 """This exception is raised when an autotest test exceeds the timeout
88 parameter passed to run_timed_test and is killed.
89 """
90
91
mbligh03f4fc72007-11-29 20:56:14 +000092# server-specific errors
93
94class AutoservError(Exception):
95 pass
96
97
mbligh34faa282008-01-16 17:44:49 +000098class AutoservSSHTimeout(AutoservError):
99 """SSH experienced a connection timeout"""
100 pass
101
102
mbligh03f4fc72007-11-29 20:56:14 +0000103class AutoservRunError(AutoservError):
mbligh6a2a2df2008-01-16 17:41:55 +0000104 """\
105 Errors raised by one of the run functions. Should always be
106 constructed with a tuple of two args (error description (str),
107 run result object).
108 """
109 def __init__(self, description, result_obj):
110 AutoservError.__init__(self, description, result_obj)
mbligh03f4fc72007-11-29 20:56:14 +0000111
112
113class AutoservVirtError(AutoservError):
114 """Vitualization related error"""
115 pass
116
117
118class AutoservUnsupportedError(AutoservError):
119 """Error raised when you try to use an unsupported optional feature"""
120 pass
121
mbligh7e1b1502008-06-06 15:05:41 +0000122
mbligh03f4fc72007-11-29 20:56:14 +0000123class AutoservHostError(AutoservError):
124 """Error reaching a host"""
125 pass
126
mbligh7e1b1502008-06-06 15:05:41 +0000127
mbligh03f4fc72007-11-29 20:56:14 +0000128class AutoservRebootError(AutoservError):
129 """Error occured while rebooting a machine"""
130 pass
mbligh6e2ffec2008-03-05 16:08:34 +0000131
mbligh7e1b1502008-06-06 15:05:41 +0000132
mbligh6e2ffec2008-03-05 16:08:34 +0000133class AutoservSubcommandError(AutoservError):
134 """Indicates an error while executing a (forked) subcommand"""
135 def __init__(self, func, exit_code):
136 AutoservError.__init__(self, func, exit_code)
137 self.func = func
138 self.exit_code = exit_code
mbligh7e1b1502008-06-06 15:05:41 +0000139
mbligh6e2ffec2008-03-05 16:08:34 +0000140 def __str__(self):
141 return ("Subcommand %s failed with exit code %d" %
mbligh158ba7b2008-03-07 18:29:12 +0000142 (self.func, self.exit_code))