commit 8dd8779b6c1f27f71c302246b5b4ac3d089f4245 Author: Kobi Samoray Date: Mon Oct 12 17:43:02 2020 +0300 Address various issues with Octavia delete cascade Cascaded loadbalancer deletion with Octavia was broken in various ways. Some NSXV specific while others are within the common code. Change-Id: Id5148b6d496645c49fccb50e33d6a371e98bbb85 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 e2fbead..a99db4f 100644 --- a/vmware_nsx/services/lbaas/nsx_v/implementation/member_mgr.py +++ b/vmware_nsx/services/lbaas/nsx_v/implementation/member_mgr.py @@ -38,11 +38,13 @@ class EdgeMemberManagerFromDict(base_mgr.EdgeLoadbalancerBaseManager): def _get_pool_lb_id(self, member): if not member.get('pool'): return - listener = member['pool']['listener'] + listener = member['pool'].get('listener') if listener: lb_id = listener['loadbalancer_id'] + elif member['pool'].get('loadbalancer_id'): + lb_id = member['pool']['loadbalancer_id'] else: - lb_id = member['pool']['loadbalancer']['id'] + lb_id = member['pool'].get('loadbalancer', []).get('id') return lb_id def _get_pool_member_ips(self, pool, operation, address): 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 1643938..7988594 100644 --- a/vmware_nsx/services/lbaas/nsx_v/implementation/pool_mgr.py +++ b/vmware_nsx/services/lbaas/nsx_v/implementation/pool_mgr.py @@ -174,15 +174,16 @@ class EdgePoolManagerFromDict(base_mgr.EdgeLoadbalancerBaseManager): listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding( context.session, lb_id, listener['id']) - vse = listener_mgr.listener_to_edge_vse( - context, - listener, - lb_binding['vip_address'], - None, - listener_binding['app_profile_id']) - with locking.LockManager.get_lock(edge_id): - self.vcns.update_vip( - edge_id, listener_binding['vse_id'], vse) + if listener_binding: + vse = listener_mgr.listener_to_edge_vse( + context, + listener, + lb_binding['vip_address'], + None, + listener_binding['app_profile_id']) + with locking.LockManager.get_lock(edge_id): + self.vcns.update_vip( + edge_id, listener_binding['vse_id'], vse) self.vcns.delete_pool(edge_id, edge_pool_id) completor(success=True) nsxv_db.del_nsxv_lbaas_pool_binding( diff --git a/vmware_nsx/services/lbaas/octavia/octavia_listener.py b/vmware_nsx/services/lbaas/octavia/octavia_listener.py index be9494e..b58ef68 100644 --- a/vmware_nsx/services/lbaas/octavia/octavia_listener.py +++ b/vmware_nsx/services/lbaas/octavia/octavia_listener.py @@ -324,26 +324,43 @@ class NSXOctaviaListenerEndpoint(object): def dummy_completor(success=True): pass + completor = self.get_completor_func(constants.LOADBALANCERS, + loadbalancer, delete=True) + + listener_dict = {} # Go over the LB tree and delete one by one using the cascade # api implemented for each resource - for listener in loadbalancer.get('listeners', []): - for policy in listener.get('l7policies', []): - for rule in policy.get('rules', []): - self.l7rule.delete_cascade(ctx, rule, dummy_completor) - self.l7policy.delete_cascade(ctx, policy, dummy_completor) - self.listener.delete_cascade(ctx, listener, dummy_completor) - for pool in loadbalancer.get('pools', []): - for member in pool.get('members', []): - self.member.delete_cascade(ctx, member, dummy_completor) - if pool.get('healthmonitor'): - self.healthmonitor.delete_cascade( - ctx, pool['healthmonitor'], dummy_completor) - self.pool.delete_cascade(ctx, pool, dummy_completor) + try: + for listener in loadbalancer.get('listeners', []): + listener['loadbalancer'] = loadbalancer + listener_dict[listener['id']] = listener + for policy in listener.get('l7policies', []): + for rule in policy.get('rules', []): + self.l7rule.delete_cascade(ctx, rule, dummy_completor) + self.l7policy.delete_cascade(ctx, policy, dummy_completor) + self.listener.delete_cascade(ctx, listener, dummy_completor) + for pool in loadbalancer.get('pools', []): + if not pool.get('loadbalancer'): + pool['loadbalancer'] = loadbalancer + if pool.get('listener_id'): + pool['listener'] = listener_dict[pool['listener_id']] + pool['listeners'] = [pool['listener']] + for member in pool.get('members', []): + if not member.get('pool'): + member['pool'] = pool + self.member.delete_cascade(ctx, member, dummy_completor) + if pool.get('healthmonitor'): + self.healthmonitor.delete_cascade( + ctx, pool['healthmonitor'], dummy_completor) + self.pool.delete_cascade(ctx, pool, dummy_completor) + except Exception as e: + LOG.error('NSX driver loadbalancer_delete_cascade failed to ' + 'delete sub-object %s', e) + completor(success=False) + return False # Delete the loadbalancer itself with the completor that marks all # as deleted - completor = self.get_completor_func(constants.LOADBALANCERS, - loadbalancer, delete=True) try: self.loadbalancer.delete_cascade( ctx, loadbalancer, self.get_completor_func(