Merge changes from topics 'YARDSTICK-1351', 'YARDSTICK-1339'
[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 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 InfluxDBConfigurationMissing(YardstickException):
83     message = ('InfluxDB configuration is not available. Add "influxdb" as '
84                'a dispatcher and the configuration section')
85
86
87 class YardstickBannedModuleImported(YardstickException):
88     message = 'Module "%(module)s" cannnot be imported. Reason: "%(reason)s"'
89
90
91 class PayloadMissingAttributes(YardstickException):
92     message = ('Error instantiating a Payload class, missing attributes: '
93                '%(missing_attributes)s')
94
95
96 class HeatTemplateError(YardstickException):
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 TrafficProfileRate(YardstickException):
110     message = 'Traffic profile rate must be "<number>[fps|%]"'
111
112
113 class DPDKSetupDriverError(YardstickException):
114     message = '"igb_uio" driver is not loaded'
115
116
117 class OVSUnsupportedVersion(YardstickException):
118     message = ('Unsupported OVS version "%(ovs_version)s". Please check the '
119                'config. OVS to DPDK version map: %(ovs_to_dpdk_map)s.')
120
121
122 class OVSHugepagesInfoError(YardstickException):
123     message = 'MemInfo cannnot be retrieved.'
124
125
126 class OVSHugepagesNotConfigured(YardstickException):
127     message = 'HugePages are not configured in this system.'
128
129
130 class OVSHugepagesZeroFree(YardstickException):
131     message = ('There are no HugePages free in this system. Total HugePages '
132                'configured: %(total_hugepages)s')
133
134
135 class OVSDeployError(YardstickException):
136     message = 'OVS deploy tool failed with error: %(stderr)s.'
137
138
139 class OVSSetupError(YardstickException):
140     message = 'OVS setup error. Command: %(command)s. Error: %(error)s.'
141
142
143 class LibvirtCreateError(YardstickException):
144     message = 'Error creating the virtual machine. Error: %(error)s.'
145
146
147 class LibvirtQemuImageBaseImageNotPresent(YardstickException):
148     message = ('Error creating the qemu image for %(vm_image)s. Base image: '
149                '%(base_image)s. Base image not present in execution host or '
150                'remote host.')
151
152
153 class LibvirtQemuImageCreateError(YardstickException):
154     message = ('Error creating the qemu image for %(vm_image)s. Base image: '
155                '%(base_image)s. Error: %(error)s.')
156
157
158 class SSHError(YardstickException):
159     message = '%(error_msg)s'
160
161
162 class SSHTimeout(SSHError):
163     pass
164
165
166 class IncorrectConfig(YardstickException):
167     message = '%(error_msg)s'
168
169
170 class IncorrectSetup(YardstickException):
171     message = '%(error_msg)s'
172
173
174 class IncorrectNodeSetup(IncorrectSetup):
175     pass
176
177
178 class ScenarioConfigContextNameNotFound(YardstickException):
179     message = 'Context for host name "%(host_name)s" not found'
180
181
182 class StackCreationInterrupt(YardstickException):
183     message = 'Stack create interrupted.'
184
185
186 class TaskRenderArgumentError(YardstickException):
187     message = 'Error reading the task input arguments'
188
189
190 class TaskReadError(YardstickException):
191     message = 'Failed to read task %(task_file)s'
192
193
194 class TaskRenderError(YardstickException):
195     message = 'Failed to render template:\n%(input_task)s'
196
197
198 class RunnerIterationIPCSetupActionNeeded(YardstickException):
199     message = ('IterationIPC needs the "setup" action to retrieve the VNF '
200                'handling processes PIDs to receive the messages sent')
201
202
203 class RunnerIterationIPCNoCtxs(YardstickException):
204     message = 'Benchmark "setup" action did not return any VNF process PID'
205
206
207 class TimerTimeout(YardstickException):
208     message = 'Timer timeout expired, %(timeout)s seconds'
209
210
211 class WaitTimeout(YardstickException):
212     message = 'Wait timeout while waiting for condition'
213
214
215 class PktgenActionError(YardstickException):
216     message = 'Error in "%(action)s" action'
217
218
219 class KubernetesApiException(YardstickException):
220     message = ('Kubernetes API errors. Action: %(action)s, '
221                'resource: %(resource)s')
222
223
224 class KubernetesConfigFileNotFound(YardstickException):
225     message = 'Config file (%s) not found' % constants.K8S_CONF_FILE
226
227
228 class KubernetesTemplateInvalidVolumeType(YardstickException):
229     message = 'No valid "volume" types present in %(volume)s'
230
231
232 class KubernetesSSHPortNotDefined(YardstickException):
233     message = 'Port 22 needs to be defined'
234
235
236 class KubernetesServiceObjectNotDefined(YardstickException):
237     message = 'ServiceObject is not defined'
238
239
240 class KubernetesServiceObjectDefinitionError(YardstickException):
241     message = ('Kubernetes Service object definition error, missing '
242                'parameters: %(missing_parameters)s')
243
244
245 class KubernetesServiceObjectNameError(YardstickException):
246     message = ('Kubernetes Service object name "%(name)s" does not comply'
247                'naming convention')
248
249
250 class KubernetesCRDObjectDefinitionError(YardstickException):
251     message = ('Kubernetes Custom Resource Definition Object error, missing '
252                'parameters: %(missing_parameters)s')
253
254
255 class KubernetesNetworkObjectDefinitionError(YardstickException):
256     message = ('Kubernetes Network object definition error, missing '
257                'parameters: %(missing_parameters)s')
258
259
260 class KubernetesNetworkObjectKindMissing(YardstickException):
261     message = 'Kubernetes kind "Network" is not defined'
262
263
264 class KubernetesWrongRestartPolicy(YardstickException):
265     message = 'Restart policy "%(rpolicy)s" is not valid'
266
267
268 class KubernetesContainerPortNotDefined(YardstickException):
269     message = 'Container port not defined in "%(port)s"'
270
271
272 class KubernetesContainerWrongImagePullPolicy(YardstickException):
273     message = 'Image pull policy must be "Always", "IfNotPresent" or "Never"'
274
275
276 class KubernetesContainerCommandType(YardstickException):
277     message = '"args" and "command" must be string or list of strings'
278
279
280 class ScenarioCreateNetworkError(YardstickException):
281     message = 'Create Neutron Network Scenario failed'
282
283
284 class ScenarioCreateSubnetError(YardstickException):
285     message = 'Create Neutron Subnet Scenario failed'
286
287
288 class ScenarioDeleteRouterError(YardstickException):
289     message = 'Delete Neutron Router Scenario failed'
290
291
292 class MissingPodInfoError(YardstickException):
293     message = 'Missing pod args, please check'
294
295
296 class UnsupportedPodFormatError(YardstickException):
297     message = 'Failed to load pod info, unsupported format'
298
299
300 class ScenarioCreateRouterError(YardstickException):
301     message = 'Create Neutron Router Scenario failed'
302
303
304 class ScenarioRemoveRouterIntError(YardstickException):
305     message = 'Remove Neutron Router Interface Scenario failed'
306
307
308 class ScenarioCreateFloatingIPError(YardstickException):
309     message = 'Create Neutron Floating IP Scenario failed'
310
311
312 class ScenarioDeleteFloatingIPError(YardstickException):
313     message = 'Delete Neutron Floating IP Scenario failed'
314
315
316 class ScenarioCreateSecurityGroupError(YardstickException):
317     message = 'Create Neutron Security Group Scenario failed'
318
319
320 class ScenarioDeleteNetworkError(YardstickException):
321     message = 'Delete Neutron Network Scenario failed'
322
323
324 class ScenarioCreateServerError(YardstickException):
325     message = 'Nova Create Server Scenario failed'
326
327
328 class ScenarioDeleteServerError(YardstickException):
329     message = 'Delete Server Scenario failed'
330
331
332 class ScenarioCreateKeypairError(YardstickException):
333     message = 'Nova Create Keypair Scenario failed'
334
335
336 class ScenarioDeleteKeypairError(YardstickException):
337     message = 'Nova Delete Keypair Scenario failed'
338
339
340 class ScenarioAttachVolumeError(YardstickException):
341     message = 'Nova Attach Volume Scenario failed'
342
343
344 class ScenarioGetServerError(YardstickException):
345     message = 'Nova Get Server Scenario failed'
346
347
348 class ScenarioGetFlavorError(YardstickException):
349     message = 'Nova Get Falvor Scenario failed'
350
351
352 class ScenarioCreateVolumeError(YardstickException):
353     message = 'Cinder Create Volume Scenario failed'
354
355
356 class ScenarioDeleteVolumeError(YardstickException):
357     message = 'Cinder Delete Volume Scenario failed'
358
359
360 class ScenarioDetachVolumeError(YardstickException):
361     message = 'Cinder Detach Volume Scenario failed'
362
363
364 class ApiServerError(YardstickException):
365     message = 'An unkown exception happened to Api Server!'
366
367
368 class UploadOpenrcError(ApiServerError):
369     message = 'Upload openrc ERROR!'
370
371
372 class UpdateOpenrcError(ApiServerError):
373     message = 'Update openrc ERROR!'
374
375
376 class ScenarioCreateImageError(YardstickException):
377     message = 'Glance Create Image Scenario failed'
378
379
380 class ScenarioDeleteImageError(YardstickException):
381     message = 'Glance Delete Image Scenario failed'
382
383
384 class IxNetworkClientNotConnected(YardstickException):
385     message = 'IxNetwork client not connected to a TCL server'
386
387
388 class IxNetworkFlowNotPresent(YardstickException):
389     message = 'Flow Group "%(flow_group)s" is not present'
390
391
392 class IxNetworkFieldNotPresentInStackItem(YardstickException):
393     message = 'Field "%(field_name)s" not present in stack item %(stack_item)s'
394
395
396 class SLAValidationError(YardstickException):
397     message = '%(case_name)s SLA validation failed. Error: %(error_msg)s'
398
399
400 class AclMissingActionArguments(YardstickException):
401     message = ('Missing ACL action parameter '
402                '[action=%(action_name)s parameter=%(action_param)s]')
403
404
405 class AclUknownActionTemplate(YardstickException):
406     message = 'No ACL CLI template found for "%(action_name)s" action'