blob: 2bf7cdd324f4189926353ccd1d6c5737ebc0e517 [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
156class BadAltAuth(TempestException):
157 """Used when trying and failing to change to alt creds.
158
159 If alt creds end up the same as primary creds, use this
160 exception. This is often going to be the case when you assume
161 project_id is in the url, but it's not.
162
163 """
164 message = "The alt auth looks the same as primary auth for %(part)s"
165
166
167class CommandFailed(Exception):
168 def __init__(self, returncode, cmd, output, stderr):
169 super(CommandFailed, self).__init__()
170 self.returncode = returncode
171 self.cmd = cmd
172 self.stdout = output
173 self.stderr = stderr
174
175 def __str__(self):
176 return ("Command '%s' returned non-zero exit status %d.\n"
177 "stdout:\n%s\n"
178 "stderr:\n%s" % (self.cmd,
179 self.returncode,
180 self.stdout,
181 self.stderr))
182
183
184class IdentityError(TempestException):
185 message = "Got identity error"
186
187
188class EndpointNotFound(TempestException):
189 message = "Endpoint not found"
190
191
192class InvalidCredentials(TempestException):
193 message = "Invalid Credentials"
194
195
196class SSHTimeout(TempestException):
197 message = ("Connection to the %(host)s via SSH timed out.\n"
198 "User: %(user)s, Password: %(password)s")
199
200
201class SSHExecCommandFailed(TempestException):
202 """Raised when remotely executed command returns nonzero status."""
203 message = ("Command '%(command)s', exit status: %(exit_status)d, "
204 "stderr:\n%(stderr)s\n"
205 "stdout:\n%(stdout)s")