blob: cb9e6b39a48490778b238919090a0262d6a80bb9 [file] [log] [blame]
Ken'ichi Ohmichie8598fa2016-06-06 14:35:28 +09001# 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]
Andreas Jaeger7716ce02020-05-03 11:11:49 +020041 self._error_string = (self._error_string
42 + "\nDetails: %s" % '\n'.join(args))
Ken'ichi Ohmichie8598fa2016-06-06 14:35:28 +090043
44 def __str__(self):
45 return self._error_string
46
47
48class RestClientException(TempestException,
49 testtools.TestCase.failureException):
50 pass
51
52
53class InvalidConfiguration(TempestException):
54 message = "Invalid Configuration"
55
56
57class InvalidCredentials(TempestException):
58 message = "Invalid Credentials"
59
60
61class InvalidServiceTag(TempestException):
62 message = "Invalid service tag"
63
64
65class InvalidIdentityVersion(TempestException):
66 message = "Invalid version %(identity_version)s of the identity service"
67
68
69class 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 VolumeBuildErrorException(TempestException):
86 message = "Volume %(volume_id)s failed to build and is in ERROR status"
87
88
89class VolumeRestoreErrorException(TempestException):
90 message = "Volume %(volume_id)s failed to restore and is in ERROR status"
91
92
93class SnapshotBuildErrorException(TempestException):
94 message = "Snapshot %(snapshot_id)s failed to build and is in ERROR status"
95
96
97class VolumeBackupException(TempestException):
98 message = "Volume backup %(backup_id)s failed and is in ERROR status"
99
100
101class StackBuildErrorException(TempestException):
102 message = ("Stack %(stack_identifier)s is in %(stack_status)s status "
103 "due to '%(stack_status_reason)s'")
104
105
106class EndpointNotFound(TempestException):
107 message = "Endpoint not found"
108
109
110class IdentityError(TempestException):
111 message = "Got identity error"
112
113
114class ServerUnreachable(TempestException):
115 message = "The server is not reachable via the configured network"
116
117
118# NOTE(andreaf) This exception is added here to facilitate the migration
119# of get_network_from_name and preprov_creds to tempest.lib, and it should
120# be migrated along with them
121class InvalidTestResource(TempestException):
zhufl3f9e3eb2016-07-27 11:14:21 +0800122 message = "%(name)s is not a valid %(type)s, or the name is ambiguous"
Ken'ichi Ohmichie8598fa2016-06-06 14:35:28 +0900123
124
125class RFCViolation(RestClientException):
126 message = "RFC Violation"
127
128
129class InvalidHttpSuccessCode(RestClientException):
130 message = "The success code is different than the expected one"
131
132
133class BadRequest(RestClientException):
134 message = "Bad request"
135
136
137class ResponseWithNonEmptyBody(RFCViolation):
138 message = ("RFC Violation! Response with %(status)d HTTP Status Code "
139 "MUST NOT have a body")
140
141
142class ResponseWithEntity(RFCViolation):
143 message = ("RFC Violation! Response with 205 HTTP Status Code "
144 "MUST NOT have an entity")
145
146
147class InvalidHTTPResponseHeader(RestClientException):
148 message = "HTTP response header is invalid"
149
150
151class InvalidStructure(TempestException):
152 message = "Invalid structure of table with details"
153
154
155class CommandFailed(Exception):
156 def __init__(self, returncode, cmd, output, stderr):
157 super(CommandFailed, self).__init__()
158 self.returncode = returncode
159 self.cmd = cmd
160 self.stdout = output
161 self.stderr = stderr
162
163 def __str__(self):
164 return ("Command '%s' returned non-zero exit status %d.\n"
165 "stdout:\n%s\n"
166 "stderr:\n%s" % (self.cmd,
167 self.returncode,
168 self.stdout,
169 self.stderr))