blob: b8e052fc423d999870ae26c7357c98773711c82f [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
Matthew Treinish8bdf6e32014-04-03 11:49:14 -040085class VolumeBuildErrorException(TempestException):
86 message = "Volume %(volume_id)s failed to build and is in ERROR status"
87
88
Matt Riedemannf77e7dc2015-08-10 16:39:39 -070089class VolumeRestoreErrorException(TempestException):
90 message = "Volume %(volume_id)s failed to restore and is in ERROR status"
91
92
Matthew Treinish8bdf6e32014-04-03 11:49:14 -040093class 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
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400106class EndpointNotFound(TempestException):
107 message = "Endpoint not found"
108
109
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400110class IdentityError(TempestException):
111 message = "Got identity error"
112
113
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400114class ServerUnreachable(TempestException):
115 message = "The server is not reachable via the configured network"
116
117
Andrea Frittoli (andreaf)940f8c62015-10-30 16:39:24 +0900118# 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):
122 message = "%(name) is not a valid %(type), or the name is ambiguous"
123
124
Ken'ichi Ohmichi4ca14f62015-01-19 02:29:56 +0000125class RFCViolation(RestClientException):
126 message = "RFC Violation"
127
128
129class InvalidHttpSuccessCode(RestClientException):
130 message = "The success code is different than the expected one"
131
132
Ken'ichi Ohmichi4ca14f62015-01-19 02:29:56 +0000133class BadRequest(RestClientException):
134 message = "Bad request"
135
136
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400137class 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
Ken'ichi Ohmichi57b384b2014-03-28 13:58:20 +0900147class InvalidHTTPResponseHeader(RestClientException):
148 message = "HTTP response header is invalid"
149
150
Matthew Treinish8bdf6e32014-04-03 11:49:14 -0400151class InvalidStructure(TempestException):
152 message = "Invalid structure of table with details"
Matthew Treinishaeb52742014-07-25 18:38:56 -0400153
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"
Matthew Treinish1d14c542014-06-17 20:25:40 -0400165 "stdout:\n%s\n"
166 "stderr:\n%s" % (self.cmd,
167 self.returncode,
168 self.stdout,
169 self.stderr))