blob: 259bbbbb0f284de3ed03e2d74a5e17e5d4c5ddbf [file] [log] [blame]
Matthew Treinish9e26ca82016-02-23 11:43:20 -05001# 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 """Base Tempest Exception
21
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 def __init__(self, resp_body=None, *args, **kwargs):
51 if 'resp' in kwargs:
52 self.resp = kwargs.get('resp')
53 self.resp_body = resp_body
54 message = kwargs.get("message", resp_body)
55 super(RestClientException, self).__init__(message, *args, **kwargs)
56
57
58class OtherRestClientException(RestClientException):
59 pass
60
61
62class ServerRestClientException(RestClientException):
63 pass
64
65
66class ClientRestClientException(RestClientException):
67 pass
68
69
70class InvalidHttpSuccessCode(OtherRestClientException):
71 message = "The success code is different than the expected one"
72
73
74class NotFound(ClientRestClientException):
75 message = "Object not found"
76
77
78class Unauthorized(ClientRestClientException):
79 message = 'Unauthorized'
80
81
82class Forbidden(ClientRestClientException):
83 message = "Forbidden"
84
85
86class TimeoutException(OtherRestClientException):
87 message = "Request timed out"
88
89
90class BadRequest(ClientRestClientException):
91 message = "Bad request"
92
93
94class UnprocessableEntity(ClientRestClientException):
95 message = "Unprocessable entity"
96
97
98class RateLimitExceeded(ClientRestClientException):
99 message = "Rate limit exceeded"
100
101
102class OverLimit(ClientRestClientException):
103 message = "Quota exceeded"
104
105
106class ServerFault(ServerRestClientException):
107 message = "Got server fault"
108
109
110class NotImplemented(ServerRestClientException):
111 message = "Got NotImplemented error"
112
113
114class Conflict(ClientRestClientException):
115 message = "An object with that identifier already exists"
116
117
118class Gone(ClientRestClientException):
119 message = "The requested resource is no longer available"
120
121
122class ResponseWithNonEmptyBody(OtherRestClientException):
123 message = ("RFC Violation! Response with %(status)d HTTP Status Code "
124 "MUST NOT have a body")
125
126
127class ResponseWithEntity(OtherRestClientException):
128 message = ("RFC Violation! Response with 205 HTTP Status Code "
129 "MUST NOT have an entity")
130
131
132class InvalidHTTPResponseBody(OtherRestClientException):
133 message = "HTTP response body is invalid json or xml"
134
135
136class InvalidHTTPResponseHeader(OtherRestClientException):
137 message = "HTTP response header is invalid"
138
139
140class InvalidContentType(ClientRestClientException):
141 message = "Invalid content type provided"
142
143
144class UnexpectedContentType(OtherRestClientException):
145 message = "Unexpected content type provided"
146
147
148class UnexpectedResponseCode(OtherRestClientException):
149 message = "Unexpected response code received"
150
151
152class InvalidStructure(TempestException):
153 message = "Invalid structure of table with details"
154
155
Ghanshyam1f47cf92016-02-25 04:57:18 +0900156class InvalidAPIVersionString(TempestException):
157 message = ("API Version String %(version)s is of invalid format. Must "
158 "be of format MajorNum.MinorNum or string 'latest'.")
159
160
161class JSONSchemaNotFound(TempestException):
162 message = ("JSON Schema for %(version)s is not found in\n"
163 " %(schema_versions_info)s")
164
165
166class InvalidAPIVersionRange(TempestException):
167 message = ("The API version range is invalid.")
168
169
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500170class BadAltAuth(TempestException):
171 """Used when trying and failing to change to alt creds.
172
173 If alt creds end up the same as primary creds, use this
174 exception. This is often going to be the case when you assume
175 project_id is in the url, but it's not.
176
177 """
178 message = "The alt auth looks the same as primary auth for %(part)s"
179
180
181class CommandFailed(Exception):
182 def __init__(self, returncode, cmd, output, stderr):
183 super(CommandFailed, self).__init__()
184 self.returncode = returncode
185 self.cmd = cmd
186 self.stdout = output
187 self.stderr = stderr
188
189 def __str__(self):
190 return ("Command '%s' returned non-zero exit status %d.\n"
191 "stdout:\n%s\n"
192 "stderr:\n%s" % (self.cmd,
193 self.returncode,
194 self.stdout,
195 self.stderr))
196
197
198class IdentityError(TempestException):
199 message = "Got identity error"
200
201
202class EndpointNotFound(TempestException):
203 message = "Endpoint not found"
204
205
206class InvalidCredentials(TempestException):
207 message = "Invalid Credentials"
208
209
Andrea Frittoli (andreaf)3e82af72016-05-05 22:53:38 +0100210class InvalidScope(TempestException):
211 message = "Invalid Scope %(scope)s for %(auth_provider)s"
212
213
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500214class SSHTimeout(TempestException):
215 message = ("Connection to the %(host)s via SSH timed out.\n"
216 "User: %(user)s, Password: %(password)s")
217
218
219class SSHExecCommandFailed(TempestException):
220 """Raised when remotely executed command returns nonzero status."""
221 message = ("Command '%(command)s', exit status: %(exit_status)d, "
222 "stderr:\n%(stderr)s\n"
223 "stdout:\n%(stdout)s")