From f6df2e704ba0c39e8a5ee59cb5fa1bd337deae82 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Tue, 13 Oct 2015 22:33:53 -0700 Subject: [PATCH] Move retries out of ML2 plugin 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 | 1 + neutron/plugins/ml2/plugin.py | 14 +------------- neutron/tests/unit/plugins/ml2/test_plugin.py | 16 +++++++--------- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/neutron/db/api.py b/neutron/db/api.py index a77bcaec9..4818f02c5 100644 --- a/neutron/db/api.py +++ b/neutron/db/api.py @@ -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 ) diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 277d6f85f..ae8c3f181 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -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) diff --git a/neutron/tests/unit/plugins/ml2/test_plugin.py b/neutron/tests/unit/plugins/ml2/test_plugin.py index 3ca117ae8..b16b9d407 100644 --- a/neutron/tests/unit/plugins/ml2/test_plugin.py +++ b/neutron/tests/unit/plugins/ml2/test_plugin.py @@ -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) -- 2.45.2