]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add oslo db retry decorator to non-CRUD actions
authorKevin Benton <blak111@gmail.com>
Thu, 16 Jul 2015 09:07:48 +0000 (02:07 -0700)
committerKevin Benton <blak111@gmail.com>
Thu, 16 Jul 2015 12:19:45 +0000 (05:19 -0700)
The previously added decorators to the create and update handlers
in the API layer only applied to actions that followed the standard
create/update path. However, for API operations like add_router_interface,
a different path is followed that wasn't covered by a retry decorator.

This patch adds the decorator to handle deadlocks in those operations as
well.

Closes-Bug: #1475218
Change-Id: Ib354074e6a3f68cedb95fd774f905d94ca16a830

neutron/api/v2/base.py
neutron/db/api.py

index 48dea6bf6d0e9e1dd5463ea266beea6ff175b6ac..edae5b1f1048532f1d886e99f1e06718e91a680f 100644 (file)
@@ -17,7 +17,6 @@ import copy
 
 import netaddr
 from oslo_config import cfg
-from oslo_db import api as oslo_db_api
 from oslo_log import log as logging
 from oslo_policy import policy as oslo_policy
 from oslo_utils import excutils
@@ -187,6 +186,7 @@ class Controller(object):
 
     def __getattr__(self, name):
         if name in self._member_actions:
+            @db_api.retry_db_errors
             def _handle_action(request, id, **kwargs):
                 arg_list = [request.context, id]
                 # Ensure policy engine is initialized
@@ -197,7 +197,7 @@ class Controller(object):
                 except oslo_policy.PolicyNotAuthorized:
                     msg = _('The resource could not be found.')
                     raise webob.exc.HTTPNotFound(msg)
-                body = kwargs.pop('body', None)
+                body = copy.deepcopy(kwargs.pop('body', None))
                 # Explicit comparison with None to distinguish from {}
                 if body is not None:
                     arg_list.append(body)
@@ -383,8 +383,7 @@ class Controller(object):
                 # We need a way for ensuring that if it has been created,
                 # it is then deleted
 
-    @oslo_db_api.wrap_db_retry(max_retries=db_api.MAX_RETRIES,
-                               retry_on_deadlock=True)
+    @db_api.retry_db_errors
     def create(self, request, body=None, **kwargs):
         """Creates a new instance of the requested entity."""
         parent_id = kwargs.get(self._parent_id_name)
@@ -470,8 +469,7 @@ class Controller(object):
                 return notify({self._resource: self._view(request.context,
                                                           obj)})
 
-    @oslo_db_api.wrap_db_retry(max_retries=db_api.MAX_RETRIES,
-                               retry_on_deadlock=True)
+    @db_api.retry_db_errors
     def delete(self, request, id, **kwargs):
         """Deletes the specified entity."""
         self._notifier.info(request.context,
@@ -506,8 +504,7 @@ class Controller(object):
                                      result,
                                      notifier_method)
 
-    @oslo_db_api.wrap_db_retry(max_retries=db_api.MAX_RETRIES,
-                               retry_on_deadlock=True)
+    @db_api.retry_db_errors
     def update(self, request, id, body=None, **kwargs):
         """Updates the specified entity's attributes."""
         parent_id = kwargs.get(self._parent_id_name)
index 0b68bd3310ad508d9e4983e5ddc3fadae0d5acc4..dec09bd35722341db3792102b9109c38261138c5 100644 (file)
@@ -17,6 +17,7 @@ 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 sqlalchemy import exc
@@ -26,6 +27,8 @@ from sqlalchemy import orm
 _FACADE = None
 
 MAX_RETRIES = 10
+retry_db_errors = oslo_db_api.wrap_db_retry(max_retries=MAX_RETRIES,
+                                            retry_on_deadlock=True)
 
 
 def _create_facade_lazily():