blob: 1fe33700450aafc172c8da7ffa692bf78508f97a [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():
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."""
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):
jadmanski0afbb632008-06-06 21:10:57 +000078 """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):
jadmanski0afbb632008-06-06 21:10:57 +000083 pass
mbligh6f015c42008-02-12 20:55:03 +000084
mbligh7e1b1502008-06-06 15:05:41 +000085
mbligh6f015c42008-02-12 20:55:03 +000086class AutotestTimeoutError(AutotestError):
jadmanski0afbb632008-06-06 21:10:57 +000087 """This exception is raised when an autotest test exceeds the timeout
88 parameter passed to run_timed_test and is killed.
89 """
mbligh6f015c42008-02-12 20:55:03 +000090
91
mbligh03f4fc72007-11-29 20:56:14 +000092# server-specific errors
93
94class AutoservError(Exception):
jadmanski0afbb632008-06-06 21:10:57 +000095 pass
mbligh03f4fc72007-11-29 20:56:14 +000096
97
mbligh34faa282008-01-16 17:44:49 +000098class AutoservSSHTimeout(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +000099 """SSH experienced a connection timeout"""
100 pass
mbligh34faa282008-01-16 17:44:49 +0000101
102
mbligh03f4fc72007-11-29 20:56:14 +0000103class AutoservRunError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +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):
jadmanski0afbb632008-06-06 21:10:57 +0000114 """Vitualization related error"""
115 pass
mbligh03f4fc72007-11-29 20:56:14 +0000116
117
118class AutoservUnsupportedError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000119 """Error raised when you try to use an unsupported optional feature"""
120 pass
mbligh03f4fc72007-11-29 20:56:14 +0000121
mbligh7e1b1502008-06-06 15:05:41 +0000122
mbligh03f4fc72007-11-29 20:56:14 +0000123class AutoservHostError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000124 """Error reaching a host"""
125 pass
mbligh03f4fc72007-11-29 20:56:14 +0000126
mbligh7e1b1502008-06-06 15:05:41 +0000127
mbligh03f4fc72007-11-29 20:56:14 +0000128class AutoservRebootError(AutoservError):
jadmanski0afbb632008-06-06 21:10:57 +0000129 """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):
jadmanski0afbb632008-06-06 21:10:57 +0000134 """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
jadmanski0afbb632008-06-06 21:10:57 +0000140 def __str__(self):
141 return ("Subcommand %s failed with exit code %d" %
142 (self.func, self.exit_code))