Merge "use retry_if_session_inactive from neutron-lib"
This commit is contained in:
commit
5f36615700
@ -25,7 +25,7 @@ from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import context
|
||||
from neutron_lib.db import api as lib_db_api
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.db import utils as db_utils
|
||||
from neutron_lib.exceptions import agent as agent_exc
|
||||
from neutron_lib.exceptions import availability_zone as az_exc
|
||||
@ -43,7 +43,6 @@ from neutron.api.rpc.callbacks import version_manager
|
||||
from neutron.common import constants as n_const
|
||||
from neutron.conf.agent.database import agents_db
|
||||
from neutron.db import _model_query as model_query
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db.models import agent as agent_model
|
||||
from neutron.extensions import _availability_zone_filter_lib as azfil_ext
|
||||
from neutron.extensions import agent as ext_agent
|
||||
@ -305,7 +304,7 @@ class AgentDbMixin(ext_agent.AgentPluginBase, AgentAvailabilityZoneMixin):
|
||||
return [self._make_agent_dict(agent, fields=fields)
|
||||
for agent in agents]
|
||||
|
||||
@lib_db_api.retry_db_errors
|
||||
@db_api.retry_db_errors
|
||||
def agent_health_check(self):
|
||||
"""Scan agents and log if some are considered dead."""
|
||||
agents = self.get_agents(context.get_admin_context(),
|
||||
|
@ -22,8 +22,6 @@ from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from osprofiler import opts as profiler_opts
|
||||
import osprofiler.sqlalchemy
|
||||
from pecan import util as p_util
|
||||
import six
|
||||
import sqlalchemy
|
||||
from sqlalchemy import event # noqa
|
||||
from sqlalchemy import orm
|
||||
@ -54,42 +52,6 @@ def _copy_if_lds(item):
|
||||
return copy.deepcopy(item) if isinstance(item, (list, dict, set)) else item
|
||||
|
||||
|
||||
def retry_if_session_inactive(context_var_name='context'):
|
||||
"""Retries only if the session in the context is inactive.
|
||||
|
||||
Calls a retry_db_errors wrapped version of the function if the context's
|
||||
session passed in is inactive, otherwise it just calls the function
|
||||
directly. This is useful to avoid retrying things inside of a transaction
|
||||
which is ineffective for DB races/errors.
|
||||
|
||||
This should be used in all cases where retries are desired and the method
|
||||
accepts a context.
|
||||
"""
|
||||
def decorator(f):
|
||||
try:
|
||||
# NOTE(kevinbenton): we use pecan's util function here because it
|
||||
# deals with the horrors of finding args of already decorated
|
||||
# functions
|
||||
ctx_arg_index = p_util.getargspec(f).args.index(context_var_name)
|
||||
except ValueError:
|
||||
raise RuntimeError("Could not find position of var %s" %
|
||||
context_var_name)
|
||||
f_with_retry = api.retry_db_errors(f)
|
||||
|
||||
@six.wraps(f)
|
||||
def wrapped(*args, **kwargs):
|
||||
# only use retry wrapper if we aren't nested in an active
|
||||
# transaction
|
||||
if context_var_name in kwargs:
|
||||
context = kwargs[context_var_name]
|
||||
else:
|
||||
context = args[ctx_arg_index]
|
||||
method = f if context.session.is_active else f_with_retry
|
||||
return method(*args, **kwargs)
|
||||
return wrapped
|
||||
return decorator
|
||||
|
||||
|
||||
@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
|
||||
|
@ -177,7 +177,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
@registry.receives(resources.RBAC_POLICY, [events.BEFORE_CREATE,
|
||||
events.BEFORE_UPDATE,
|
||||
events.BEFORE_DELETE])
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def validate_network_rbac_policy_change(self, resource, event, trigger,
|
||||
context, object_type, policy,
|
||||
**kwargs):
|
||||
@ -380,11 +380,11 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
{'resource': resource, 'item': item})
|
||||
return objects
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_network_bulk(self, context, networks):
|
||||
return self._create_bulk('network', context, networks)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_network(self, context, network):
|
||||
"""Handle creation of a single network."""
|
||||
net_db = self.create_network_db(context, network)
|
||||
@ -411,7 +411,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
context.session.add(network)
|
||||
return network
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def update_network(self, context, id, network):
|
||||
n = network['network']
|
||||
with db_api.context_manager.writer.using(context):
|
||||
@ -459,7 +459,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
if non_auto_ports.count():
|
||||
raise exc.NetworkInUse(net_id=net_id)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def delete_network(self, context, id):
|
||||
registry.notify(resources.NETWORK, events.BEFORE_DELETE, self,
|
||||
context=context, network_id=id)
|
||||
@ -496,12 +496,12 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
registry.notify(resources.NETWORK, events.AFTER_DELETE,
|
||||
self, context=context, network=network)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_network(self, context, id, fields=None):
|
||||
network = self._get_network(context, id)
|
||||
return self._make_network_dict(network, fields, context=context)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def _get_networks(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
@ -517,7 +517,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
marker_obj=marker_obj,
|
||||
page_reverse=page_reverse)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_networks(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
@ -530,12 +530,12 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
limit=limit, marker=marker, page_reverse=page_reverse)
|
||||
]
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_networks_count(self, context, filters=None):
|
||||
return model_query.get_collection_count(context, models_v2.Network,
|
||||
filters=filters)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_subnet_bulk(self, context, subnets):
|
||||
return self._create_bulk('subnet', context, subnets)
|
||||
|
||||
@ -716,7 +716,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
external_gateway_info}}
|
||||
l3plugin.update_router(context, router_id, info)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def _create_subnet_postcommit(self, context, result, network, ipam_subnet):
|
||||
if hasattr(network, 'external') and network.external:
|
||||
self._update_router_gw_ports(context,
|
||||
@ -779,7 +779,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
msg = _('No default subnetpool found for IPv%s') % ip_version
|
||||
raise exc.BadRequest(resource='subnets', msg=msg)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_subnet(self, context, subnet):
|
||||
result, net, ipam_sub = self._create_subnet_precommit(context, subnet)
|
||||
self._create_subnet_postcommit(context, result, net, ipam_sub)
|
||||
@ -848,7 +848,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
'end': str(netaddr.IPAddress(p.last, subnet['ip_version']))}
|
||||
for p in allocation_pools]
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def update_subnet(self, context, id, subnet):
|
||||
"""Update the subnet with new info.
|
||||
|
||||
@ -989,7 +989,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
"cannot delete", subnet_id)
|
||||
raise exc.SubnetInUse(subnet_id=subnet_id)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def _remove_subnet_from_port(self, context, sub_id, port_id, auto_subnet):
|
||||
try:
|
||||
fixed = [f for f in self.get_port(context, port_id)['fixed_ips']
|
||||
@ -1017,7 +1017,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
'subnet': id})
|
||||
raise exc.SubnetInUse(subnet_id=id)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def _remove_subnet_ip_allocations_from_ports(self, context, id):
|
||||
# Do not allow a subnet to be deleted if a router is attached to it
|
||||
self._subnet_check_ip_allocations_internal_router_ports(
|
||||
@ -1035,7 +1035,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
self._remove_subnet_from_port(context, id, port_id,
|
||||
auto_subnet=is_auto_addr_subnet)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def delete_subnet(self, context, id):
|
||||
LOG.debug("Deleting subnet %s", id)
|
||||
# Make sure the subnet isn't used by other resources
|
||||
@ -1056,12 +1056,12 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
registry.notify(resources.SUBNET, events.AFTER_DELETE,
|
||||
self, context=context, subnet=subnet.to_dict())
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_subnet(self, context, id, fields=None):
|
||||
subnet_obj = self._get_subnet_object(context, id)
|
||||
return self._make_subnet_dict(subnet_obj, fields, context=context)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_subnets(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
@ -1072,13 +1072,13 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
for subnet_object in subnet_objs
|
||||
]
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_subnets_count(self, context, filters=None):
|
||||
filters = filters or {}
|
||||
return subnet_obj.Subnet.count(context, validate_filters=False,
|
||||
**filters)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_subnets_by_network(self, context, network_id):
|
||||
return [self._make_subnet_dict(subnet_obj) for subnet_obj in
|
||||
self._get_subnets_by_network(context, network_id)]
|
||||
@ -1152,7 +1152,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
"been set. Only one default may exist per IP family")
|
||||
raise exc.InvalidInput(error_message=msg)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_subnetpool(self, context, subnetpool):
|
||||
sp = subnetpool['subnetpool']
|
||||
sp_reader = subnet_alloc.SubnetPoolReader(sp)
|
||||
@ -1181,7 +1181,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
|
||||
return self._make_subnetpool_dict(subnetpool.db_obj)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def update_subnetpool(self, context, id, subnetpool):
|
||||
new_sp = subnetpool['subnetpool']
|
||||
|
||||
@ -1219,12 +1219,12 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
updated, orig_sp.db_obj)
|
||||
return updated
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_subnetpool(self, context, id, fields=None):
|
||||
subnetpool = self._get_subnetpool(context, id)
|
||||
return self._make_subnetpool_dict(subnetpool.db_obj, fields)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_subnetpools(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
@ -1237,7 +1237,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
for pool in subnetpools
|
||||
]
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_default_subnetpool(self, context, ip_version):
|
||||
"""Retrieve the default subnetpool for the given IP version."""
|
||||
filters = {'is_default': True,
|
||||
@ -1246,7 +1246,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
if subnetpool:
|
||||
return subnetpool[0]
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def delete_subnetpool(self, context, id):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
subnetpool = self._get_subnetpool(context, id=id)
|
||||
@ -1263,7 +1263,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
op=_("mac address update"), port_id=id,
|
||||
device_owner=device_owner)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_port_bulk(self, context, ports):
|
||||
return self._create_bulk('port', context, ports)
|
||||
|
||||
@ -1280,7 +1280,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
context.session.add(db_port)
|
||||
return db_port
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_port(self, context, port):
|
||||
db_port = self.create_port_db(context, port)
|
||||
return self._make_port_dict(db_port, process_extensions=False)
|
||||
@ -1344,7 +1344,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
self._check_mac_addr_update(context, db_port,
|
||||
new_mac, current_owner)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def update_port(self, context, id, port):
|
||||
new_port = port['port']
|
||||
|
||||
@ -1379,7 +1379,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
raise os_db_exc.RetryRequest(e)
|
||||
return self._make_port_dict(db_port)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def delete_port(self, context, id):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
self.ipam.delete_port(context, id)
|
||||
@ -1401,7 +1401,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
"The port has already been deleted.",
|
||||
port_id)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
@db_api.context_manager.reader
|
||||
def get_port(self, context, id, fields=None):
|
||||
port = self._get_port(context, id)
|
||||
@ -1426,7 +1426,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
Port.fixed_ips.any(IPAllocation.subnet_id.in_(subnet_ids)))
|
||||
return query
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_ports(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
@ -1441,7 +1441,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
items.reverse()
|
||||
return items
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_ports_count(self, context, filters=None):
|
||||
return self._get_ports_query(context, filters).count()
|
||||
|
||||
|
@ -20,6 +20,7 @@ from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.db import api as lib_db_api
|
||||
from neutron_lib import exceptions as n_exc
|
||||
from neutron_lib.exceptions import dvr as dvr_exc
|
||||
from neutron_lib.objects import exceptions
|
||||
@ -59,7 +60,7 @@ class DVRDbMixin(ext_dvr.DVRMacAddressPluginBase):
|
||||
return self._plugin
|
||||
|
||||
@staticmethod
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def _db_delete_mac_associated_with_agent(context, agent):
|
||||
host = agent['host']
|
||||
plugin = directory.get_plugin()
|
||||
@ -92,7 +93,7 @@ class DVRDbMixin(ext_dvr.DVRMacAddressPluginBase):
|
||||
return self._make_dvr_mac_address_dict(dvr_obj)
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def _create_dvr_mac_address_retry(self, context, host, base_mac):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
mac_address = net.get_random_mac(base_mac)
|
||||
@ -141,7 +142,7 @@ class DVRDbMixin(ext_dvr.DVRMacAddressPluginBase):
|
||||
'mac_address': str(dvr_mac_entry['mac_address'])}
|
||||
|
||||
@log_helpers.log_method_call
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_ports_on_host_by_subnet(self, context, host, subnet):
|
||||
"""Returns DVR serviced ports on a given subnet in the input host
|
||||
|
||||
@ -171,7 +172,7 @@ class DVRDbMixin(ext_dvr.DVRMacAddressPluginBase):
|
||||
return ports
|
||||
|
||||
@log_helpers.log_method_call
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_subnet_for_dvr(self, context, subnet, fixed_ips=None):
|
||||
if fixed_ips:
|
||||
subnet_data = fixed_ips[0]['subnet_id']
|
||||
|
@ -26,7 +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 n_ctx
|
||||
from neutron_lib.db import api as lib_db_api
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.db import utils as lib_db_utils
|
||||
from neutron_lib import exceptions as n_exc
|
||||
from neutron_lib.exceptions import l3 as l3_exc
|
||||
@ -47,7 +47,6 @@ from neutron.common import utils
|
||||
from neutron.db import _model_query as model_query
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import _utils as db_utils
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db.models import l3 as l3_models
|
||||
from neutron.db import models_v2
|
||||
from neutron.db import standardattrdescription_db as st_attr
|
||||
@ -718,7 +717,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
|
||||
raise n_exc.BadRequest(resource='router', msg=msg)
|
||||
|
||||
def _validate_router_port_info(self, context, router, port_id):
|
||||
with lib_db_api.autonested_transaction(context.session):
|
||||
with db_api.autonested_transaction(context.session):
|
||||
# check again within transaction to mitigate race
|
||||
port = self._check_router_port(context, port_id, router.id)
|
||||
|
||||
|
@ -23,7 +23,7 @@ from neutron_lib.callbacks import priority_group
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import constants as const
|
||||
from neutron_lib.db import api as lib_db_api
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib import exceptions as n_exc
|
||||
from neutron_lib.exceptions import agent as agent_exc
|
||||
from neutron_lib.exceptions import l3 as l3_exc
|
||||
@ -40,7 +40,6 @@ from neutron._i18n import _
|
||||
from neutron.common import constants as l3_const
|
||||
from neutron.common import utils as n_utils
|
||||
from neutron.conf.db import l3_dvr_db
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import l3_attrs_db
|
||||
from neutron.db import l3_db
|
||||
from neutron.db.models import allowed_address_pair as aap_models
|
||||
@ -452,7 +451,7 @@ class DVRResourceOperationHandler(object):
|
||||
# with the csnat port.
|
||||
# TODO(kevinbenton): switch to taskflow to manage
|
||||
# these rollbacks.
|
||||
@lib_db_api.retry_db_errors
|
||||
@db_api.retry_db_errors
|
||||
def revert():
|
||||
# TODO(kevinbenton): even though we get the
|
||||
# port each time, there is a potential race
|
||||
|
@ -28,6 +28,7 @@ from neutron_lib.callbacks import priority_group
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib import exceptions as n_exc
|
||||
from neutron_lib.exceptions import l3 as l3_exc
|
||||
from neutron_lib.exceptions import l3_ext_ha_mode as l3ha_exc
|
||||
@ -48,7 +49,6 @@ from neutron.common import constants as n_const
|
||||
from neutron.common import utils as n_utils
|
||||
from neutron.conf.db import l3_hamode_db
|
||||
from neutron.db import _utils as db_utils
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db.availability_zone import router as router_az_db
|
||||
from neutron.db import l3_dvr_db
|
||||
from neutron.db.models import l3ha as l3ha_model
|
||||
|
@ -15,9 +15,9 @@
|
||||
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib.db import api as db_api
|
||||
from oslo_log import log as logging
|
||||
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import models_v2
|
||||
from neutron.objects import provisioning_blocks as pb_obj
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
import collections
|
||||
import datetime
|
||||
|
||||
from neutron_lib.db import api as lib_db_api
|
||||
|
||||
from neutron.db import api as db_api
|
||||
from neutron.objects import quota as quota_obj
|
||||
|
||||
@ -35,7 +37,7 @@ class ReservationInfo(collections.namedtuple(
|
||||
"""Information about a resource reservation."""
|
||||
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_quota_usage_by_resource_and_tenant(context, resource, tenant_id):
|
||||
"""Return usage info for a given resource and tenant.
|
||||
|
||||
@ -53,7 +55,7 @@ def get_quota_usage_by_resource_and_tenant(context, resource, tenant_id):
|
||||
result.dirty)
|
||||
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_quota_usage_by_resource(context, resource):
|
||||
objs = quota_obj.QuotaUsage.get_objects(context, resource=resource)
|
||||
return [QuotaUsageInfo(item.resource,
|
||||
@ -62,7 +64,7 @@ def get_quota_usage_by_resource(context, resource):
|
||||
item.dirty) for item in objs]
|
||||
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_quota_usage_by_tenant_id(context, tenant_id):
|
||||
objs = quota_obj.QuotaUsage.get_objects(context, project_id=tenant_id)
|
||||
return [QuotaUsageInfo(item.resource,
|
||||
@ -71,7 +73,7 @@ def get_quota_usage_by_tenant_id(context, tenant_id):
|
||||
item.dirty) for item in objs]
|
||||
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def set_quota_usage(context, resource, tenant_id,
|
||||
in_use=None, delta=False):
|
||||
"""Set resource quota usage.
|
||||
@ -105,7 +107,7 @@ def set_quota_usage(context, resource, tenant_id,
|
||||
usage_data.in_use, usage_data.dirty)
|
||||
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
@db_api.context_manager.writer
|
||||
def set_quota_usage_dirty(context, resource, tenant_id, dirty=True):
|
||||
"""Set quota usage dirty bit for a given resource and tenant.
|
||||
@ -124,7 +126,7 @@ def set_quota_usage_dirty(context, resource, tenant_id, dirty=True):
|
||||
return 0
|
||||
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
@db_api.context_manager.writer
|
||||
def set_resources_quota_usage_dirty(context, resources, tenant_id, dirty=True):
|
||||
"""Set quota usage dirty bit for a given tenant and multiple resources.
|
||||
@ -145,7 +147,7 @@ def set_resources_quota_usage_dirty(context, resources, tenant_id, dirty=True):
|
||||
return len(objs)
|
||||
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
@db_api.context_manager.writer
|
||||
def set_all_quota_usage_dirty(context, resource, dirty=True):
|
||||
"""Set the dirty bit on quota usage for all tenants.
|
||||
@ -163,7 +165,7 @@ def set_all_quota_usage_dirty(context, resource, dirty=True):
|
||||
return len(objs)
|
||||
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_reservation(context, tenant_id, deltas, expiration=None):
|
||||
# This method is usually called from within another transaction.
|
||||
# Consider using begin_nested
|
||||
@ -183,7 +185,7 @@ def create_reservation(context, tenant_id, deltas, expiration=None):
|
||||
for delta in reserv_obj.resource_deltas))
|
||||
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_reservation(context, reservation_id):
|
||||
reserv_obj = quota_obj.Reservation.get_object(context, id=reservation_id)
|
||||
if not reserv_obj:
|
||||
@ -195,7 +197,7 @@ def get_reservation(context, reservation_id):
|
||||
for delta in reserv_obj.resource_deltas))
|
||||
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
@db_api.context_manager.writer
|
||||
def remove_reservation(context, reservation_id, set_dirty=False):
|
||||
reservation = quota_obj.Reservation.get_object(context, id=reservation_id)
|
||||
@ -212,7 +214,7 @@ def remove_reservation(context, reservation_id, set_dirty=False):
|
||||
return 1
|
||||
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_reservations_for_resources(context, tenant_id, resources,
|
||||
expired=False):
|
||||
"""Retrieve total amount of reservations for specified resources.
|
||||
@ -231,7 +233,7 @@ def get_reservations_for_resources(context, tenant_id, resources,
|
||||
context, utcnow(), tenant_id, resources, expired)
|
||||
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
@db_api.context_manager.writer
|
||||
def remove_expired_reservations(context, tenant_id=None):
|
||||
return quota_obj.Reservation.delete_expired(context, utcnow(), tenant_id)
|
||||
|
@ -14,6 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api import attributes
|
||||
from neutron_lib.db import api as lib_db_api
|
||||
from neutron_lib import exceptions
|
||||
from neutron_lib.plugins import constants
|
||||
from neutron_lib.plugins import directory
|
||||
@ -52,7 +53,7 @@ class DbQuotaDriver(object):
|
||||
for key, resource in resources.items())
|
||||
|
||||
@staticmethod
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_tenant_quotas(context, resources, tenant_id):
|
||||
"""Given a list of resources, retrieve the quotas for the given
|
||||
tenant. If no limits are found for the specified tenant, the operation
|
||||
@ -76,7 +77,7 @@ class DbQuotaDriver(object):
|
||||
return tenant_quota
|
||||
|
||||
@staticmethod
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_detailed_tenant_quotas(context, resources, tenant_id):
|
||||
"""Given a list of resources and a sepecific tenant, retrieve
|
||||
the detailed quotas (limit, used, reserved).
|
||||
@ -111,7 +112,7 @@ class DbQuotaDriver(object):
|
||||
return tenant_quota_ext
|
||||
|
||||
@staticmethod
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def delete_tenant_quota(context, tenant_id):
|
||||
"""Delete the quota entries for a given tenant_id.
|
||||
|
||||
@ -125,7 +126,7 @@ class DbQuotaDriver(object):
|
||||
raise n_exc.TenantQuotaNotFound(tenant_id=tenant_id)
|
||||
|
||||
@staticmethod
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_all_quotas(context, resources):
|
||||
"""Given a list of resources, retrieve the quotas for the all tenants.
|
||||
|
||||
@ -158,7 +159,7 @@ class DbQuotaDriver(object):
|
||||
return list(all_tenant_quotas.values())
|
||||
|
||||
@staticmethod
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def update_quota_limit(context, tenant_id, resource, limit):
|
||||
tenant_quotas = quota_obj.Quota.get_objects(
|
||||
context, project_id=tenant_id, resource=resource)
|
||||
@ -193,7 +194,7 @@ class DbQuotaDriver(object):
|
||||
quota_api.remove_expired_reservations(
|
||||
context, tenant_id=tenant_id)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def make_reservation(self, context, tenant_id, resources, deltas, plugin):
|
||||
# Lock current reservation table
|
||||
# NOTE(salv-orlando): This routine uses DB write locks.
|
||||
|
@ -17,13 +17,13 @@ from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import exceptions as c_exc
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.db import utils as db_utils
|
||||
from neutron_lib import exceptions as n_exc
|
||||
from oslo_db import exception as db_exc
|
||||
from sqlalchemy.orm import exc
|
||||
|
||||
from neutron.db import _model_query as model_query
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import common_db_mixin
|
||||
from neutron.db import rbac_db_models as models
|
||||
from neutron.extensions import rbac as ext_rbac
|
||||
|
@ -20,6 +20,7 @@ from neutron_lib.callbacks import exceptions
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.db import api as lib_db_api
|
||||
from neutron_lib.db import utils as db_utils
|
||||
from neutron_lib import exceptions as n_exc
|
||||
from neutron_lib.utils import helpers
|
||||
@ -67,7 +68,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
|
||||
{'event': event, 'reason': e})
|
||||
raise exc_cls(reason=reason, id=id)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_security_group(self, context, security_group, default_sg=False):
|
||||
"""Create security group.
|
||||
|
||||
@ -133,7 +134,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
|
||||
**kwargs)
|
||||
return secgroup_dict
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_security_groups(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None,
|
||||
marker=None, page_reverse=False, default_sg=False):
|
||||
@ -159,13 +160,13 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
|
||||
|
||||
return [self._make_security_group_dict(obj, fields) for obj in sg_objs]
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_security_groups_count(self, context, filters=None):
|
||||
filters = filters or {}
|
||||
return sg_obj.SecurityGroup.count(
|
||||
context, validate_filters=False, **filters)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_security_group(self, context, id, fields=None, tenant_id=None):
|
||||
"""Tenant id is given to handle the case when creating a security
|
||||
group rule on behalf of another use.
|
||||
@ -192,7 +193,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
|
||||
raise ext_sg.SecurityGroupNotFound(id=id)
|
||||
return sg
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def delete_security_group(self, context, id):
|
||||
filters = {'security_group_id': [id]}
|
||||
with db_api.context_manager.reader.using(context):
|
||||
@ -234,7 +235,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
|
||||
registry.notify(resources.SECURITY_GROUP, events.AFTER_DELETE,
|
||||
self, **kwargs)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def update_security_group(self, context, id, security_group):
|
||||
s = security_group['security_group']
|
||||
|
||||
@ -287,7 +288,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
|
||||
'security_group_id': security_group['security_group_id']}
|
||||
return db_utils.resource_fields(res, fields)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def _create_port_security_group_binding(self, context, port_id,
|
||||
security_group_id):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
@ -302,7 +303,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
|
||||
self._make_security_group_binding_dict,
|
||||
filters=filters, fields=fields)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def _delete_port_security_group_bindings(self, context, port_id):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
query = model_query.query_with_hooks(
|
||||
@ -312,12 +313,12 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
|
||||
for binding in bindings:
|
||||
context.session.delete(binding)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_security_group_rule_bulk(self, context, security_group_rules):
|
||||
return self._create_bulk('security_group_rule', context,
|
||||
security_group_rules)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_security_group_rule_bulk_native(self, context,
|
||||
security_group_rules):
|
||||
rules = security_group_rules['security_group_rules']
|
||||
@ -340,7 +341,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
|
||||
context=context, security_group_rule=rdict)
|
||||
return ret
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_security_group_rule(self, context, security_group_rule):
|
||||
res = self._create_security_group_rule(context, security_group_rule)
|
||||
registry.notify(
|
||||
@ -662,7 +663,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
|
||||
raise ext_sg.SecurityGroupRuleParameterConflict(
|
||||
ethertype=rule['ethertype'], cidr=input_prefix)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_security_group_rules(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
@ -678,13 +679,13 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
|
||||
for obj in rule_objs
|
||||
]
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_security_group_rules_count(self, context, filters=None):
|
||||
filters = filters or {}
|
||||
return sg_obj.SecurityGroupRule.count(
|
||||
context, validate_filters=False, **filters)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_security_group_rule(self, context, id, fields=None):
|
||||
security_group_rule = self._get_security_group_rule(context, id)
|
||||
return self._make_security_group_rule_dict(
|
||||
@ -696,7 +697,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase):
|
||||
raise ext_sg.SecurityGroupRuleNotFound(id=id)
|
||||
return sgr
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def delete_security_group_rule(self, context, id):
|
||||
kwargs = {
|
||||
'context': context,
|
||||
|
@ -18,10 +18,10 @@ from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import constants as const
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.utils import helpers
|
||||
|
||||
from neutron._i18n import _
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db.models import allowed_address_pair as aap_models
|
||||
from neutron.db.models import securitygroup as sg_models
|
||||
from neutron.db import models_v2
|
||||
|
@ -877,7 +877,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
return result, mech_context
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_network(self, context, network):
|
||||
self._before_create_network(context, network)
|
||||
result, mech_context = self._create_network_db(context, network)
|
||||
@ -897,14 +897,14 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
return result
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_network_bulk(self, context, networks):
|
||||
objects = self._create_bulk_ml2(
|
||||
net_def.RESOURCE_NAME, context, networks)
|
||||
return [obj['result'] for obj in objects]
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def update_network(self, context, id, network):
|
||||
net_data = network[net_def.RESOURCE_NAME]
|
||||
provider._raise_if_updates_provider_attributes(net_data)
|
||||
@ -971,7 +971,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
self.notifier.network_update(context, updated_network)
|
||||
return updated_network
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_network(self, context, id, fields=None):
|
||||
# NOTE(ihrachys) use writer manager to be able to update mtu
|
||||
# TODO(ihrachys) remove in Queens+ when mtu is not nullable
|
||||
@ -989,7 +989,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
|
||||
return db_utils.resource_fields(net_data, fields)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_networks(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None, page_reverse=False):
|
||||
# NOTE(ihrachys) use writer manager to be able to update mtu
|
||||
@ -1092,7 +1092,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
return result, mech_context
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_subnet(self, context, subnet):
|
||||
self._before_create_subnet(context, subnet)
|
||||
result, mech_context = self._create_subnet_db(context, subnet)
|
||||
@ -1111,14 +1111,14 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
return result
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_subnet_bulk(self, context, subnets):
|
||||
objects = self._create_bulk_ml2(
|
||||
subnet_def.RESOURCE_NAME, context, subnets)
|
||||
return [obj['result'] for obj in objects]
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def update_subnet(self, context, id, subnet):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
updated_subnet, original_subnet = self._update_subnet_precommit(
|
||||
@ -1252,7 +1252,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
return result, mech_context
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_port(self, context, port):
|
||||
self._before_create_port(context, port)
|
||||
result, mech_context = self._create_port_db(context, port)
|
||||
@ -1281,7 +1281,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
return bound_context.current
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_port_bulk(self, context, ports):
|
||||
objects = self._create_bulk_ml2(port_def.RESOURCE_NAME, context, ports)
|
||||
return [obj['result'] for obj in objects]
|
||||
@ -1330,7 +1330,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
raise psec_exc.PortSecurityPortHasSecurityGroup()
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def update_port(self, context, id, port):
|
||||
attrs = port[port_def.RESOURCE_NAME]
|
||||
need_port_update_notify = False
|
||||
@ -1492,7 +1492,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
binding.persist_state_to_session(plugin_context.session)
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def update_distributed_port_binding(self, context, id, port):
|
||||
attrs = port[port_def.RESOURCE_NAME]
|
||||
|
||||
@ -1550,7 +1550,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
raise exc.ServicePortInUse(port_id=port_id, reason=e)
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def delete_port(self, context, id, l3_port_check=True):
|
||||
self._pre_delete_port(context, id, l3_port_check)
|
||||
# TODO(armax): get rid of the l3 dependency in the with block
|
||||
@ -1636,7 +1636,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
self.notifier.port_delete(context, port['id'])
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive(context_var_name='plugin_context')
|
||||
@lib_db_api.retry_if_session_inactive(context_var_name='plugin_context')
|
||||
def get_bound_port_context(self, plugin_context, port_id, host=None,
|
||||
cached_networks=None):
|
||||
# NOTE(ihrachys) use writer manager to be able to update mtu when
|
||||
@ -1693,7 +1693,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
return self._bind_port_if_needed(port_context)
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive(context_var_name='plugin_context')
|
||||
@lib_db_api.retry_if_session_inactive(context_var_name='plugin_context')
|
||||
def get_bound_ports_contexts(self, plugin_context, dev_ids, host=None):
|
||||
result = {}
|
||||
# NOTE(ihrachys) use writer manager to be able to update mtu when
|
||||
@ -1758,7 +1758,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
context, {port_id: status}, host)[port_id]
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def update_port_statuses(self, context, port_id_to_status, host=None):
|
||||
result = {}
|
||||
port_ids = port_id_to_status.keys()
|
||||
@ -1866,7 +1866,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
|
||||
return port['id']
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def port_bound_to_host(self, context, port_id, host):
|
||||
if not host:
|
||||
return
|
||||
@ -1886,7 +1886,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
port_host = db.get_port_binding_host(context, port_id)
|
||||
return port if (port_host == host) else None
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_ports_from_devices(self, context, devices):
|
||||
port_ids_to_devices = dict(
|
||||
(self._device_to_port_id(context, device), device)
|
||||
@ -2051,7 +2051,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
mech_context._plugin_context.session)
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def create_port_binding(self, context, port_id, binding):
|
||||
attrs = binding[pbe_ext.RESOURCE_NAME]
|
||||
with db_api.context_manager.writer.using(context):
|
||||
@ -2097,7 +2097,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
return self._make_port_binding_dict(bind_context._binding)
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_port_bindings(self, context, port_id, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
@ -2114,7 +2114,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
for binding in bindings]
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def get_port_binding(self, context, host, port_id, fields=None):
|
||||
port = ports_obj.Port.get_object(context, id=port_id)
|
||||
if not port:
|
||||
@ -2132,7 +2132,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
return binding
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def update_port_binding(self, context, host, port_id, binding):
|
||||
attrs = binding[pbe_ext.RESOURCE_NAME]
|
||||
with db_api.context_manager.writer.using(context):
|
||||
@ -2166,7 +2166,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
return self._make_port_binding_dict(bind_context._binding)
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def activate(self, context, host, port_id):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
# TODO(mlavalle) Next two lines can be removed when bug #1770267 is
|
||||
@ -2218,7 +2218,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
raise n_exc.PortBindingError(port_id=port_id, host=host)
|
||||
|
||||
@utils.transaction_guard
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def delete_port_binding(self, context, host, port_id):
|
||||
ports_obj.PortBinding.delete_objects(context, host=host,
|
||||
port_id=port_id)
|
||||
|
@ -219,7 +219,7 @@ class TrackedResource(BaseResource):
|
||||
# can happen is two or more workers are trying to create a resource of a
|
||||
# give kind for the same tenant concurrently. Retrying the operation will
|
||||
# ensure that an UPDATE statement is emitted rather than an INSERT one
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def _set_quota_usage(self, context, tenant_id, in_use):
|
||||
return quota_api.set_quota_usage(
|
||||
context, self.name, tenant_id, in_use=in_use)
|
||||
|
@ -20,6 +20,7 @@ from neutron_lib.api.definitions import network as net_def
|
||||
from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib.db import utils as db_utils
|
||||
from neutron_lib import exceptions as n_exc
|
||||
from neutron_lib.objects import exceptions as obj_exc
|
||||
@ -31,7 +32,6 @@ from oslo_log import log as logging
|
||||
from neutron._i18n import _
|
||||
from neutron.common import exceptions as c_exc
|
||||
from neutron.db import _resource_extend as resource_extend
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db import common_db_mixin
|
||||
from neutron.objects import auto_allocate as auto_allocate_obj
|
||||
from neutron.objects import base as base_obj
|
||||
|
@ -23,6 +23,7 @@ from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import constants as lib_consts
|
||||
from neutron_lib.db import api as lib_db_api
|
||||
from neutron_lib.db import utils as db_utils
|
||||
from neutron_lib import exceptions as lib_exc
|
||||
from neutron_lib.exceptions import l3 as lib_l3_exc
|
||||
@ -136,7 +137,7 @@ class PortForwardingPlugin(fip_pf.PortForwardingPluginBase):
|
||||
|
||||
@registry.receives(resources.PORT, [events.AFTER_UPDATE,
|
||||
events.PRECOMMIT_DELETE])
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def _process_port_request(self, resource, event, trigger, context,
|
||||
**kwargs):
|
||||
# Deleting floatingip will receive port resource with precommit_delete
|
||||
|
@ -18,6 +18,7 @@ from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.db import api as lib_db_api
|
||||
from neutron_lib.db import utils as db_utils
|
||||
from neutron_lib import exceptions as n_exc
|
||||
from neutron_lib.plugins import directory
|
||||
@ -183,7 +184,7 @@ class SegmentDbMixin(common_db_mixin.CommonDbMixin):
|
||||
segment=segment_dict)
|
||||
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
@lockutils.synchronized('update_segment_host_mapping')
|
||||
def update_segment_host_mapping(context, host, current_segment_ids):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
|
@ -12,6 +12,7 @@
|
||||
# under the License.
|
||||
#
|
||||
|
||||
from neutron_lib.db import api as lib_db_api
|
||||
from neutron_lib.objects import exceptions as obj_exc
|
||||
from neutron_lib.plugins import directory
|
||||
from oslo_log import helpers as log_helpers
|
||||
@ -72,7 +73,7 @@ class TagPlugin(common_db_mixin.CommonDbMixin, tagging.TagPluginBase):
|
||||
raise tagging.TagNotFound(tag=tag)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
@db_api.retry_if_session_inactive()
|
||||
@lib_db_api.retry_if_session_inactive()
|
||||
def update_tags(self, context, resource, resource_id, body):
|
||||
with db_api.context_manager.writer.using(context):
|
||||
# We get and do all operations with objects in one session
|
||||
|
Loading…
Reference in New Issue
Block a user