diff --git a/vmware_nsx/services/lbaas/nsx_p/implementation/lb_utils.py b/vmware_nsx/services/lbaas/nsx_p/implementation/lb_utils.py index 6c70655da2..fa9457ca0f 100644 --- a/vmware_nsx/services/lbaas/nsx_p/implementation/lb_utils.py +++ b/vmware_nsx/services/lbaas/nsx_p/implementation/lb_utils.py @@ -167,7 +167,7 @@ def build_persistence_profile_tags(pool_tags, listener): # With octavia loadbalancer name might not be among data passed # down to the driver lb_data = listener.get('loadbalancer') - if lb_data: + if lb_data and lb_data.get('name'): tags.append({ 'scope': lb_const.LB_LB_NAME, 'tag': lb_data['name'][:utils.MAX_TAG_LEN]}) diff --git a/vmware_nsx/services/lbaas/nsx_p/implementation/listener_mgr.py b/vmware_nsx/services/lbaas/nsx_p/implementation/listener_mgr.py index 698626bdd9..b00f0982cc 100644 --- a/vmware_nsx/services/lbaas/nsx_p/implementation/listener_mgr.py +++ b/vmware_nsx/services/lbaas/nsx_p/implementation/listener_mgr.py @@ -39,12 +39,14 @@ class EdgeListenerManagerFromDict(base_mgr.NsxpLoadbalancerBaseManager): lb_const.LB_LISTENER_TYPE, listener.get('tenant_id'), context.project_name) - tags.append({ - 'scope': lb_const.LB_LB_NAME, - 'tag': listener['loadbalancer']['name'][:utils.MAX_TAG_LEN]}) + if listener['loadbalancer'].get('name'): + tags.append({ + 'scope': lb_const.LB_LB_NAME, + 'tag': listener['loadbalancer']['name'][:utils.MAX_TAG_LEN]}) tags.append({ 'scope': lb_const.LB_LB_TYPE, 'tag': listener['loadbalancer_id']}) + LOG.error("DEBUG ADIT _get_listener_tags end") return tags def _upload_certificate(self, listener_id, cert_href, tags, diff --git a/vmware_nsx/services/lbaas/nsx_v3/implementation/lb_utils.py b/vmware_nsx/services/lbaas/nsx_v3/implementation/lb_utils.py index b887831a86..c311ed4cd9 100644 --- a/vmware_nsx/services/lbaas/nsx_v3/implementation/lb_utils.py +++ b/vmware_nsx/services/lbaas/nsx_v3/implementation/lb_utils.py @@ -256,7 +256,7 @@ def build_persistence_profile_tags(pool_tags, listener): # With octavia loadbalancer name might not be among data passed # down to the driver lb_data = listener.get('loadbalancer') - if lb_data: + if lb_data and lb_data.get('name'): tags.append({ 'scope': lb_const.LB_LB_NAME, 'tag': lb_data['name'][:utils.MAX_TAG_LEN]}) diff --git a/vmware_nsx/services/lbaas/nsx_v3/implementation/listener_mgr.py b/vmware_nsx/services/lbaas/nsx_v3/implementation/listener_mgr.py index 4b723f62f9..2fa0079bdf 100644 --- a/vmware_nsx/services/lbaas/nsx_v3/implementation/listener_mgr.py +++ b/vmware_nsx/services/lbaas/nsx_v3/implementation/listener_mgr.py @@ -104,9 +104,10 @@ class EdgeListenerManagerFromDict(base_mgr.Nsxv3LoadbalancerBaseManager): lb_const.LB_LISTENER_TYPE, listener['tenant_id'], context.project_name) - tags.append({ - 'scope': lb_const.LB_LB_NAME, - 'tag': listener['loadbalancer']['name'][:utils.MAX_TAG_LEN]}) + if listener['loadbalancer'].get('name'): + tags.append({ + 'scope': lb_const.LB_LB_NAME, + 'tag': listener['loadbalancer']['name'][:utils.MAX_TAG_LEN]}) tags.append({ 'scope': lb_const.LB_LB_TYPE, 'tag': listener['loadbalancer_id']}) diff --git a/vmware_nsx/tests/unit/services/lbaas/test_nsxp_driver.py b/vmware_nsx/tests/unit/services/lbaas/test_nsxp_driver.py index c184317916..f23b62c9ea 100644 --- a/vmware_nsx/tests/unit/services/lbaas/test_nsxp_driver.py +++ b/vmware_nsx/tests/unit/services/lbaas/test_nsxp_driver.py @@ -13,7 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import copy + import mock + from neutron.tests import base from neutron_lbaas.services.loadbalancer import data_models as lb_models from neutron_lib import context @@ -893,6 +896,38 @@ class TestEdgeLbaasV2Listener(BaseTestEdgeLbaasV2): self.context, listener_dict, self.completor) + def test_create_listener_lb_no_name(self, protocol='HTTP'): + self.reset_completor() + with mock.patch.object(self.core_plugin, 'get_floatingips' + ) as mock_get_floatingips, \ + mock.patch.object(self.core_plugin, + 'get_waf_profile_path_and_mode', + return_value=(None, None)), \ + mock.patch.object(self.vs_client, 'create_or_overwrite' + ) as mock_add_virtual_server: + mock_get_floatingips.return_value = [] + listener = copy.deepcopy(self.listener_dict) + listener['loadbalancer']['name'] = None + listener_id = LISTENER_ID + + self.edge_driver.listener.create(self.context, listener, + self.completor) + + mock_add_virtual_server.assert_called_with( + application_profile_id=listener_id, + description=listener['description'], + lb_service_id=LB_ID, + ip_address=LB_VIP, + tags=mock.ANY, + name=mock.ANY, + ports=[listener['protocol_port']], + max_concurrent_connections=None, + virtual_server_id=listener_id, + pool_id='', + lb_persistence_profile_id='') + self.assertTrue(self.last_completor_called) + self.assertTrue(self.last_completor_succees) + def test_update(self): new_listener = lb_models.Listener(LISTENER_ID, LB_TENANT_ID, 'listener1-new', 'new-description',