Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 3 | # Copyright 2012 OpenStack Foundation |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
ivan-zhu | 4322bb7 | 2013-02-04 11:51:16 +0800 | [diff] [blame] | 18 | import testtools |
Attila Fazekas | 9652403 | 2013-01-29 19:52:49 +0100 | [diff] [blame] | 19 | |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 20 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 21 | class TempestException(Exception): |
| 22 | """ |
| 23 | Base Tempest Exception |
| 24 | |
| 25 | To correctly use this class, inherit from it and define |
| 26 | a 'message' property. That message will get printf'd |
| 27 | with the keyword arguments provided to the constructor. |
| 28 | """ |
| 29 | message = "An unknown exception occurred" |
| 30 | |
| 31 | def __init__(self, *args, **kwargs): |
Attila Fazekas | 9652403 | 2013-01-29 19:52:49 +0100 | [diff] [blame] | 32 | super(TempestException, self).__init__() |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 33 | try: |
| 34 | self._error_string = self.message % kwargs |
| 35 | except Exception: |
| 36 | # at least get the core message out if something happened |
| 37 | self._error_string = self.message |
| 38 | if len(args) > 0: |
| 39 | # If there is a non-kwarg parameter, assume it's the error |
| 40 | # message or reason description and tack it on to the end |
| 41 | # of the exception message |
| 42 | # Convert all arguments into their string representations... |
| 43 | args = ["%s" % arg for arg in args] |
| 44 | self._error_string = (self._error_string + |
| 45 | "\nDetails: %s" % '\n'.join(args)) |
Daryl Walleck | f008703 | 2011-12-18 13:37:05 -0600 | [diff] [blame] | 46 | |
| 47 | def __str__(self): |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 48 | return self._error_string |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 49 | |
| 50 | |
Daryl Walleck | 587385b | 2012-03-03 13:00:26 -0600 | [diff] [blame] | 51 | class InvalidConfiguration(TempestException): |
| 52 | message = "Invalid Configuration" |
| 53 | |
| 54 | |
Attila Fazekas | 9652403 | 2013-01-29 19:52:49 +0100 | [diff] [blame] | 55 | class RestClientException(TempestException, |
ivan-zhu | 4322bb7 | 2013-02-04 11:51:16 +0800 | [diff] [blame] | 56 | testtools.TestCase.failureException): |
Attila Fazekas | 9652403 | 2013-01-29 19:52:49 +0100 | [diff] [blame] | 57 | pass |
| 58 | |
| 59 | |
Attila Fazekas | 54a4286 | 2013-07-28 22:31:06 +0200 | [diff] [blame] | 60 | class InvalidHttpSuccessCode(RestClientException): |
| 61 | message = "The success code is different than the expected one" |
| 62 | |
| 63 | |
Attila Fazekas | 9652403 | 2013-01-29 19:52:49 +0100 | [diff] [blame] | 64 | class NotFound(RestClientException): |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 65 | message = "Object not found" |
Daryl Walleck | adea1fa | 2011-11-15 18:36:39 -0600 | [diff] [blame] | 66 | |
| 67 | |
Attila Fazekas | 9652403 | 2013-01-29 19:52:49 +0100 | [diff] [blame] | 68 | class Unauthorized(RestClientException): |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 69 | message = 'Unauthorized' |
| 70 | |
| 71 | |
Matthew Treinish | 16c4379 | 2013-09-09 19:55:23 +0000 | [diff] [blame] | 72 | class InvalidServiceTag(RestClientException): |
| 73 | message = "Invalid service tag" |
| 74 | |
| 75 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 76 | class TimeoutException(TempestException): |
| 77 | message = "Request timed out" |
Brian Lamar | 12d9b29 | 2011-12-08 12:41:21 -0500 | [diff] [blame] | 78 | |
| 79 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 80 | class BuildErrorException(TempestException): |
| 81 | message = "Server %(server_id)s failed to build and is in ERROR status" |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 82 | |
| 83 | |
Attila Fazekas | 195f1d4 | 2013-10-24 10:33:16 +0200 | [diff] [blame] | 84 | class ImageKilledException(TempestException): |
Attila Fazekas | 9dfb907 | 2013-11-13 16:45:36 +0100 | [diff] [blame] | 85 | message = "Image %(image_id)s 'killed' while waiting for '%(status)s'" |
Attila Fazekas | 195f1d4 | 2013-10-24 10:33:16 +0200 | [diff] [blame] | 86 | |
| 87 | |
Katherine Elliott | 74f6851 | 2012-05-18 10:19:22 -0600 | [diff] [blame] | 88 | class AddImageException(TempestException): |
Armando Migliaccio | 93225f6 | 2012-12-12 13:56:55 +0000 | [diff] [blame] | 89 | message = "Image %(image_id)s failed to become ACTIVE in the allotted time" |
Katherine Elliott | 74f6851 | 2012-05-18 10:19:22 -0600 | [diff] [blame] | 90 | |
| 91 | |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 92 | class EC2RegisterImageException(TempestException): |
Armando Migliaccio | 93225f6 | 2012-12-12 13:56:55 +0000 | [diff] [blame] | 93 | message = ("Image %(image_id)s failed to become 'available' " |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 94 | "in the allotted time") |
| 95 | |
| 96 | |
rajalakshmi-ganesan | e3bb58f | 2012-05-16 12:01:15 +0530 | [diff] [blame] | 97 | class VolumeBuildErrorException(TempestException): |
| 98 | message = "Volume %(volume_id)s failed to build and is in ERROR status" |
| 99 | |
| 100 | |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 101 | class SnapshotBuildErrorException(TempestException): |
| 102 | message = "Snapshot %(snapshot_id)s failed to build and is in ERROR status" |
| 103 | |
| 104 | |
Steve Baker | c60e4e3 | 2013-05-06 15:22:41 +1200 | [diff] [blame] | 105 | class StackBuildErrorException(TempestException): |
| 106 | message = ("Stack %(stack_identifier)s is in %(stack_status)s status " |
| 107 | "due to '%(stack_status_reason)s'") |
| 108 | |
| 109 | |
Attila Fazekas | 9652403 | 2013-01-29 19:52:49 +0100 | [diff] [blame] | 110 | class BadRequest(RestClientException): |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 111 | message = "Bad request" |
Adam Gandelman | e2d46b4 | 2012-01-03 17:40:44 -0800 | [diff] [blame] | 112 | |
| 113 | |
Wangpan | a9b54c6 | 2013-02-28 11:04:32 +0800 | [diff] [blame] | 114 | class UnprocessableEntity(RestClientException): |
| 115 | message = "Unprocessable entity" |
| 116 | |
| 117 | |
Attila Fazekas | 9652403 | 2013-01-29 19:52:49 +0100 | [diff] [blame] | 118 | class AuthenticationFailure(RestClientException): |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 119 | message = ("Authentication with user %(user)s and password " |
Matthew Treinish | b86cda9 | 2013-07-29 11:22:23 -0400 | [diff] [blame] | 120 | "%(password)s failed auth using tenant %(tenant)s.") |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 121 | |
| 122 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 123 | class EndpointNotFound(TempestException): |
| 124 | message = "Endpoint not found" |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 125 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 126 | |
Jay Pipes | 9b04384 | 2012-01-23 23:34:26 -0500 | [diff] [blame] | 127 | class RateLimitExceeded(TempestException): |
| 128 | message = ("Rate limit exceeded.\nMessage: %(message)s\n" |
| 129 | "Details: %(details)s") |
| 130 | |
| 131 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 132 | class OverLimit(TempestException): |
| 133 | message = "Quota exceeded" |
| 134 | |
| 135 | |
Anju5 | c3e510c | 2013-10-18 06:40:29 +0530 | [diff] [blame] | 136 | class ServerFault(TempestException): |
| 137 | message = "Got server fault" |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 138 | |
| 139 | |
Matthew Treinish | 72ea442 | 2013-02-07 14:42:49 -0500 | [diff] [blame] | 140 | class ImageFault(TempestException): |
| 141 | message = "Got image fault" |
| 142 | |
| 143 | |
Jay Pipes | edba062 | 2012-07-08 21:34:36 -0400 | [diff] [blame] | 144 | class IdentityError(TempestException): |
| 145 | message = "Got identity error" |
| 146 | |
| 147 | |
Anju5 | c3e510c | 2013-10-18 06:40:29 +0530 | [diff] [blame] | 148 | class Conflict(RestClientException): |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 149 | message = "An object with that identifier already exists" |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 150 | |
| 151 | |
| 152 | class SSHTimeout(TempestException): |
| 153 | message = ("Connection to the %(host)s via SSH timed out.\n" |
Jaroslav Henner | ab32784 | 2012-09-11 15:44:29 +0200 | [diff] [blame] | 154 | "User: %(user)s, Password: %(password)s") |
| 155 | |
| 156 | |
| 157 | class SSHExecCommandFailed(TempestException): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 158 | """Raised when remotely executed command returns nonzero status.""" |
Jaroslav Henner | ab32784 | 2012-09-11 15:44:29 +0200 | [diff] [blame] | 159 | message = ("Command '%(command)s', exit status: %(exit_status)d, " |
| 160 | "Error:\n%(strerror)s") |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 161 | |
| 162 | |
| 163 | class ServerUnreachable(TempestException): |
| 164 | message = "The server is not reachable via the configured network" |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 165 | |
| 166 | |
| 167 | class SQLException(TempestException): |
| 168 | message = "SQL error: %(message)s" |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 169 | |
| 170 | |
| 171 | class TearDownException(TempestException): |
| 172 | message = "%(num)d cleanUp operation failed" |
Attila Fazekas | 72c7a5f | 2012-12-03 17:17:23 +0100 | [diff] [blame] | 173 | |
| 174 | |
Attila Fazekas | 9652403 | 2013-01-29 19:52:49 +0100 | [diff] [blame] | 175 | class RFCViolation(RestClientException): |
Attila Fazekas | 72c7a5f | 2012-12-03 17:17:23 +0100 | [diff] [blame] | 176 | message = "RFC Violation" |
| 177 | |
| 178 | |
| 179 | class ResponseWithNonEmptyBody(RFCViolation): |
Armando Migliaccio | 93225f6 | 2012-12-12 13:56:55 +0000 | [diff] [blame] | 180 | message = ("RFC Violation! Response with %(status)d HTTP Status Code " |
Attila Fazekas | 72c7a5f | 2012-12-03 17:17:23 +0100 | [diff] [blame] | 181 | "MUST NOT have a body") |
| 182 | |
| 183 | |
| 184 | class ResponseWithEntity(RFCViolation): |
| 185 | message = ("RFC Violation! Response with 205 HTTP Status Code " |
| 186 | "MUST NOT have an entity") |
Rohan Kanade | 433994a | 2013-12-05 22:34:07 +0530 | [diff] [blame] | 187 | |
| 188 | |
| 189 | class InvalidHTTPResponseBody(RestClientException): |
| 190 | message = "HTTP response body is invalid json or xml" |