blob: 9b2b4d463771770d1d8b0ae1c19066f1dbff1bb9 [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
54class RFCViolation(RestClientException):
55 message = "RFC Violation"
56
57
58class InvalidConfiguration(TempestException):
59 message = "Invalid Configuration"
60
61
62class InvalidCredentials(TempestException):
63 message = "Invalid Credentials"
64
65
66class InvalidHttpSuccessCode(RestClientException):
67 message = "The success code is different than the expected one"
68
69
70class NotFound(RestClientException):
71 message = "Object not found"
72
73
74class Unauthorized(RestClientException):
75 message = 'Unauthorized'
76
77
Ken'ichi Ohmichi53c963a2014-12-10 06:06:25 +000078class InvalidServiceTag(TempestException):
Matthew Treinish8bdf6e32014-04-03 11:49:14 -040079 message = "Invalid service tag"
80
81
82class TimeoutException(TempestException):
83 message = "Request timed out"
84
85
86class BuildErrorException(TempestException):
87 message = "Server %(server_id)s failed to build and is in ERROR status"
88
89
90class ImageKilledException(TempestException):
91 message = "Image %(image_id)s 'killed' while waiting for '%(status)s'"
92
93
94class AddImageException(TempestException):
95 message = "Image %(image_id)s failed to become ACTIVE in the allotted time"
96
97
98class EC2RegisterImageException(TempestException):
99 message = ("Image %(image_id)s failed to become 'available' "
100 "in the allotted time")
101
102
103class VolumeBuildErrorException(TempestException):
104 message = "Volume %(volume_id)s failed to build and is in ERROR status"
105
106
107class SnapshotBuildErrorException(TempestException):
108 message = "Snapshot %(snapshot_id)s failed to build and is in ERROR status"
109
110
111class VolumeBackupException(TempestException):
112 message = "Volume backup %(backup_id)s failed and is in ERROR status"
113
114
115class StackBuildErrorException(TempestException):
116 message = ("Stack %(stack_identifier)s is in %(stack_status)s status "
117 "due to '%(stack_status_reason)s'")
118
119
120class StackResourceBuildErrorException(TempestException):
Masayuki Igawa89ba5682014-04-28 19:25:53 +0900121 message = ("Resource %(resource_name)s in stack %(stack_identifier)s is "
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400122 "in %(resource_status)s status due to "
123 "'%(resource_status_reason)s'")
124
125
126class BadRequest(RestClientException):
127 message = "Bad request"
128
129
130class UnprocessableEntity(RestClientException):
131 message = "Unprocessable entity"
132
133
134class AuthenticationFailure(RestClientException):
135 message = ("Authentication with user %(user)s and password "
136 "%(password)s failed auth using tenant %(tenant)s.")
137
138
139class EndpointNotFound(TempestException):
140 message = "Endpoint not found"
141
142
Ken'ichi Ohmichic240bcc2014-12-10 06:21:16 +0000143class RateLimitExceeded(RestClientException):
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400144 message = "Rate limit exceeded"
145
146
Ken'ichi Ohmichic240bcc2014-12-10 06:21:16 +0000147class OverLimit(RestClientException):
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400148 message = "Quota exceeded"
149
150
Ken'ichi Ohmichic240bcc2014-12-10 06:21:16 +0000151class ServerFault(RestClientException):
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400152 message = "Got server fault"
153
154
Ken'ichi Ohmichi43a694a2014-12-11 05:29:02 +0000155class NotImplemented(RestClientException):
156 message = "Got NotImplemented error"
157
158
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400159class ImageFault(TempestException):
160 message = "Got image fault"
161
162
163class IdentityError(TempestException):
164 message = "Got identity error"
165
166
167class Conflict(RestClientException):
168 message = "An object with that identifier already exists"
169
170
171class SSHTimeout(TempestException):
172 message = ("Connection to the %(host)s via SSH timed out.\n"
173 "User: %(user)s, Password: %(password)s")
174
175
176class SSHExecCommandFailed(TempestException):
177 """Raised when remotely executed command returns nonzero status."""
178 message = ("Command '%(command)s', exit status: %(exit_status)d, "
179 "Error:\n%(strerror)s")
180
181
182class ServerUnreachable(TempestException):
183 message = "The server is not reachable via the configured network"
184
185
186class TearDownException(TempestException):
187 message = "%(num)d cleanUp operation failed"
188
189
190class 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))