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 |
| 35 | if len(args) > 0: |
| 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 | |
| 47 | |
| 48 | class RestClientException(TempestException, |
| 49 | testtools.TestCase.failureException): |
| 50 | def __init__(self, resp_body=None, *args, **kwargs): |
| 51 | if 'resp' in kwargs: |
| 52 | self.resp = kwargs.get('resp') |
| 53 | self.resp_body = resp_body |
| 54 | message = kwargs.get("message", resp_body) |
| 55 | super(RestClientException, self).__init__(message, *args, **kwargs) |
| 56 | |
| 57 | |
| 58 | class OtherRestClientException(RestClientException): |
| 59 | pass |
| 60 | |
| 61 | |
| 62 | class ServerRestClientException(RestClientException): |
| 63 | pass |
| 64 | |
| 65 | |
| 66 | class ClientRestClientException(RestClientException): |
| 67 | pass |
| 68 | |
| 69 | |
| 70 | class InvalidHttpSuccessCode(OtherRestClientException): |
| 71 | message = "The success code is different than the expected one" |
| 72 | |
| 73 | |
| 74 | class NotFound(ClientRestClientException): |
| 75 | message = "Object not found" |
| 76 | |
| 77 | |
| 78 | class Unauthorized(ClientRestClientException): |
| 79 | message = 'Unauthorized' |
| 80 | |
| 81 | |
| 82 | class Forbidden(ClientRestClientException): |
| 83 | message = "Forbidden" |
| 84 | |
| 85 | |
| 86 | class TimeoutException(OtherRestClientException): |
| 87 | message = "Request timed out" |
| 88 | |
| 89 | |
| 90 | class BadRequest(ClientRestClientException): |
| 91 | message = "Bad request" |
| 92 | |
| 93 | |
| 94 | class UnprocessableEntity(ClientRestClientException): |
| 95 | message = "Unprocessable entity" |
| 96 | |
| 97 | |
| 98 | class RateLimitExceeded(ClientRestClientException): |
| 99 | message = "Rate limit exceeded" |
| 100 | |
| 101 | |
| 102 | class OverLimit(ClientRestClientException): |
| 103 | message = "Quota exceeded" |
| 104 | |
| 105 | |
| 106 | class ServerFault(ServerRestClientException): |
| 107 | message = "Got server fault" |
| 108 | |
| 109 | |
| 110 | class NotImplemented(ServerRestClientException): |
| 111 | message = "Got NotImplemented error" |
| 112 | |
| 113 | |
| 114 | class Conflict(ClientRestClientException): |
| 115 | message = "An object with that identifier already exists" |
| 116 | |
| 117 | |
| 118 | class Gone(ClientRestClientException): |
| 119 | message = "The requested resource is no longer available" |
| 120 | |
| 121 | |
| 122 | class ResponseWithNonEmptyBody(OtherRestClientException): |
| 123 | message = ("RFC Violation! Response with %(status)d HTTP Status Code " |
| 124 | "MUST NOT have a body") |
| 125 | |
| 126 | |
| 127 | class ResponseWithEntity(OtherRestClientException): |
| 128 | message = ("RFC Violation! Response with 205 HTTP Status Code " |
| 129 | "MUST NOT have an entity") |
| 130 | |
| 131 | |
| 132 | class InvalidHTTPResponseBody(OtherRestClientException): |
| 133 | message = "HTTP response body is invalid json or xml" |
| 134 | |
| 135 | |
| 136 | class InvalidHTTPResponseHeader(OtherRestClientException): |
| 137 | message = "HTTP response header is invalid" |
| 138 | |
| 139 | |
| 140 | class InvalidContentType(ClientRestClientException): |
| 141 | message = "Invalid content type provided" |
| 142 | |
| 143 | |
| 144 | class UnexpectedContentType(OtherRestClientException): |
| 145 | message = "Unexpected content type provided" |
| 146 | |
| 147 | |
| 148 | class UnexpectedResponseCode(OtherRestClientException): |
| 149 | message = "Unexpected response code received" |
| 150 | |
| 151 | |
ghanshyam | c0d500a | 2016-06-15 09:50:21 +0900 | [diff] [blame] | 152 | class InvalidIdentityVersion(TempestException): |
| 153 | message = "Invalid version %(identity_version)s of the identity service" |
| 154 | |
| 155 | |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 156 | class InvalidStructure(TempestException): |
| 157 | message = "Invalid structure of table with details" |
| 158 | |
| 159 | |
Ghanshyam | 1f47cf9 | 2016-02-25 04:57:18 +0900 | [diff] [blame] | 160 | class InvalidAPIVersionString(TempestException): |
| 161 | message = ("API Version String %(version)s is of invalid format. Must " |
| 162 | "be of format MajorNum.MinorNum or string 'latest'.") |
| 163 | |
| 164 | |
| 165 | class JSONSchemaNotFound(TempestException): |
| 166 | message = ("JSON Schema for %(version)s is not found in\n" |
| 167 | " %(schema_versions_info)s") |
| 168 | |
| 169 | |
| 170 | class InvalidAPIVersionRange(TempestException): |
| 171 | message = ("The API version range is invalid.") |
| 172 | |
| 173 | |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 174 | class BadAltAuth(TempestException): |
| 175 | """Used when trying and failing to change to alt creds. |
| 176 | |
| 177 | If alt creds end up the same as primary creds, use this |
| 178 | exception. This is often going to be the case when you assume |
| 179 | project_id is in the url, but it's not. |
| 180 | |
| 181 | """ |
| 182 | message = "The alt auth looks the same as primary auth for %(part)s" |
| 183 | |
| 184 | |
| 185 | class CommandFailed(Exception): |
| 186 | def __init__(self, returncode, cmd, output, stderr): |
| 187 | super(CommandFailed, self).__init__() |
| 188 | self.returncode = returncode |
| 189 | self.cmd = cmd |
| 190 | self.stdout = output |
| 191 | self.stderr = stderr |
| 192 | |
| 193 | def __str__(self): |
| 194 | return ("Command '%s' returned non-zero exit status %d.\n" |
| 195 | "stdout:\n%s\n" |
| 196 | "stderr:\n%s" % (self.cmd, |
| 197 | self.returncode, |
| 198 | self.stdout, |
| 199 | self.stderr)) |
| 200 | |
| 201 | |
| 202 | class IdentityError(TempestException): |
| 203 | message = "Got identity error" |
| 204 | |
| 205 | |
| 206 | class EndpointNotFound(TempestException): |
| 207 | message = "Endpoint not found" |
| 208 | |
| 209 | |
| 210 | class InvalidCredentials(TempestException): |
| 211 | message = "Invalid Credentials" |
| 212 | |
| 213 | |
Andrea Frittoli (andreaf) | 3e82af7 | 2016-05-05 22:53:38 +0100 | [diff] [blame] | 214 | class InvalidScope(TempestException): |
| 215 | message = "Invalid Scope %(scope)s for %(auth_provider)s" |
| 216 | |
| 217 | |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 218 | class SSHTimeout(TempestException): |
| 219 | message = ("Connection to the %(host)s via SSH timed out.\n" |
| 220 | "User: %(user)s, Password: %(password)s") |
| 221 | |
| 222 | |
| 223 | class SSHExecCommandFailed(TempestException): |
| 224 | """Raised when remotely executed command returns nonzero status.""" |
| 225 | message = ("Command '%(command)s', exit status: %(exit_status)d, " |
| 226 | "stderr:\n%(stderr)s\n" |
| 227 | "stdout:\n%(stdout)s") |
Andrea Frittoli (andreaf) | de5fb0c | 2016-06-13 12:15:00 +0100 | [diff] [blame] | 228 | |
| 229 | |
| 230 | class UnknownServiceClient(TempestException): |
| 231 | message = "Service clients named %(services)s are not known" |
Andrea Frittoli (andreaf) | 6d4d85a | 2016-06-21 17:20:31 +0100 | [diff] [blame] | 232 | |
| 233 | |
| 234 | class ServiceClientRegistrationException(TempestException): |
| 235 | message = ("Error registering module %(name)s in path %(module_path)s, " |
| 236 | "with service %(service_version)s and clients " |
| 237 | "%(client_names)s: %(detailed_error)s") |
| 238 | |
| 239 | |
| 240 | class PluginRegistrationException(TempestException): |
| 241 | message = "Error registering plugin %(name)s: %(detailed_error)s" |