]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Move retries out of ML2 plugin
authorKevin Benton <blak111@gmail.com>
Wed, 14 Oct 2015 05:33:53 +0000 (22:33 -0700)
committerKevin Benton <blak111@gmail.com>
Wed, 14 Oct 2015 07:46:22 +0000 (00:46 -0700)
There are several DB retry decorators in the ML2 plugin.
We want to keep them in the API layer as much possible so
this patch removes all but 1 and adds the retryrequest catch
to the API-level decorator.

The remaining one is the update_port_status which is an internal
RPC called method so it's not clear if there is a benefit to
moving it to the ml2 rpc file.

Change-Id: Ifffd424b693f57b5dd3de4dc625b50acc23abe0f
Closes-Bug: #1505908

neutron/db/api.py
neutron/plugins/ml2/plugin.py
neutron/tests/unit/plugins/ml2/test_plugin.py

index a77bcaec9ebe5869735029ace98e6f4c4cb06199..4818f02c51fad02cfc7fa1701cb89639e44cf19b 100644 (file)
@@ -32,6 +32,7 @@ MAX_RETRIES = 10
 is_deadlock = lambda e: isinstance(e, db_exc.DBDeadlock)
 retry_db_errors = oslo_db_api.wrap_db_retry(
     max_retries=MAX_RETRIES,
+    retry_on_request=True,
     exception_checker=is_deadlock
 )
 
index 277d6f85f59da37556eb7636dbb81f9cfb9fb725..ae8c3f181f830dbd1e714a53f1628a98b31316d0 100644 (file)
@@ -572,8 +572,6 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
                               {'res': resource,
                                'id': obj['result']['id']})
 
-    @oslo_db_api.wrap_db_retry(max_retries=db_api.MAX_RETRIES,
-                               retry_on_request=True)
     def _create_bulk_ml2(self, resource, context, request_items):
         objects = []
         collection = "%ss" % resource
@@ -637,14 +635,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
 
         return result, mech_context
 
-    @oslo_db_api.wrap_db_retry(max_retries=db_api.MAX_RETRIES,
-                               retry_on_request=True)
-    def _create_network_with_retries(self, context, network):
-        return self._create_network_db(context, network)
-
     def create_network(self, context, network):
-        result, mech_context = self._create_network_with_retries(context,
-                                                                 network)
+        result, mech_context = self._create_network_db(context, network)
         try:
             self.mechanism_manager.create_network_postcommit(mech_context)
         except ml2_exc.MechanismDriverError:
@@ -876,8 +868,6 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
         self.mechanism_manager.update_subnet_postcommit(mech_context)
         return updated_subnet
 
-    @oslo_db_api.wrap_db_retry(max_retries=db_api.MAX_RETRIES,
-                               retry_on_request=True)
     def delete_subnet(self, context, id):
         # REVISIT(rkukura) The super(Ml2Plugin, self).delete_subnet()
         # function is not used because it deallocates the subnet's addresses
@@ -1033,8 +1023,6 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
 
         return result, mech_context
 
-    @oslo_db_api.wrap_db_retry(max_retries=db_api.MAX_RETRIES,
-                               retry_on_request=True)
     def create_port(self, context, port):
         attrs = port[attributes.PORT]
         result, mech_context = self._create_port_db(context, port)
index 3ca117ae803fd3a4919bc9530de09833c506778b..b16b9d4073403a4e374c9f963876f06a1491cd99 100644 (file)
@@ -312,15 +312,13 @@ class TestMl2NetworksV2(test_plugin.TestNetworksV2,
 
     def test_create_network_segment_allocation_fails(self):
         plugin = manager.NeutronManager.get_plugin()
-        with mock.patch.object(plugin.type_manager, 'create_network_segments',
-            side_effect=db_exc.RetryRequest(ValueError())) as f:
-            self.assertRaises(ValueError,
-                              plugin.create_network,
-                              context.get_admin_context(),
-                              {'network': {'tenant_id': 'sometenant',
-                                           'name': 'dummy',
-                                           'admin_state_up': True,
-                                           'shared': False}})
+        with mock.patch.object(
+            plugin.type_manager, 'create_network_segments',
+            side_effect=db_exc.RetryRequest(ValueError())
+        ) as f:
+            data = {'network': {'tenant_id': 'sometenant', 'name': 'dummy',
+                                'admin_state_up': True, 'shared': False}}
+            self.new_create_request('networks', data).get_response(self.api)
             self.assertEqual(db_api.MAX_RETRIES + 1, f.call_count)