blob: 09f701683b2d7d81aaf5942afe6ccd9e3ee99d16 [file] [log] [blame]
Maru Newbyb096d9f2015-03-09 18:54:54 +00001# Copyright 2012 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16import testtools
17
18
19class TempestException(Exception):
20 """
21 Base Tempest Exception
22
23 To correctly use this class, inherit from it and define
24 a 'message' property. That message will get printf'd
25 with the keyword arguments provided to the constructor.
26 """
27 message = "An unknown exception occurred"
28
29 def __init__(self, *args, **kwargs):
30 super(TempestException, self).__init__()
31 try:
32 self._error_string = self.message % kwargs
33 except Exception:
34 # at least get the core message out if something happened
35 self._error_string = self.message
36 if len(args) > 0:
37 # If there is a non-kwarg parameter, assume it's the error
38 # message or reason description and tack it on to the end
39 # of the exception message
40 # Convert all arguments into their string representations...
41 args = ["%s" % arg for arg in args]
42 self._error_string = (self._error_string +
43 "\nDetails: %s" % '\n'.join(args))
44
45 def __str__(self):
46 return self._error_string
47
48
49class RestClientException(TempestException,
50 testtools.TestCase.failureException):
51 pass
52
53
54class InvalidConfiguration(TempestException):
55 message = "Invalid Configuration"
56
57
58class InvalidCredentials(TempestException):
59 message = "Invalid Credentials"
60
61
62class InvalidServiceTag(TempestException):
63 message = "Invalid service tag"
64
65
66class InvalidIdentityVersion(TempestException):
67 message = "Invalid version %(identity_version) of the identity service"
68
69
70class TimeoutException(TempestException):
71 message = "Request timed out"
72
73
74class BuildErrorException(TempestException):
75 message = "Server %(server_id)s failed to build and is in ERROR status"
76
77
78class ImageKilledException(TempestException):
79 message = "Image %(image_id)s 'killed' while waiting for '%(status)s'"
80
81
82class AddImageException(TempestException):
83 message = "Image %(image_id)s failed to become ACTIVE in the allotted time"
84
85
86class EC2RegisterImageException(TempestException):
87 message = ("Image %(image_id)s failed to become 'available' "
88 "in the allotted time")
89
90
91class VolumeBuildErrorException(TempestException):
92 message = "Volume %(volume_id)s failed to build and is in ERROR status"
93
94
95class SnapshotBuildErrorException(TempestException):
96 message = "Snapshot %(snapshot_id)s failed to build and is in ERROR status"
97
98
99class VolumeBackupException(TempestException):
100 message = "Volume backup %(backup_id)s failed and is in ERROR status"
101
102
103class StackBuildErrorException(TempestException):
104 message = ("Stack %(stack_identifier)s is in %(stack_status)s status "
105 "due to '%(stack_status_reason)s'")
106
107
108class StackResourceBuildErrorException(TempestException):
109 message = ("Resource %(resource_name)s in stack %(stack_identifier)s is "
110 "in %(resource_status)s status due to "
111 "'%(resource_status_reason)s'")
112
113
114class AuthenticationFailure(TempestException):
115 message = ("Authentication with user %(user)s and password "
116 "%(password)s failed auth using tenant %(tenant)s.")
117
118
119class EndpointNotFound(TempestException):
120 message = "Endpoint not found"
121
122
123class ImageFault(TempestException):
124 message = "Got image fault"
125
126
127class IdentityError(TempestException):
128 message = "Got identity error"
129
130
131class SSHTimeout(TempestException):
132 message = ("Connection to the %(host)s via SSH timed out.\n"
133 "User: %(user)s, Password: %(password)s")
134
135
136class SSHExecCommandFailed(TempestException):
137 """Raised when remotely executed command returns nonzero status."""
138 message = ("Command '%(command)s', exit status: %(exit_status)d, "
139 "Error:\n%(strerror)s")
140
141
142class ServerUnreachable(TempestException):
143 message = "The server is not reachable via the configured network"
144
145
146class TearDownException(TempestException):
147 message = "%(num)d cleanUp operation failed"
148
149
150class RFCViolation(RestClientException):
151 message = "RFC Violation"
152
153
154class InvalidHttpSuccessCode(RestClientException):
155 message = "The success code is different than the expected one"
156
157
158class BadRequest(RestClientException):
159 message = "Bad request"
160
161
162class ResponseWithNonEmptyBody(RFCViolation):
163 message = ("RFC Violation! Response with %(status)d HTTP Status Code "
164 "MUST NOT have a body")
165
166
167class ResponseWithEntity(RFCViolation):
168 message = ("RFC Violation! Response with 205 HTTP Status Code "
169 "MUST NOT have an entity")
170
171
172class InvalidHTTPResponseHeader(RestClientException):
173 message = "HTTP response header is invalid"
174
175
176class InvalidStructure(TempestException):
177 message = "Invalid structure of table with details"
178
179
180class CommandFailed(Exception):
181 def __init__(self, returncode, cmd, output, stderr):
182 super(CommandFailed, self).__init__()
183 self.returncode = returncode
184 self.cmd = cmd
185 self.stdout = output
186 self.stderr = stderr
187
188 def __str__(self):
189 return ("Command '%s' returned non-zero exit status %d.\n"
190 "stdout:\n%s\n"
191 "stderr:\n%s" % (self.cmd,
192 self.returncode,
193 self.stdout,
194 self.stderr))