2b72d7fcfca6312338bcb1111c857d9eaaf79668
[yardstick.git] / yardstick / common / exceptions.py
1 # Copyright (c) 2017 Intel Corporation
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 from oslo_utils import excutils
16
17
18 class ProcessExecutionError(RuntimeError):
19     def __init__(self, message, returncode):
20         super(ProcessExecutionError, self).__init__(message)
21         self.returncode = returncode
22
23
24 class ErrorClass(object):
25
26     def __init__(self, *args, **kwargs):
27         if 'test' not in kwargs:
28             raise RuntimeError
29
30     def __getattr__(self, item):
31         raise AttributeError
32
33
34 class YardstickException(Exception):
35     """Base Yardstick Exception.
36
37     To correctly use this class, inherit from it and define
38     a 'message' property. That message will get printf'd
39     with the keyword arguments provided to the constructor.
40
41     Based on NeutronException class.
42     """
43     message = "An unknown exception occurred."
44
45     def __init__(self, **kwargs):
46         try:
47             super(YardstickException, self).__init__(self.message % kwargs)
48             self.msg = self.message % kwargs
49         except Exception:  # pylint: disable=broad-except
50             with excutils.save_and_reraise_exception() as ctxt:
51                 if not self.use_fatal_exceptions():
52                     ctxt.reraise = False
53                     # at least get the core message out if something happened
54                     super(YardstickException, self).__init__(self.message)
55
56     def __str__(self):
57         return self.msg
58
59     def use_fatal_exceptions(self):
60         """Is the instance using fatal exceptions.
61
62         :returns: Always returns False.
63         """
64         return False
65
66
67 class FunctionNotImplemented(YardstickException):
68     message = ('The function "%(function_name)s" is not implemented in '
69                '"%(class_name)" class.')
70
71
72 class YardstickBannedModuleImported(YardstickException):
73     # pragma: no cover
74     message = 'Module "%(module)s" cannnot be imported. Reason: "%(reason)s"'
75
76
77 class HeatTemplateError(YardstickException):
78     """Error in Heat during the stack deployment"""
79     message = ('Error in Heat during the creation of the OpenStack stack '
80                '"%(stack_name)s"')
81
82
83 class IPv6RangeError(YardstickException):
84     message = 'Start IP "%(start_ip)s" is greater than end IP "%(end_ip)s"'
85
86
87 class TrafficProfileNotImplemented(YardstickException):
88     message = 'No implementation for traffic profile %(profile_class)s.'
89
90
91 class DPDKSetupDriverError(YardstickException):
92     message = '"igb_uio" driver is not loaded'
93
94
95 class OVSUnsupportedVersion(YardstickException):
96     message = ('Unsupported OVS version "%(ovs_version)s". Please check the '
97                'config. OVS to DPDK version map: %(ovs_to_dpdk_map)s.')
98
99
100 class OVSHugepagesInfoError(YardstickException):
101     message = 'MemInfo cannnot be retrieved.'
102
103
104 class OVSHugepagesNotConfigured(YardstickException):
105     message = 'HugePages are not configured in this system.'
106
107
108 class OVSHugepagesZeroFree(YardstickException):
109     message = ('There are no HugePages free in this system. Total HugePages '
110                'configured: %(total_hugepages)s')
111
112
113 class OVSDeployError(YardstickException):
114     message = 'OVS deploy tool failed with error: %(stderr)s.'
115
116
117 class OVSSetupError(YardstickException):
118     message = 'OVS setup error. Command: %(command)s. Error: %(error)s.'
119
120
121 class LibvirtCreateError(YardstickException):
122     message = 'Error creating the virtual machine. Error: %(error)s.'
123
124
125 class SSHError(YardstickException):
126     message = '%(error_msg)s'
127
128
129 class SSHTimeout(SSHError):
130     pass
131
132
133 class IncorrectConfig(YardstickException):
134     message = '%(error_msg)s'
135
136
137 class IncorrectSetup(YardstickException):
138     message = '%(error_msg)s'
139
140
141 class IncorrectNodeSetup(IncorrectSetup):
142     pass
143
144
145 class ScenarioConfigContextNameNotFound(YardstickException):
146     message = 'Context name "%(context_name)s" not found'
147
148
149 class StackCreationInterrupt(YardstickException):
150     message = 'Stack create interrupted.'
151
152
153 class TaskRenderArgumentError(YardstickException):
154     message = 'Error reading the task input arguments'
155
156
157 class TaskReadError(YardstickException):
158     message = 'Failed to read task %(task_file)s'
159
160
161 class TaskRenderError(YardstickException):
162     message = 'Failed to render template:\n%(input_task)s'
163
164
165 class ScenarioCreateNetworkError(YardstickException):
166     message = 'Create Neutron Network Scenario failed'
167
168
169 class ScenarioCreateSubnetError(YardstickException):
170     message = 'Create Neutron Subnet Scenario failed'
171
172
173 class ScenarioDeleteRouterError(YardstickException):
174     message = 'Delete Neutron Router Scenario failed'
175
176
177 class MissingPodInfoError(YardstickException):
178     message = 'Missing pod args, please check'
179
180
181 class UnsupportedPodFormatError(YardstickException):
182     message = 'Failed to load pod info, unsupported format'
183
184
185 class ScenarioCreateRouterError(YardstickException):
186     message = 'Create Neutron Router Scenario failed'
187
188
189 class ScenarioRemoveRouterIntError(YardstickException):
190     message = 'Remove Neutron Router Interface Scenario failed'
191
192
193 class ScenarioCreateFloatingIPError(YardstickException):
194     message = 'Create Neutron Floating IP Scenario failed'
195
196
197 class ScenarioDeleteFloatingIPError(YardstickException):
198     message = 'Delete Neutron Floating IP Scenario failed'
199
200
201 class ApiServerError(YardstickException):
202     message = 'An unkown exception happened to Api Server!'
203
204
205 class UploadOpenrcError(ApiServerError):
206     message = 'Upload openrc ERROR!'
207
208
209 class UpdateOpenrcError(ApiServerError):
210     message = 'Update openrc ERROR!'