Convert SSH custom exceptions to Yardstick exceptions
[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 YardstickException(Exception):
25     """Base Yardstick Exception.
26
27     To correctly use this class, inherit from it and define
28     a 'message' property. That message will get printf'd
29     with the keyword arguments provided to the constructor.
30
31     Based on NeutronException class.
32     """
33     message = "An unknown exception occurred."
34
35     def __init__(self, **kwargs):
36         try:
37             super(YardstickException, self).__init__(self.message % kwargs)
38             self.msg = self.message % kwargs
39         except Exception:  # pylint: disable=broad-except
40             with excutils.save_and_reraise_exception() as ctxt:
41                 if not self.use_fatal_exceptions():
42                     ctxt.reraise = False
43                     # at least get the core message out if something happened
44                     super(YardstickException, self).__init__(self.message)
45
46     def __str__(self):
47         return self.msg
48
49     def use_fatal_exceptions(self):
50         """Is the instance using fatal exceptions.
51
52         :returns: Always returns False.
53         """
54         return False
55
56
57 class ResourceCommandError(YardstickException):
58     message = 'Command: "%(command)s" Failed, stderr: "%(stderr)s"'
59
60
61 class FunctionNotImplemented(YardstickException):
62     message = ('The function "%(function_name)s" is not implemented in '
63                '"%(class_name)" class.')
64
65
66 class InfluxDBConfigurationMissing(YardstickException):
67     message = ('InfluxDB configuration is not available. Add "influxdb" as '
68                'a dispatcher and the configuration section')
69
70
71 class YardstickBannedModuleImported(YardstickException):
72     # pragma: no cover
73     message = 'Module "%(module)s" cannnot be imported. Reason: "%(reason)s"'
74
75
76 class PayloadMissingAttributes(YardstickException):
77     message = ('Error instantiating a Payload class, missing attributes: '
78                '%(missing_attributes)s')
79
80
81 class HeatTemplateError(YardstickException):
82     """Error in Heat during the stack deployment"""
83     message = ('Error in Heat during the creation of the OpenStack stack '
84                '"%(stack_name)s"')
85
86
87 class IPv6RangeError(YardstickException):
88     message = 'Start IP "%(start_ip)s" is greater than end IP "%(end_ip)s"'
89
90
91 class TrafficProfileNotImplemented(YardstickException):
92     message = 'No implementation for traffic profile %(profile_class)s.'
93
94
95 class DPDKSetupDriverError(YardstickException):
96     message = '"igb_uio" driver is not loaded'
97
98
99 class OVSUnsupportedVersion(YardstickException):
100     message = ('Unsupported OVS version "%(ovs_version)s". Please check the '
101                'config. OVS to DPDK version map: %(ovs_to_dpdk_map)s.')
102
103
104 class OVSHugepagesInfoError(YardstickException):
105     message = 'MemInfo cannnot be retrieved.'
106
107
108 class OVSHugepagesNotConfigured(YardstickException):
109     message = 'HugePages are not configured in this system.'
110
111
112 class OVSHugepagesZeroFree(YardstickException):
113     message = ('There are no HugePages free in this system. Total HugePages '
114                'configured: %(total_hugepages)s')
115
116
117 class OVSDeployError(YardstickException):
118     message = 'OVS deploy tool failed with error: %(stderr)s.'
119
120
121 class OVSSetupError(YardstickException):
122     message = 'OVS setup error. Command: %(command)s. Error: %(error)s.'
123
124
125 class LibvirtCreateError(YardstickException):
126     message = 'Error creating the virtual machine. Error: %(error)s.'
127
128
129 class LibvirtQemuImageBaseImageNotPresent(YardstickException):
130     message = ('Error creating the qemu image for %(vm_image)s. Base image: '
131                '%(base_image)s. Base image not present in execution host or '
132                'remote host.')
133
134
135 class LibvirtQemuImageCreateError(YardstickException):
136     message = ('Error creating the qemu image for %(vm_image)s. Base image: '
137                '%(base_image)s. Error: %(error)s.')
138
139
140 class SSHError(YardstickException):
141     message = '%(error_msg)s'
142
143
144 class SSHTimeout(SSHError):
145     pass
146
147
148 class ScenarioConfigContextNameNotFound(YardstickException):
149     message = 'Context name "%(context_name)s" not found'
150
151
152 class StackCreationInterrupt(YardstickException):
153     message = 'Stack create interrupted.'
154
155
156 class TaskRenderArgumentError(YardstickException):
157     message = 'Error reading the task input arguments'
158
159
160 class TaskReadError(YardstickException):
161     message = 'Failed to read task %(task_file)s'
162
163
164 class TaskRenderError(YardstickException):
165     message = 'Failed to render template:\n%(input_task)s'
166
167
168 class TimerTimeout(YardstickException):
169     message = 'Timer timeout expired, %(timeout)s seconds'
170
171
172 class WaitTimeout(YardstickException):
173     message = 'Wait timeout while waiting for condition'
174
175
176 class ScenarioCreateNetworkError(YardstickException):
177     message = 'Create Neutron Network Scenario failed'
178
179
180 class ScenarioCreateSubnetError(YardstickException):
181     message = 'Create Neutron Subnet Scenario failed'
182
183
184 class ScenarioDeleteRouterError(YardstickException):
185     message = 'Delete Neutron Router Scenario failed'
186
187
188 class MissingPodInfoError(YardstickException):
189     message = 'Missing pod args, please check'
190
191
192 class UnsupportedPodFormatError(YardstickException):
193     message = 'Failed to load pod info, unsupported format'
194
195
196 class ScenarioCreateRouterError(YardstickException):
197     message = 'Create Neutron Router Scenario failed'
198
199
200 class ScenarioRemoveRouterIntError(YardstickException):
201     message = 'Remove Neutron Router Interface Scenario failed'
202
203
204 class ScenarioCreateFloatingIPError(YardstickException):
205     message = 'Create Neutron Floating IP Scenario failed'
206
207
208 class ScenarioDeleteFloatingIPError(YardstickException):
209     message = 'Delete Neutron Floating IP Scenario failed'
210
211
212 class ScenarioCreateSecurityGroupError(YardstickException):
213     message = 'Create Neutron Security Group Scenario failed'
214
215
216 class ScenarioDeleteNetworkError(YardstickException):
217     message = 'Delete Neutron Network Scenario failed'
218
219
220 class ScenarioCreateServerError(YardstickException):
221     message = 'Nova Create Server Scenario failed'
222
223
224 class ScenarioDeleteServerError(YardstickException):
225     message = 'Delete Server Scenario failed'
226
227
228 class ScenarioCreateKeypairError(YardstickException):
229     message = 'Nova Create Keypair Scenario failed'
230
231
232 class ScenarioDeleteKeypairError(YardstickException):
233     message = 'Nova Delete Keypair Scenario failed'
234
235
236 class ScenarioAttachVolumeError(YardstickException):
237     message = 'Nova Attach Volume Scenario failed'
238
239
240 class ScenarioGetServerError(YardstickException):
241     message = 'Nova Get Server Scenario failed'
242
243
244 class ScenarioGetFlavorError(YardstickException):
245     message = 'Nova Get Falvor Scenario failed'
246
247
248 class ScenarioCreateVolumeError(YardstickException):
249     message = 'Cinder Create Volume Scenario failed'
250
251
252 class ScenarioDeleteVolumeError(YardstickException):
253     message = 'Cinder Delete Volume Scenario failed'
254
255
256 class ScenarioDetachVolumeError(YardstickException):
257     message = 'Cinder Detach Volume Scenario failed'
258
259
260 class ApiServerError(YardstickException):
261     message = 'An unkown exception happened to Api Server!'
262
263
264 class UploadOpenrcError(ApiServerError):
265     message = 'Upload openrc ERROR!'
266
267
268 class UpdateOpenrcError(ApiServerError):
269     message = 'Update openrc ERROR!'
270
271
272 class ScenarioCreateImageError(YardstickException):
273     message = 'Glance Create Image Scenario failed'
274
275
276 class ScenarioDeleteImageError(YardstickException):
277     message = 'Glance Delete Image Scenario failed'