]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Get rid of exception converter in db/api.py
authorKevin Benton <blak111@gmail.com>
Sun, 16 Aug 2015 09:32:39 +0000 (02:32 -0700)
committerKevin Benton <blak111@gmail.com>
Sun, 16 Aug 2015 09:40:23 +0000 (02:40 -0700)
The exception converter was necessary because the exceptions the
oslo db decorator looked for before were statically defined. The
retry decorator now accepts an exception_checker argument that takes
a function to call on exceptions to determine if they should be
caught.

This patch gets rid of the converted and replaces the one use case
with the new exception_checker argument.

Closes-Bug: #1485819
Change-Id: Ic619b03737cbf51276f87c4458ecc4183424731c

neutron/db/api.py
neutron/plugins/ml2/plugin.py

index b4384eec0c01cd3ab213c41767641f82eeffdc11..53ef51b957b6532b4dd5f8777caae371c564deb4 100644 (file)
 #    under the License.
 
 import contextlib
-import six
 
 from oslo_config import cfg
 from oslo_db import api as oslo_db_api
-from oslo_db import exception as os_db_exception
 from oslo_db.sqlalchemy import session
 from oslo_utils import uuidutils
 from sqlalchemy import exc
-from sqlalchemy import orm
 
 from neutron.common import exceptions as n_exc
 from neutron.db import common_db_mixin
@@ -76,24 +73,6 @@ def autonested_transaction(sess):
             yield tx
 
 
-class convert_db_exception_to_retry(object):
-    """Converts other types of DB exceptions into RetryRequests."""
-
-    def __init__(self, stale_data=False):
-        self.to_catch = ()
-        if stale_data:
-            self.to_catch += (orm.exc.StaleDataError, )
-
-    def __call__(self, f):
-        @six.wraps(f)
-        def wrapper(*args, **kwargs):
-            try:
-                return f(*args, **kwargs)
-            except self.to_catch as e:
-                raise os_db_exception.RetryRequest(e)
-        return wrapper
-
-
 # Common database operation implementations
 def get_object(context, model, **kwargs):
     with context.session.begin(subtransactions=True):
index 48d5241d076bc0a233fd34aa21aa8799b96a6c20..904abe9c1a7369cb085235b580a9312424ee3ffd 100644 (file)
@@ -1419,10 +1419,11 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
 
         return self._bind_port_if_needed(port_context)
 
-    @oslo_db_api.wrap_db_retry(max_retries=db_api.MAX_RETRIES,
-                               retry_on_deadlock=True,
-                               retry_on_request=True)
-    @db_api.convert_db_exception_to_retry(stale_data=True)
+    @oslo_db_api.wrap_db_retry(
+        max_retries=db_api.MAX_RETRIES,
+        retry_on_deadlock=True, retry_on_request=True,
+        exception_checker=lambda e: isinstance(e, sa_exc.StaleDataError)
+    )
     def update_port_status(self, context, port_id, status, host=None,
                            network=None):
         """