From 60f212fba852509cdc4e65279a536f92b5b08fcf Mon Sep 17 00:00:00 2001 From: asarfaty Date: Thu, 28 Jan 2021 10:12:47 +0200 Subject: [PATCH] NSX|V: Fix delete cascade for deleted loadbalancers In case a loadbalancer was alrady deleted from neutron & nsx but not from octavia, delete cascade fails to find binding entries. Fixing that and also adding some logs in the delete cascade logic to make debugging easier. Change-Id: Id385366436eda75ad07dc073c5027791efb4d3d9 (cherry picked from commit 17458351533e3da9e5b0b53ce3342d4ca1c57373) --- .../lbaas/nsx_v/implementation/healthmon_mgr.py | 7 +++++++ .../lbaas/nsx_v/implementation/member_mgr.py | 6 ++++++ .../services/lbaas/nsx_v/implementation/pool_mgr.py | 11 ++++++++--- .../services/lbaas/octavia/octavia_listener.py | 12 ++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/vmware_nsx/services/lbaas/nsx_v/implementation/healthmon_mgr.py b/vmware_nsx/services/lbaas/nsx_v/implementation/healthmon_mgr.py index fed713278e..70f9350a7e 100644 --- a/vmware_nsx/services/lbaas/nsx_v/implementation/healthmon_mgr.py +++ b/vmware_nsx/services/lbaas/nsx_v/implementation/healthmon_mgr.py @@ -147,6 +147,13 @@ class EdgeHealthMonitorManagerFromDict(base_mgr.EdgeLoadbalancerBaseManager): lb_id = hm['pool']['loadbalancer_id'] lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding( context.session, lb_id) + if not lb_binding: + # Don't fail deletion if the resource is already gone + LOG.warning("Couldn't find LB %s binding during HM deletion", + lb_id) + completor(success=True) + return + edge_id = lb_binding['edge_id'] pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding( diff --git a/vmware_nsx/services/lbaas/nsx_v/implementation/member_mgr.py b/vmware_nsx/services/lbaas/nsx_v/implementation/member_mgr.py index a99db4fe02..f762b24f1d 100644 --- a/vmware_nsx/services/lbaas/nsx_v/implementation/member_mgr.py +++ b/vmware_nsx/services/lbaas/nsx_v/implementation/member_mgr.py @@ -170,6 +170,12 @@ class EdgeMemberManagerFromDict(base_mgr.EdgeLoadbalancerBaseManager): lb_id = self._get_pool_lb_id(member) lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding( context.session, lb_id) + if not lb_binding: + # Don't fail deletion if the resource is already gone + LOG.warning("Couldn't find LB %s binding during member deletion", + lb_id) + completor(success=True) + return pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding( context.session, lb_id, member['pool_id']) edge_id = lb_binding['edge_id'] diff --git a/vmware_nsx/services/lbaas/nsx_v/implementation/pool_mgr.py b/vmware_nsx/services/lbaas/nsx_v/implementation/pool_mgr.py index 99b7661b1c..002012bb52 100644 --- a/vmware_nsx/services/lbaas/nsx_v/implementation/pool_mgr.py +++ b/vmware_nsx/services/lbaas/nsx_v/implementation/pool_mgr.py @@ -157,14 +157,19 @@ class EdgePoolManagerFromDict(base_mgr.EdgeLoadbalancerBaseManager): lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding( context.session, lb_id) + if not lb_binding: + # Don't fail deletion if the resource is already gone + LOG.warning("Couldn't find LB %s binding during pool deletion", + lb_id) + completor(success=True) + return + edge_id = lb_binding['edge_id'] + pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding( context.session, lb_id, pool['id']) - - edge_id = lb_binding['edge_id'] if not pool_binding: completor(success=True) return - edge_pool_id = pool_binding['edge_pool_id'] listeners_to_update = [] diff --git a/vmware_nsx/services/lbaas/octavia/octavia_listener.py b/vmware_nsx/services/lbaas/octavia/octavia_listener.py index 72e07a1197..7f450c5f8c 100644 --- a/vmware_nsx/services/lbaas/octavia/octavia_listener.py +++ b/vmware_nsx/services/lbaas/octavia/octavia_listener.py @@ -335,8 +335,14 @@ class NSXOctaviaListenerEndpoint(object): listener_dict[listener['id']] = listener for policy in listener.get('l7policies', []): for rule in policy.get('rules', []): + LOG.info("Delete cascade: deleting l7 rule of lb %s", + loadbalancer['id']) self.l7rule.delete_cascade(ctx, rule, dummy_completor) + LOG.info("Delete cascade: deleting l7 policy of lb %s", + loadbalancer['id']) self.l7policy.delete_cascade(ctx, policy, dummy_completor) + LOG.info("Delete cascade: deleting listener of lb %s", + loadbalancer['id']) self.listener.delete_cascade(ctx, listener, dummy_completor) for pool in loadbalancer.get('pools', []): if not pool.get('loadbalancer'): @@ -352,11 +358,17 @@ class NSXOctaviaListenerEndpoint(object): for member in pool.get('members', []): if not member.get('pool'): member['pool'] = pool + LOG.info("Delete cascade: deleting old_member of lb %s", + loadbalancer['id']) self.member.delete_cascade(ctx, member, dummy_completor) if pool.get('healthmonitor'): pool['healthmonitor']['pool'] = pool + LOG.info("Delete cascade: deleting HM of lb %s", + loadbalancer['id']) self.healthmonitor.delete_cascade( ctx, pool['healthmonitor'], dummy_completor) + LOG.info("Delete cascade: deleting pool of lb %s", + loadbalancer['id']) self.pool.delete_cascade(ctx, pool, dummy_completor) except Exception as e: LOG.error('NSX driver loadbalancer_delete_cascade failed to '