blob: 84b7ee6ebb5dacb1b22628833e5a7097dd521aef [file] [log] [blame]
Matthew Treinish9e26ca82016-02-23 11:43:20 -05001# 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 """Base Tempest Exception
21
22 To correctly use this class, inherit from it and define
23 a 'message' property. That message will get printf'd
24 with the keyword arguments provided to the constructor.
25 """
26 message = "An unknown exception occurred"
27
28 def __init__(self, *args, **kwargs):
29 super(TempestException, self).__init__()
30 try:
31 self._error_string = self.message % kwargs
32 except Exception:
33 # at least get the core message out if something happened
34 self._error_string = self.message
Masayuki Igawa0c0f0142017-04-10 17:22:02 +090035 if args:
Matthew Treinish9e26ca82016-02-23 11:43:20 -050036 # If there is a non-kwarg parameter, assume it's the error
37 # message or reason description and tack it on to the end
38 # of the exception message
39 # Convert all arguments into their string representations...
40 args = ["%s" % arg for arg in args]
41 self._error_string = (self._error_string +
42 "\nDetails: %s" % '\n'.join(args))
43
44 def __str__(self):
45 return self._error_string
46
Andrea Frittoli (andreaf)ff50cc52016-08-08 10:34:31 +010047 def __repr__(self):
48 return self._error_string
49
Matthew Treinish9e26ca82016-02-23 11:43:20 -050050
51class RestClientException(TempestException,
52 testtools.TestCase.failureException):
53 def __init__(self, resp_body=None, *args, **kwargs):
54 if 'resp' in kwargs:
55 self.resp = kwargs.get('resp')
56 self.resp_body = resp_body
57 message = kwargs.get("message", resp_body)
58 super(RestClientException, self).__init__(message, *args, **kwargs)
59
60
61class OtherRestClientException(RestClientException):
62 pass
63
64
65class ServerRestClientException(RestClientException):
66 pass
67
68
69class ClientRestClientException(RestClientException):
70 pass
71
72
73class InvalidHttpSuccessCode(OtherRestClientException):
74 message = "The success code is different than the expected one"
75
76
Ken'ichi Ohmichi2553e3b2016-12-06 15:50:36 -080077class BadRequest(ClientRestClientException):
78 status_code = 400
79 message = "Bad request"
Matthew Treinish9e26ca82016-02-23 11:43:20 -050080
81
82class Unauthorized(ClientRestClientException):
Ken'ichi Ohmichi2553e3b2016-12-06 15:50:36 -080083 status_code = 401
Matthew Treinish9e26ca82016-02-23 11:43:20 -050084 message = 'Unauthorized'
85
86
87class Forbidden(ClientRestClientException):
Ken'ichi Ohmichi2553e3b2016-12-06 15:50:36 -080088 status_code = 403
Matthew Treinish9e26ca82016-02-23 11:43:20 -050089 message = "Forbidden"
90
91
Ken'ichi Ohmichi2553e3b2016-12-06 15:50:36 -080092class NotFound(ClientRestClientException):
93 status_code = 404
94 message = "Object not found"
Matthew Treinish9e26ca82016-02-23 11:43:20 -050095
96
97class Conflict(ClientRestClientException):
Ken'ichi Ohmichi2553e3b2016-12-06 15:50:36 -080098 status_code = 409
zhuflf312f152017-11-23 16:51:37 +080099 message = "Conflict with state of target resource"
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500100
101
102class Gone(ClientRestClientException):
Ken'ichi Ohmichi2553e3b2016-12-06 15:50:36 -0800103 status_code = 410
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500104 message = "The requested resource is no longer available"
105
106
Kevin Bentona82bc862017-02-13 01:16:13 -0800107class PreconditionFailed(ClientRestClientException):
108 status_code = 412
109 message = "Precondition Failed"
110
111
Ken'ichi Ohmichi2553e3b2016-12-06 15:50:36 -0800112class RateLimitExceeded(ClientRestClientException):
113 status_code = 413
114 message = "Rate limit exceeded"
115
116
117class OverLimit(ClientRestClientException):
118 status_code = 413
119 message = "Request entity is too large"
120
121
122class InvalidContentType(ClientRestClientException):
123 status_code = 415
124 message = "Invalid content type provided"
125
126
127class UnprocessableEntity(ClientRestClientException):
128 status_code = 422
129 message = "Unprocessable entity"
130
131
132class ServerFault(ServerRestClientException):
133 status_code = 500
134 message = "Got server fault"
135
136
137class NotImplemented(ServerRestClientException):
138 status_code = 501
139 message = "Got NotImplemented error"
140
141
142class TimeoutException(OtherRestClientException):
143 message = "Request timed out"
144
145
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500146class ResponseWithNonEmptyBody(OtherRestClientException):
147 message = ("RFC Violation! Response with %(status)d HTTP Status Code "
148 "MUST NOT have a body")
149
150
151class ResponseWithEntity(OtherRestClientException):
152 message = ("RFC Violation! Response with 205 HTTP Status Code "
153 "MUST NOT have an entity")
154
155
156class InvalidHTTPResponseBody(OtherRestClientException):
157 message = "HTTP response body is invalid json or xml"
158
159
160class InvalidHTTPResponseHeader(OtherRestClientException):
161 message = "HTTP response header is invalid"
162
163
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500164class UnexpectedContentType(OtherRestClientException):
165 message = "Unexpected content type provided"
166
167
168class UnexpectedResponseCode(OtherRestClientException):
169 message = "Unexpected response code received"
170
171
Matthew Treinish4217a702016-10-07 17:27:11 -0400172class InvalidConfiguration(TempestException):
173 message = "Invalid Configuration"
174
175
ghanshyamc0d500a2016-06-15 09:50:21 +0900176class InvalidIdentityVersion(TempestException):
177 message = "Invalid version %(identity_version)s of the identity service"
178
179
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500180class InvalidStructure(TempestException):
181 message = "Invalid structure of table with details"
182
183
Ghanshyam1f47cf92016-02-25 04:57:18 +0900184class InvalidAPIVersionString(TempestException):
185 message = ("API Version String %(version)s is of invalid format. Must "
186 "be of format MajorNum.MinorNum or string 'latest'.")
187
188
189class JSONSchemaNotFound(TempestException):
190 message = ("JSON Schema for %(version)s is not found in\n"
191 " %(schema_versions_info)s")
192
193
194class InvalidAPIVersionRange(TempestException):
195 message = ("The API version range is invalid.")
196
197
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500198class BadAltAuth(TempestException):
199 """Used when trying and failing to change to alt creds.
200
201 If alt creds end up the same as primary creds, use this
202 exception. This is often going to be the case when you assume
203 project_id is in the url, but it's not.
204
205 """
206 message = "The alt auth looks the same as primary auth for %(part)s"
207
208
209class CommandFailed(Exception):
210 def __init__(self, returncode, cmd, output, stderr):
211 super(CommandFailed, self).__init__()
212 self.returncode = returncode
213 self.cmd = cmd
214 self.stdout = output
215 self.stderr = stderr
216
217 def __str__(self):
218 return ("Command '%s' returned non-zero exit status %d.\n"
219 "stdout:\n%s\n"
220 "stderr:\n%s" % (self.cmd,
221 self.returncode,
222 self.stdout,
223 self.stderr))
224
225
226class IdentityError(TempestException):
227 message = "Got identity error"
228
229
230class EndpointNotFound(TempestException):
231 message = "Endpoint not found"
232
233
234class InvalidCredentials(TempestException):
235 message = "Invalid Credentials"
236
237
Andrea Frittoli (andreaf)3e82af72016-05-05 22:53:38 +0100238class InvalidScope(TempestException):
239 message = "Invalid Scope %(scope)s for %(auth_provider)s"
240
241
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500242class SSHTimeout(TempestException):
243 message = ("Connection to the %(host)s via SSH timed out.\n"
244 "User: %(user)s, Password: %(password)s")
245
246
247class SSHExecCommandFailed(TempestException):
248 """Raised when remotely executed command returns nonzero status."""
249 message = ("Command '%(command)s', exit status: %(exit_status)d, "
250 "stderr:\n%(stderr)s\n"
251 "stdout:\n%(stdout)s")
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100252
253
Rodolfo Alonso Hernandezbcfa06d2020-01-22 17:29:18 +0000254class SSHClientProxyClientLoop(TempestException):
255 message = ("SSH client proxy client has same host: %(host)s, port: "
256 "%(port)s and username: %(username)s as parent")
257
258
Andrea Frittoli (andreaf)de5fb0c2016-06-13 12:15:00 +0100259class UnknownServiceClient(TempestException):
260 message = "Service clients named %(services)s are not known"
Andrea Frittoli (andreaf)6d4d85a2016-06-21 17:20:31 +0100261
262
263class ServiceClientRegistrationException(TempestException):
264 message = ("Error registering module %(name)s in path %(module_path)s, "
265 "with service %(service_version)s and clients "
266 "%(client_names)s: %(detailed_error)s")
267
268
269class PluginRegistrationException(TempestException):
270 message = "Error registering plugin %(name)s: %(detailed_error)s"
David Paterson9eabc332016-09-20 06:53:47 -0700271
272
273class VolumeBackupException(TempestException):
274 message = "Volume backup %(backup_id)s failed and is in ERROR status"
zoukeke33726c32017-02-07 17:25:20 +0800275
276
277class DeleteErrorException(TempestException):
278 message = ("Resource %(resource_id)s failed to delete "
279 "and is in ERROR status")
Matthew Treinishb19c55d2017-07-17 12:38:35 -0400280
281
282class InvalidTestResource(TempestException):
283 message = "%(name)s is not a valid %(type)s, or the name is ambiguous"
Felipe Monteiro9ff5c282017-06-21 21:05:07 +0100284
285
286class InvalidParam(TempestException):
287 message = ("Invalid Parameter passed: %(invalid_param)s")
Rajat Dhasmanafbea8232020-01-06 10:44:33 +0000288
289
290class ConsistencyGroupException(TempestException):
291 message = "Consistency group %(cg_id)s failed and is in ERROR status"
292
293
294class ConsistencyGroupSnapshotException(TempestException):
295 message = ("Consistency group snapshot %(cgsnapshot_id)s failed and is "
296 "in ERROR status")