From 9849209bbdc0ec110ac43b871f6f1140f95def17 Mon Sep 17 00:00:00 2001 From: Boden R Date: Tue, 18 Sep 2018 15:28:18 -0600 Subject: [PATCH] use is_retriable from neutron-lib The db api is_retriable function is now available in neutron-lib. This patch consumes it by removing is_retriable and related internal functions and using neutron-lib's version where applicable. NeutronLibImpact Change-Id: Ie33a4eb4d1e52b2d985c9498edea2efb63ef569c --- neutron/db/api.py | 45 --------------------------------- neutron/plugins/ml2/managers.py | 23 +++++++++-------- 2 files changed, 12 insertions(+), 56 deletions(-) diff --git a/neutron/db/api.py b/neutron/db/api.py index 08d6c6149eb..27c01f44af2 100644 --- a/neutron/db/api.py +++ b/neutron/db/api.py @@ -18,12 +18,8 @@ import weakref from neutron_lib.db import api from neutron_lib.db import model_base -from neutron_lib import exceptions -from neutron_lib.objects import exceptions as obj_exc from oslo_config import cfg -from oslo_db import exception as db_exc from oslo_log import log as logging -from oslo_utils import excutils from osprofiler import opts as profiler_opts import osprofiler.sqlalchemy from pecan import util as p_util @@ -31,7 +27,6 @@ import six import sqlalchemy from sqlalchemy import event # noqa from sqlalchemy import orm -from sqlalchemy.orm import exc def set_hook(engine): @@ -54,35 +49,6 @@ MAX_RETRIES = 10 LOG = logging.getLogger(__name__) -def is_retriable(e): - if getattr(e, '_RETRY_EXCEEDED', False): - return False - if _is_nested_instance(e, (db_exc.DBDeadlock, exc.StaleDataError, - db_exc.DBConnectionError, - db_exc.DBDuplicateEntry, db_exc.RetryRequest, - obj_exc.NeutronDbObjectDuplicateEntry)): - return True - # looking savepoints mangled by deadlocks. see bug/1590298 for details. - return _is_nested_instance(e, db_exc.DBError) and '1305' in str(e) - - -def _tag_retriables_as_unretriable(f): - """Puts a flag on retriable exceptions so is_retriable returns False. - - This decorator can be used outside of a retry decorator to prevent - decorators higher up from retrying again. - """ - @six.wraps(f) - def wrapped(*args, **kwargs): - try: - return f(*args, **kwargs) - except Exception as e: - with excutils.save_and_reraise_exception(): - if is_retriable(e): - setattr(e, '_RETRY_EXCEEDED', True) - return wrapped - - def _copy_if_lds(item): """Deepcopy lists/dicts/sets, leave everything else alone.""" return copy.deepcopy(item) if isinstance(item, (list, dict, set)) else item @@ -124,17 +90,6 @@ def retry_if_session_inactive(context_var_name='context'): return decorator -def _is_nested_instance(e, etypes): - """Check if exception or its inner excepts are an instance of etypes.""" - if isinstance(e, etypes): - return True - if isinstance(e, exceptions.MultipleExceptions): - return any(_is_nested_instance(i, etypes) for i in e.inner_exceptions) - if isinstance(e, db_exc.DBError): - return _is_nested_instance(e.inner_exception, etypes) - return False - - @event.listens_for(orm.session.Session, "after_flush") def add_to_rel_load_list(session, flush_context=None): # keep track of new items to load relationships on during commit diff --git a/neutron/plugins/ml2/managers.py b/neutron/plugins/ml2/managers.py index 954a19942fd..6c803519e2d 100644 --- a/neutron/plugins/ml2/managers.py +++ b/neutron/plugins/ml2/managers.py @@ -19,6 +19,7 @@ from neutron_lib.api.definitions import portbindings from neutron_lib.api.definitions import provider_net as provider from neutron_lib.api import validators from neutron_lib import constants +from neutron_lib.db import api as lib_db_api from neutron_lib import exceptions as exc from neutron_lib.exceptions import multiprovidernet as mpnet_exc from neutron_lib.exceptions import vlantransparent as vlan_exc @@ -420,7 +421,7 @@ class MechanismManager(stevedore.named.NamedExtensionManager): that upper layer can handle it or error in ML2 player :raises: neutron.plugins.ml2.common.MechanismDriverError if any mechanism driver call fails. or DB retriable error when - raise_db_retriable=False. See neutron.db.api.is_retriable for + raise_db_retriable=False. See neutron_lib.db.api.is_retriable for what db exception is retriable """ errors = [] @@ -428,7 +429,7 @@ class MechanismManager(stevedore.named.NamedExtensionManager): try: getattr(driver.obj, method_name)(context) except Exception as e: - if raise_db_retriable and db_api.is_retriable(e): + if raise_db_retriable and lib_db_api.is_retriable(e): with excutils.save_and_reraise_exception(): LOG.debug("DB exception raised by Mechanism driver " "'%(name)s' in %(method)s", @@ -451,7 +452,7 @@ class MechanismManager(stevedore.named.NamedExtensionManager): """Notify all mechanism drivers during network creation. :raises: DB retriable error if create_network_precommit raises them - See neutron.db.api.is_retriable for what db exception is retriable + See neutron_lib.db.api.is_retriable for what db exception is retriable or neutron.plugins.ml2.common.MechanismDriverError if any mechanism driver create_network_precommit call fails. @@ -482,7 +483,7 @@ class MechanismManager(stevedore.named.NamedExtensionManager): """Notify all mechanism drivers during network update. :raises: DB retriable error if create_network_precommit raises them - See neutron.db.api.is_retriable for what db exception is retriable + See neutron_lib.db.api.is_retriable for what db exception is retriable or neutron.plugins.ml2.common.MechanismDriverError if any mechanism driver update_network_precommit call fails. @@ -512,7 +513,7 @@ class MechanismManager(stevedore.named.NamedExtensionManager): """Notify all mechanism drivers during network deletion. :raises: DB retriable error if create_network_precommit raises them - See neutron.db.api.is_retriable for what db exception is retriable + See neutron_lib.db.api.is_retriable for what db exception is retriable or neutron.plugins.ml2.common.MechanismDriverError if any mechanism driver delete_network_precommit call fails. @@ -546,7 +547,7 @@ class MechanismManager(stevedore.named.NamedExtensionManager): """Notify all mechanism drivers during subnet creation. :raises: DB retriable error if create_network_precommit raises them - See neutron.db.api.is_retriable for what db exception is retriable + See neutron_lib.db.api.is_retriable for what db exception is retriable or neutron.plugins.ml2.common.MechanismDriverError if any mechanism driver create_subnet_precommit call fails. @@ -576,7 +577,7 @@ class MechanismManager(stevedore.named.NamedExtensionManager): """Notify all mechanism drivers during subnet update. :raises: DB retriable error if create_network_precommit raises them - See neutron.db.api.is_retriable for what db exception is retriable + See neutron_lib.db.api.is_retriable for what db exception is retriable or neutron.plugins.ml2.common.MechanismDriverError if any mechanism driver update_subnet_precommit call fails. @@ -606,7 +607,7 @@ class MechanismManager(stevedore.named.NamedExtensionManager): """Notify all mechanism drivers during subnet deletion. :raises: DB retriable error if create_network_precommit raises them - See neutron.db.api.is_retriable for what db exception is retriable + See neutron_lib.db.api.is_retriable for what db exception is retriable or neutron.plugins.ml2.common.MechanismDriverError if any mechanism driver delete_subnet_precommit call fails. @@ -640,7 +641,7 @@ class MechanismManager(stevedore.named.NamedExtensionManager): """Notify all mechanism drivers during port creation. :raises: DB retriable error if create_network_precommit raises them - See neutron.db.api.is_retriable for what db exception is retriable + See neutron_lib.db.api.is_retriable for what db exception is retriable or neutron.plugins.ml2.common.MechanismDriverError if any mechanism driver create_port_precommit call fails. @@ -670,7 +671,7 @@ class MechanismManager(stevedore.named.NamedExtensionManager): """Notify all mechanism drivers during port update. :raises: DB retriable error if create_network_precommit raises them - See neutron.db.api.is_retriable for what db exception is retriable + See neutron_lib.db.api.is_retriable for what db exception is retriable or neutron.plugins.ml2.common.MechanismDriverError if any mechanism driver update_port_precommit call fails. @@ -700,7 +701,7 @@ class MechanismManager(stevedore.named.NamedExtensionManager): """Notify all mechanism drivers during port deletion. :raises:DB retriable error if create_network_precommit raises them - See neutron.db.api.is_retriable for what db exception is retriable + See neutron_lib.db.api.is_retriable for what db exception is retriable or neutron.plugins.ml2.common.MechanismDriverError if any mechanism driver delete_port_precommit call fails.