Merge "Fix exception handling ixload"
[yardstick.git] / yardstick / common / exceptions.py
1 # Copyright (c) 2017-2019 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 from yardstick.common import constants
18
19
20 class ProcessExecutionError(RuntimeError):
21     def __init__(self, message, returncode):
22         super(ProcessExecutionError, self).__init__(message)
23         self.returncode = returncode
24
25
26 class ErrorClass(object):
27
28     def __init__(self, *args, **kwargs):
29         if 'test' not in kwargs:
30             raise RuntimeError
31
32     def __getattr__(self, item):
33         raise AttributeError
34
35
36 class YardstickException(Exception):
37     """Base Yardstick Exception.
38
39     To correctly use this class, inherit from it and define
40     a 'message' property. That message will get printf'd
41     with the keyword arguments provided to the constructor.
42
43     Based on NeutronException class.
44     """
45     message = "An unknown exception occurred."
46
47     def __init__(self, **kwargs):
48         try:
49             super(YardstickException, self).__init__(self.message % kwargs)
50             self.msg = self.message % kwargs
51         except Exception:  # pylint: disable=broad-except
52             with excutils.save_and_reraise_exception() as ctxt:
53                 if not self.use_fatal_exceptions():
54                     ctxt.reraise = False
55                     # at least get the core message out if something happened
56                     super(YardstickException, self).__init__(self.message)
57
58     def __str__(self):
59         return self.msg
60
61     def use_fatal_exceptions(self):
62         """Is the instance using fatal exceptions.
63
64         :returns: Always returns False.
65         """
66         return False
67
68
69 class ResourceCommandError(YardstickException):
70     message = 'Command: "%(command)s" Failed, stderr: "%(stderr)s"'
71
72
73 class ContextUpdateCollectdForNodeError(YardstickException):
74     message = 'Cannot find node %(attr_name)s'
75
76
77 class FunctionNotImplemented(YardstickException):
78     message = ('The function "%(function_name)s" is not implemented in '
79                '"%(class_name)" class.')
80
81
82 class InvalidType(YardstickException):
83     message = 'Type "%(type_to_convert)s" is not valid'
84
85
86 class InfluxDBConfigurationMissing(YardstickException):
87     message = ('InfluxDB configuration is not available. Add "influxdb" as '
88                'a dispatcher and the configuration section')
89
90
91 class YardstickBannedModuleImported(YardstickException):
92     message = 'Module "%(module)s" cannnot be imported. Reason: "%(reason)s"'
93
94
95 class IXIAUnsupportedProtocol(YardstickException):
96     message = 'Protocol "%(protocol)" is not supported in IXIA'
97
98
99 class PayloadMissingAttributes(YardstickException):
100     message = ('Error instantiating a Payload class, missing attributes: '
101                '%(missing_attributes)s')
102
103
104 class HeatTemplateError(YardstickException):
105     message = ('Error in Heat during the creation of the OpenStack stack '
106                '"%(stack_name)s"')
107
108
109 class IPv6RangeError(YardstickException):
110     message = 'Start IP "%(start_ip)s" is greater than end IP "%(end_ip)s"'
111
112
113 class TrafficProfileNotImplemented(YardstickException):
114     message = 'No implementation for traffic profile %(profile_class)s.'
115
116
117 class TrafficProfileRate(YardstickException):
118     message = 'Traffic profile rate must be "<number>[fps|%]"'
119
120
121 class DPDKSetupDriverError(YardstickException):
122     message = '"igb_uio" driver is not loaded'
123
124
125 class OVSUnsupportedVersion(YardstickException):
126     message = ('Unsupported OVS version "%(ovs_version)s". Please check the '
127                'config. OVS to DPDK version map: %(ovs_to_dpdk_map)s.')
128
129
130 class OVSHugepagesInfoError(YardstickException):
131     message = 'MemInfo cannnot be retrieved.'
132
133
134 class OVSHugepagesNotConfigured(YardstickException):
135     message = 'HugePages are not configured in this system.'
136
137
138 class OVSHugepagesZeroFree(YardstickException):
139     message = ('There are no HugePages free in this system. Total HugePages '
140                'configured: %(total_hugepages)s')
141
142
143 class OVSDeployError(YardstickException):
144     message = 'OVS deploy tool failed with error: %(stderr)s.'
145
146
147 class OVSSetupError(YardstickException):
148     message = 'OVS setup error. Command: %(command)s. Error: %(error)s.'
149
150
151 class LibvirtCreateError(YardstickException):
152     message = 'Error creating the virtual machine. Error: %(error)s.'
153
154
155 class LibvirtQemuImageBaseImageNotPresent(YardstickException):
156     message = ('Error creating the qemu image for %(vm_image)s. Base image: '
157                '%(base_image)s. Base image not present in execution host or '
158                'remote host.')
159
160
161 class LibvirtQemuImageCreateError(YardstickException):
162     message = ('Error creating the qemu image for %(vm_image)s. Base image: '
163                '%(base_image)s. Error: %(error)s.')
164
165
166 class SSHError(YardstickException):
167     message = '%(error_msg)s'
168
169
170 class SSHTimeout(SSHError):
171     pass
172
173
174 class IncorrectConfig(YardstickException):
175     message = '%(error_msg)s'
176
177
178 class IncorrectSetup(YardstickException):
179     message = '%(error_msg)s'
180
181
182 class IncorrectNodeSetup(IncorrectSetup):
183     pass
184
185
186 class ScenarioConfigContextNameNotFound(YardstickException):
187     message = 'Context for host name "%(host_name)s" not found'
188
189
190 class StackCreationInterrupt(YardstickException):
191     message = 'Stack create interrupted.'
192
193
194 class TaskRenderArgumentError(YardstickException):
195     message = 'Error reading the task input arguments'
196
197
198 class TaskReadError(YardstickException):
199     message = 'Failed to read task %(task_file)s'
200
201
202 class TaskRenderError(YardstickException):
203     message = 'Failed to render template:\n%(input_task)s'
204
205
206 class TimerTimeout(YardstickException):
207     message = 'Timer timeout expired, %(timeout)s seconds'
208
209
210 class WaitTimeout(YardstickException):
211     message = 'Wait timeout while waiting for condition'
212
213
214 class PktgenActionError(YardstickException):
215     message = 'Error in "%(action)s" action'
216
217
218 class KubernetesApiException(YardstickException):
219     message = ('Kubernetes API errors. Action: %(action)s, '
220                'resource: %(resource)s')
221
222
223 class KubernetesConfigFileNotFound(YardstickException):
224     message = 'Config file (%s) not found' % constants.K8S_CONF_FILE
225
226
227 class KubernetesTemplateInvalidVolumeType(YardstickException):
228     message = 'No valid "volume" types present in %(volume)s'
229
230
231 class KubernetesSSHPortNotDefined(YardstickException):
232     message = 'Port 22 needs to be defined'
233
234
235 class KubernetesServiceObjectNotDefined(YardstickException):
236     message = 'ServiceObject is not defined'
237
238
239 class KubernetesServiceObjectDefinitionError(YardstickException):
240     message = ('Kubernetes Service object definition error, missing '
241                'parameters: %(missing_parameters)s')
242
243
244 class KubernetesServiceObjectNameError(YardstickException):
245     message = ('Kubernetes Service object name "%(name)s" does not comply'
246                'naming convention')
247
248
249 class KubernetesCRDObjectDefinitionError(YardstickException):
250     message = ('Kubernetes Custom Resource Definition Object error, missing '
251                'parameters: %(missing_parameters)s')
252
253
254 class KubernetesNetworkObjectDefinitionError(YardstickException):
255     message = ('Kubernetes Network object definition error, missing '
256                'parameters: %(missing_parameters)s')
257
258
259 class KubernetesNetworkObjectKindMissing(YardstickException):
260     message = 'Kubernetes kind "Network" is not defined'
261
262
263 class KubernetesWrongRestartPolicy(YardstickException):
264     message = 'Restart policy "%(rpolicy)s" is not valid'
265
266
267 class KubernetesContainerPortNotDefined(YardstickException):
268     message = 'Container port not defined in "%(port)s"'
269
270
271 class KubernetesContainerWrongImagePullPolicy(YardstickException):
272     message = 'Image pull policy must be "Always", "IfNotPresent" or "Never"'
273
274
275 class KubernetesContainerCommandType(YardstickException):
276     message = '"args" and "command" must be string or list of strings'
277
278
279 class ScenarioCreateNetworkError(YardstickException):
280     message = 'Create Neutron Network Scenario failed'
281
282
283 class ScenarioCreateSubnetError(YardstickException):
284     message = 'Create Neutron Subnet Scenario failed'
285
286
287 class ScenarioDeleteRouterError(YardstickException):
288     message = 'Delete Neutron Router Scenario failed'
289
290
291 class MissingPodInfoError(YardstickException):
292     message = 'Missing pod args, please check'
293
294
295 class UnsupportedPodFormatError(YardstickException):
296     message = 'Failed to load pod info, unsupported format'
297
298
299 class ScenarioCreateRouterError(YardstickException):
300     message = 'Create Neutron Router Scenario failed'
301
302
303 class ScenarioRemoveRouterIntError(YardstickException):
304     message = 'Remove Neutron Router Interface Scenario failed'
305
306
307 class ScenarioCreateFloatingIPError(YardstickException):
308     message = 'Create Neutron Floating IP Scenario failed'
309
310
311 class ScenarioDeleteFloatingIPError(YardstickException):
312     message = 'Delete Neutron Floating IP Scenario failed'
313
314
315 class ScenarioCreateSecurityGroupError(YardstickException):
316     message = 'Create Neutron Security Group Scenario failed'
317
318
319 class ScenarioDeleteNetworkError(YardstickException):
320     message = 'Delete Neutron Network Scenario failed'
321
322
323 class ScenarioCreateServerError(YardstickException):
324     message = 'Nova Create Server Scenario failed'
325
326
327 class ScenarioDeleteServerError(YardstickException):
328     message = 'Delete Server Scenario failed'
329
330
331 class ScenarioCreateKeypairError(YardstickException):
332     message = 'Nova Create Keypair Scenario failed'
333
334
335 class ScenarioDeleteKeypairError(YardstickException):
336     message = 'Nova Delete Keypair Scenario failed'
337
338
339 class ScenarioAttachVolumeError(YardstickException):
340     message = 'Nova Attach Volume Scenario failed'
341
342
343 class ScenarioGetServerError(YardstickException):
344     message = 'Nova Get Server Scenario failed'
345
346
347 class ScenarioGetFlavorError(YardstickException):
348     message = 'Nova Get Falvor Scenario failed'
349
350
351 class ScenarioCreateVolumeError(YardstickException):
352     message = 'Cinder Create Volume Scenario failed'
353
354
355 class ScenarioDeleteVolumeError(YardstickException):
356     message = 'Cinder Delete Volume Scenario failed'
357
358
359 class ScenarioDetachVolumeError(YardstickException):
360     message = 'Cinder Detach Volume Scenario failed'
361
362
363 class ApiServerError(YardstickException):
364     message = 'An unkown exception happened to Api Server!'
365
366
367 class UploadOpenrcError(ApiServerError):
368     message = 'Upload openrc ERROR!'
369
370
371 class UpdateOpenrcError(ApiServerError):
372     message = 'Update openrc ERROR!'
373
374
375 class ScenarioCreateImageError(YardstickException):
376     message = 'Glance Create Image Scenario failed'
377
378
379 class ScenarioDeleteImageError(YardstickException):
380     message = 'Glance Delete Image Scenario failed'
381
382
383 class IxNetworkClientNotConnected(YardstickException):
384     message = 'IxNetwork client not connected to a TCL server'
385
386
387 class IxNetworkFlowNotPresent(YardstickException):
388     message = 'Flow Group "%(flow_group)s" is not present'
389
390
391 class IxNetworkFieldNotPresentInStackItem(YardstickException):
392     message = 'Field "%(field_name)s" not present in stack item %(stack_item)s'
393
394
395 class IncorrectFlowOption(YardstickException):
396     message = 'Flow option {option} for {link} is incorrect'
397
398
399 class SLAValidationError(YardstickException):
400     message = '%(case_name)s SLA validation failed. Error: %(error_msg)s'
401
402
403 class AclMissingActionArguments(YardstickException):
404     message = ('Missing ACL action parameter '
405                '[action=%(action_name)s parameter=%(action_param)s]')
406
407
408 class AclUnknownActionTemplate(YardstickException):
409     message = 'No ACL CLI template found for "%(action_name)s" action'
410
411
412 class InvalidMacAddress(YardstickException):
413     message = 'Mac address "%(mac_address)s" is invalid'
414
415
416 class ValueCheckError(YardstickException):
417     message = 'Constraint "%(value1)s %(operator)s %(value2)s" does not hold'
418
419
420 class RestApiError(RuntimeError):
421     def __init__(self, message):
422         self._message = message
423         super(RestApiError, self).__init__(message)
424
425
426 class LandslideTclException(RuntimeError):
427     def __init__(self, message):
428         self._message = message
429         super(LandslideTclException, self).__init__(message)