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