Merge "NSXv3: Delete lb binding after pool deletion"
This commit is contained in:
commit
6df5003916
@ -89,6 +89,7 @@ class EdgePoolManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
|||||||
lb_id = pool.loadbalancer_id
|
lb_id = pool.loadbalancer_id
|
||||||
pool_client = self.core_plugin.nsxlib.load_balancer.pool
|
pool_client = self.core_plugin.nsxlib.load_balancer.pool
|
||||||
vs_client = self.core_plugin.nsxlib.load_balancer.virtual_server
|
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(
|
binding = nsx_db.get_nsx_lbaas_pool_binding(
|
||||||
context.session, lb_id, pool.id)
|
context.session, lb_id, pool.id)
|
||||||
@ -112,6 +113,30 @@ class EdgePoolManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
|||||||
raise n_exc.BadRequest(resource='lbaas-pool', msg=msg)
|
raise n_exc.BadRequest(resource='lbaas-pool', msg=msg)
|
||||||
nsx_db.delete_nsx_lbaas_pool_binding(context.session,
|
nsx_db.delete_nsx_lbaas_pool_binding(context.session,
|
||||||
lb_id, pool.id)
|
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(
|
self.lbv2_driver.pool.successful_completion(
|
||||||
context, pool, delete=True)
|
context, pool, delete=True)
|
||||||
|
@ -349,8 +349,11 @@ class TestEdgeLbaasV2Pool(BaseTestEdgeLbaasV2):
|
|||||||
mock.patch.object(self.pool_client, 'delete'
|
mock.patch.object(self.pool_client, 'delete'
|
||||||
) as mock_delete_pool, \
|
) as mock_delete_pool, \
|
||||||
mock.patch.object(nsx_db, 'delete_nsx_lbaas_pool_binding'
|
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_pool_binding.return_value = POOL_BINDING
|
||||||
|
mock_get_lb_binding.return_value = None
|
||||||
|
|
||||||
self.edge_driver.pool.delete(self.context, self.pool)
|
self.edge_driver.pool.delete(self.context, self.pool)
|
||||||
|
|
||||||
@ -632,7 +635,7 @@ class TestEdgeLbaasV2L7Rule(BaseTestEdgeLbaasV2):
|
|||||||
mock_successful_completion.assert_called_with(
|
mock_successful_completion.assert_called_with(
|
||||||
self.context, new_l7rule)
|
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',
|
with mock.patch.object(nsx_db, 'get_nsx_lbaas_l7rule_binding',
|
||||||
) as mock_get_l7rule_binding, \
|
) as mock_get_l7rule_binding, \
|
||||||
mock.patch.object(self.rule_client, 'delete',
|
mock.patch.object(self.rule_client, 'delete',
|
||||||
|
Loading…
Reference in New Issue
Block a user