blob: 8537898b2f6095289f0da439c2c4b3741093d889 [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):
Ken'ichi Ohmichi2e2ee192015-11-19 09:48:27 +000020 """Base Tempest Exception
Matthew Treinish8bdf6e32014-04-03 11:49:14 -040021
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]
41 self._error_string = (self._error_string +
42 "\nDetails: %s" % '\n'.join(args))
43
44 def __str__(self):
45 return self._error_string
46
47
48class RestClientException(TempestException,
49 testtools.TestCase.failureException):
50 pass
51
52
Matthew Treinish8bdf6e32014-04-03 11:49:14 -040053class InvalidConfiguration(TempestException):
54 message = "Invalid Configuration"
55
56
57class InvalidCredentials(TempestException):
58 message = "Invalid Credentials"
59
60
Ken'ichi Ohmichi53c963a2014-12-10 06:06:25 +000061class InvalidServiceTag(TempestException):
Matthew Treinish8bdf6e32014-04-03 11:49:14 -040062 message = "Invalid service tag"
63
64
Andrea Frittoli878d5ab2015-01-30 13:22:50 +000065class InvalidIdentityVersion(TempestException):
ghanshyam367c6932015-09-11 18:51:02 +090066 message = "Invalid version %(identity_version)s of the identity service"
Andrea Frittoli878d5ab2015-01-30 13:22:50 +000067
68
Matthew Treinish8bdf6e32014-04-03 11:49:14 -040069class TimeoutException(TempestException):
70 message = "Request timed out"
71
72
73class BuildErrorException(TempestException):
74 message = "Server %(server_id)s failed to build and is in ERROR status"
75
76
77class ImageKilledException(TempestException):
78 message = "Image %(image_id)s 'killed' while waiting for '%(status)s'"
79
80
81class AddImageException(TempestException):
82 message = "Image %(image_id)s failed to become ACTIVE in the allotted time"
83
84
85class EC2RegisterImageException(TempestException):
86 message = ("Image %(image_id)s failed to become 'available' "
87 "in the allotted time")
88
89
90class VolumeBuildErrorException(TempestException):
91 message = "Volume %(volume_id)s failed to build and is in ERROR status"
92
93
Matt Riedemannf77e7dc2015-08-10 16:39:39 -070094class VolumeRestoreErrorException(TempestException):
95 message = "Volume %(volume_id)s failed to restore and is in ERROR status"
96
97
Matthew Treinish8bdf6e32014-04-03 11:49:14 -040098class SnapshotBuildErrorException(TempestException):
99 message = "Snapshot %(snapshot_id)s failed to build and is in ERROR status"
100
101
102class VolumeBackupException(TempestException):
103 message = "Volume backup %(backup_id)s failed and is in ERROR status"
104
105
106class StackBuildErrorException(TempestException):
107 message = ("Stack %(stack_identifier)s is in %(stack_status)s status "
108 "due to '%(stack_status_reason)s'")
109
110
111class StackResourceBuildErrorException(TempestException):
Masayuki Igawa89ba5682014-04-28 19:25:53 +0900112 message = ("Resource %(resource_name)s in stack %(stack_identifier)s is "
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400113 "in %(resource_status)s status due to "
114 "'%(resource_status_reason)s'")
115
116
Ken'ichi Ohmichi4ca14f62015-01-19 02:29:56 +0000117class AuthenticationFailure(TempestException):
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400118 message = ("Authentication with user %(user)s and password "
119 "%(password)s failed auth using tenant %(tenant)s.")
120
121
122class EndpointNotFound(TempestException):
123 message = "Endpoint not found"
124
125
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400126class ImageFault(TempestException):
127 message = "Got image fault"
128
129
130class IdentityError(TempestException):
131 message = "Got identity error"
132
133
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400134class ServerUnreachable(TempestException):
135 message = "The server is not reachable via the configured network"
136
137
138class TearDownException(TempestException):
139 message = "%(num)d cleanUp operation failed"
140
141
Andrea Frittoli (andreaf)940f8c62015-10-30 16:39:24 +0900142# NOTE(andreaf) This exception is added here to facilitate the migration
143# of get_network_from_name and preprov_creds to tempest-lib, and it should
144# be migrated along with them
145class InvalidTestResource(TempestException):
146 message = "%(name) is not a valid %(type), or the name is ambiguous"
147
148
Ken'ichi Ohmichi4ca14f62015-01-19 02:29:56 +0000149class RFCViolation(RestClientException):
150 message = "RFC Violation"
151
152
153class InvalidHttpSuccessCode(RestClientException):
154 message = "The success code is different than the expected one"
155
156
Ken'ichi Ohmichi4ca14f62015-01-19 02:29:56 +0000157class BadRequest(RestClientException):
158 message = "Bad request"
159
160
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400161class ResponseWithNonEmptyBody(RFCViolation):
162 message = ("RFC Violation! Response with %(status)d HTTP Status Code "
163 "MUST NOT have a body")
164
165
166class ResponseWithEntity(RFCViolation):
167 message = ("RFC Violation! Response with 205 HTTP Status Code "
168 "MUST NOT have an entity")
169
170
Ken'ichi Ohmichi57b384b2014-03-28 13:58:20 +0900171class InvalidHTTPResponseHeader(RestClientException):
172 message = "HTTP response header is invalid"
173
174
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400175class InvalidStructure(TempestException):
176 message = "Invalid structure of table with details"
Matthew Treinishaeb52742014-07-25 18:38:56 -0400177
178
Ken'ichi Ohmichi4d237e72015-11-05 06:32:33 +0000179class InvalidAPIVersionString(TempestException):
180 msg_fmt = ("API Version String %(version)s is of invalid format. Must "
181 "be of format MajorNum.MinorNum.")
182
183
Matthew Treinishaeb52742014-07-25 18:38:56 -0400184class CommandFailed(Exception):
185 def __init__(self, returncode, cmd, output, stderr):
186 super(CommandFailed, self).__init__()
187 self.returncode = returncode
188 self.cmd = cmd
189 self.stdout = output
190 self.stderr = stderr
191
192 def __str__(self):
193 return ("Command '%s' returned non-zero exit status %d.\n"
Matthew Treinish1d14c542014-06-17 20:25:40 -0400194 "stdout:\n%s\n"
195 "stderr:\n%s" % (self.cmd,
196 self.returncode,
197 self.stdout,
198 self.stderr))