From 9ca37ab19c6490c4c5929982d3b882a3506d6006 Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Wed, 24 Feb 2016 05:10:25 -0800 Subject: [PATCH] VMware: make the opaque network attachment more robust Ensure that the correct network ID is used when attaching the instance to the opaque network. Change-Id: I6bd615370075d44232d28f5ecebc34c08075daec Closes-bug: #1549288 Depends-On: Iea09105912f2a8d8766f02e71b45163e233a0eac --- nova/tests/unit/virt/vmwareapi/test_vif.py | 19 +++++++++++++++++++ nova/virt/vmwareapi/vif.py | 15 +++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/nova/tests/unit/virt/vmwareapi/test_vif.py b/nova/tests/unit/virt/vmwareapi/test_vif.py index 515f298e2fbf..0c81c32e08f7 100644 --- a/nova/tests/unit/virt/vmwareapi/test_vif.py +++ b/nova/tests/unit/virt/vmwareapi/test_vif.py @@ -250,6 +250,25 @@ class VMwareVifTestCase(test.NoDBTestCase): self.assertEqual(expected_ref, network_ref) mock_check.assert_called_once_with('fake-session') + @mock.patch.object(vif, '_check_ovs_supported_version') + def test_get_neutron_network_ovs_logical_switch_id(self, mock_check): + vif_info = network_model.NetworkInfo([ + network_model.VIF(type=network_model.VIF_TYPE_OVS, + address='DE:AD:BE:EF:00:00', + network=self._network, + details={'nsx-logical-switch-id': + 'fake-nsx-id'})] + )[0] + network_ref = vif._get_neutron_network('fake-session', + 'fake-cluster', + vif_info) + expected_ref = {'type': 'OpaqueNetwork', + 'network-id': 'fake-nsx-id', + 'network-type': 'nsx.LogicalSwitch', + 'use-external-id': True} + self.assertEqual(expected_ref, network_ref) + mock_check.assert_called_once_with('fake-session') + @mock.patch.object(network_util, 'get_network_with_the_name') def test_get_neutron_network_dvs(self, mock_network_name): fake_network_obj = {'type': 'DistributedVirtualPortgroup', diff --git a/nova/virt/vmwareapi/vif.py b/nova/virt/vmwareapi/vif.py index eb8882c11166..f56c5ad18a3f 100644 --- a/nova/virt/vmwareapi/vif.py +++ b/nova/virt/vmwareapi/vif.py @@ -21,7 +21,7 @@ from oslo_utils import versionutils from oslo_vmware import vim_util from nova import exception -from nova.i18n import _, _LW +from nova.i18n import _, _LI, _LW from nova.network import model from nova.virt.vmwareapi import constants from nova.virt.vmwareapi import network_util @@ -124,7 +124,18 @@ def _get_neutron_network(session, cluster, vif): use_external_id = False network_type = 'opaque' else: - net_id = vif['network']['id'] + # The NSX|V3 plugin will pass the nsx-logical-switch-id as part + # of the port details. This will enable the VC to connect to + # that specific opaque network + net_id = (vif.get('details') and + vif['details'].get('nsx-logical-switch-id')) + if not net_id: + # Make use of the original one, in the event that the + # plugin does not pass the aforementioned id + LOG.info(_LI('NSX Logical switch ID is not present. ' + 'Using network ID to attach to the ' + 'opaque network.')) + net_id = vif['network']['id'] use_external_id = True network_type = 'nsx.LogicalSwitch' network_ref = {'type': 'OpaqueNetwork',