From 0e9168de80bbb6b4a3d84a46d833509ed4560e51 Mon Sep 17 00:00:00 2001 From: Sergey Belous Date: Thu, 15 Jan 2015 14:47:42 +0300 Subject: [PATCH] base.py: Improve exception handling When logging exceptions the exception handling should make use of save_and_reraise. Change-Id: I3fd3aea1719d493b4184247991e2e5f79c4218aa Closes-bug: #1305032 --- neutron/api/v2/base.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/neutron/api/v2/base.py b/neutron/api/v2/base.py index 4c1810cff..5e1f6114f 100644 --- a/neutron/api/v2/base.py +++ b/neutron/api/v2/base.py @@ -351,25 +351,26 @@ class Controller(object): return objs # Note(salvatore-orlando): broad catch as in theory a plugin # could raise any kind of exception - except Exception as ex: - for obj in objs: - obj_deleter = getattr(self._plugin, - self._plugin_handlers[self.DELETE]) - try: - kwargs = ({self._parent_id_name: parent_id} if parent_id - else {}) - obj_deleter(request.context, obj['id'], **kwargs) - except Exception: - # broad catch as our only purpose is to log the exception - LOG.exception(_LE("Unable to undo add for " - "%(resource)s %(id)s"), - {'resource': self._resource, - 'id': obj['id']}) - # TODO(salvatore-orlando): The object being processed when the - # plugin raised might have been created or not in the db. - # We need a way for ensuring that if it has been created, - # it is then deleted - raise ex + except Exception: + with excutils.save_and_reraise_exception(): + for obj in objs: + obj_deleter = getattr(self._plugin, + self._plugin_handlers[self.DELETE]) + try: + kwargs = ({self._parent_id_name: parent_id} + if parent_id else {}) + obj_deleter(request.context, obj['id'], **kwargs) + except Exception: + # broad catch as our only purpose is to log the + # exception + LOG.exception(_LE("Unable to undo add for " + "%(resource)s %(id)s"), + {'resource': self._resource, + 'id': obj['id']}) + # TODO(salvatore-orlando): The object being processed when the + # plugin raised might have been created or not in the db. + # We need a way for ensuring that if it has been created, + # it is then deleted def create(self, request, body=None, **kwargs): """Creates a new instance of the requested entity.""" -- 2.45.2