NSXv3: Delete lb binding after pool deletion
LBaaS allows user to delete pool that still has members. In that way, it deletes the pool members first and then delete the pool. So, in backend we need to to delete lb service and lb binding if user delete the pool with all members. Change-Id: If967be52afbbd0e35ca502f79a99cafad7a49088
This commit is contained in:
parent
435702a6a2
commit
92e68ad895
@ -89,6 +89,7 @@ class EdgePoolManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
lb_id = pool.loadbalancer_id
|
||||
pool_client = self.core_plugin.nsxlib.load_balancer.pool
|
||||
vs_client = self.core_plugin.nsxlib.load_balancer.virtual_server
|
||||
service_client = self.core_plugin.nsxlib.load_balancer.service
|
||||
|
||||
binding = nsx_db.get_nsx_lbaas_pool_binding(
|
||||
context.session, lb_id, pool.id)
|
||||
@ -112,6 +113,30 @@ class EdgePoolManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
raise n_exc.BadRequest(resource='lbaas-pool', msg=msg)
|
||||
nsx_db.delete_nsx_lbaas_pool_binding(context.session,
|
||||
lb_id, pool.id)
|
||||
lb_binding = nsx_db.get_nsx_lbaas_loadbalancer_binding(
|
||||
context.session, lb_id)
|
||||
if lb_binding:
|
||||
lb_service_id = lb_binding['lb_service_id']
|
||||
try:
|
||||
lb_service = service_client.get(lb_service_id)
|
||||
vs_list = lb_service.get('virtual_server_ids')
|
||||
if vs_list and vs_id in vs_list:
|
||||
vs_list.remove(vs_id)
|
||||
else:
|
||||
LOG.debug('virtual server id %s is not in the lb '
|
||||
'service virtual server list %s',
|
||||
vs_id, vs_list)
|
||||
service_client.update(lb_service_id,
|
||||
virtual_server_ids=vs_list)
|
||||
if not vs_list:
|
||||
service_client.delete(lb_service_id)
|
||||
nsx_db.delete_nsx_lbaas_loadbalancer_binding(
|
||||
context.session, lb_id)
|
||||
except nsxlib_exc.ManagerError:
|
||||
self.lbv2_driver.pool.failed_completion(context, pool)
|
||||
msg = (_('Failed to delete lb pool from nsx: %(pool)s') %
|
||||
{'pool': lb_pool_id})
|
||||
raise n_exc.BadRequest(resource='lbaas-pool', msg=msg)
|
||||
|
||||
self.lbv2_driver.pool.successful_completion(
|
||||
context, pool, delete=True)
|
||||
|
@ -349,8 +349,11 @@ class TestEdgeLbaasV2Pool(BaseTestEdgeLbaasV2):
|
||||
mock.patch.object(self.pool_client, 'delete'
|
||||
) as mock_delete_pool, \
|
||||
mock.patch.object(nsx_db, 'delete_nsx_lbaas_pool_binding'
|
||||
) as mock_delete_pool_binding:
|
||||
) as mock_delete_pool_binding, \
|
||||
mock.patch.object(nsx_db, 'get_nsx_lbaas_loadbalancer_binding'
|
||||
) as mock_get_lb_binding:
|
||||
mock_get_pool_binding.return_value = POOL_BINDING
|
||||
mock_get_lb_binding.return_value = None
|
||||
|
||||
self.edge_driver.pool.delete(self.context, self.pool)
|
||||
|
||||
@ -632,7 +635,7 @@ class TestEdgeLbaasV2L7Rule(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion.assert_called_with(
|
||||
self.context, new_l7rule)
|
||||
|
||||
def test_delete(self):
|
||||
def test_delete_pool_without_members(self):
|
||||
with mock.patch.object(nsx_db, 'get_nsx_lbaas_l7rule_binding',
|
||||
) as mock_get_l7rule_binding, \
|
||||
mock.patch.object(self.rule_client, 'delete',
|
||||
|
Loading…
Reference in New Issue
Block a user