blob: 7ddeeff9ba8b76ed193e1a6c52348d104a1e23b2 [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
Ken'ichi Ohmichi4ca14f62015-01-19 02:29:56 +0000166class OverLimit(RestClientException):
167 message = "Quota exceeded"
168
169
Ken'ichi Ohmichi4ca14f62015-01-19 02:29:56 +0000170class Conflict(RestClientException):
171 message = "An object with that identifier already exists"
172
173
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400174class ResponseWithNonEmptyBody(RFCViolation):
175 message = ("RFC Violation! Response with %(status)d HTTP Status Code "
176 "MUST NOT have a body")
177
178
179class ResponseWithEntity(RFCViolation):
180 message = ("RFC Violation! Response with 205 HTTP Status Code "
181 "MUST NOT have an entity")
182
183
Ken'ichi Ohmichi57b384b2014-03-28 13:58:20 +0900184class InvalidHTTPResponseHeader(RestClientException):
185 message = "HTTP response header is invalid"
186
187
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400188class InvalidStructure(TempestException):
189 message = "Invalid structure of table with details"
Matthew Treinishaeb52742014-07-25 18:38:56 -0400190
191
192class CommandFailed(Exception):
193 def __init__(self, returncode, cmd, output, stderr):
194 super(CommandFailed, self).__init__()
195 self.returncode = returncode
196 self.cmd = cmd
197 self.stdout = output
198 self.stderr = stderr
199
200 def __str__(self):
201 return ("Command '%s' returned non-zero exit status %d.\n"
Matthew Treinish1d14c542014-06-17 20:25:40 -0400202 "stdout:\n%s\n"
203 "stderr:\n%s" % (self.cmd,
204 self.returncode,
205 self.stdout,
206 self.stderr))