Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2012 OpenStack, LLC |
| 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 | |
| 60 | class NotFound(RestClientException): |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 61 | message = "Object not found" |
Daryl Walleck | adea1fa | 2011-11-15 18:36:39 -0600 | [diff] [blame] | 62 | |
| 63 | |
Attila Fazekas | 9652403 | 2013-01-29 19:52:49 +0100 | [diff] [blame] | 64 | class Unauthorized(RestClientException): |
Daryl Walleck | ced8eb8 | 2012-03-19 13:52:37 -0500 | [diff] [blame] | 65 | message = 'Unauthorized' |
| 66 | |
| 67 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 68 | class TimeoutException(TempestException): |
| 69 | message = "Request timed out" |
Brian Lamar | 12d9b29 | 2011-12-08 12:41:21 -0500 | [diff] [blame] | 70 | |
| 71 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 72 | class BuildErrorException(TempestException): |
| 73 | 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] | 74 | |
| 75 | |
Katherine Elliott | 74f6851 | 2012-05-18 10:19:22 -0600 | [diff] [blame] | 76 | class AddImageException(TempestException): |
Armando Migliaccio | 93225f6 | 2012-12-12 13:56:55 +0000 | [diff] [blame] | 77 | 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] | 78 | |
| 79 | |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 80 | class EC2RegisterImageException(TempestException): |
Armando Migliaccio | 93225f6 | 2012-12-12 13:56:55 +0000 | [diff] [blame] | 81 | message = ("Image %(image_id)s failed to become 'available' " |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 82 | "in the allotted time") |
| 83 | |
| 84 | |
rajalakshmi-ganesan | e3bb58f | 2012-05-16 12:01:15 +0530 | [diff] [blame] | 85 | class VolumeBuildErrorException(TempestException): |
| 86 | message = "Volume %(volume_id)s failed to build and is in ERROR status" |
| 87 | |
| 88 | |
Attila Fazekas | 36b1fcf | 2013-01-31 16:41:04 +0100 | [diff] [blame] | 89 | class SnapshotBuildErrorException(TempestException): |
| 90 | message = "Snapshot %(snapshot_id)s failed to build and is in ERROR status" |
| 91 | |
| 92 | |
Steve Baker | c60e4e3 | 2013-05-06 15:22:41 +1200 | [diff] [blame^] | 93 | class StackBuildErrorException(TempestException): |
| 94 | message = ("Stack %(stack_identifier)s is in %(stack_status)s status " |
| 95 | "due to '%(stack_status_reason)s'") |
| 96 | |
| 97 | |
Attila Fazekas | 9652403 | 2013-01-29 19:52:49 +0100 | [diff] [blame] | 98 | class BadRequest(RestClientException): |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 99 | message = "Bad request" |
Adam Gandelman | e2d46b4 | 2012-01-03 17:40:44 -0800 | [diff] [blame] | 100 | |
| 101 | |
Wangpan | a9b54c6 | 2013-02-28 11:04:32 +0800 | [diff] [blame] | 102 | class UnprocessableEntity(RestClientException): |
| 103 | message = "Unprocessable entity" |
| 104 | |
| 105 | |
Attila Fazekas | 9652403 | 2013-01-29 19:52:49 +0100 | [diff] [blame] | 106 | class AuthenticationFailure(RestClientException): |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 107 | message = ("Authentication with user %(user)s and password " |
| 108 | "%(password)s failed") |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 109 | |
| 110 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 111 | class EndpointNotFound(TempestException): |
| 112 | message = "Endpoint not found" |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 113 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 114 | |
Jay Pipes | 9b04384 | 2012-01-23 23:34:26 -0500 | [diff] [blame] | 115 | class RateLimitExceeded(TempestException): |
| 116 | message = ("Rate limit exceeded.\nMessage: %(message)s\n" |
| 117 | "Details: %(details)s") |
| 118 | |
| 119 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 120 | class OverLimit(TempestException): |
| 121 | message = "Quota exceeded" |
| 122 | |
| 123 | |
| 124 | class ComputeFault(TempestException): |
| 125 | message = "Got compute fault" |
| 126 | |
| 127 | |
Matthew Treinish | 72ea442 | 2013-02-07 14:42:49 -0500 | [diff] [blame] | 128 | class ImageFault(TempestException): |
| 129 | message = "Got image fault" |
| 130 | |
| 131 | |
Jay Pipes | edba062 | 2012-07-08 21:34:36 -0400 | [diff] [blame] | 132 | class IdentityError(TempestException): |
| 133 | message = "Got identity error" |
| 134 | |
| 135 | |
Attila Fazekas | 9652403 | 2013-01-29 19:52:49 +0100 | [diff] [blame] | 136 | class Duplicate(RestClientException): |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 137 | message = "An object with that identifier already exists" |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 138 | |
| 139 | |
| 140 | class SSHTimeout(TempestException): |
| 141 | message = ("Connection to the %(host)s via SSH timed out.\n" |
Jaroslav Henner | ab32784 | 2012-09-11 15:44:29 +0200 | [diff] [blame] | 142 | "User: %(user)s, Password: %(password)s") |
| 143 | |
| 144 | |
| 145 | class SSHExecCommandFailed(TempestException): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 146 | """Raised when remotely executed command returns nonzero status.""" |
Jaroslav Henner | ab32784 | 2012-09-11 15:44:29 +0200 | [diff] [blame] | 147 | message = ("Command '%(command)s', exit status: %(exit_status)d, " |
| 148 | "Error:\n%(strerror)s") |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 149 | |
| 150 | |
| 151 | class ServerUnreachable(TempestException): |
| 152 | message = "The server is not reachable via the configured network" |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 153 | |
| 154 | |
| 155 | class SQLException(TempestException): |
| 156 | message = "SQL error: %(message)s" |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 157 | |
| 158 | |
| 159 | class TearDownException(TempestException): |
| 160 | message = "%(num)d cleanUp operation failed" |
Attila Fazekas | 72c7a5f | 2012-12-03 17:17:23 +0100 | [diff] [blame] | 161 | |
| 162 | |
Attila Fazekas | 9652403 | 2013-01-29 19:52:49 +0100 | [diff] [blame] | 163 | class RFCViolation(RestClientException): |
Attila Fazekas | 72c7a5f | 2012-12-03 17:17:23 +0100 | [diff] [blame] | 164 | message = "RFC Violation" |
| 165 | |
| 166 | |
| 167 | class ResponseWithNonEmptyBody(RFCViolation): |
Armando Migliaccio | 93225f6 | 2012-12-12 13:56:55 +0000 | [diff] [blame] | 168 | message = ("RFC Violation! Response with %(status)d HTTP Status Code " |
Attila Fazekas | 72c7a5f | 2012-12-03 17:17:23 +0100 | [diff] [blame] | 169 | "MUST NOT have a body") |
| 170 | |
| 171 | |
| 172 | class ResponseWithEntity(RFCViolation): |
| 173 | message = ("RFC Violation! Response with 205 HTTP Status Code " |
| 174 | "MUST NOT have an entity") |