[TrivialFix] Fix BarbicanException error propagation

Fix BarbicanException error propagation in Deckhand by ensuring
that the exception details are passed around via str(e) rather
than e.message as the Barbican exceptions [0] don't have additional
attributes like falcon.

Example stack trace:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/falcon/api.py", line 244, in __call__
    responder(req, resp, **params)
  File "./deckhand/policy.py", line 104, in handler
    return func(*args, **kwargs)
  File "./deckhand/control/buckets.py", line 70, in on_put
    self._prepare_secret_documents(documents)
  File "./deckhand/control/buckets.py", line 83, in _prepare_secret_documents
    secret_data = self.secrets_mgr.create(document)
  File "./deckhand/engine/secrets_manager.py", line 74, in create
    resp = self.barbican_driver.create_secret(**kwargs)
  File "./deckhand/barbican/driver.py", line 39, in create_secret
    LOG.exception(e.message)
AttributeError: 'HTTPServerError' object has no attribute 'message'

[0] https://github.com/openstack/python-barbicanclient/blob/master/barbicanclient/exceptions.py

Change-Id: I58410c3729fe4fd066227311589e5ee5d30dc171
This commit is contained in:
Felipe Monteiro 2018-02-23 21:42:04 +00:00
parent b3385558f8
commit f0cc8b6c1a
3 changed files with 19 additions and 16 deletions

View File

@ -61,9 +61,8 @@ class BarbicanClientWrapper(object):
self._cached_client = cli
except barbican_exc.HTTPAuthError as e:
LOG.exception(e.message)
raise errors.BarbicanException(message=e.message,
code=e.status_code)
LOG.exception(str(e))
raise errors.BarbicanException(details=str(e))
return cli

View File

@ -36,9 +36,8 @@ class BarbicanDriver(object):
except (barbicanclient.exceptions.HTTPAuthError,
barbicanclient.exceptions.HTTPClientError,
barbicanclient.exceptions.HTTPServerError) as e:
LOG.exception(e.message)
raise errors.BarbicanException(message=e.message,
code=e.status_code)
LOG.exception(str(e))
raise errors.BarbicanException(details=str(e))
# NOTE(fmontei): The dictionary representation of the Secret object by
# default has keys that are not snake case -- so make them snake case.

View File

@ -356,16 +356,6 @@ class SubstitutionSourceNotFound(DeckhandException):
code = 409
class BarbicanException(DeckhandException):
"""An error occurred with Barbican.
**Troubleshoot:**
"""
def __init__(self, message, code):
super(BarbicanException, self).__init__(message=message, code=code)
class PolicyNotAuthorized(DeckhandException):
"""The policy action is not found in the list of registered rules.
@ -375,6 +365,21 @@ class PolicyNotAuthorized(DeckhandException):
code = 403
class BarbicanException(DeckhandException):
"""An error occurred with Barbican.
**Troubleshoot:**
* Ensure that Deckhand can authenticate against Keystone.
* Ensure that Deckhand's Barbican configuration options are correct.
* Ensure that Deckhand and Barbican are contained in the Keystone service
catalog.
"""
msg_fmt = ('An exception occurred while trying to communicate with '
'Barbican. Details: %(details)s')
code = 500
class UnknownSubstitutionError(DeckhandException):
"""An unknown error occurred during substitution.