blob: 86f488a6f6e729b6ca8a578b1d73b2e6d2d48bf7 [file] [log] [blame]
Matthew Treinish8bdf6e32014-04-03 11:49:14 -04001# 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
16import testtools
17
18
19class 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
49class RestClientException(TempestException,
50 testtools.TestCase.failureException):
51 pass
52
53
Matthew Treinish8bdf6e32014-04-03 11:49:14 -040054class InvalidConfiguration(TempestException):
55 message = "Invalid Configuration"
56
57
58class InvalidCredentials(TempestException):
59 message = "Invalid Credentials"
60
61
Ken'ichi Ohmichi53c963a2014-12-10 06:06:25 +000062class InvalidServiceTag(TempestException):
Matthew Treinish8bdf6e32014-04-03 11:49:14 -040063 message = "Invalid service tag"
64
65
66class TimeoutException(TempestException):
67 message = "Request timed out"
68
69
70class BuildErrorException(TempestException):
71 message = "Server %(server_id)s failed to build and is in ERROR status"
72
73
74class ImageKilledException(TempestException):
75 message = "Image %(image_id)s 'killed' while waiting for '%(status)s'"
76
77
78class AddImageException(TempestException):
79 message = "Image %(image_id)s failed to become ACTIVE in the allotted time"
80
81
82class EC2RegisterImageException(TempestException):
83 message = ("Image %(image_id)s failed to become 'available' "
84 "in the allotted time")
85
86
87class VolumeBuildErrorException(TempestException):
88 message = "Volume %(volume_id)s failed to build and is in ERROR status"
89
90
91class SnapshotBuildErrorException(TempestException):
92 message = "Snapshot %(snapshot_id)s failed to build and is in ERROR status"
93
94
95class VolumeBackupException(TempestException):
96 message = "Volume backup %(backup_id)s failed and is in ERROR status"
97
98
99class StackBuildErrorException(TempestException):
100 message = ("Stack %(stack_identifier)s is in %(stack_status)s status "
101 "due to '%(stack_status_reason)s'")
102
103
104class StackResourceBuildErrorException(TempestException):
Masayuki Igawa89ba5682014-04-28 19:25:53 +0900105 message = ("Resource %(resource_name)s in stack %(stack_identifier)s is "
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400106 "in %(resource_status)s status due to "
107 "'%(resource_status_reason)s'")
108
109
Ken'ichi Ohmichi4ca14f62015-01-19 02:29:56 +0000110class AuthenticationFailure(TempestException):
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400111 message = ("Authentication with user %(user)s and password "
112 "%(password)s failed auth using tenant %(tenant)s.")
113
114
115class EndpointNotFound(TempestException):
116 message = "Endpoint not found"
117
118
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400119class ImageFault(TempestException):
120 message = "Got image fault"
121
122
123class IdentityError(TempestException):
124 message = "Got identity error"
125
126
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400127class SSHTimeout(TempestException):
128 message = ("Connection to the %(host)s via SSH timed out.\n"
129 "User: %(user)s, Password: %(password)s")
130
131
132class SSHExecCommandFailed(TempestException):
133 """Raised when remotely executed command returns nonzero status."""
134 message = ("Command '%(command)s', exit status: %(exit_status)d, "
135 "Error:\n%(strerror)s")
136
137
138class ServerUnreachable(TempestException):
139 message = "The server is not reachable via the configured network"
140
141
142class TearDownException(TempestException):
143 message = "%(num)d cleanUp operation failed"
144
145
Ken'ichi Ohmichi4ca14f62015-01-19 02:29:56 +0000146class RFCViolation(RestClientException):
147 message = "RFC Violation"
148
149
150class InvalidHttpSuccessCode(RestClientException):
151 message = "The success code is different than the expected one"
152
153
154class NotFound(RestClientException):
155 message = "Object not found"
156
157
158class Unauthorized(RestClientException):
159 message = 'Unauthorized'
160
161
162class BadRequest(RestClientException):
163 message = "Bad request"
164
165
166class UnprocessableEntity(RestClientException):
167 message = "Unprocessable entity"
168
169
170class RateLimitExceeded(RestClientException):
171 message = "Rate limit exceeded"
172
173
174class OverLimit(RestClientException):
175 message = "Quota exceeded"
176
177
178class ServerFault(RestClientException):
179 message = "Got server fault"
180
181
182class NotImplemented(RestClientException):
183 message = "Got NotImplemented error"
184
185
186class Conflict(RestClientException):
187 message = "An object with that identifier already exists"
188
189
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400190class ResponseWithNonEmptyBody(RFCViolation):
191 message = ("RFC Violation! Response with %(status)d HTTP Status Code "
192 "MUST NOT have a body")
193
194
195class ResponseWithEntity(RFCViolation):
196 message = ("RFC Violation! Response with 205 HTTP Status Code "
197 "MUST NOT have an entity")
198
199
200class InvalidHTTPResponseBody(RestClientException):
201 message = "HTTP response body is invalid json or xml"
202
203
Ken'ichi Ohmichi57b384b2014-03-28 13:58:20 +0900204class InvalidHTTPResponseHeader(RestClientException):
205 message = "HTTP response header is invalid"
206
207
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400208class InvalidContentType(RestClientException):
209 message = "Invalid content type provided"
210
211
212class UnexpectedResponseCode(RestClientException):
213 message = "Unexpected response code received"
214
215
216class InvalidStructure(TempestException):
217 message = "Invalid structure of table with details"
Matthew Treinishaeb52742014-07-25 18:38:56 -0400218
219
220class CommandFailed(Exception):
221 def __init__(self, returncode, cmd, output, stderr):
222 super(CommandFailed, self).__init__()
223 self.returncode = returncode
224 self.cmd = cmd
225 self.stdout = output
226 self.stderr = stderr
227
228 def __str__(self):
229 return ("Command '%s' returned non-zero exit status %d.\n"
Matthew Treinish1d14c542014-06-17 20:25:40 -0400230 "stdout:\n%s\n"
231 "stderr:\n%s" % (self.cmd,
232 self.returncode,
233 self.stdout,
234 self.stderr))