Ken'ichi Ohmichi | e8598fa | 2016-06-06 14:35:28 +0900 | [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 | """Base Tempest Exception |
| 21 | |
| 22 | To correctly use this class, inherit from it and define |
| 23 | a 'message' property. That message will get printf'd |
| 24 | with the keyword arguments provided to the constructor. |
| 25 | """ |
| 26 | message = "An unknown exception occurred" |
| 27 | |
| 28 | def __init__(self, *args, **kwargs): |
| 29 | super(TempestException, self).__init__() |
| 30 | try: |
| 31 | self._error_string = self.message % kwargs |
| 32 | except Exception: |
| 33 | # at least get the core message out if something happened |
| 34 | self._error_string = self.message |
| 35 | if len(args) > 0: |
| 36 | # If there is a non-kwarg parameter, assume it's the error |
| 37 | # message or reason description and tack it on to the end |
| 38 | # of the exception message |
| 39 | # Convert all arguments into their string representations... |
| 40 | args = ["%s" % arg for arg in args] |
Andreas Jaeger | 7716ce0 | 2020-05-03 11:11:49 +0200 | [diff] [blame] | 41 | self._error_string = (self._error_string |
| 42 | + "\nDetails: %s" % '\n'.join(args)) |
Ken'ichi Ohmichi | e8598fa | 2016-06-06 14:35:28 +0900 | [diff] [blame] | 43 | |
| 44 | def __str__(self): |
| 45 | return self._error_string |
| 46 | |
| 47 | |
| 48 | class RestClientException(TempestException, |
| 49 | testtools.TestCase.failureException): |
| 50 | pass |
| 51 | |
| 52 | |
| 53 | class InvalidConfiguration(TempestException): |
| 54 | message = "Invalid Configuration" |
| 55 | |
| 56 | |
| 57 | class InvalidCredentials(TempestException): |
| 58 | message = "Invalid Credentials" |
| 59 | |
| 60 | |
| 61 | class InvalidServiceTag(TempestException): |
| 62 | message = "Invalid service tag" |
| 63 | |
| 64 | |
| 65 | class InvalidIdentityVersion(TempestException): |
| 66 | message = "Invalid version %(identity_version)s of the identity service" |
| 67 | |
| 68 | |
| 69 | class TimeoutException(TempestException): |
| 70 | message = "Request timed out" |
| 71 | |
| 72 | |
| 73 | class BuildErrorException(TempestException): |
| 74 | message = "Server %(server_id)s failed to build and is in ERROR status" |
| 75 | |
| 76 | |
| 77 | class ImageKilledException(TempestException): |
| 78 | message = "Image %(image_id)s 'killed' while waiting for '%(status)s'" |
| 79 | |
| 80 | |
| 81 | class AddImageException(TempestException): |
| 82 | message = "Image %(image_id)s failed to become ACTIVE in the allotted time" |
| 83 | |
| 84 | |
| 85 | class VolumeBuildErrorException(TempestException): |
| 86 | message = "Volume %(volume_id)s failed to build and is in ERROR status" |
| 87 | |
| 88 | |
| 89 | class VolumeRestoreErrorException(TempestException): |
| 90 | message = "Volume %(volume_id)s failed to restore and is in ERROR status" |
| 91 | |
| 92 | |
| 93 | class SnapshotBuildErrorException(TempestException): |
| 94 | message = "Snapshot %(snapshot_id)s failed to build and is in ERROR status" |
| 95 | |
| 96 | |
| 97 | class VolumeBackupException(TempestException): |
| 98 | message = "Volume backup %(backup_id)s failed and is in ERROR status" |
| 99 | |
| 100 | |
| 101 | class StackBuildErrorException(TempestException): |
| 102 | message = ("Stack %(stack_identifier)s is in %(stack_status)s status " |
| 103 | "due to '%(stack_status_reason)s'") |
| 104 | |
| 105 | |
| 106 | class EndpointNotFound(TempestException): |
| 107 | message = "Endpoint not found" |
| 108 | |
| 109 | |
| 110 | class IdentityError(TempestException): |
| 111 | message = "Got identity error" |
| 112 | |
| 113 | |
| 114 | class ServerUnreachable(TempestException): |
| 115 | message = "The server is not reachable via the configured network" |
| 116 | |
| 117 | |
| 118 | # NOTE(andreaf) This exception is added here to facilitate the migration |
| 119 | # of get_network_from_name and preprov_creds to tempest.lib, and it should |
| 120 | # be migrated along with them |
| 121 | class InvalidTestResource(TempestException): |
zhufl | 3f9e3eb | 2016-07-27 11:14:21 +0800 | [diff] [blame] | 122 | message = "%(name)s is not a valid %(type)s, or the name is ambiguous" |
Ken'ichi Ohmichi | e8598fa | 2016-06-06 14:35:28 +0900 | [diff] [blame] | 123 | |
| 124 | |
| 125 | class RFCViolation(RestClientException): |
| 126 | message = "RFC Violation" |
| 127 | |
| 128 | |
| 129 | class InvalidHttpSuccessCode(RestClientException): |
| 130 | message = "The success code is different than the expected one" |
| 131 | |
| 132 | |
| 133 | class BadRequest(RestClientException): |
| 134 | message = "Bad request" |
| 135 | |
| 136 | |
| 137 | class ResponseWithNonEmptyBody(RFCViolation): |
| 138 | message = ("RFC Violation! Response with %(status)d HTTP Status Code " |
| 139 | "MUST NOT have a body") |
| 140 | |
| 141 | |
| 142 | class ResponseWithEntity(RFCViolation): |
| 143 | message = ("RFC Violation! Response with 205 HTTP Status Code " |
| 144 | "MUST NOT have an entity") |
| 145 | |
| 146 | |
| 147 | class InvalidHTTPResponseHeader(RestClientException): |
| 148 | message = "HTTP response header is invalid" |
| 149 | |
| 150 | |
| 151 | class InvalidStructure(TempestException): |
| 152 | message = "Invalid structure of table with details" |
| 153 | |
| 154 | |
| 155 | class CommandFailed(Exception): |
| 156 | def __init__(self, returncode, cmd, output, stderr): |
| 157 | super(CommandFailed, self).__init__() |
| 158 | self.returncode = returncode |
| 159 | self.cmd = cmd |
| 160 | self.stdout = output |
| 161 | self.stderr = stderr |
| 162 | |
| 163 | def __str__(self): |
| 164 | return ("Command '%s' returned non-zero exit status %d.\n" |
| 165 | "stdout:\n%s\n" |
| 166 | "stderr:\n%s" % (self.cmd, |
| 167 | self.returncode, |
| 168 | self.stdout, |
| 169 | self.stderr)) |