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