Merge "Improve port delete performance"
This commit is contained in:
commit
d2bb0ec0a5
@ -1499,9 +1499,9 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
return self._make_port_dict(db_port)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
def delete_port(self, context, id):
|
||||
def delete_port(self, context, id, port=None):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
self.ipam.delete_port(context, id)
|
||||
self.ipam.delete_port(context, id, port)
|
||||
|
||||
def delete_ports_by_device_id(self, context, device_id, network_id=None):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
|
@ -483,9 +483,9 @@ class IpamPluggableBackend(ipam_backend_mixin.IpamBackendMixin):
|
||||
revert_on_fail=False)
|
||||
return changes
|
||||
|
||||
def delete_port(self, context, id):
|
||||
def delete_port(self, context, id, port=None):
|
||||
# Get fixed_ips list before port deletion
|
||||
port = self._get_port(context, id)
|
||||
port = port or self._get_port(context, id)
|
||||
ipam_driver = driver.Pool.get_instance(None, context)
|
||||
|
||||
super(IpamPluggableBackend, self).delete_port(context, id)
|
||||
|
@ -105,7 +105,8 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
|
||||
l3plugin = directory.get_plugin(plugin_constants.L3)
|
||||
if l3plugin and payload.metadata['port_check']:
|
||||
l3plugin.prevent_l3_port_deletion(
|
||||
payload.context, payload.resource_id)
|
||||
payload.context, payload.resource_id,
|
||||
port=payload.metadata.get('port'))
|
||||
|
||||
@staticmethod
|
||||
def _validate_subnet_address_mode(subnet):
|
||||
@ -1561,7 +1562,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
|
||||
filters = filters or {}
|
||||
return l3_obj.FloatingIP.count(context, **filters)
|
||||
|
||||
def prevent_l3_port_deletion(self, context, port_id):
|
||||
def prevent_l3_port_deletion(self, context, port_id, port=None):
|
||||
"""Checks to make sure a port is allowed to be deleted.
|
||||
|
||||
Raises an exception if this is not the case. This should be called by
|
||||
@ -1571,7 +1572,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
|
||||
deletion checks.
|
||||
"""
|
||||
try:
|
||||
port = self._core_plugin.get_port(context, port_id)
|
||||
port = port or self._core_plugin.get_port(context, port_id)
|
||||
except n_exc.PortNotFound:
|
||||
# non-existent ports don't need to be protected from deletion
|
||||
return
|
||||
|
@ -1881,7 +1881,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
return
|
||||
self._bind_port_if_needed(mech_context)
|
||||
|
||||
def _pre_delete_port(self, context, port_id, port_check):
|
||||
def _pre_delete_port(self, context, port_id, port_check, port=None):
|
||||
"""Do some preliminary operations before deleting the port."""
|
||||
LOG.debug("Deleting port %s", port_id)
|
||||
try:
|
||||
@ -1890,7 +1890,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
registry.publish(
|
||||
resources.PORT, events.BEFORE_DELETE, self,
|
||||
payload=events.DBEventPayload(
|
||||
context, metadata={'port_check': port_check},
|
||||
context, metadata={'port_check': port_check, 'port': port},
|
||||
resource_id=port_id))
|
||||
except exceptions.CallbackFailure as e:
|
||||
# NOTE(armax): preserve old check's behavior
|
||||
@ -1901,21 +1901,22 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
@utils.transaction_guard
|
||||
@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)
|
||||
try:
|
||||
port_db = self._get_port(context, id)
|
||||
port = self._make_port_dict(port_db)
|
||||
except exc.PortNotFound:
|
||||
LOG.debug("The port '%s' was deleted", id)
|
||||
return
|
||||
|
||||
self._pre_delete_port(context, id, l3_port_check, port)
|
||||
# TODO(armax): get rid of the l3 dependency in the with block
|
||||
router_ids = []
|
||||
l3plugin = directory.get_plugin(plugin_constants.L3)
|
||||
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
try:
|
||||
port_db = self._get_port(context, id)
|
||||
binding = p_utils.get_port_binding_by_status_and_host(
|
||||
port_db.port_bindings, const.ACTIVE,
|
||||
raise_if_not_found=True, port_id=id)
|
||||
except exc.PortNotFound:
|
||||
LOG.debug("The port '%s' was deleted", id)
|
||||
return
|
||||
port = self._make_port_dict(port_db)
|
||||
binding = p_utils.get_port_binding_by_status_and_host(
|
||||
port_db.port_bindings, const.ACTIVE,
|
||||
raise_if_not_found=True, port_id=id)
|
||||
|
||||
network = self.get_network(context, port['network_id'])
|
||||
bound_mech_contexts = []
|
||||
@ -1957,7 +1958,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
|
||||
LOG.debug("Calling delete_port for %(port_id)s owned by %(owner)s",
|
||||
{"port_id": id, "owner": device_owner})
|
||||
super(Ml2Plugin, self).delete_port(context, id)
|
||||
super(Ml2Plugin, self).delete_port(context, id, port)
|
||||
|
||||
self._post_delete_port(
|
||||
context, port, router_ids, bound_mech_contexts)
|
||||
|
@ -1328,10 +1328,8 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase):
|
||||
plugin = directory.get_plugin()
|
||||
with mock.patch.object(ml2_plugin.LOG, 'debug') as log_debug:
|
||||
plugin.delete_port(ctx, 'invalid-uuid', l3_port_check=False)
|
||||
log_debug.assert_has_calls([
|
||||
mock.call(_("Deleting port %s"), 'invalid-uuid'),
|
||||
mock.call(_("The port '%s' was deleted"), 'invalid-uuid')
|
||||
])
|
||||
log_debug.assert_called_with(
|
||||
_("The port '%s' was deleted"), 'invalid-uuid')
|
||||
|
||||
def test_l3_cleanup_on_net_delete(self):
|
||||
l3plugin = directory.get_plugin(plugin_constants.L3)
|
||||
|
Loading…
Reference in New Issue
Block a user