From c08f93a115c970256ad42b0f476c39ee95dcd2e5 Mon Sep 17 00:00:00 2001 From: Tong Liu Date: Tue, 24 Oct 2017 21:34:41 +0000 Subject: [PATCH] NSXv3: Fix load balancer delete issue If there are multiple load balancers share the same LB service, LB service will be deleted if there is no virtual server attached to it. This patch fixes an load balancer deletion issue if LB service has already been deleted. Change-Id: I797c0bcbcaa90156577aa3b853c31ecb9bb96636 --- .../services/lbaas/nsx_v3/loadbalancer_mgr.py | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/vmware_nsx/services/lbaas/nsx_v3/loadbalancer_mgr.py b/vmware_nsx/services/lbaas/nsx_v3/loadbalancer_mgr.py index 067f2de6e0..334c58bae1 100644 --- a/vmware_nsx/services/lbaas/nsx_v3/loadbalancer_mgr.py +++ b/vmware_nsx/services/lbaas/nsx_v3/loadbalancer_mgr.py @@ -63,22 +63,27 @@ class EdgeLoadBalancerManager(base_mgr.Nsxv3LoadbalancerBaseManager): if lb_binding: lb_service_id = lb_binding['lb_service_id'] nsx_router_id = lb_binding['lb_router_id'] - lb_service = service_client.get(lb_service_id) - vs_list = lb_service.get('virtual_server_ids') - if not vs_list: - try: - service_client.delete(lb_service_id) - # If there is no lb service attached to the router, - # update the router advertise_lb_vip flag to false. - router_client = self.core_plugin.nsxlib.logical_router - router_client.update_advertisement(nsx_router_id, - advertise_lb_vip=False) - except nsxlib_exc.ManagerError: - self.lbv2_driver.load_balancer.failed_completion( - context, lb, delete=True) - msg = (_('Failed to delete lb service %(lbs)s from nsx') % - {'lbs': lb_service_id}) - raise n_exc.BadRequest(resource='lbaas-lb', msg=msg) + try: + lb_service = service_client.get(lb_service_id) + except nsxlib_exc.ManagerError: + LOG.warning("LB service %(lbs)s is not found", + {'lbs': lb_service_id}) + else: + vs_list = lb_service.get('virtual_server_ids') + if not vs_list: + try: + service_client.delete(lb_service_id) + # If there is no lb service attached to the router, + # update the router advertise_lb_vip flag to false. + router_client = self.core_plugin.nsxlib.logical_router + router_client.update_advertisement( + nsx_router_id, advertise_lb_vip=False) + except nsxlib_exc.ManagerError: + self.lbv2_driver.load_balancer.failed_completion( + context, lb, delete=True) + msg = (_('Failed to delete lb service %(lbs)s from nsx' + ) % {'lbs': lb_service_id}) + raise n_exc.BadRequest(resource='lbaas-lb', msg=msg) nsx_db.delete_nsx_lbaas_loadbalancer_binding( context.session, lb.id) self.lbv2_driver.load_balancer.successful_completion(