NSX|P: Fix LB deletion without a router

In case the loadbalancer is attached to an external vip
the nsx loadbalancer was not deleted.

Change-Id: I1009f51e0d6c1c95c4c03f149d6f6962cd0e84d8
This commit is contained in:
Adit Sarfaty 2019-06-02 15:55:24 +03:00
parent 2d68de6ce4
commit 0a7e9a0e34
2 changed files with 24 additions and 8 deletions

View File

@ -111,25 +111,41 @@ class EdgeLoadBalancerManagerFromDict(base_mgr.NsxpLoadbalancerBaseManager):
@log_helpers.log_method_call
def delete(self, context, lb, completor):
service_client = self.core_plugin.nsxpolicy.load_balancer.lb_service
router_id = lb_utils.get_router_from_network(
context, self.core_plugin, lb['vip_subnet_id'])
service_client = self.core_plugin.nsxpolicy.load_balancer.lb_service
if not router_id:
# Try to get it from the service
try:
service = service_client.get(lb['id'])
except nsxlib_exc.ResourceNotFound:
pass
else:
router_id = lib_p_utils.path_to_id(
service.get('connectivity_path', ''))
try:
service_client.delete(lb['id'])
except Exception as e:
with excutils.save_and_reraise_exception():
completor(success=False)
LOG.error('Failed to delete loadbalancer %(lb)s for lb '
'with error %(err)s',
{'lb': lb['id'], 'err': e})
# if no router for vip - should check the member router
if router_id:
try:
service_client.delete(lb['id'])
if not self.core_plugin.service_router_has_services(
context.elevated(), router_id):
self.core_plugin.delete_service_router(router_id)
except Exception as e:
with excutils.save_and_reraise_exception():
completor(success=False)
LOG.error('Failed to delete loadbalancer %(lb)s for lb '
'with error %(err)s',
LOG.error('Failed to delete service router upon deletion '
'of loadbalancer %(lb)s with error %(err)s',
{'lb': lb['id'], 'err': e})
else:
LOG.warning('Router not found for loadbalancer %s', lb['id'])
completor(success=True)
@log_helpers.log_method_call

View File

@ -76,7 +76,7 @@ class EdgeMemberManagerFromDict(base_mgr.NsxpLoadbalancerBaseManager):
tags = lb_utils.get_tags(self.core_plugin,
router_id,
lb_const.LR_ROUTER_TYPE,
lb['tenant_id'], context.project_name)
lb.get('tenant_id'), context.project_name)
try:
service_client.update(lb['id'],
tags=tags,