From 2f851fa3c67cca2e005f5141c9b4d2f18fe410f7 Mon Sep 17 00:00:00 2001 From: asarfaty Date: Thu, 20 Feb 2020 12:18:09 +0200 Subject: [PATCH] NSX|V3+P: Fix loadbalancer delete to support error cases If the loadbalancer is in error, the subnet / port might not exist so the service should just log this error and continue Change-Id: If8dd1cec562a6252ead7115287c219a3f4701f5e --- .../nsx_p/implementation/loadbalancer_mgr.py | 30 ++++++++++++------- .../nsx_v3/implementation/loadbalancer_mgr.py | 23 +++++++++----- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/vmware_nsx/services/lbaas/nsx_p/implementation/loadbalancer_mgr.py b/vmware_nsx/services/lbaas/nsx_p/implementation/loadbalancer_mgr.py index 843747b9cb..b293a029d5 100644 --- a/vmware_nsx/services/lbaas/nsx_p/implementation/loadbalancer_mgr.py +++ b/vmware_nsx/services/lbaas/nsx_p/implementation/loadbalancer_mgr.py @@ -113,8 +113,14 @@ class EdgeLoadBalancerManagerFromDict(base_mgr.NsxpLoadbalancerBaseManager): completor(success=True) def delete(self, context, lb, completor): - router_id = lb_utils.get_router_from_network( - context, self.core_plugin, lb['vip_subnet_id']) + router_id = None + try: + router_id = lb_utils.get_router_from_network( + context, self.core_plugin, lb['vip_subnet_id']) + except n_exc.SubnetNotFound: + LOG.warning("VIP subnet %s not found while deleting " + "loadbalancer %s", lb['vip_subnet_id'], lb['id']) + service_client = self.core_plugin.nsxpolicy.load_balancer.lb_service if not router_id: @@ -149,18 +155,22 @@ class EdgeLoadBalancerManagerFromDict(base_mgr.NsxpLoadbalancerBaseManager): {'lb': lb['id'], 'err': e}) # Make sure the vip port is not marked with a vmware device owner - port = self.core_plugin.get_port( - context.elevated(), lb['vip_port_id']) - if port.get('device_owner') == lb_const.VMWARE_LB_VIP_OWNER: - try: + try: + port = self.core_plugin.get_port( + context.elevated(), lb['vip_port_id']) + if port.get('device_owner') == lb_const.VMWARE_LB_VIP_OWNER: self.core_plugin.update_port( context.elevated(), lb['vip_port_id'], {'port': {'device_id': '', 'device_owner': ''}}) - except Exception as e: - # Just log the error as all other resources were deleted - LOG.error("Failed to update neutron port %s devices upon " - "loadbalancer deletion: %s", lb['vip_port_id'], e) + except n_exc.PortNotFound: + # Only log the error and continue anyway + LOG.warning("VIP port %s not found while deleting loadbalancer %s", + lb['vip_port_id'], lb['id']) + except Exception as e: + # Just log the error as all other resources were deleted + LOG.error("Failed to update neutron port %s devices upon " + "loadbalancer deletion: %s", lb['vip_port_id'], e) completor(success=True) diff --git a/vmware_nsx/services/lbaas/nsx_v3/implementation/loadbalancer_mgr.py b/vmware_nsx/services/lbaas/nsx_v3/implementation/loadbalancer_mgr.py index 1eb3b6bb71..eefc09b653 100644 --- a/vmware_nsx/services/lbaas/nsx_v3/implementation/loadbalancer_mgr.py +++ b/vmware_nsx/services/lbaas/nsx_v3/implementation/loadbalancer_mgr.py @@ -222,13 +222,22 @@ class EdgeLoadBalancerManagerFromDict(base_mgr.Nsxv3LoadbalancerBaseManager): self.core_plugin.delete_service_router(context, router_id) # Make sure the vip port is not marked with a vmware device owner - port = self.core_plugin.get_port( - context.elevated(), lb['vip_port_id']) - if port.get('device_owner') == lb_const.VMWARE_LB_VIP_OWNER: - self.core_plugin.update_port( - context.elevated(), lb['vip_port_id'], - {'port': {'device_id': '', - 'device_owner': ''}}) + try: + port = self.core_plugin.get_port( + context.elevated(), lb['vip_port_id']) + if port.get('device_owner') == lb_const.VMWARE_LB_VIP_OWNER: + self.core_plugin.update_port( + context.elevated(), lb['vip_port_id'], + {'port': {'device_id': '', + 'device_owner': ''}}) + except n_exc.PortNotFound: + # Only log the error and continue anyway + LOG.warning("VIP port %s not found while deleting loadbalancer %s", + lb['vip_port_id'], lb['id']) + except Exception as e: + # Just log the error as all other resources were deleted + LOG.error("Failed to update neutron port %s devices upon " + "loadbalancer deletion: %s", lb['vip_port_id'], e) completor(success=True)