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 | 9652403 | 2013-01-29 19:52:49 +0100 | [diff] [blame] | 89 | class BadRequest(RestClientException): |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 90 | message = "Bad request" |
Adam Gandelman | e2d46b4 | 2012-01-03 17:40:44 -0800 | [diff] [blame] | 91 | |
| 92 | |
Attila Fazekas | 9652403 | 2013-01-29 19:52:49 +0100 | [diff] [blame] | 93 | class AuthenticationFailure(RestClientException): |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 94 | message = ("Authentication with user %(user)s and password " |
| 95 | "%(password)s failed") |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 96 | |
| 97 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 98 | class EndpointNotFound(TempestException): |
| 99 | message = "Endpoint not found" |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 100 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 101 | |
Jay Pipes | 9b04384 | 2012-01-23 23:34:26 -0500 | [diff] [blame] | 102 | class RateLimitExceeded(TempestException): |
| 103 | message = ("Rate limit exceeded.\nMessage: %(message)s\n" |
| 104 | "Details: %(details)s") |
| 105 | |
| 106 | |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 107 | class OverLimit(TempestException): |
| 108 | message = "Quota exceeded" |
| 109 | |
| 110 | |
| 111 | class ComputeFault(TempestException): |
| 112 | message = "Got compute fault" |
| 113 | |
| 114 | |
Matthew Treinish | 72ea442 | 2013-02-07 14:42:49 -0500 | [diff] [blame^] | 115 | class ImageFault(TempestException): |
| 116 | message = "Got image fault" |
| 117 | |
| 118 | |
Jay Pipes | edba062 | 2012-07-08 21:34:36 -0400 | [diff] [blame] | 119 | class IdentityError(TempestException): |
| 120 | message = "Got identity error" |
| 121 | |
| 122 | |
Attila Fazekas | 9652403 | 2013-01-29 19:52:49 +0100 | [diff] [blame] | 123 | class Duplicate(RestClientException): |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 124 | message = "An object with that identifier already exists" |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 125 | |
| 126 | |
| 127 | class SSHTimeout(TempestException): |
| 128 | message = ("Connection to the %(host)s via SSH timed out.\n" |
Jaroslav Henner | ab32784 | 2012-09-11 15:44:29 +0200 | [diff] [blame] | 129 | "User: %(user)s, Password: %(password)s") |
| 130 | |
| 131 | |
| 132 | class SSHExecCommandFailed(TempestException): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 133 | """Raised when remotely executed command returns nonzero status.""" |
Jaroslav Henner | ab32784 | 2012-09-11 15:44:29 +0200 | [diff] [blame] | 134 | message = ("Command '%(command)s', exit status: %(exit_status)d, " |
| 135 | "Error:\n%(strerror)s") |
Daryl Walleck | 6b9b288 | 2012-04-08 21:43:39 -0500 | [diff] [blame] | 136 | |
| 137 | |
| 138 | class ServerUnreachable(TempestException): |
| 139 | message = "The server is not reachable via the configured network" |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 140 | |
| 141 | |
| 142 | class SQLException(TempestException): |
| 143 | message = "SQL error: %(message)s" |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 144 | |
| 145 | |
| 146 | class TearDownException(TempestException): |
| 147 | message = "%(num)d cleanUp operation failed" |
Attila Fazekas | 72c7a5f | 2012-12-03 17:17:23 +0100 | [diff] [blame] | 148 | |
| 149 | |
Attila Fazekas | 9652403 | 2013-01-29 19:52:49 +0100 | [diff] [blame] | 150 | class RFCViolation(RestClientException): |
Attila Fazekas | 72c7a5f | 2012-12-03 17:17:23 +0100 | [diff] [blame] | 151 | message = "RFC Violation" |
| 152 | |
| 153 | |
| 154 | class ResponseWithNonEmptyBody(RFCViolation): |
Armando Migliaccio | 93225f6 | 2012-12-12 13:56:55 +0000 | [diff] [blame] | 155 | message = ("RFC Violation! Response with %(status)d HTTP Status Code " |
Attila Fazekas | 72c7a5f | 2012-12-03 17:17:23 +0100 | [diff] [blame] | 156 | "MUST NOT have a body") |
| 157 | |
| 158 | |
| 159 | class ResponseWithEntity(RFCViolation): |
| 160 | message = ("RFC Violation! Response with 205 HTTP Status Code " |
| 161 | "MUST NOT have an entity") |