blob: b8e470e3747f1075ac1f1bbb0c88067610e00295 [file] [log] [blame]
vponomaryov82411ed2014-02-23 09:40:48 +02001# 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
54class RFCViolation(RestClientException):
55 message = "RFC Violation"