NSX|P: Fix listener create & update

Use tags to find the lb service id from the loadbalancer id

Change-Id: Ic6a756aaa98c27362d34f3eff488864a4eedd036
(cherry picked from commit 4d5cbfd7a1)
This commit is contained in:
asarfaty 2020-07-01 15:58:01 +02:00 committed by Adit Sarfaty
parent cf10c49b56
commit 13f7c3b795
2 changed files with 31 additions and 1 deletions

View File

@ -91,11 +91,14 @@ class EdgeListenerManagerFromDict(base_mgr.NsxpLoadbalancerBaseManager):
lb_vip_address = floating_ips[0]['floating_ip_address'] lb_vip_address = floating_ips[0]['floating_ip_address']
else: else:
lb_vip_address = listener['loadbalancer']['vip_address'] lb_vip_address = listener['loadbalancer']['vip_address']
lb_service = lb_utils.get_lb_nsx_lb_service(
self.core_plugin.nsxpolicy, listener['loadbalancer_id'])
kwargs = {'virtual_server_id': listener['id'], kwargs = {'virtual_server_id': listener['id'],
'ip_address': lb_vip_address, 'ip_address': lb_vip_address,
'ports': [listener['protocol_port']], 'ports': [listener['protocol_port']],
'application_profile_id': listener['id'], 'application_profile_id': listener['id'],
'lb_service_id': listener['loadbalancer_id'], 'lb_service_id': lb_service['id'],
'description': listener.get('description')} 'description': listener.get('description')}
if vs_name: if vs_name:
kwargs['name'] = vs_name kwargs['name'] = vs_name

View File

@ -717,6 +717,9 @@ class TestEdgeLbaasV2Listener(BaseTestEdgeLbaasV2):
mock.patch.object(self.core_plugin, mock.patch.object(self.core_plugin,
'get_waf_profile_path_and_mode', 'get_waf_profile_path_and_mode',
return_value=(None, None)), \ return_value=(None, None)), \
mock.patch.object(self.core_plugin.nsxpolicy, 'search_by_tags',
return_value={'results': [
{'id': LB_SERVICE_ID}]}),\
mock.patch.object(self.vs_client, 'create_or_overwrite' mock.patch.object(self.vs_client, 'create_or_overwrite'
) as mock_add_virtual_server: ) as mock_add_virtual_server:
mock_get_floatingips.return_value = [] mock_get_floatingips.return_value = []
@ -758,6 +761,9 @@ class TestEdgeLbaasV2Listener(BaseTestEdgeLbaasV2):
mock.patch.object(self.core_plugin, mock.patch.object(self.core_plugin,
'get_waf_profile_path_and_mode', 'get_waf_profile_path_and_mode',
return_value=(None, None)), \ return_value=(None, None)), \
mock.patch.object(self.core_plugin.nsxpolicy, 'search_by_tags',
return_value={'results': [
{'id': LB_SERVICE_ID}]}),\
mock.patch.object(self.vs_client, 'create_or_overwrite' mock.patch.object(self.vs_client, 'create_or_overwrite'
) as mock_add_virtual_server: ) as mock_add_virtual_server:
mock_get_floatingips.return_value = [] mock_get_floatingips.return_value = []
@ -793,6 +799,9 @@ class TestEdgeLbaasV2Listener(BaseTestEdgeLbaasV2):
mock.patch.object(self.core_plugin, mock.patch.object(self.core_plugin,
'get_waf_profile_path_and_mode', 'get_waf_profile_path_and_mode',
return_value=(None, None)), \ return_value=(None, None)), \
mock.patch.object(self.core_plugin.nsxpolicy, 'search_by_tags',
return_value={'results': [
{'id': LB_SERVICE_ID}]}),\
mock.patch.object(self.vs_client, 'create_or_overwrite' mock.patch.object(self.vs_client, 'create_or_overwrite'
) as mock_add_virtual_server: ) as mock_add_virtual_server:
mock_get_floatingips.return_value = [] mock_get_floatingips.return_value = []
@ -850,6 +859,9 @@ class TestEdgeLbaasV2Listener(BaseTestEdgeLbaasV2):
return_value=(None, None)), \ return_value=(None, None)), \
mock.patch.object(self.vs_client, 'create_or_overwrite' mock.patch.object(self.vs_client, 'create_or_overwrite'
) as mock_add_virtual_server,\ ) as mock_add_virtual_server,\
mock.patch.object(self.core_plugin.nsxpolicy, 'search_by_tags',
return_value={'results': [
{'id': LB_SERVICE_ID}]}),\
mock.patch.object(self.vs_client, 'get', return_value={}),\ mock.patch.object(self.vs_client, 'get', return_value={}),\
mock.patch.object(self.edge_driver.listener, '_get_pool_tags'),\ mock.patch.object(self.edge_driver.listener, '_get_pool_tags'),\
mock.patch.object(self.pp_cookie_client, 'create_or_overwrite' mock.patch.object(self.pp_cookie_client, 'create_or_overwrite'
@ -900,6 +912,9 @@ class TestEdgeLbaasV2Listener(BaseTestEdgeLbaasV2):
mock.patch.object(self.core_plugin, mock.patch.object(self.core_plugin,
'get_waf_profile_path_and_mode', 'get_waf_profile_path_and_mode',
return_value=(None, None)), \ return_value=(None, None)), \
mock.patch.object(self.core_plugin.nsxpolicy, 'search_by_tags',
return_value={'results': [
{'id': LB_SERVICE_ID}]}),\
mock.patch.object(self.vs_client, 'create_or_overwrite' mock.patch.object(self.vs_client, 'create_or_overwrite'
) as mock_add_virtual_server: ) as mock_add_virtual_server:
mock_get_floatingips.return_value = [] mock_get_floatingips.return_value = []
@ -935,6 +950,9 @@ class TestEdgeLbaasV2Listener(BaseTestEdgeLbaasV2):
with mock.patch.object(self.core_plugin, with mock.patch.object(self.core_plugin,
'get_waf_profile_path_and_mode', 'get_waf_profile_path_and_mode',
return_value=(None, None)), \ return_value=(None, None)), \
mock.patch.object(self.core_plugin.nsxpolicy, 'search_by_tags',
return_value={'results': [
{'id': LB_SERVICE_ID}]}),\
mock.patch.object(self.core_plugin, 'get_floatingips' mock.patch.object(self.core_plugin, 'get_floatingips'
) as mock_get_floatingips: ) as mock_get_floatingips:
mock_get_floatingips.return_value = [] mock_get_floatingips.return_value = []
@ -957,6 +975,9 @@ class TestEdgeLbaasV2Listener(BaseTestEdgeLbaasV2):
with mock.patch.object(self.core_plugin, with mock.patch.object(self.core_plugin,
'get_waf_profile_path_and_mode', 'get_waf_profile_path_and_mode',
return_value=(None, None)), \ return_value=(None, None)), \
mock.patch.object(self.core_plugin.nsxpolicy, 'search_by_tags',
return_value={'results': [
{'id': LB_SERVICE_ID}]}),\
mock.patch.object(self.core_plugin, 'get_floatingips' mock.patch.object(self.core_plugin, 'get_floatingips'
) as mock_get_floatingips: ) as mock_get_floatingips:
mock_get_floatingips.return_value = [] mock_get_floatingips.return_value = []
@ -981,6 +1002,9 @@ class TestEdgeLbaasV2Listener(BaseTestEdgeLbaasV2):
mock.patch.object(self.core_plugin, mock.patch.object(self.core_plugin,
'get_waf_profile_path_and_mode', 'get_waf_profile_path_and_mode',
return_value=(None, None)), \ return_value=(None, None)), \
mock.patch.object(self.core_plugin.nsxpolicy, 'search_by_tags',
return_value={'results': [
{'id': LB_SERVICE_ID}]}),\
mock.patch.object(self.edge_driver.listener, '_get_pool_tags'),\ mock.patch.object(self.edge_driver.listener, '_get_pool_tags'),\
mock.patch.object(self.vs_client, 'get', return_value={}),\ mock.patch.object(self.vs_client, 'get', return_value={}),\
mock.patch.object(self.vs_client, 'update', mock.patch.object(self.vs_client, 'update',
@ -1030,6 +1054,9 @@ class TestEdgeLbaasV2Listener(BaseTestEdgeLbaasV2):
) as mock_create_pp, \ ) as mock_create_pp, \
mock.patch.object(self.pp_generic_client, 'delete' mock.patch.object(self.pp_generic_client, 'delete'
) as mock_delete_pp, \ ) as mock_delete_pp, \
mock.patch.object(self.core_plugin.nsxpolicy, 'search_by_tags',
return_value={'results': [
{'id': LB_SERVICE_ID}]}),\
mock.patch.object(self.core_plugin, 'get_floatingips' mock.patch.object(self.core_plugin, 'get_floatingips'
) as mock_get_floatingips, \ ) as mock_get_floatingips, \
mock.patch.object(self.edge_driver.listener, mock.patch.object(self.edge_driver.listener,