blob: b3d60f63996b62b7d8575df0b20ce67e0c6a0a47 [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):
ghanshyam367c6932015-09-11 18:51:02 +090067 message = "Invalid version %(identity_version)s of the identity service"
Andrea Frittoli878d5ab2015-01-30 13:22:50 +000068
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
Matt Riedemannf77e7dc2015-08-10 16:39:39 -070095class VolumeRestoreErrorException(TempestException):
96 message = "Volume %(volume_id)s failed to restore and is in ERROR status"
97
98
Matthew Treinish8bdf6e32014-04-03 11:49:14 -040099class SnapshotBuildErrorException(TempestException):
100 message = "Snapshot %(snapshot_id)s failed to build and is in ERROR status"
101
102
103class VolumeBackupException(TempestException):
104 message = "Volume backup %(backup_id)s failed and is in ERROR status"
105
106
107class StackBuildErrorException(TempestException):
108 message = ("Stack %(stack_identifier)s is in %(stack_status)s status "
109 "due to '%(stack_status_reason)s'")
110
111
112class StackResourceBuildErrorException(TempestException):
Masayuki Igawa89ba5682014-04-28 19:25:53 +0900113 message = ("Resource %(resource_name)s in stack %(stack_identifier)s is "
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400114 "in %(resource_status)s status due to "
115 "'%(resource_status_reason)s'")
116
117
Ken'ichi Ohmichi4ca14f62015-01-19 02:29:56 +0000118class AuthenticationFailure(TempestException):
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400119 message = ("Authentication with user %(user)s and password "
120 "%(password)s failed auth using tenant %(tenant)s.")
121
122
123class EndpointNotFound(TempestException):
124 message = "Endpoint not found"
125
126
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400127class ImageFault(TempestException):
128 message = "Got image fault"
129
130
131class IdentityError(TempestException):
132 message = "Got identity error"
133
134
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400135class ServerUnreachable(TempestException):
136 message = "The server is not reachable via the configured network"
137
138
139class TearDownException(TempestException):
140 message = "%(num)d cleanUp operation failed"
141
142
Ken'ichi Ohmichi4ca14f62015-01-19 02:29:56 +0000143class RFCViolation(RestClientException):
144 message = "RFC Violation"
145
146
147class InvalidHttpSuccessCode(RestClientException):
148 message = "The success code is different than the expected one"
149
150
Ken'ichi Ohmichi4ca14f62015-01-19 02:29:56 +0000151class BadRequest(RestClientException):
152 message = "Bad request"
153
154
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400155class ResponseWithNonEmptyBody(RFCViolation):
156 message = ("RFC Violation! Response with %(status)d HTTP Status Code "
157 "MUST NOT have a body")
158
159
160class ResponseWithEntity(RFCViolation):
161 message = ("RFC Violation! Response with 205 HTTP Status Code "
162 "MUST NOT have an entity")
163
164
Ken'ichi Ohmichi57b384b2014-03-28 13:58:20 +0900165class InvalidHTTPResponseHeader(RestClientException):
166 message = "HTTP response header is invalid"
167
168
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400169class InvalidStructure(TempestException):
170 message = "Invalid structure of table with details"
Matthew Treinishaeb52742014-07-25 18:38:56 -0400171
172
173class CommandFailed(Exception):
174 def __init__(self, returncode, cmd, output, stderr):
175 super(CommandFailed, self).__init__()
176 self.returncode = returncode
177 self.cmd = cmd
178 self.stdout = output
179 self.stderr = stderr
180
181 def __str__(self):
182 return ("Command '%s' returned non-zero exit status %d.\n"
Matthew Treinish1d14c542014-06-17 20:25:40 -0400183 "stdout:\n%s\n"
184 "stderr:\n%s" % (self.cmd,
185 self.returncode,
186 self.stdout,
187 self.stderr))