]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
base.py: Improve exception handling
authorSergey Belous <sbelous@mirantis.com>
Thu, 15 Jan 2015 11:47:42 +0000 (14:47 +0300)
committerSergey Belous <sbelous@mirantis.com>
Thu, 15 Jan 2015 12:20:09 +0000 (15:20 +0300)
When logging exceptions the exception handling should make use
of save_and_reraise.

Change-Id: I3fd3aea1719d493b4184247991e2e5f79c4218aa
Closes-bug: #1305032

neutron/api/v2/base.py

index 4c1810cff8e9bb19f04603d7a849c988a041145c..5e1f6114f654ba52f60203e5d1a1b8c32bed8d7f 100644 (file)
@@ -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."""