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 | |
Matthew Treinish | 8bdf6e3 | 2014-04-03 11:49:14 -0400 | [diff] [blame] | 54 | class InvalidConfiguration(TempestException): |
| 55 | message = "Invalid Configuration" |
| 56 | |
| 57 | |
| 58 | class InvalidCredentials(TempestException): |
| 59 | message = "Invalid Credentials" |
| 60 | |
| 61 | |
Ken'ichi Ohmichi | 53c963a | 2014-12-10 06:06:25 +0000 | [diff] [blame] | 62 | class InvalidServiceTag(TempestException): |
Matthew Treinish | 8bdf6e3 | 2014-04-03 11:49:14 -0400 | [diff] [blame] | 63 | message = "Invalid service tag" |
| 64 | |
| 65 | |
Andrea Frittoli | 878d5ab | 2015-01-30 13:22:50 +0000 | [diff] [blame] | 66 | class InvalidIdentityVersion(TempestException): |
ghanshyam | 367c693 | 2015-09-11 18:51:02 +0900 | [diff] [blame] | 67 | message = "Invalid version %(identity_version)s of the identity service" |
Andrea Frittoli | 878d5ab | 2015-01-30 13:22:50 +0000 | [diff] [blame] | 68 | |
| 69 | |
Matthew Treinish | 8bdf6e3 | 2014-04-03 11:49:14 -0400 | [diff] [blame] | 70 | class TimeoutException(TempestException): |
| 71 | message = "Request timed out" |
| 72 | |
| 73 | |
| 74 | class BuildErrorException(TempestException): |
| 75 | message = "Server %(server_id)s failed to build and is in ERROR status" |
| 76 | |
| 77 | |
| 78 | class ImageKilledException(TempestException): |
| 79 | message = "Image %(image_id)s 'killed' while waiting for '%(status)s'" |
| 80 | |
| 81 | |
| 82 | class AddImageException(TempestException): |
| 83 | message = "Image %(image_id)s failed to become ACTIVE in the allotted time" |
| 84 | |
| 85 | |
| 86 | class EC2RegisterImageException(TempestException): |
| 87 | message = ("Image %(image_id)s failed to become 'available' " |
| 88 | "in the allotted time") |
| 89 | |
| 90 | |
| 91 | class VolumeBuildErrorException(TempestException): |
| 92 | message = "Volume %(volume_id)s failed to build and is in ERROR status" |
| 93 | |
| 94 | |
Matt Riedemann | f77e7dc | 2015-08-10 16:39:39 -0700 | [diff] [blame] | 95 | class VolumeRestoreErrorException(TempestException): |
| 96 | message = "Volume %(volume_id)s failed to restore and is in ERROR status" |
| 97 | |
| 98 | |
Matthew Treinish | 8bdf6e3 | 2014-04-03 11:49:14 -0400 | [diff] [blame] | 99 | class SnapshotBuildErrorException(TempestException): |
| 100 | message = "Snapshot %(snapshot_id)s failed to build and is in ERROR status" |
| 101 | |
| 102 | |
| 103 | class VolumeBackupException(TempestException): |
| 104 | message = "Volume backup %(backup_id)s failed and is in ERROR status" |
| 105 | |
| 106 | |
| 107 | class StackBuildErrorException(TempestException): |
| 108 | message = ("Stack %(stack_identifier)s is in %(stack_status)s status " |
| 109 | "due to '%(stack_status_reason)s'") |
| 110 | |
| 111 | |
| 112 | class StackResourceBuildErrorException(TempestException): |
Masayuki Igawa | 89ba568 | 2014-04-28 19:25:53 +0900 | [diff] [blame] | 113 | message = ("Resource %(resource_name)s in stack %(stack_identifier)s is " |
Matthew Treinish | 8bdf6e3 | 2014-04-03 11:49:14 -0400 | [diff] [blame] | 114 | "in %(resource_status)s status due to " |
| 115 | "'%(resource_status_reason)s'") |
| 116 | |
| 117 | |
Ken'ichi Ohmichi | 4ca14f6 | 2015-01-19 02:29:56 +0000 | [diff] [blame] | 118 | class AuthenticationFailure(TempestException): |
Matthew Treinish | 8bdf6e3 | 2014-04-03 11:49:14 -0400 | [diff] [blame] | 119 | message = ("Authentication with user %(user)s and password " |
| 120 | "%(password)s failed auth using tenant %(tenant)s.") |
| 121 | |
| 122 | |
| 123 | class EndpointNotFound(TempestException): |
| 124 | message = "Endpoint not found" |
| 125 | |
| 126 | |
Matthew Treinish | 8bdf6e3 | 2014-04-03 11:49:14 -0400 | [diff] [blame] | 127 | class ImageFault(TempestException): |
| 128 | message = "Got image fault" |
| 129 | |
| 130 | |
| 131 | class IdentityError(TempestException): |
| 132 | message = "Got identity error" |
| 133 | |
| 134 | |
Matthew Treinish | 8bdf6e3 | 2014-04-03 11:49:14 -0400 | [diff] [blame] | 135 | class ServerUnreachable(TempestException): |
| 136 | message = "The server is not reachable via the configured network" |
| 137 | |
| 138 | |
| 139 | class TearDownException(TempestException): |
| 140 | message = "%(num)d cleanUp operation failed" |
| 141 | |
| 142 | |
Ken'ichi Ohmichi | 4ca14f6 | 2015-01-19 02:29:56 +0000 | [diff] [blame] | 143 | class RFCViolation(RestClientException): |
| 144 | message = "RFC Violation" |
| 145 | |
| 146 | |
| 147 | class InvalidHttpSuccessCode(RestClientException): |
| 148 | message = "The success code is different than the expected one" |
| 149 | |
| 150 | |
Ken'ichi Ohmichi | 4ca14f6 | 2015-01-19 02:29:56 +0000 | [diff] [blame] | 151 | class BadRequest(RestClientException): |
| 152 | message = "Bad request" |
| 153 | |
| 154 | |
Matthew Treinish | 8bdf6e3 | 2014-04-03 11:49:14 -0400 | [diff] [blame] | 155 | class ResponseWithNonEmptyBody(RFCViolation): |
| 156 | message = ("RFC Violation! Response with %(status)d HTTP Status Code " |
| 157 | "MUST NOT have a body") |
| 158 | |
| 159 | |
| 160 | class ResponseWithEntity(RFCViolation): |
| 161 | message = ("RFC Violation! Response with 205 HTTP Status Code " |
| 162 | "MUST NOT have an entity") |
| 163 | |
| 164 | |
Ken'ichi Ohmichi | 57b384b | 2014-03-28 13:58:20 +0900 | [diff] [blame] | 165 | class InvalidHTTPResponseHeader(RestClientException): |
| 166 | message = "HTTP response header is invalid" |
| 167 | |
| 168 | |
Matthew Treinish | 8bdf6e3 | 2014-04-03 11:49:14 -0400 | [diff] [blame] | 169 | class InvalidStructure(TempestException): |
| 170 | message = "Invalid structure of table with details" |
Matthew Treinish | aeb5274 | 2014-07-25 18:38:56 -0400 | [diff] [blame] | 171 | |
| 172 | |
| 173 | class CommandFailed(Exception): |
| 174 | def __init__(self, returncode, cmd, output, stderr): |
| 175 | super(CommandFailed, self).__init__() |
| 176 | self.returncode = returncode |
| 177 | self.cmd = cmd |
| 178 | self.stdout = output |
| 179 | self.stderr = stderr |
| 180 | |
| 181 | def __str__(self): |
| 182 | return ("Command '%s' returned non-zero exit status %d.\n" |
Matthew Treinish | 1d14c54 | 2014-06-17 20:25:40 -0400 | [diff] [blame] | 183 | "stdout:\n%s\n" |
| 184 | "stderr:\n%s" % (self.cmd, |
| 185 | self.returncode, |
| 186 | self.stdout, |
| 187 | self.stderr)) |