diff --git a/nova/conf/vmware.py b/nova/conf/vmware.py index 5f391cd317a5..63a5f04ea4aa 100644 --- a/nova/conf/vmware.py +++ b/nova/conf/vmware.py @@ -29,19 +29,6 @@ virtual machines. """) vmwareapi_vif_opts = [ - cfg.StrOpt('vlan_interface', - default='vmnic0', - help=""" -This option specifies the physical ethernet adapter name for VLAN -networking. - -Set the vlan_interface configuration option to match the ESX host -interface that handles VLAN-tagged VM traffic. - -Possible values: - -* Any valid string representing VLAN interface name -"""), cfg.StrOpt('integration_bridge', help=""" This option should be configured only when using the NSX-MH Neutron diff --git a/nova/exception.py b/nova/exception.py index 6da5c0544d28..52a600bf5937 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -573,19 +573,6 @@ class InvalidIpAddressError(Invalid): msg_fmt = _("%(address)s is not a valid IP v4/6 address.") -class InvalidVLANTag(Invalid): - msg_fmt = _("VLAN tag is not appropriate for the port group " - "%(bridge)s. Expected VLAN tag is %(tag)s, " - "but the one associated with the port group is %(pgroup)s.") - - -class InvalidVLANPortGroup(Invalid): - msg_fmt = _("vSwitch which contains the port group %(bridge)s is " - "not associated with the desired physical adapter. " - "Expected vSwitch is %(expected)s, but the one associated " - "is %(actual)s.") - - class InvalidDiskFormat(Invalid): msg_fmt = _("Disk format %(disk_format)s is not acceptable") @@ -1260,15 +1247,6 @@ class FileNotFound(NotFound): msg_fmt = _("File %(file_path)s could not be found.") -class SwitchNotFoundForNetworkAdapter(NotFound): - msg_fmt = _("Virtual switch associated with the " - "network adapter %(adapter)s not found.") - - -class NetworkAdapterNotFound(NotFound): - msg_fmt = _("Network adapter %(adapter)s could not be found.") - - class ClassNotFound(NotFound): msg_fmt = _("Class %(class_name)s could not be found: %(exception)s") diff --git a/nova/tests/unit/virt/vmwareapi/stubs.py b/nova/tests/unit/virt/vmwareapi/stubs.py index 41d5e38794eb..553f9ca8ed6f 100644 --- a/nova/tests/unit/virt/vmwareapi/stubs.py +++ b/nova/tests/unit/virt/vmwareapi/stubs.py @@ -78,7 +78,5 @@ def set_stubs(test): fake_vim_prop) test.stub_out('nova.virt.vmwareapi.driver.VMwareAPISession._is_vim_object', fake_is_vim_object) - if CONF.use_neutron: - test.stub_out( - 'nova.network.neutronv2.api.API.update_instance_vnic_index', - lambda *args, **kwargs: None) + test.stub_out('nova.network.neutronv2.api.API.update_instance_vnic_index', + lambda *args, **kwargs: None) diff --git a/nova/tests/unit/virt/vmwareapi/test_network_util.py b/nova/tests/unit/virt/vmwareapi/test_network_util.py index 9d6533ebfb00..10f258394629 100644 --- a/nova/tests/unit/virt/vmwareapi/test_network_util.py +++ b/nova/tests/unit/virt/vmwareapi/test_network_util.py @@ -19,13 +19,11 @@ import collections import mock from oslo_vmware import vim_util -from nova import exception from nova import test from nova.tests.unit.virt.vmwareapi import fake from nova.tests.unit.virt.vmwareapi import stubs from nova.virt.vmwareapi import driver from nova.virt.vmwareapi import network_util -from nova.virt.vmwareapi import vm_util ResultSet = collections.namedtuple('ResultSet', ['objects']) @@ -157,59 +155,6 @@ class GetNetworkWithTheNameTestCase(test.NoDBTestCase): self.assertIsNotNone(res) -class GetVlanIdAndVswitchForPortgroupTestCase(test.NoDBTestCase): - - @mock.patch.object(vm_util, 'get_host_ref') - def test_no_port_groups(self, mock_get_host_ref): - session = mock.Mock() - session._call_method.return_value = None - self.assertRaises( - exception.NovaException, - network_util.get_vlanid_and_vswitch_for_portgroup, - session, - 'port_group_name', - 'fake_cluster' - ) - - @mock.patch.object(vm_util, 'get_host_ref') - def test_valid_port_group(self, mock_get_host_ref): - session = mock.Mock() - session._call_method.return_value = self._fake_port_groups() - vlanid, vswitch = network_util.get_vlanid_and_vswitch_for_portgroup( - session, - 'port_group_name', - 'fake_cluster' - ) - self.assertEqual(vlanid, 100) - self.assertEqual(vswitch, 'vswitch_name') - - @mock.patch.object(vm_util, 'get_host_ref') - def test_unknown_port_group(self, mock_get_host_ref): - session = mock.Mock() - session._call_method.return_value = self._fake_port_groups() - vlanid, vswitch = network_util.get_vlanid_and_vswitch_for_portgroup( - session, - 'unknown_port_group', - 'fake_cluster' - ) - self.assertIsNone(vlanid) - self.assertIsNone(vswitch) - - def _fake_port_groups(self): - port_group_spec = fake.DataObject() - port_group_spec.name = 'port_group_name' - port_group_spec.vlanId = 100 - port_group_spec.vswitchName = 'vswitch_name' - - port_group = fake.DataObject() - port_group.vswitch = 'vswitch_name' - port_group.spec = port_group_spec - - response = fake.DataObject() - response.HostPortGroup = [port_group] - return response - - class GetDVSNetworkNameTestCase(test.NoDBTestCase): def test__get_name_from_dvs_name(self): diff --git a/nova/tests/unit/virt/vmwareapi/test_vif.py b/nova/tests/unit/virt/vmwareapi/test_vif.py index 869ff8ba8546..b0fb9df47c21 100644 --- a/nova/tests/unit/virt/vmwareapi/test_vif.py +++ b/nova/tests/unit/virt/vmwareapi/test_vif.py @@ -14,25 +14,21 @@ # under the License. import mock -from oslo_vmware import exceptions as vexc from oslo_vmware import vim_util from nova import exception from nova.network import model as network_model from nova import test -from nova.tests.unit import matchers from nova.tests.unit import utils from nova.tests.unit.virt.vmwareapi import fake from nova.virt.vmwareapi import constants from nova.virt.vmwareapi import network_util from nova.virt.vmwareapi import vif -from nova.virt.vmwareapi import vm_util class VMwareVifTestCase(test.NoDBTestCase): def setUp(self): super(VMwareVifTestCase, self).setUp() - self.flags(vlan_interface='vmnet0', group='vmware') network = network_model.Network(id=0, bridge='fa0', label='fake', @@ -52,181 +48,21 @@ class VMwareVifTestCase(test.NoDBTestCase): self.session = fake.FakeSession() self.cluster = None - @mock.patch.object(network_util, 'get_network_with_the_name', - return_value=None) - @mock.patch.object(network_util, 'get_vswitch_for_vlan_interface', - return_value='vmnet0') - @mock.patch.object(network_util, 'check_if_vlan_interface_exists', - return_value=True) - @mock.patch.object(network_util, 'create_port_group') - def test_ensure_vlan_bridge(self, - mock_create_port_group, - mock_check_if_vlan_exists, - mock_get_vswitch_for_vlan, - mock_get_network_with_name): - - vif.ensure_vlan_bridge(self.session, self.vif, create_vlan=True) - - expected_calls = [mock.call(self.session, 'fa0', self.cluster), - mock.call(self.session, 'fa0', None)] - mock_get_network_with_name.assert_has_calls(expected_calls) - self.assertEqual(2, mock_get_network_with_name.call_count) - mock_get_vswitch_for_vlan.assert_called_once_with( - self.session, 'vmnet0', self.cluster) - mock_check_if_vlan_exists.assert_called_once_with( - self.session, 'vmnet0', self.cluster) - mock_create_port_group.assert_called_once_with( - self.session, 'fa0', 'vmnet0', 3, self.cluster) - - # FlatDHCP network mode without vlan - network doesn't exist with the host - @mock.patch.object(network_util, 'get_network_with_the_name', - return_value=None) - @mock.patch.object(network_util, 'get_vswitch_for_vlan_interface', - return_value='vmnet0') - @mock.patch.object(network_util, 'check_if_vlan_interface_exists', - return_value=True) - @mock.patch.object(network_util, 'create_port_group') - def test_ensure_vlan_bridge_without_vlan(self, - mock_create_port_group, - mock_check_if_vlan_exists, - mock_get_vswitch_for_vlan, - mock_get_network_with_name): - vif.ensure_vlan_bridge(self.session, self.vif, create_vlan=False) - - expected_calls = [mock.call(self.session, 'fa0', self.cluster), - mock.call(self.session, 'fa0', None)] - mock_get_network_with_name.assert_has_calls(expected_calls) - self.assertEqual(2, mock_get_network_with_name.call_count) - mock_get_vswitch_for_vlan.assert_called_once_with( - self.session, 'vmnet0', self.cluster) - mock_check_if_vlan_exists.assert_called_once_with( - self.session, 'vmnet0', self.cluster) - mock_create_port_group.assert_called_once_with( - self.session, 'fa0', 'vmnet0', 0, self.cluster) - - # FlatDHCP network mode without vlan - network exists with the host - # Get vswitch and check vlan interface should not be called - @mock.patch.object(network_util, 'get_network_with_the_name') - @mock.patch.object(network_util, 'get_vswitch_for_vlan_interface') - @mock.patch.object(network_util, 'check_if_vlan_interface_exists') - @mock.patch.object(network_util, 'create_port_group') - def test_ensure_vlan_bridge_with_network(self, - mock_create_port_group, - mock_check_if_vlan_exists, - mock_get_vswitch_for_vlan, - mock_get_network_with_name - ): - vm_network = {'name': 'VM Network', 'type': 'Network'} - mock_get_network_with_name.return_value = vm_network - vif.ensure_vlan_bridge(self.session, self.vif, create_vlan=False) - mock_get_network_with_name.assert_called_once_with(self.session, - 'fa0', - self.cluster) - mock_check_if_vlan_exists.assert_not_called() - mock_get_vswitch_for_vlan.assert_not_called() - mock_create_port_group.assert_not_called() - - # Flat network mode with DVS - @mock.patch.object(network_util, 'get_network_with_the_name') - @mock.patch.object(network_util, 'get_vswitch_for_vlan_interface') - @mock.patch.object(network_util, 'check_if_vlan_interface_exists') - @mock.patch.object(network_util, 'create_port_group') - def test_ensure_vlan_bridge_with_existing_dvs(self, - mock_create_port_group, - mock_check_if_vlan_exists, - mock_get_vswitch_for_vlan, - mock_get_network_with_name - ): - network_ref = {'dvpg': 'dvportgroup-2062', - 'type': 'DistributedVirtualPortgroup'} - mock_get_network_with_name.return_value = network_ref - ref = vif.ensure_vlan_bridge(self.session, - self.vif, - create_vlan=False) - - self.assertThat(ref, matchers.DictMatches(network_ref)) - mock_get_network_with_name.assert_called_once_with(self.session, - 'fa0', - self.cluster) - mock_check_if_vlan_exists.assert_not_called() - mock_get_vswitch_for_vlan.assert_not_called() - mock_create_port_group.assert_not_called() - - @mock.patch.object(vif, 'ensure_vlan_bridge') - def test_get_network_ref_flat_dhcp(self, mock_ensure_vlan_bridge): - vif.get_network_ref(self.session, self.cluster, self.vif, False) - mock_ensure_vlan_bridge.assert_called_once_with( - self.session, self.vif, cluster=self.cluster, create_vlan=False) - - @mock.patch.object(vif, 'ensure_vlan_bridge') - def test_get_network_ref_bridge(self, mock_ensure_vlan_bridge): - network = network_model.Network(id=0, - bridge='fa0', - label='fake', - vlan=3, - bridge_interface='eth0', - injected=True, - should_create_vlan=True) - self.vif = network_model.NetworkInfo([ - network_model.VIF(id=None, - address='DE:AD:BE:EF:00:00', - network=network, - type=None, - devname=None, - ovs_interfaceid=None, - rxtx_cap=3) - ])[0] - vif.get_network_ref(self.session, self.cluster, self.vif, False) - mock_ensure_vlan_bridge.assert_called_once_with( - self.session, self.vif, cluster=self.cluster, create_vlan=True) - - def test_create_port_group_already_exists(self): - def fake_call_method(module, method, *args, **kwargs): - if method == 'AddPortGroup': - raise vexc.AlreadyExistsException() - - with test.nested( - mock.patch.object(vm_util, 'get_add_vswitch_port_group_spec'), - mock.patch.object(vm_util, 'get_host_ref'), - mock.patch.object(self.session, '_call_method', - fake_call_method) - ) as (_add_vswitch, _get_host, _call_method): - network_util.create_port_group(self.session, 'pg_name', - 'vswitch_name', vlan_id=0, - cluster=None) - - def test_create_port_group_exception(self): - def fake_call_method(module, method, *args, **kwargs): - if method == 'AddPortGroup': - raise vexc.VMwareDriverException() - - with test.nested( - mock.patch.object(vm_util, 'get_add_vswitch_port_group_spec'), - mock.patch.object(vm_util, 'get_host_ref'), - mock.patch.object(self.session, '_call_method', - fake_call_method) - ) as (_add_vswitch, _get_host, _call_method): - self.assertRaises(vexc.VMwareDriverException, - network_util.create_port_group, - self.session, 'pg_name', - 'vswitch_name', vlan_id=0, - cluster=None) - def test_get_vif_info_none(self): vif_info = vif.get_vif_info('fake_session', 'fake_cluster', - 'is_neutron', 'fake_model', None) + 'fake_model', None) self.assertEqual([], vif_info) def test_get_vif_info_empty_list(self): vif_info = vif.get_vif_info('fake_session', 'fake_cluster', - 'is_neutron', 'fake_model', []) + 'fake_model', []) self.assertEqual([], vif_info) @mock.patch.object(vif, 'get_network_ref', return_value='fake_ref') def test_get_vif_info(self, mock_get_network_ref): network_info = utils.get_test_network_info() vif_info = vif.get_vif_info('fake_session', 'fake_cluster', - 'is_neutron', 'fake_model', network_info) + 'fake_model', network_info) expected = [{'iface_id': utils.FAKE_VIF_UUID, 'mac_address': utils.FAKE_VIF_MAC, 'network_name': utils.FAKE_NETWORK_BRIDGE, @@ -235,17 +71,16 @@ class VMwareVifTestCase(test.NoDBTestCase): self.assertEqual(expected, vif_info) @mock.patch.object(vif, '_check_ovs_supported_version') - def test_get_neutron_network_ovs_integration_bridge(self, - mock_check): + def test_get_network_ref_ovs_integration_bridge(self, mock_check): self.flags(integration_bridge='fake-bridge-id', group='vmware') vif_info = network_model.NetworkInfo([ network_model.VIF(type=network_model.VIF_TYPE_OVS, address='DE:AD:BE:EF:00:00', network=self._network)] )[0] - network_ref = vif._get_neutron_network('fake-session', - 'fake-cluster', - vif_info) + network_ref = vif.get_network_ref('fake-session', + 'fake-cluster', + vif_info) expected_ref = {'type': 'OpaqueNetwork', 'network-id': 'fake-bridge-id', 'network-type': 'opaque', @@ -254,15 +89,15 @@ class VMwareVifTestCase(test.NoDBTestCase): mock_check.assert_called_once_with('fake-session') @mock.patch.object(vif, '_check_ovs_supported_version') - def test_get_neutron_network_ovs(self, mock_check): + def test_get_network_ref_ovs(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)] )[0] - network_ref = vif._get_neutron_network('fake-session', - 'fake-cluster', - vif_info) + network_ref = vif.get_network_ref('fake-session', + 'fake-cluster', + vif_info) expected_ref = {'type': 'OpaqueNetwork', 'network-id': 0, 'network-type': 'nsx.LogicalSwitch', @@ -271,7 +106,7 @@ class VMwareVifTestCase(test.NoDBTestCase): 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): + def test_get_network_ref_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', @@ -279,9 +114,9 @@ class VMwareVifTestCase(test.NoDBTestCase): details={'nsx-logical-switch-id': 'fake-nsx-id'})] )[0] - network_ref = vif._get_neutron_network('fake-session', - 'fake-cluster', - vif_info) + network_ref = vif.get_network_ref('fake-session', + 'fake-cluster', + vif_info) expected_ref = {'type': 'OpaqueNetwork', 'network-id': 'fake-nsx-id', 'network-type': 'nsx.LogicalSwitch', @@ -290,7 +125,7 @@ class VMwareVifTestCase(test.NoDBTestCase): 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): + def test_get_network_ref_dvs(self, mock_network_name): fake_network_obj = {'type': 'DistributedVirtualPortgroup', 'dvpg': 'fake-key', 'dvsw': 'fake-props'} @@ -300,16 +135,16 @@ class VMwareVifTestCase(test.NoDBTestCase): address='DE:AD:BE:EF:00:00', network=self._network)] )[0] - network_ref = vif._get_neutron_network('fake-session', - 'fake-cluster', - vif_info) + network_ref = vif.get_network_ref('fake-session', + 'fake-cluster', + vif_info) mock_network_name.assert_called_once_with('fake-session', 'fa0', 'fake-cluster') self.assertEqual(fake_network_obj, network_ref) @mock.patch.object(network_util, 'get_network_with_the_name') - def test_get_neutron_network_dvs_vif_details(self, mock_network_name): + def test_get_network_ref_dvs_vif_details(self, mock_network_name): fake_network_obj = {'type': 'DistributedVirtualPortgroup', 'dvpg': 'pg1', 'dvsw': 'fake-props'} @@ -320,9 +155,9 @@ class VMwareVifTestCase(test.NoDBTestCase): 'dvs_port_group_name': 'pg1'}, address='DE:AD:BE:EF:00:00', network=self._network)])[0] - network_ref = vif._get_neutron_network('fake-session', - 'fake-cluster', - vif_info) + network_ref = vif.get_network_ref('fake-session', + 'fake-cluster', + vif_info) mock_network_name.assert_called_once_with('fake-session', 'pg1', 'fake-cluster') @@ -330,25 +165,25 @@ class VMwareVifTestCase(test.NoDBTestCase): @mock.patch.object(network_util, 'get_network_with_the_name', return_value=None) - def test_get_neutron_network_dvs_no_match(self, mock_network_name): + def test_get_network_ref_dvs_no_match(self, mock_network_name): vif_info = network_model.NetworkInfo([ network_model.VIF(type=network_model.VIF_TYPE_DVS, address='DE:AD:BE:EF:00:00', network=self._network)] )[0] self.assertRaises(exception.NetworkNotFoundForBridge, - vif._get_neutron_network, + vif.get_network_ref, 'fake-session', 'fake-cluster', vif_info) - def test_get_neutron_network_invalid_type(self): + def test_get_network_ref_invalid_type(self): vif_info = network_model.NetworkInfo([ network_model.VIF(address='DE:AD:BE:EF:00:00', network=self._network)] )[0] self.assertRaises(exception.InvalidInput, - vif._get_neutron_network, + vif.get_network_ref, 'fake-session', 'fake-cluster', vif_info) @@ -368,7 +203,7 @@ class VMwareVifTestCase(test.NoDBTestCase): self.assertTrue(version_arg_found) @mock.patch.object(network_util, 'get_network_with_the_name') - def test_get_neutron_network_dvs_provider(self, mock_network_name): + def test_get_network_ref_dvs_provider(self, mock_network_name): fake_network_obj = {'type': 'DistributedVirtualPortgroup', 'dvpg': 'fake-key', 'dvsw': 'fake-props'} @@ -378,9 +213,9 @@ class VMwareVifTestCase(test.NoDBTestCase): address='DE:AD:BE:EF:00:00', network=self._network)] )[0] - network_ref = vif._get_neutron_network('fake-session', - 'fake-cluster', - vif_info) + network_ref = vif.get_network_ref('fake-session', + 'fake-cluster', + vif_info) calls = [mock.call('fake-session', 'fa0', 'fake-cluster')] mock_network_name.assert_has_calls(calls) self.assertEqual(fake_network_obj, network_ref) @@ -396,13 +231,13 @@ class VMwareVifTestCase(test.NoDBTestCase): )[0] self.assertRaises(exception.NetworkNotFoundForBridge, - vif._get_neutron_network, + vif.get_network_ref, 'fake-session', 'fake-cluster', vif_info) @mock.patch.object(network_util, 'get_network_with_the_name') - def test_get_neutron_network_dvs_with_dvs_pg_id(self, mock_network_name): + def test_get_network_ref_dvs_with_dvs_pg_id(self, mock_network_name): fake_network_obj = {'type': 'DistributedVirtualPortgroup', 'dvpg': 'fake-key', 'dvsw': 'fake-props'} @@ -417,9 +252,9 @@ class VMwareVifTestCase(test.NoDBTestCase): network=self._network, details=vif_details)] )[0] - network_ref = vif._get_neutron_network('fake-session', - 'fake-cluster', - vif_info) + network_ref = vif.get_network_ref('fake-session', + 'fake-cluster', + vif_info) fake_network_ref = {'type': 'DistributedVirtualPortgroup', 'dvpg': 'fake-key', diff --git a/nova/tests/unit/virt/vmwareapi/test_vmops.py b/nova/tests/unit/virt/vmwareapi/test_vmops.py index 28abbc81aca1..b0bd685f441e 100644 --- a/nova/tests/unit/virt/vmwareapi/test_vmops.py +++ b/nova/tests/unit/virt/vmwareapi/test_vmops.py @@ -36,7 +36,6 @@ from nova.tests.unit import fake_instance import nova.tests.unit.image.fake from nova.tests.unit.virt.vmwareapi import fake as vmwareapi_fake from nova.tests.unit.virt.vmwareapi import stubs -from nova import utils from nova import version from nova.virt import hardware from nova.virt.vmwareapi import constants @@ -1582,8 +1581,6 @@ class VMwareVMOpsTestCase(test.NoDBTestCase): 'nova.virt.vmwareapi.vmops.VMwareVMOps.get_datacenter_ref_and_name') @mock.patch('nova.virt.vmwareapi.vif.get_vif_info', return_value=[]) - @mock.patch('nova.utils.is_neutron', - return_value=False) @mock.patch('nova.virt.vmwareapi.vm_util.get_vm_create_spec', return_value='fake_create_spec') @mock.patch('nova.virt.vmwareapi.vm_util.create_vm', @@ -1606,7 +1603,6 @@ class VMwareVMOpsTestCase(test.NoDBTestCase): mock_mkdir, mock_create_vm, mock_get_create_spec, - mock_is_neutron, mock_get_vif_info, mock_get_datacenter_ref_and_name, mock_get_datastore, @@ -1665,12 +1661,10 @@ class VMwareVMOpsTestCase(test.NoDBTestCase): network_info=network_info, block_device_info=block_device_info) - mock_is_neutron.assert_called_once_with() - self.assertEqual(2, mock_mkdir.call_count) mock_get_vif_info.assert_called_once_with( - self._session, self._cluster.obj, False, + self._session, self._cluster.obj, constants.DEFAULT_VIF_MODEL, network_info) mock_get_create_spec.assert_called_once_with( self._session.vim.client.factory, @@ -2849,9 +2843,7 @@ class VMwareVMOpsTestCase(test.NoDBTestCase): self._vmops._network_api = _network_api vif_info = vif.get_vif_dict(self._session, self._cluster, - 'VirtualE1000', - utils.is_neutron(), - self._network_values) + 'VirtualE1000', self._network_values) extra_specs = vm_util.ExtraSpecs() mock_extra_specs.return_value = extra_specs self._vmops.attach_interface(self._context, self._instance, @@ -2955,9 +2947,7 @@ class VMwareVMOpsTestCase(test.NoDBTestCase): self._vmops._network_api = _network_api vif_info = vif.get_vif_dict(self._session, self._cluster, - 'VirtualE1000', - utils.is_neutron(), - self._network_values) + 'VirtualE1000', self._network_values) vif_limits = vm_util.Limits(shares_level='custom', shares_share=40) extra_specs = vm_util.ExtraSpecs(vif_limits=vif_limits) diff --git a/nova/virt/vmwareapi/network_util.py b/nova/virt/vmwareapi/network_util.py index f62ecd405f81..a6a84bfdb3e2 100644 --- a/nova/virt/vmwareapi/network_util.py +++ b/nova/virt/vmwareapi/network_util.py @@ -20,11 +20,8 @@ Utility functions for ESX Networking. import re from oslo_log import log as logging -from oslo_vmware import exceptions as vexc from oslo_vmware import vim_util as vutil -from nova import exception -from nova.i18n import _ from nova.virt.vmwareapi import vim_util from nova.virt.vmwareapi import vm_util @@ -116,99 +113,3 @@ def get_network_with_the_name(session, network_name="vmnet0", cluster=None): return network_obj LOG.debug("Network %s not found on cluster!", network_name) - - -def get_vswitch_for_vlan_interface(session, vlan_interface, cluster=None): - """Gets the vswitch associated with the physical network adapter - with the name supplied. - """ - # Get the list of vSwicthes on the Host System - host_mor = vm_util.get_host_ref(session, cluster) - vswitches_ret = session._call_method(vutil, - "get_object_property", - host_mor, - "config.network.vswitch") - # Meaning there are no vSwitches on the host. Shouldn't be the case, - # but just doing code check - if not vswitches_ret: - return - vswitches = vswitches_ret.HostVirtualSwitch - # Get the vSwitch associated with the network adapter - for elem in vswitches: - try: - for nic_elem in elem.pnic: - if str(nic_elem).split('-')[-1].find(vlan_interface) != -1: - return elem.name - # Catching Attribute error as a vSwitch may not be associated with a - # physical NIC. - except AttributeError: - pass - - -def check_if_vlan_interface_exists(session, vlan_interface, cluster=None): - """Checks if the vlan_interface exists on the esx host.""" - host_mor = vm_util.get_host_ref(session, cluster) - physical_nics_ret = session._call_method(vutil, - "get_object_property", - host_mor, - "config.network.pnic") - # Meaning there are no physical nics on the host - if not physical_nics_ret: - return False - physical_nics = physical_nics_ret.PhysicalNic - for pnic in physical_nics: - if vlan_interface == pnic.device: - return True - return False - - -def get_vlanid_and_vswitch_for_portgroup(session, pg_name, cluster=None): - """Get the vlan id and vswitch associated with the port group.""" - host_mor = vm_util.get_host_ref(session, cluster) - port_grps_on_host_ret = session._call_method(vutil, - "get_object_property", - host_mor, - "config.network.portgroup") - if not port_grps_on_host_ret: - msg = _("ESX SOAP server returned an empty port group " - "for the host system in its response") - LOG.error(msg) - raise exception.NovaException(msg) - port_grps_on_host = port_grps_on_host_ret.HostPortGroup - for p_gp in port_grps_on_host: - if p_gp.spec.name == pg_name: - p_grp_vswitch_name = p_gp.spec.vswitchName - return p_gp.spec.vlanId, p_grp_vswitch_name - return None, None - - -def create_port_group(session, pg_name, vswitch_name, vlan_id=0, cluster=None): - """Creates a port group on the host system with the vlan tags - supplied. VLAN id 0 means no vlan id association. - """ - client_factory = session.vim.client.factory - add_prt_grp_spec = vm_util.get_add_vswitch_port_group_spec( - client_factory, - vswitch_name, - pg_name, - vlan_id) - host_mor = vm_util.get_host_ref(session, cluster) - network_system_mor = session._call_method(vutil, - "get_object_property", - host_mor, - "configManager.networkSystem") - LOG.debug("Creating Port Group with name %s on " - "the ESX host", pg_name) - try: - session._call_method(session.vim, - "AddPortGroup", network_system_mor, - portgrp=add_prt_grp_spec) - except vexc.AlreadyExistsException: - # There can be a race condition when two instances try - # adding port groups at the same time. One succeeds, then - # the other one will get an exception. Since we are - # concerned with the port group being created, which is done - # by the other call, we can ignore the exception. - LOG.debug("Port Group %s already exists.", pg_name) - LOG.debug("Created Port Group with name %s on " - "the ESX host", pg_name) diff --git a/nova/virt/vmwareapi/vif.py b/nova/virt/vmwareapi/vif.py index bac2f3d23e67..49d7911289b8 100644 --- a/nova/virt/vmwareapi/vif.py +++ b/nova/virt/vmwareapi/vif.py @@ -31,64 +31,6 @@ LOG = logging.getLogger(__name__) CONF = nova.conf.CONF -def _get_associated_vswitch_for_interface(session, interface, cluster=None): - # Check if the physical network adapter exists on the host. - if not network_util.check_if_vlan_interface_exists(session, - interface, cluster): - raise exception.NetworkAdapterNotFound(adapter=interface) - # Get the vSwitch associated with the Physical Adapter - vswitch_associated = network_util.get_vswitch_for_vlan_interface( - session, interface, cluster) - if not vswitch_associated: - raise exception.SwitchNotFoundForNetworkAdapter(adapter=interface) - return vswitch_associated - - -def ensure_vlan_bridge(session, vif, cluster=None, create_vlan=True): - """Create a vlan and bridge unless they already exist.""" - vlan_num = vif['network'].get_meta('vlan') - bridge = vif['network']['bridge'] - vlan_interface = CONF.vmware.vlan_interface - - network_ref = network_util.get_network_with_the_name(session, bridge, - cluster) - if network_ref and network_ref['type'] == 'DistributedVirtualPortgroup': - return network_ref - - if not network_ref: - # Create a port group on the vSwitch associated with the - # vlan_interface corresponding physical network adapter on the ESX - # host. - vswitch_associated = _get_associated_vswitch_for_interface(session, - vlan_interface, cluster) - network_util.create_port_group(session, bridge, - vswitch_associated, - vlan_num if create_vlan else 0, - cluster) - network_ref = network_util.get_network_with_the_name(session, - bridge, - cluster) - elif create_vlan: - # Get the vSwitch associated with the Physical Adapter - vswitch_associated = _get_associated_vswitch_for_interface(session, - vlan_interface, cluster) - # Get the vlan id and vswitch corresponding to the port group - _get_pg_info = network_util.get_vlanid_and_vswitch_for_portgroup - pg_vlanid, pg_vswitch = _get_pg_info(session, bridge, cluster) - - # Check if the vswitch associated is proper - if pg_vswitch != vswitch_associated: - raise exception.InvalidVLANPortGroup( - bridge=bridge, expected=vswitch_associated, - actual=pg_vswitch) - - # Check if the vlan id is proper for the port group - if pg_vlanid != vlan_num: - raise exception.InvalidVLANTag(bridge=bridge, tag=vlan_num, - pgroup=pg_vlanid) - return network_ref - - def _check_ovs_supported_version(session): # The port type 'ovs' is only support by the VC version 5.5 onwards min_version = versionutils.convert_version_to_int( @@ -101,7 +43,7 @@ def _check_ovs_supported_version(session): {'version': constants.MIN_VC_OVS_VERSION}) -def _get_neutron_network(session, cluster, vif): +def get_network_ref(session, cluster, vif): if vif['type'] == model.VIF_TYPE_OVS: _check_ovs_supported_version(session) # Check if this is the NSX-MH plugin is used @@ -159,20 +101,10 @@ def _get_neutron_network(session, cluster, vif): return network_ref -def get_network_ref(session, cluster, vif, is_neutron): - if is_neutron: - network_ref = _get_neutron_network(session, cluster, vif) - else: - create_vlan = vif['network'].get_meta('should_create_vlan', False) - network_ref = ensure_vlan_bridge(session, vif, cluster=cluster, - create_vlan=create_vlan) - return network_ref - - -def get_vif_dict(session, cluster, vif_model, is_neutron, vif): +def get_vif_dict(session, cluster, vif_model, vif): mac = vif['address'] name = vif['network']['bridge'] or CONF.vmware.integration_bridge - ref = get_network_ref(session, cluster, vif, is_neutron) + ref = get_network_ref(session, cluster, vif) return {'network_name': name, 'mac_address': mac, 'network_ref': ref, @@ -180,13 +112,12 @@ def get_vif_dict(session, cluster, vif_model, is_neutron, vif): 'vif_model': vif_model} -def get_vif_info(session, cluster, is_neutron, vif_model, network_info): +def get_vif_info(session, cluster, vif_model, network_info): vif_infos = [] if network_info is None: return vif_infos for vif in network_info: - vif_infos.append(get_vif_dict(session, cluster, vif_model, - is_neutron, vif)) + vif_infos.append(get_vif_dict(session, cluster, vif_model, vif)) return vif_infos diff --git a/nova/virt/vmwareapi/vm_util.py b/nova/virt/vmwareapi/vm_util.py index 22820d5d8432..eecede0b8da7 100644 --- a/nova/virt/vmwareapi/vm_util.py +++ b/nova/virt/vmwareapi/vm_util.py @@ -1022,25 +1022,6 @@ def get_machine_id_change_spec(client_factory, machine_id_str): return virtual_machine_config_spec -def get_add_vswitch_port_group_spec(client_factory, vswitch_name, - port_group_name, vlan_id): - """Builds the virtual switch port group add spec.""" - vswitch_port_group_spec = client_factory.create('ns0:HostPortGroupSpec') - vswitch_port_group_spec.name = port_group_name - vswitch_port_group_spec.vswitchName = vswitch_name - - # VLAN ID of 0 means that VLAN tagging is not to be done for the network. - vswitch_port_group_spec.vlanId = int(vlan_id) - - policy = client_factory.create('ns0:HostNetworkPolicy') - nicteaming = client_factory.create('ns0:HostNicTeamingPolicy') - nicteaming.notifySwitches = True - policy.nicTeaming = nicteaming - - vswitch_port_group_spec.policy = policy - return vswitch_port_group_spec - - def get_vnc_config_spec(client_factory, port): """Builds the vnc config spec.""" virtual_machine_config_spec = client_factory.create( diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py index f96b242815df..ae6bd67c5587 100644 --- a/nova/virt/vmwareapi/vmops.py +++ b/nova/virt/vmwareapi/vmops.py @@ -274,7 +274,6 @@ class VMwareVMOps(object): metadata): vif_infos = vmwarevif.get_vif_info(self._session, self._cluster, - utils.is_neutron(), image_info.vif_model, network_info) LOG.debug('Instance VIF info %s', vif_infos, instance=instance) @@ -1644,7 +1643,7 @@ class VMwareVMOps(object): constants.DEFAULT_VIF_MODEL) for vif in network_info: vif_info = vmwarevif.get_vif_dict( - self._session, cluster_ref, vif_model, utils.is_neutron(), vif) + self._session, cluster_ref, vif_model, vif) device = vmwarevif.get_network_device(hardware_devices, vif['address']) devices.append(vm_util.update_vif_spec(client_factory, vif_info, @@ -1905,7 +1904,7 @@ class VMwareVMOps(object): constants.DEFAULT_VIF_MODEL) vif_model = vm_util.convert_vif_model(vif_model) vif_info = vmwarevif.get_vif_dict(self._session, self._cluster, - vif_model, utils.is_neutron(), vif) + vif_model, vif) vm_ref = vm_util.get_vm_ref(self._session, instance) # Ensure that there is not a race with the port index management with lockutils.lock(instance.uuid, diff --git a/releasenotes/notes/remove-nova-network-c02953ba72a1795d.yaml b/releasenotes/notes/remove-nova-network-c02953ba72a1795d.yaml index 459465538977..a6ff1ab073a9 100644 --- a/releasenotes/notes/remove-nova-network-c02953ba72a1795d.yaml +++ b/releasenotes/notes/remove-nova-network-c02953ba72a1795d.yaml @@ -54,3 +54,9 @@ upgrade: - | The ``nova-dhcpbridge`` service has been removed. This was only used with the now-removed *nova-network* service. + - | + The following config options only applied when using the *nova-network* + network driver which has now been removed. The config options have + therefore been removed also. + + * ``vmware.vlan_interface``