Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 1 | # 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 | |
| 16 | import testtools |
| 17 | |
| 18 | |
| 19 | class 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 Igawa | 0c0f014 | 2017-04-10 17:22:02 +0900 | [diff] [blame] | 35 | if args: |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 36 | # 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) | ff50cc5 | 2016-08-08 10:34:31 +0100 | [diff] [blame] | 47 | def __repr__(self): |
| 48 | return self._error_string |
| 49 | |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 50 | |
| 51 | class 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 | |
| 61 | class OtherRestClientException(RestClientException): |
| 62 | pass |
| 63 | |
| 64 | |
| 65 | class ServerRestClientException(RestClientException): |
| 66 | pass |
| 67 | |
| 68 | |
| 69 | class ClientRestClientException(RestClientException): |
| 70 | pass |
| 71 | |
| 72 | |
| 73 | class InvalidHttpSuccessCode(OtherRestClientException): |
| 74 | message = "The success code is different than the expected one" |
| 75 | |
| 76 | |
Ken'ichi Ohmichi | 2553e3b | 2016-12-06 15:50:36 -0800 | [diff] [blame] | 77 | class BadRequest(ClientRestClientException): |
| 78 | status_code = 400 |
| 79 | message = "Bad request" |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 80 | |
| 81 | |
| 82 | class Unauthorized(ClientRestClientException): |
Ken'ichi Ohmichi | 2553e3b | 2016-12-06 15:50:36 -0800 | [diff] [blame] | 83 | status_code = 401 |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 84 | message = 'Unauthorized' |
| 85 | |
| 86 | |
| 87 | class Forbidden(ClientRestClientException): |
Ken'ichi Ohmichi | 2553e3b | 2016-12-06 15:50:36 -0800 | [diff] [blame] | 88 | status_code = 403 |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 89 | message = "Forbidden" |
| 90 | |
| 91 | |
Ken'ichi Ohmichi | 2553e3b | 2016-12-06 15:50:36 -0800 | [diff] [blame] | 92 | class NotFound(ClientRestClientException): |
| 93 | status_code = 404 |
| 94 | message = "Object not found" |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 95 | |
| 96 | |
| 97 | class Conflict(ClientRestClientException): |
Ken'ichi Ohmichi | 2553e3b | 2016-12-06 15:50:36 -0800 | [diff] [blame] | 98 | status_code = 409 |
zhufl | f312f15 | 2017-11-23 16:51:37 +0800 | [diff] [blame] | 99 | message = "Conflict with state of target resource" |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 100 | |
| 101 | |
| 102 | class Gone(ClientRestClientException): |
Ken'ichi Ohmichi | 2553e3b | 2016-12-06 15:50:36 -0800 | [diff] [blame] | 103 | status_code = 410 |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 104 | message = "The requested resource is no longer available" |
| 105 | |
| 106 | |
Kevin Benton | a82bc86 | 2017-02-13 01:16:13 -0800 | [diff] [blame] | 107 | class PreconditionFailed(ClientRestClientException): |
| 108 | status_code = 412 |
| 109 | message = "Precondition Failed" |
| 110 | |
| 111 | |
Ken'ichi Ohmichi | 2553e3b | 2016-12-06 15:50:36 -0800 | [diff] [blame] | 112 | class RateLimitExceeded(ClientRestClientException): |
| 113 | status_code = 413 |
| 114 | message = "Rate limit exceeded" |
| 115 | |
| 116 | |
| 117 | class OverLimit(ClientRestClientException): |
| 118 | status_code = 413 |
| 119 | message = "Request entity is too large" |
| 120 | |
| 121 | |
| 122 | class InvalidContentType(ClientRestClientException): |
| 123 | status_code = 415 |
| 124 | message = "Invalid content type provided" |
| 125 | |
| 126 | |
| 127 | class UnprocessableEntity(ClientRestClientException): |
| 128 | status_code = 422 |
| 129 | message = "Unprocessable entity" |
| 130 | |
| 131 | |
| 132 | class ServerFault(ServerRestClientException): |
| 133 | status_code = 500 |
| 134 | message = "Got server fault" |
| 135 | |
| 136 | |
| 137 | class NotImplemented(ServerRestClientException): |
| 138 | status_code = 501 |
| 139 | message = "Got NotImplemented error" |
| 140 | |
| 141 | |
| 142 | class TimeoutException(OtherRestClientException): |
| 143 | message = "Request timed out" |
| 144 | |
| 145 | |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 146 | class ResponseWithNonEmptyBody(OtherRestClientException): |
| 147 | message = ("RFC Violation! Response with %(status)d HTTP Status Code " |
| 148 | "MUST NOT have a body") |
| 149 | |
| 150 | |
| 151 | class ResponseWithEntity(OtherRestClientException): |
| 152 | message = ("RFC Violation! Response with 205 HTTP Status Code " |
| 153 | "MUST NOT have an entity") |
| 154 | |
| 155 | |
| 156 | class InvalidHTTPResponseBody(OtherRestClientException): |
| 157 | message = "HTTP response body is invalid json or xml" |
| 158 | |
| 159 | |
| 160 | class InvalidHTTPResponseHeader(OtherRestClientException): |
| 161 | message = "HTTP response header is invalid" |
| 162 | |
| 163 | |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 164 | class UnexpectedContentType(OtherRestClientException): |
| 165 | message = "Unexpected content type provided" |
| 166 | |
| 167 | |
| 168 | class UnexpectedResponseCode(OtherRestClientException): |
| 169 | message = "Unexpected response code received" |
| 170 | |
| 171 | |
Matthew Treinish | 4217a70 | 2016-10-07 17:27:11 -0400 | [diff] [blame] | 172 | class InvalidConfiguration(TempestException): |
| 173 | message = "Invalid Configuration" |
| 174 | |
| 175 | |
ghanshyam | c0d500a | 2016-06-15 09:50:21 +0900 | [diff] [blame] | 176 | class InvalidIdentityVersion(TempestException): |
| 177 | message = "Invalid version %(identity_version)s of the identity service" |
| 178 | |
| 179 | |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 180 | class InvalidStructure(TempestException): |
| 181 | message = "Invalid structure of table with details" |
| 182 | |
| 183 | |
Ghanshyam | 1f47cf9 | 2016-02-25 04:57:18 +0900 | [diff] [blame] | 184 | class 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 | |
| 189 | class JSONSchemaNotFound(TempestException): |
| 190 | message = ("JSON Schema for %(version)s is not found in\n" |
| 191 | " %(schema_versions_info)s") |
| 192 | |
| 193 | |
| 194 | class InvalidAPIVersionRange(TempestException): |
| 195 | message = ("The API version range is invalid.") |
| 196 | |
| 197 | |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 198 | class 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 | |
| 209 | class 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 | |
| 226 | class IdentityError(TempestException): |
| 227 | message = "Got identity error" |
| 228 | |
| 229 | |
| 230 | class EndpointNotFound(TempestException): |
| 231 | message = "Endpoint not found" |
| 232 | |
| 233 | |
| 234 | class InvalidCredentials(TempestException): |
| 235 | message = "Invalid Credentials" |
| 236 | |
| 237 | |
Andrea Frittoli (andreaf) | 3e82af7 | 2016-05-05 22:53:38 +0100 | [diff] [blame] | 238 | class InvalidScope(TempestException): |
| 239 | message = "Invalid Scope %(scope)s for %(auth_provider)s" |
| 240 | |
| 241 | |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 242 | class SSHTimeout(TempestException): |
| 243 | message = ("Connection to the %(host)s via SSH timed out.\n" |
| 244 | "User: %(user)s, Password: %(password)s") |
| 245 | |
| 246 | |
| 247 | class 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) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 252 | |
| 253 | |
Rodolfo Alonso Hernandez | bcfa06d | 2020-01-22 17:29:18 +0000 | [diff] [blame] | 254 | class 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) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 259 | class UnknownServiceClient(TempestException): |
| 260 | message = "Service clients named %(services)s are not known" |
Andrea Frittoli (andreaf) | 6d4d85a | 2016-06-21 17:20:31 +0100 | [diff] [blame] | 261 | |
| 262 | |
| 263 | class 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 | |
| 269 | class PluginRegistrationException(TempestException): |
| 270 | message = "Error registering plugin %(name)s: %(detailed_error)s" |
David Paterson | 9eabc33 | 2016-09-20 06:53:47 -0700 | [diff] [blame] | 271 | |
| 272 | |
| 273 | class VolumeBackupException(TempestException): |
| 274 | message = "Volume backup %(backup_id)s failed and is in ERROR status" |
zoukeke | 33726c3 | 2017-02-07 17:25:20 +0800 | [diff] [blame] | 275 | |
| 276 | |
| 277 | class DeleteErrorException(TempestException): |
| 278 | message = ("Resource %(resource_id)s failed to delete " |
| 279 | "and is in ERROR status") |
Matthew Treinish | b19c55d | 2017-07-17 12:38:35 -0400 | [diff] [blame] | 280 | |
| 281 | |
| 282 | class InvalidTestResource(TempestException): |
| 283 | message = "%(name)s is not a valid %(type)s, or the name is ambiguous" |
Felipe Monteiro | 9ff5c28 | 2017-06-21 21:05:07 +0100 | [diff] [blame] | 284 | |
| 285 | |
| 286 | class InvalidParam(TempestException): |
| 287 | message = ("Invalid Parameter passed: %(invalid_param)s") |
Rajat Dhasmana | fbea823 | 2020-01-06 10:44:33 +0000 | [diff] [blame] | 288 | |
| 289 | |
| 290 | class ConsistencyGroupException(TempestException): |
| 291 | message = "Consistency group %(cg_id)s failed and is in ERROR status" |
| 292 | |
| 293 | |
| 294 | class ConsistencyGroupSnapshotException(TempestException): |
| 295 | message = ("Consistency group snapshot %(cgsnapshot_id)s failed and is " |
| 296 | "in ERROR status") |