From ffbcb838c2779327f3a010d273078bfe390dc970 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Wed, 2 Sep 2015 04:04:54 -0700 Subject: [PATCH] Fix create router port with no IPs Even if a router port without IP cannot be used, Neutron allows for doing that as the IP can be updated at a later stage. This patch backport the fix already in master for not assuming a router port always has an IP upon creation. Change-Id: I99fba50cf9de243f84a9f7ce17e90aaa24168ccb --- vmware_nsx/neutron/plugins/vmware/common/nsx_utils.py | 2 ++ vmware_nsx/neutron/plugins/vmware/plugins/base.py | 6 ++++-- vmware_nsx/neutron/tests/unit/vmware/test_nsx_utils.py | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/vmware_nsx/neutron/plugins/vmware/common/nsx_utils.py b/vmware_nsx/neutron/plugins/vmware/common/nsx_utils.py index 242ae70d71..142386ee3a 100644 --- a/vmware_nsx/neutron/plugins/vmware/common/nsx_utils.py +++ b/vmware_nsx/neutron/plugins/vmware/common/nsx_utils.py @@ -174,6 +174,8 @@ def get_nsx_router_id(session, cluster, neutron_router_id): First, look up the Neutron database. If not found, execute a query on NSX platform as the mapping might be missing. """ + if not neutron_router_id: + return nsx_router_id = nsx_db.get_nsx_router_id( session, neutron_router_id) if not nsx_router_id: diff --git a/vmware_nsx/neutron/plugins/vmware/plugins/base.py b/vmware_nsx/neutron/plugins/vmware/plugins/base.py index 267cddc234..927a64fbf7 100644 --- a/vmware_nsx/neutron/plugins/vmware/plugins/base.py +++ b/vmware_nsx/neutron/plugins/vmware/plugins/base.py @@ -554,8 +554,10 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin, context.session, selected_lswitch['uuid'], port_data, False) # Assuming subnet being attached is on first fixed ip - # element in port data - subnet_id = port_data['fixed_ips'][0]['subnet_id'] + # element in port data - if specified + subnet_id = None + if port_data['fixed_ips']: + subnet_id = port_data['fixed_ips'][0]['subnet_id'] nsx_router_id = nsx_utils.get_nsx_router_id( context.session, self.cluster, port_data['device_id']) # Create peer port on logical router diff --git a/vmware_nsx/neutron/tests/unit/vmware/test_nsx_utils.py b/vmware_nsx/neutron/tests/unit/vmware/test_nsx_utils.py index 95ae3f13d9..efcb842cf7 100644 --- a/vmware_nsx/neutron/tests/unit/vmware/test_nsx_utils.py +++ b/vmware_nsx/neutron/tests/unit/vmware/test_nsx_utils.py @@ -85,7 +85,9 @@ class NsxUtilsTestCase(base.BaseTestCase): def _verify_get_nsx_router_id(self, exp_lr_uuid): # The nsxlib and db calls are mocked, therefore the cluster # and the neutron_router_id parameters can be set to None - lr_uuid = nsx_utils.get_nsx_router_id(db_api.get_session(), None, None) + neutron_router_id = uuidutils.generate_uuid() + lr_uuid = nsx_utils.get_nsx_router_id(db_api.get_session(), None, + neutron_router_id) self.assertEqual(exp_lr_uuid, lr_uuid) def test_get_nsx_switch_and_port_id_from_db_mappings(self):