-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathexception.py
443 lines (266 loc) · 12.8 KB
/
exception.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Plugin base exception handling.
Includes decorator for re-raising Plugin-type exceptions.
SHOULD include dedicated exception logging.
"""
import sys
from oslo_config import cfg
from oslo_log import log as logging
import six
import webob.exc
from webob.util import status_generic_reasons
from webob.util import status_reasons
from hpedockerplugin.i18n import _, _LE
LOG = logging.getLogger(__name__)
exc_log_opts = [
cfg.BoolOpt('fatal_exception_format_errors',
default=False,
help='Make exception message format errors fatal.'),
]
CONF = cfg.CONF
CONF.register_opts(exc_log_opts)
class ConvertedException(webob.exc.WSGIHTTPException):
def __init__(self, code=500, title="", explanation=""):
self.code = code
# There is a strict rule about constructing status line for HTTP:
# '...Status-Line, consisting of the protocol version followed by a
# numeric status code and its associated textual phrase, with each
# element separated by SP characters'
# (http://www.faqs.org/rfcs/rfc2616.html)
# 'code' and 'title' can not be empty because they correspond
# to numeric status code and its associated text
if title:
self.title = title
else:
try:
self.title = status_reasons[self.code]
except KeyError:
generic_code = self.code // 100
self.title = status_generic_reasons[generic_code]
self.explanation = explanation
super(ConvertedException, self).__init__()
class Error(Exception):
pass
class PluginException(Exception):
"""Base Plugin Exception
To correctly use this class, inherit from it and define
a 'message' property. That message will get printf'd
with the keyword arguments provided to the constructor.
"""
message = _("An unknown exception occurred.")
code = 500
headers = {}
safe = False
def __init__(self, message=None, **kwargs):
self.kwargs = kwargs
self.kwargs['message'] = message
if 'code' not in self.kwargs:
try:
self.kwargs['code'] = self.code
except AttributeError:
pass
for k, v in self.kwargs.items():
if isinstance(v, Exception):
self.kwargs[k] = six.text_type(v)
if self._should_format():
try:
message = self.message % kwargs
except Exception:
exc_info = sys.exc_info()
# kwargs doesn't match a variable in the message
# log the issue and the kwargs
LOG.exception(_LE('Exception in string format operation'))
for name, value in kwargs.items():
LOG.error(_LE("%(name)s: %(value)s"),
{'name': name, 'value': value})
if CONF.fatal_exception_format_errors:
six.reraise(*exc_info)
# at least get the core message out if something happened
message = self.message
elif isinstance(message, Exception):
message = six.text_type(message)
# NOTE(luisg): We put the actual message in 'msg' so that we can access
# it, because if we try to access the message via 'message' it will be
# overshadowed by the class' message attribute
self.msg = message
super(PluginException, self).__init__(message)
def _should_format(self):
return self.kwargs['message'] is None or '%(message)' in self.message
def __unicode__(self):
return six.text_type(self.msg)
class Duplicate(PluginException):
pass
class Invalid(PluginException):
message = _("Unacceptable parameters.")
class Invalid3PARDomain(PluginException):
message = _("Invalid 3PAR Domain: %(err)s")
class ConnectionError(PluginException):
message = _("Unable to connect to storage array/appliance: %(err)s")
class InvalidInput(PluginException):
message = _("Invalid input received: %(reason)s")
class NotAuthorized(PluginException):
message = _("Not authorized.")
class RevertSnapshotException(PluginException):
message = _("Exception during revering the snapshot")
class VolumeBackendAPIException(PluginException):
message = _("Bad or unexpected response from the storage volume "
"backend API: %(data)s")
class VolumeIsBusy(PluginException):
message = _("deleting volume %(volume_name)s that has snapshot")
# HPE Docker Volume Plugin
class HPEPluginStartPluginException(PluginException):
message = _("HPE Docker Volume Plugin Start Plugin Service Failed: "
"%(reason)s")
class HPEPluginNotInitializedException(PluginException):
message = _("HPE Docker Volume plugin not ready: %(reason)s")
class HPEPluginCreateException(PluginException):
message = _("HPE Docker Volume plugin Create volume failed: %(reason)s")
class HPEPluginRemoveException(PluginException):
message = _("HPE Docker Volume plugin Remove volume failed: %(reason)s")
class HPEPluginMountException(PluginException):
message = _("HPE Docker Volume Plugin Mount Failed: %(reason)s")
class HPEPluginCheckMountException(PluginException):
message = _("HPE Docker Volume Plugin Check if Mount already exists"
" on host Failed: %(reason)s")
class HPEPluginUMountException(PluginException):
message = _("HPE Docker Volume Plugin Unmount Failed: %(reason)s")
class HPEPluginMapHourException(PluginException):
message = _("HPE Docker Volume Plugin Failed to map expiration hours:"
"%(reason)s")
class HPEPluginMapSizeException(PluginException):
message = _("HPE Docker Volume Plugin Failed to map size: %(reason)s")
class HPEPluginMapProvisioningException(PluginException):
message = _("HPE Docker Volume Plugin Failed to map provisioning:"
"%(reason)s")
class HPEPluginMakeDirException(PluginException):
message = _("HPE Docker Volume Plugin Makedir Failed: %(reason)s")
class HPEPluginRemoveDirException(PluginException):
message = _("HPE Docker Volume Plugin Removedir Failed: %(reason)s")
class HPEPluginFileSystemException(PluginException):
message = _("HPE Docker Volume Plugin File System error: %(reason)s")
class HPEPluginMakeEtcdRootException(PluginException):
message = _("HPE Docker Volume Plugin Make Etcd Root error: %(reason)s")
class HPEPluginEtcdException(PluginException):
message = _("Encountered Etcd exception: %(reason)s")
class HPEPluginSaveFailed(HPEPluginEtcdException):
message = _("ETCD data save failed: %(obj)s")
class HPEPluginLockFailed(HPEPluginEtcdException):
message = _("ETCD lock failed: %(obj)s")
class HPEPluginReadBackendFailed(HPEPluginEtcdException):
message = _("ETCD read for backend failed for vol: %(volname)s")
class HPEPluginActiveDriverEntryNotFound(HPEPluginEtcdException):
message = _("ETCD active driver info not found: %(key)s")
class HPEPluginUnlockFailed(HPEPluginEtcdException):
message = _("ETCD unlock failed: %(obj)s")
class HPEDriverException(PluginException):
message = _("Driver exception: %(msg)")
class HPEDriverInvalidInput(HPEDriverException):
message = _("Invalid input received: %(reason)s")
class HPEDriverInvalidSizeForCompressedVolume(HPEDriverException):
message = _("Invalid input received: %(reason)s")
class HPEDriverInvalidDedupVersion(HPEDriverException):
message = _("Invalid input received: %(reason)s")
class HPEDriverManageVolumeAttached(HPEDriverException):
message = _("Failed to manage volume/snapshot because its attached:"
"%(reason)s")
class HPEDriverCreateVolumeWithQosFailed(HPEDriverException):
message = ""
class HPEDriverGetQosFromVvSetFailed(HPEDriverException):
message = _("Failed to retrieve QOS from VV-Set %(vvset_name)s:"
" %(reason)s")
class HPEDriverSetFlashCacheOnVvsFailed(HPEDriverException):
message = _("%(reason)s")
class HPEDriverVolumeAlreadyExists(HPEDriverException):
message = ""
class HPEDriverAddVvToVvSetFailed(HPEDriverException):
message = ""
class HPEDriverCreateScheduleFailed(HPEDriverException):
message = _("Creation of snapshot schedule failed: %(reason)s")
class HPEDriverRemoveScheduleFailed(HPEDriverException):
message = _("Removal of snapshot schedule failed: %(reason)s")
class HPEDriverForceRemoveVLUNFailed(HPEDriverException):
message = "Forced removal of VLUN failed: %(reason)"
class HPEDriverNoVLUNsCreated(HPEDriverException):
message = "No new VLUN(s) were created!"
class HPEDriverRemoteCopyGroupNotFound(HPEDriverException):
message = "Remote copy group '%(name)s' not found"
class HPEArrayNotReachable(PluginException):
message = "Array is not reachable: '%(url)s'"
# message = "Array is not reachable: '%(array_ip)'"
class HPERemoteCopyGroupBackendAPIException(PluginException):
message = _("Bad or unexpected response from the RCG "
"backend API: %(data)s")
class HPERemoteCopyGroupAlreadyExists(PluginException):
message = "Remote copy group %(rcg_name)s already exists"
class HPERemoteCopyGroupNotPrimary(PluginException):
message = "Remote copy group '%(rcg_name)s' not in Primary role"
class HPEDriverUnknownException(HPEDriverException):
message = "An unknown exception occurred: %(ex)s"
class InvalidRcgRoleForDeleteVolume(PluginException):
message = _("Error: %(reason)s")
class DeleteReplicatedVolumeFailed(PluginException):
message = _("Delete Replication Volume Failed: %(reason)s")
class RcgStateInTransitionException(PluginException):
message = _("Remote copy group state is in transition: %(reason)s")
class HPEDriverNoQosOrFlashCacheSetForVolume(PluginException):
message = _("Volume in VVS without being associated with QOS or "
"flash-cache: %(reason)s")
class EtcdMetadataNotFound(PluginException):
message = _("ETCD metadata not found: %(msg)s")
class ShareBackendException(PluginException):
message = _("Share backend exception: %(msg)s")
class EtcdFpgEntryForCpgNotFound(PluginException):
message = _("FPG %(fpg)s does not exist under the specified/default "
"CPG %(cpg)s")
class FpgNotFound(PluginException):
message = _("FPG %(fpg)s does not exist")
class EtcdCpgEntryNotFound(PluginException):
message = _("CPG %(cpg)s does not exist %(cpg)s")
class CmdExecutionError(PluginException):
message = _("Failed to execute command. Cause: %(msg)s")
class EtcdInvalidLockType(PluginException):
message = _("Invalid lock type %(type)s specified")
class FileIPPoolExhausted(PluginException):
message = _("IP pool exhausted for %(backend)s")
class EtcdMaxSharesPerFpgLimitException(PluginException):
message = _("Max share limit reached for FPG %(fpg_name)s")
class EtcdDefaultFpgNotAvailable(PluginException):
message = _("No default FPG is available under CPG %(cpg)s")
class EtcdDefaultFpgNotPresent(PluginException):
message = _("No default FPG is not present for CPG %(cpg)s")
class EtcdBackendMetadataDoesNotExist(PluginException):
message = _("Backend metadata doesn't exist for backend: %(backend)s")
class EtcdUnknownException(PluginException):
message = _("Unknown exception occured: %(reason)s")
class IPAddressPoolExhausted(PluginException):
message = _("IP address pool exhausted")
class VfsCreationFailed(PluginException):
message = _("VFS creation failed: %(reason)s")
class ShareCreationFailed(PluginException):
message = _("Share creation failed: %(reason)s")
class FpgCreationFailed(PluginException):
message = _("FPG creation failed: %(reason)s")
class FpgAlreadyExists(PluginException):
message = _("FPG already exists: %(reason)s")
class UserGroupNotFoundOn3PAR(PluginException):
message = _("fsusergroup or fsuser doesn't exist on 3PAR: %(reason)s")
class SetQuotaFailed(PluginException):
message = _("Set quota failed: %(reason)s")
class HPEDriverNonExistentCpg(HPEDriverException):
message = "CPG %(cpg)s does not exist"
class FpgCapacityInsufficient(PluginException):
message = _("FPG %(fpg)s does not have enough capacity")