Matthew Treinish | 8bdf6e3 | 2014-04-03 11:49:14 -0400 | [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 | """ |
| 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 | |
| 49 | class RestClientException(TempestException, |
| 50 | testtools.TestCase.failureException): |
| 51 | pass |
| 52 | |
| 53 | |
| 54 | class RFCViolation(RestClientException): |
| 55 | message = "RFC Violation" |
| 56 | |
| 57 | |
| 58 | class InvalidConfiguration(TempestException): |
| 59 | message = "Invalid Configuration" |
| 60 | |
| 61 | |
| 62 | class InvalidCredentials(TempestException): |
| 63 | message = "Invalid Credentials" |
| 64 | |
| 65 | |
| 66 | class InvalidHttpSuccessCode(RestClientException): |
| 67 | message = "The success code is different than the expected one" |
| 68 | |
| 69 | |
| 70 | class NotFound(RestClientException): |
| 71 | message = "Object not found" |
| 72 | |
| 73 | |
| 74 | class Unauthorized(RestClientException): |
| 75 | message = 'Unauthorized' |
| 76 | |
| 77 | |
| 78 | class InvalidServiceTag(RestClientException): |
| 79 | message = "Invalid service tag" |
| 80 | |
| 81 | |
| 82 | class TimeoutException(TempestException): |
| 83 | message = "Request timed out" |
| 84 | |
| 85 | |
| 86 | class BuildErrorException(TempestException): |
| 87 | message = "Server %(server_id)s failed to build and is in ERROR status" |
| 88 | |
| 89 | |
| 90 | class ImageKilledException(TempestException): |
| 91 | message = "Image %(image_id)s 'killed' while waiting for '%(status)s'" |
| 92 | |
| 93 | |
| 94 | class AddImageException(TempestException): |
| 95 | message = "Image %(image_id)s failed to become ACTIVE in the allotted time" |
| 96 | |
| 97 | |
| 98 | class EC2RegisterImageException(TempestException): |
| 99 | message = ("Image %(image_id)s failed to become 'available' " |
| 100 | "in the allotted time") |
| 101 | |
| 102 | |
| 103 | class VolumeBuildErrorException(TempestException): |
| 104 | message = "Volume %(volume_id)s failed to build and is in ERROR status" |
| 105 | |
| 106 | |
| 107 | class SnapshotBuildErrorException(TempestException): |
| 108 | message = "Snapshot %(snapshot_id)s failed to build and is in ERROR status" |
| 109 | |
| 110 | |
| 111 | class VolumeBackupException(TempestException): |
| 112 | message = "Volume backup %(backup_id)s failed and is in ERROR status" |
| 113 | |
| 114 | |
| 115 | class StackBuildErrorException(TempestException): |
| 116 | message = ("Stack %(stack_identifier)s is in %(stack_status)s status " |
| 117 | "due to '%(stack_status_reason)s'") |
| 118 | |
| 119 | |
| 120 | class StackResourceBuildErrorException(TempestException): |
Masayuki Igawa | 89ba568 | 2014-04-28 19:25:53 +0900 | [diff] [blame] | 121 | message = ("Resource %(resource_name)s in stack %(stack_identifier)s is " |
Matthew Treinish | 8bdf6e3 | 2014-04-03 11:49:14 -0400 | [diff] [blame] | 122 | "in %(resource_status)s status due to " |
| 123 | "'%(resource_status_reason)s'") |
| 124 | |
| 125 | |
| 126 | class BadRequest(RestClientException): |
| 127 | message = "Bad request" |
| 128 | |
| 129 | |
| 130 | class UnprocessableEntity(RestClientException): |
| 131 | message = "Unprocessable entity" |
| 132 | |
| 133 | |
| 134 | class AuthenticationFailure(RestClientException): |
| 135 | message = ("Authentication with user %(user)s and password " |
| 136 | "%(password)s failed auth using tenant %(tenant)s.") |
| 137 | |
| 138 | |
| 139 | class EndpointNotFound(TempestException): |
| 140 | message = "Endpoint not found" |
| 141 | |
| 142 | |
| 143 | class RateLimitExceeded(TempestException): |
| 144 | message = "Rate limit exceeded" |
| 145 | |
| 146 | |
| 147 | class OverLimit(TempestException): |
| 148 | message = "Quota exceeded" |
| 149 | |
| 150 | |
| 151 | class ServerFault(TempestException): |
| 152 | message = "Got server fault" |
| 153 | |
| 154 | |
| 155 | class ImageFault(TempestException): |
| 156 | message = "Got image fault" |
| 157 | |
| 158 | |
| 159 | class IdentityError(TempestException): |
| 160 | message = "Got identity error" |
| 161 | |
| 162 | |
| 163 | class Conflict(RestClientException): |
| 164 | message = "An object with that identifier already exists" |
| 165 | |
| 166 | |
| 167 | class SSHTimeout(TempestException): |
| 168 | message = ("Connection to the %(host)s via SSH timed out.\n" |
| 169 | "User: %(user)s, Password: %(password)s") |
| 170 | |
| 171 | |
| 172 | class SSHExecCommandFailed(TempestException): |
| 173 | """Raised when remotely executed command returns nonzero status.""" |
| 174 | message = ("Command '%(command)s', exit status: %(exit_status)d, " |
| 175 | "Error:\n%(strerror)s") |
| 176 | |
| 177 | |
| 178 | class ServerUnreachable(TempestException): |
| 179 | message = "The server is not reachable via the configured network" |
| 180 | |
| 181 | |
| 182 | class TearDownException(TempestException): |
| 183 | message = "%(num)d cleanUp operation failed" |
| 184 | |
| 185 | |
| 186 | class ResponseWithNonEmptyBody(RFCViolation): |
| 187 | message = ("RFC Violation! Response with %(status)d HTTP Status Code " |
| 188 | "MUST NOT have a body") |
| 189 | |
| 190 | |
| 191 | class ResponseWithEntity(RFCViolation): |
| 192 | message = ("RFC Violation! Response with 205 HTTP Status Code " |
| 193 | "MUST NOT have an entity") |
| 194 | |
| 195 | |
| 196 | class InvalidHTTPResponseBody(RestClientException): |
| 197 | message = "HTTP response body is invalid json or xml" |
| 198 | |
| 199 | |
Ken'ichi Ohmichi | 57b384b | 2014-03-28 13:58:20 +0900 | [diff] [blame] | 200 | class InvalidHTTPResponseHeader(RestClientException): |
| 201 | message = "HTTP response header is invalid" |
| 202 | |
| 203 | |
Matthew Treinish | 8bdf6e3 | 2014-04-03 11:49:14 -0400 | [diff] [blame] | 204 | class InvalidContentType(RestClientException): |
| 205 | message = "Invalid content type provided" |
| 206 | |
| 207 | |
| 208 | class UnexpectedResponseCode(RestClientException): |
| 209 | message = "Unexpected response code received" |
| 210 | |
| 211 | |
| 212 | class InvalidStructure(TempestException): |
| 213 | message = "Invalid structure of table with details" |