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