blob: 15617c64e9b17c4080869e47a431e104dfdcda25 [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
Andrea Frittoli878d5ab2015-01-30 13:22:50 +000066class InvalidIdentityVersion(TempestException):
67 message = "Invalid version %(identity_version) of the identity service"
68
69
Matthew Treinish8bdf6e32014-04-03 11:49:14 -040070class TimeoutException(TempestException):
71 message = "Request timed out"
72
73
74class BuildErrorException(TempestException):
75 message = "Server %(server_id)s failed to build and is in ERROR status"
76
77
78class ImageKilledException(TempestException):
79 message = "Image %(image_id)s 'killed' while waiting for '%(status)s'"
80
81
82class AddImageException(TempestException):
83 message = "Image %(image_id)s failed to become ACTIVE in the allotted time"
84
85
86class EC2RegisterImageException(TempestException):
87 message = ("Image %(image_id)s failed to become 'available' "
88 "in the allotted time")
89
90
91class VolumeBuildErrorException(TempestException):
92 message = "Volume %(volume_id)s failed to build and is in ERROR status"
93
94
95class SnapshotBuildErrorException(TempestException):
96 message = "Snapshot %(snapshot_id)s failed to build and is in ERROR status"
97
98
99class VolumeBackupException(TempestException):
100 message = "Volume backup %(backup_id)s failed and is in ERROR status"
101
102
103class StackBuildErrorException(TempestException):
104 message = ("Stack %(stack_identifier)s is in %(stack_status)s status "
105 "due to '%(stack_status_reason)s'")
106
107
108class StackResourceBuildErrorException(TempestException):
Masayuki Igawa89ba5682014-04-28 19:25:53 +0900109 message = ("Resource %(resource_name)s in stack %(stack_identifier)s is "
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400110 "in %(resource_status)s status due to "
111 "'%(resource_status_reason)s'")
112
113
Ken'ichi Ohmichi4ca14f62015-01-19 02:29:56 +0000114class AuthenticationFailure(TempestException):
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400115 message = ("Authentication with user %(user)s and password "
116 "%(password)s failed auth using tenant %(tenant)s.")
117
118
119class EndpointNotFound(TempestException):
120 message = "Endpoint not found"
121
122
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400123class ImageFault(TempestException):
124 message = "Got image fault"
125
126
127class IdentityError(TempestException):
128 message = "Got identity error"
129
130
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400131class ServerUnreachable(TempestException):
132 message = "The server is not reachable via the configured network"
133
134
135class TearDownException(TempestException):
136 message = "%(num)d cleanUp operation failed"
137
138
Ken'ichi Ohmichi4ca14f62015-01-19 02:29:56 +0000139class RFCViolation(RestClientException):
140 message = "RFC Violation"
141
142
143class InvalidHttpSuccessCode(RestClientException):
144 message = "The success code is different than the expected one"
145
146
Ken'ichi Ohmichi4ca14f62015-01-19 02:29:56 +0000147class BadRequest(RestClientException):
148 message = "Bad request"
149
150
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400151class ResponseWithNonEmptyBody(RFCViolation):
152 message = ("RFC Violation! Response with %(status)d HTTP Status Code "
153 "MUST NOT have a body")
154
155
156class ResponseWithEntity(RFCViolation):
157 message = ("RFC Violation! Response with 205 HTTP Status Code "
158 "MUST NOT have an entity")
159
160
Ken'ichi Ohmichi57b384b2014-03-28 13:58:20 +0900161class InvalidHTTPResponseHeader(RestClientException):
162 message = "HTTP response header is invalid"
163
164
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400165class InvalidStructure(TempestException):
166 message = "Invalid structure of table with details"
Matthew Treinishaeb52742014-07-25 18:38:56 -0400167
168
169class CommandFailed(Exception):
170 def __init__(self, returncode, cmd, output, stderr):
171 super(CommandFailed, self).__init__()
172 self.returncode = returncode
173 self.cmd = cmd
174 self.stdout = output
175 self.stderr = stderr
176
177 def __str__(self):
178 return ("Command '%s' returned non-zero exit status %d.\n"
Matthew Treinish1d14c542014-06-17 20:25:40 -0400179 "stdout:\n%s\n"
180 "stderr:\n%s" % (self.cmd,
181 self.returncode,
182 self.stdout,
183 self.stderr))