blob: 645aa3fa6681decbacf90b7c20b2b4b259beafc8 [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
17class JobContinue(SystemExit):
18 """Allow us to bail out requesting continuance."""
19 pass
20
21class JobComplete(SystemExit):
22 """Allow us to bail out indicating continuation not required."""
23 pass
24
25class AutotestError(Exception):
26 """The parent of all errors deliberatly thrown within the client code."""
27 pass
28
29class JobError(AutotestError):
30 """Indicates an error which terminates and fails the whole job."""
31 pass
32
33class TestError(AutotestError):
34 """Indicates an error which terminates and fails the test."""
35 pass
36
mbligh302482e2008-05-01 20:06:16 +000037class TestNAError(AutotestError):
38 """Indictates that the test is Not Applicable. Should be thrown
39 when various conditions are such that the test is inappropriate"""
40 pass
mbligh6a2a2df2008-01-16 17:41:55 +000041
mbligh906b9f72007-11-29 18:56:17 +000042class CmdError(TestError):
mbligh6a2a2df2008-01-16 17:41:55 +000043 """\
44 Indicates that a command failed, is fatal to the test unless caught.
45 """
mbligh8ea61e22008-05-09 18:09:37 +000046 def __init__(self, command, result_obj):
47 TestError.__init__(self, command, result_obj)
mbligh6a2a2df2008-01-16 17:41:55 +000048
49
mbligh906b9f72007-11-29 18:56:17 +000050 def __str__(self):
mbligh8ea61e22008-05-09 18:09:37 +000051 return "Command <" + self.args[0] + "> failed, rc=%d" % (self.args[1].exit_status)
mbligh906b9f72007-11-29 18:56:17 +000052
53class PackageError(TestError):
mbligh642b03e2008-01-14 16:53:15 +000054 """Indicates an error trying to perform a package operation."""
55 pass
mbligh906b9f72007-11-29 18:56:17 +000056
57class UnhandledError(TestError):
58 """Indicates an unhandled exception in a test."""
59 def __init__(self, prefix):
60 msg = prefix + format_error()
61 TestError.__init__(self, msg)
mbligh03f4fc72007-11-29 20:56:14 +000062
mbligh5deff3d2008-01-04 21:21:28 +000063class InstallError(JobError):
64 """Indicates an installation error which Terminates and fails the job."""
65 pass
mbligh03f4fc72007-11-29 20:56:14 +000066
mbligh6f015c42008-02-12 20:55:03 +000067class AutotestRunError(AutotestError):
68 pass
69
70class AutotestTimeoutError(AutotestError):
71 """This exception is raised when an autotest test exceeds the timeout
72 parameter passed to run_timed_test and is killed.
73 """
74
75
mbligh03f4fc72007-11-29 20:56:14 +000076# server-specific errors
77
78class AutoservError(Exception):
79 pass
80
81
mbligh34faa282008-01-16 17:44:49 +000082class AutoservSSHTimeout(AutoservError):
83 """SSH experienced a connection timeout"""
84 pass
85
86
mbligh03f4fc72007-11-29 20:56:14 +000087class AutoservRunError(AutoservError):
mbligh6a2a2df2008-01-16 17:41:55 +000088 """\
89 Errors raised by one of the run functions. Should always be
90 constructed with a tuple of two args (error description (str),
91 run result object).
92 """
93 def __init__(self, description, result_obj):
94 AutoservError.__init__(self, description, result_obj)
mbligh03f4fc72007-11-29 20:56:14 +000095
96
97class AutoservVirtError(AutoservError):
98 """Vitualization related error"""
99 pass
100
101
102class AutoservUnsupportedError(AutoservError):
103 """Error raised when you try to use an unsupported optional feature"""
104 pass
105
106class AutoservHostError(AutoservError):
107 """Error reaching a host"""
108 pass
109
110class AutoservRebootError(AutoservError):
111 """Error occured while rebooting a machine"""
112 pass
mbligh6e2ffec2008-03-05 16:08:34 +0000113
114class AutoservSubcommandError(AutoservError):
115 """Indicates an error while executing a (forked) subcommand"""
116 def __init__(self, func, exit_code):
117 AutoservError.__init__(self, func, exit_code)
118 self.func = func
119 self.exit_code = exit_code
120 def __str__(self):
121 return ("Subcommand %s failed with exit code %d" %
mbligh158ba7b2008-03-07 18:29:12 +0000122 (self.func, self.exit_code))