diff --git a/neutron/db/api.py b/neutron/db/api.py index ce5afcb711a..c05820e58ed 100644 --- a/neutron/db/api.py +++ b/neutron/db/api.py @@ -175,17 +175,6 @@ def _is_nested_instance(e, etypes): return False -@contextlib.contextmanager -def exc_to_retry(etypes): - try: - yield - except Exception as e: - with excutils.save_and_reraise_exception() as ctx: - if _is_nested_instance(e, etypes): - ctx.reraise = False - raise db_exc.RetryRequest(e) - - def get_reader_session(): """Helper to get reader session""" return context_manager.reader.get_sessionmaker()() diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index db9242e54c1..efce6b1dfe5 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -26,6 +26,7 @@ from neutron_lib.callbacks import registry from neutron_lib.callbacks import resources from neutron_lib import constants from neutron_lib import context as ctx +from neutron_lib.db import api as lib_db_api from neutron_lib import exceptions as exc from neutron_lib.exceptions import l3 as l3_exc from neutron_lib.plugins import constants as plugin_constants @@ -471,7 +472,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, "The port has already been deleted.", port_id) # clean up subnets subnets = self._get_subnets_by_network(context, id) - with db_api.exc_to_retry(os_db_exc.DBReferenceError): + with lib_db_api.exc_to_retry(os_db_exc.DBReferenceError): # retry reference errors so we can check the port type and # cleanup if a network-owned port snuck in without failing for subnet in subnets: @@ -1032,7 +1033,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, self._delete_subnet(context, subnet) def _delete_subnet(self, context, subnet): - with db_api.exc_to_retry(sql_exc.IntegrityError), \ + with lib_db_api.exc_to_retry(sql_exc.IntegrityError), \ db_api.context_manager.writer.using(context): registry.notify(resources.SUBNET, events.PRECOMMIT_DELETE, self, context=context, subnet_id=subnet.id) diff --git a/neutron/tests/unit/db/test_api.py b/neutron/tests/unit/db/test_api.py index 3b9b113a619..ce55ab88e9f 100644 --- a/neutron/tests/unit/db/test_api.py +++ b/neutron/tests/unit/db/test_api.py @@ -24,43 +24,6 @@ from neutron.db import api as db_api from neutron.tests import base -class TestExceptionToRetryContextManager(base.BaseTestCase): - - def test_translates_single_exception(self): - with testtools.ExpectedException(db_exc.RetryRequest): - with db_api.exc_to_retry(ValueError): - raise ValueError() - - def test_translates_multiple_exception_types(self): - with testtools.ExpectedException(db_exc.RetryRequest): - with db_api.exc_to_retry((ValueError, TypeError)): - raise TypeError() - - def test_translates_DBerror_inner_exception(self): - with testtools.ExpectedException(db_exc.RetryRequest): - with db_api.exc_to_retry(ValueError): - raise db_exc.DBError(ValueError()) - - def test_passes_other_exceptions(self): - with testtools.ExpectedException(ValueError): - with db_api.exc_to_retry(TypeError): - raise ValueError() - - def test_inner_exception_preserved_in_retryrequest(self): - try: - exc = ValueError('test') - with db_api.exc_to_retry(ValueError): - raise exc - except db_exc.RetryRequest as e: - self.assertEqual(exc, e.inner_exc) - - def test_retries_on_multi_exception_containing_target(self): - with testtools.ExpectedException(db_exc.RetryRequest): - with db_api.exc_to_retry(ValueError): - e = exceptions.MultipleExceptions([ValueError(), TypeError()]) - raise e - - class TestDeadLockDecorator(base.BaseTestCase): @db_api.retry_db_errors