8afd2708570cad60288836b635bd481cbb2292bc
[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 ResourceCommandError(YardstickException):
68     message = 'Command: "%(command)s" Failed, stderr: "%(stderr)s"'
69
70
71 class ContextUpdateCollectdForNodeError(YardstickException):
72     message = 'Cannot find node %(attr_name)s'
73
74
75 class FunctionNotImplemented(YardstickException):
76     message = ('The function "%(function_name)s" is not implemented in '
77                '"%(class_name)" class.')
78
79
80 class InfluxDBConfigurationMissing(YardstickException):
81     message = ('InfluxDB configuration is not available. Add "influxdb" as '
82                'a dispatcher and the configuration section')
83
84
85 class YardstickBannedModuleImported(YardstickException):
86     # pragma: no cover
87     message = 'Module "%(module)s" cannnot be imported. Reason: "%(reason)s"'
88
89
90 class PayloadMissingAttributes(YardstickException):
91     message = ('Error instantiating a Payload class, missing attributes: '
92                '%(missing_attributes)s')
93
94
95 class HeatTemplateError(YardstickException):
96     """Error in Heat during the stack deployment"""
97     message = ('Error in Heat during the creation of the OpenStack stack '
98                '"%(stack_name)s"')
99
100
101 class IPv6RangeError(YardstickException):
102     message = 'Start IP "%(start_ip)s" is greater than end IP "%(end_ip)s"'
103
104
105 class TrafficProfileNotImplemented(YardstickException):
106     message = 'No implementation for traffic profile %(profile_class)s.'
107
108
109 class DPDKSetupDriverError(YardstickException):
110     message = '"igb_uio" driver is not loaded'
111
112
113 class OVSUnsupportedVersion(YardstickException):
114     message = ('Unsupported OVS version "%(ovs_version)s". Please check the '
115                'config. OVS to DPDK version map: %(ovs_to_dpdk_map)s.')
116
117
118 class OVSHugepagesInfoError(YardstickException):
119     message = 'MemInfo cannnot be retrieved.'
120
121
122 class OVSHugepagesNotConfigured(YardstickException):
123     message = 'HugePages are not configured in this system.'
124
125
126 class OVSHugepagesZeroFree(YardstickException):
127     message = ('There are no HugePages free in this system. Total HugePages '
128                'configured: %(total_hugepages)s')
129
130
131 class OVSDeployError(YardstickException):
132     message = 'OVS deploy tool failed with error: %(stderr)s.'
133
134
135 class OVSSetupError(YardstickException):
136     message = 'OVS setup error. Command: %(command)s. Error: %(error)s.'
137
138
139 class LibvirtCreateError(YardstickException):
140     message = 'Error creating the virtual machine. Error: %(error)s.'
141
142
143 class LibvirtQemuImageBaseImageNotPresent(YardstickException):
144     message = ('Error creating the qemu image for %(vm_image)s. Base image: '
145                '%(base_image)s. Base image not present in execution host or '
146                'remote host.')
147
148
149 class LibvirtQemuImageCreateError(YardstickException):
150     message = ('Error creating the qemu image for %(vm_image)s. Base image: '
151                '%(base_image)s. Error: %(error)s.')
152
153
154 class SSHError(YardstickException):
155     message = '%(error_msg)s'
156
157
158 class SSHTimeout(SSHError):
159     pass
160
161
162 class IncorrectConfig(YardstickException):
163     message = '%(error_msg)s'
164
165
166 class IncorrectSetup(YardstickException):
167     message = '%(error_msg)s'
168
169
170 class IncorrectNodeSetup(IncorrectSetup):
171     pass
172
173
174 class ScenarioConfigContextNameNotFound(YardstickException):
175     message = 'Context for host name "%(host_name)s" not found'
176
177
178 class StackCreationInterrupt(YardstickException):
179     message = 'Stack create interrupted.'
180
181
182 class TaskRenderArgumentError(YardstickException):
183     message = 'Error reading the task input arguments'
184
185
186 class TaskReadError(YardstickException):
187     message = 'Failed to read task %(task_file)s'
188
189
190 class TaskRenderError(YardstickException):
191     message = 'Failed to render template:\n%(input_task)s'
192
193
194 class RunnerIterationIPCSetupActionNeeded(YardstickException):
195     message = ('IterationIPC needs the "setup" action to retrieve the VNF '
196                'handling processes PIDs to receive the messages sent')
197
198
199 class RunnerIterationIPCNoCtxs(YardstickException):
200     message = 'Benchmark "setup" action did not return any VNF process PID'
201
202
203 class TimerTimeout(YardstickException):
204     message = 'Timer timeout expired, %(timeout)s seconds'
205
206
207 class WaitTimeout(YardstickException):
208     message = 'Wait timeout while waiting for condition'
209
210
211 class KubernetesTemplateInvalidVolumeType(YardstickException):
212     message = 'No valid "volume" types present in %(volume)s'
213
214
215 class ScenarioCreateNetworkError(YardstickException):
216     message = 'Create Neutron Network Scenario failed'
217
218
219 class ScenarioCreateSubnetError(YardstickException):
220     message = 'Create Neutron Subnet Scenario failed'
221
222
223 class ScenarioDeleteRouterError(YardstickException):
224     message = 'Delete Neutron Router Scenario failed'
225
226
227 class MissingPodInfoError(YardstickException):
228     message = 'Missing pod args, please check'
229
230
231 class UnsupportedPodFormatError(YardstickException):
232     message = 'Failed to load pod info, unsupported format'
233
234
235 class ScenarioCreateRouterError(YardstickException):
236     message = 'Create Neutron Router Scenario failed'
237
238
239 class ScenarioRemoveRouterIntError(YardstickException):
240     message = 'Remove Neutron Router Interface Scenario failed'
241
242
243 class ScenarioCreateFloatingIPError(YardstickException):
244     message = 'Create Neutron Floating IP Scenario failed'
245
246
247 class ScenarioDeleteFloatingIPError(YardstickException):
248     message = 'Delete Neutron Floating IP Scenario failed'
249
250
251 class ScenarioCreateSecurityGroupError(YardstickException):
252     message = 'Create Neutron Security Group Scenario failed'
253
254
255 class ScenarioDeleteNetworkError(YardstickException):
256     message = 'Delete Neutron Network Scenario failed'
257
258
259 class ScenarioCreateServerError(YardstickException):
260     message = 'Nova Create Server Scenario failed'
261
262
263 class ScenarioDeleteServerError(YardstickException):
264     message = 'Delete Server Scenario failed'
265
266
267 class ScenarioCreateKeypairError(YardstickException):
268     message = 'Nova Create Keypair Scenario failed'
269
270
271 class ScenarioDeleteKeypairError(YardstickException):
272     message = 'Nova Delete Keypair Scenario failed'
273
274
275 class ScenarioAttachVolumeError(YardstickException):
276     message = 'Nova Attach Volume Scenario failed'
277
278
279 class ScenarioGetServerError(YardstickException):
280     message = 'Nova Get Server Scenario failed'
281
282
283 class ScenarioGetFlavorError(YardstickException):
284     message = 'Nova Get Falvor Scenario failed'
285
286
287 class ScenarioCreateVolumeError(YardstickException):
288     message = 'Cinder Create Volume Scenario failed'
289
290
291 class ScenarioDeleteVolumeError(YardstickException):
292     message = 'Cinder Delete Volume Scenario failed'
293
294
295 class ScenarioDetachVolumeError(YardstickException):
296     message = 'Cinder Detach Volume Scenario failed'
297
298
299 class ApiServerError(YardstickException):
300     message = 'An unkown exception happened to Api Server!'
301
302
303 class UploadOpenrcError(ApiServerError):
304     message = 'Upload openrc ERROR!'
305
306
307 class UpdateOpenrcError(ApiServerError):
308     message = 'Update openrc ERROR!'
309
310
311 class ScenarioCreateImageError(YardstickException):
312     message = 'Glance Create Image Scenario failed'
313
314
315 class ScenarioDeleteImageError(YardstickException):
316     message = 'Glance Delete Image Scenario failed'
317
318
319 class IxNetworkClientNotConnected(YardstickException):
320     message = 'IxNetwork client not connected to a TCL server'
321
322
323 class IxNetworkFlowNotPresent(YardstickException):
324     message = 'Flow Group "%(flow_group)s" is not present'
325
326
327 class IxNetworkFieldNotPresentInStackItem(YardstickException):
328     message = 'Field "%(field_name)s" not present in stack item %(stack_item)s'
329
330
331 class SLAValidationError(YardstickException):
332     message = '%(case_name)s SLA validation failed. Error: %(error_msg)s'
333
334
335 class AclMissingActionArguments(YardstickException):
336     message = ('Missing ACL action parameter '
337                '[action=%(action_name)s parameter=%(action_param)s]')
338
339
340 class AclUknownActionTemplate(YardstickException):
341     message = 'No ACL CLI template found for "%(action_name)s" action'