blob: 6052584c9435938299597d2e4d4e736b1a093c22 [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):
jadmanski0afbb632008-06-06 21:10:57 +000039 """Indicates an error which terminates and fails the test."""
40 pass
mbligh906b9f72007-11-29 18:56:17 +000041
mbligh7e1b1502008-06-06 15:05:41 +000042
mbligh302482e2008-05-01 20:06:16 +000043class TestNAError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +000044 """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):
jadmanski0afbb632008-06-06 21:10:57 +000050 """\
51 Indicates that a command failed, is fatal to the test unless caught.
52 """
53 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
jadmanski0afbb632008-06-06 21:10:57 +000057 def __str__(self):
58 msg = "Command <%s> failed, rc=%d" % (self.args[0],
59 self.args[1].exit_status)
60 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):
jadmanski0afbb632008-06-06 21:10:57 +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):
jadmanski0afbb632008-06-06 21:10:57 +000071 """Indicates an unhandled exception in a test."""
jadmanski6f731362008-06-17 16:47:06 +000072 def __init__(self, unhandled_exception):
73 if isinstance(unhandled_exception, TestError):
74 TestError.__init__(self, *unhandled_exception.args)
75 else:
76 msg = "Unhandled %s: %s"
77 msg %= (unhandled_exception.__class__.__name__,
78 unhandled_exception)
79 msg += "\n" + "\n".join(traceback.format_exc())
80 TestError.__init__(self, msg)
mbligh03f4fc72007-11-29 20:56:14 +000081
mbligh7e1b1502008-06-06 15:05:41 +000082
mbligh5deff3d2008-01-04 21:21:28 +000083class InstallError(JobError):
jadmanski0afbb632008-06-06 21:10:57 +000084 """Indicates an installation error which Terminates and fails the job."""
85 pass
mbligh03f4fc72007-11-29 20:56:14 +000086
mbligh7e1b1502008-06-06 15:05:41 +000087
mbligh6f015c42008-02-12 20:55:03 +000088class AutotestRunError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +000089 pass
mbligh6f015c42008-02-12 20:55:03 +000090
mbligh7e1b1502008-06-06 15:05:41 +000091
mbligh6f015c42008-02-12 20:55:03 +000092class AutotestTimeoutError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +000093 """This exception is raised when an autotest test exceeds the timeout
94 parameter passed to run_timed_test and is killed.
95 """
mbligh6f015c42008-02-12 20:55:03 +000096
97
mbligh03f4fc72007-11-29 20:56:14 +000098# server-specific errors
99
100class AutoservError(Exception):
jadmanski0afbb632008-06-06 21:10:57 +0000101 pass
mbligh03f4fc72007-11-29 20:56:14 +0000102
103
mbligh34faa282008-01-16 17:44:49 +0000104class AutoservSSHTimeout(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000105 """SSH experienced a connection timeout"""
106 pass
mbligh34faa282008-01-16 17:44:49 +0000107
108
mbligh03f4fc72007-11-29 20:56:14 +0000109class AutoservRunError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000110 """\
111 Errors raised by one of the run functions. Should always be
112 constructed with a tuple of two args (error description (str),
113 run result object).
114 """
115 def __init__(self, description, result_obj):
116 AutoservError.__init__(self, description, result_obj)
mbligh03f4fc72007-11-29 20:56:14 +0000117
118
119class AutoservVirtError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000120 """Vitualization related error"""
121 pass
mbligh03f4fc72007-11-29 20:56:14 +0000122
123
124class AutoservUnsupportedError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000125 """Error raised when you try to use an unsupported optional feature"""
126 pass
mbligh03f4fc72007-11-29 20:56:14 +0000127
mbligh7e1b1502008-06-06 15:05:41 +0000128
mbligh03f4fc72007-11-29 20:56:14 +0000129class AutoservHostError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000130 """Error reaching a host"""
131 pass
mbligh03f4fc72007-11-29 20:56:14 +0000132
mbligh7e1b1502008-06-06 15:05:41 +0000133
mbligh03f4fc72007-11-29 20:56:14 +0000134class AutoservRebootError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000135 """Error occured while rebooting a machine"""
136 pass
mbligh6e2ffec2008-03-05 16:08:34 +0000137
mbligh7e1b1502008-06-06 15:05:41 +0000138
mbligh6e2ffec2008-03-05 16:08:34 +0000139class AutoservSubcommandError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000140 """Indicates an error while executing a (forked) subcommand"""
141 def __init__(self, func, exit_code):
142 AutoservError.__init__(self, func, exit_code)
143 self.func = func
144 self.exit_code = exit_code
mbligh7e1b1502008-06-06 15:05:41 +0000145
jadmanski0afbb632008-06-06 21:10:57 +0000146 def __str__(self):
147 return ("Subcommand %s failed with exit code %d" %
148 (self.func, self.exit_code))