From c941dba4143928a18df553d926fca80ab66955fe Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Mon, 25 Oct 2021 23:58:54 -0700 Subject: [PATCH] [NSX-P] Improve port deletion handling During port deletion on the backend, we remove profile bindings and then the actual port. If for any reason a binding is not found, the process should still proceed to delete remaining resources up to the segment port. This change fixes this behaviour, as the code was instead returning as soon an object was not found. Change-Id: I529ce34db323f900129865befc6bd64e1ff4f5ff --- vmware_nsx/plugins/nsx_p/plugin.py | 37 ++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/vmware_nsx/plugins/nsx_p/plugin.py b/vmware_nsx/plugins/nsx_p/plugin.py index f9e8f598eb..c848885a51 100644 --- a/vmware_nsx/plugins/nsx_p/plugin.py +++ b/vmware_nsx/plugins/nsx_p/plugin.py @@ -2294,21 +2294,34 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base): return port_data def _delete_port_on_backend(self, context, net_id, port_id): + # Ignore resources not found on the backend, but still + # try and delete all of them! try: segment_id = self._get_network_nsx_segment_id(context, net_id) - self.nsxpolicy.segment_port_security_profiles.delete( - segment_id, port_id) - self.nsxpolicy.segment_port_discovery_profiles.delete( - segment_id, port_id) - if directory.get_plugin(plugin_const.QOS): - self.nsxpolicy.segment_port_qos_profiles.delete( + try: + self.nsxpolicy.segment_port_security_profiles.delete( segment_id, port_id) - self.nsxpolicy.segment_port.delete(segment_id, port_id) - except nsx_lib_exc.ResourceNotFound: - # If the resource was not found on the backend do not worry about - # it. The conditions has already been logged, so there is no need - # to do further logging - pass + except nsx_lib_exc.ResourceNotFound: + LOG.debug("Skipping deletion of port security profile for " + "port %s: Not Found", port_id) + try: + self.nsxpolicy.segment_port_discovery_profiles.delete( + segment_id, port_id) + except nsx_lib_exc.ResourceNotFound: + LOG.debug("Skipping deletion of port discovery profile for " + "port %s: Not Found", port_id) + try: + if directory.get_plugin(plugin_const.QOS): + self.nsxpolicy.segment_port_qos_profiles.delete( + segment_id, port_id) + except nsx_lib_exc.ResourceNotFound: + LOG.debug("Skipping deletion of port QoS profile for " + "port %s: Not Found", port_id) + try: + self.nsxpolicy.segment_port.delete(segment_id, port_id) + except nsx_lib_exc.ResourceNotFound: + LOG.debug("Skipping deletion of sement port for " + "port %s: Not Found", port_id) except nsx_lib_exc.ManagerError as e: # If there is a failure in deleting the resource. # In this case the neutron port was not deleted yet.