From 5ecfa674082920356b844e861e4ca3edfe66e98e Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Mon, 25 Nov 2019 11:01:08 +0000 Subject: [PATCH] hyperv: Remove vestigial nova-network support Remove the last few references to nova-net from the Hyper-V driver, simplifying some of the code in the process. Change-Id: I170d57f834e0a0e2b373eb98a15c52a052a6bce1 Signed-off-by: Stephen Finucane --- nova/tests/unit/virt/hyperv/test_vif.py | 39 +----------------- nova/tests/unit/virt/hyperv/test_vmops.py | 8 +--- nova/virt/hyperv/vif.py | 49 ++--------------------- nova/virt/hyperv/vmops.py | 7 ++-- 4 files changed, 11 insertions(+), 92 deletions(-) diff --git a/nova/tests/unit/virt/hyperv/test_vif.py b/nova/tests/unit/virt/hyperv/test_vif.py index 5f8da6a2aa4d..c1f5951b7997 100644 --- a/nova/tests/unit/virt/hyperv/test_vif.py +++ b/nova/tests/unit/virt/hyperv/test_vif.py @@ -25,50 +25,17 @@ from nova.virt.hyperv import vif CONF = nova.conf.CONF -class HyperVNovaNetworkVIFPluginTestCase(test_base.HyperVBaseTestCase): - def setUp(self): - super(HyperVNovaNetworkVIFPluginTestCase, self).setUp() - self.vif_driver = vif.HyperVNovaNetworkVIFPlugin() - - def test_plug(self): - self.flags(vswitch_name='fake_vswitch_name', group='hyperv') - fake_vif = {'id': mock.sentinel.fake_id} - - self.vif_driver.plug(mock.sentinel.instance, fake_vif) - netutils = self.vif_driver._netutils - netutils.connect_vnic_to_vswitch.assert_called_once_with( - 'fake_vswitch_name', mock.sentinel.fake_id) - - class HyperVVIFDriverTestCase(test_base.HyperVBaseTestCase): def setUp(self): super(HyperVVIFDriverTestCase, self).setUp() self.vif_driver = vif.HyperVVIFDriver() self.vif_driver._netutils = mock.MagicMock() - self.vif_driver._vif_plugin = mock.MagicMock() - - @mock.patch.object(vif.nova.network, 'is_neutron') - def test_init_neutron(self, mock_is_neutron): - mock_is_neutron.return_value = True - - driver = vif.HyperVVIFDriver() - self.assertIsInstance(driver._vif_plugin, vif.HyperVNeutronVIFPlugin) - - @mock.patch.object(vif.nova.network, 'is_neutron') - def test_init_nova(self, mock_is_neutron): - mock_is_neutron.return_value = False - - driver = vif.HyperVVIFDriver() - self.assertIsInstance(driver._vif_plugin, - vif.HyperVNovaNetworkVIFPlugin) def test_plug(self): vif = {'type': model.VIF_TYPE_HYPERV} + # this is handled by neutron so just assert it doesn't blow up self.vif_driver.plug(mock.sentinel.instance, vif) - self.vif_driver._vif_plugin.plug.assert_called_once_with( - mock.sentinel.instance, vif) - @mock.patch.object(vif, 'os_vif') @mock.patch.object(vif.os_vif_util, 'nova_to_osvif_instance') @mock.patch.object(vif.os_vif_util, 'nova_to_osvif_vif') @@ -95,11 +62,9 @@ class HyperVVIFDriverTestCase(test_base.HyperVBaseTestCase): def test_unplug(self): vif = {'type': model.VIF_TYPE_HYPERV} + # this is handled by neutron so just assert it doesn't blow up self.vif_driver.unplug(mock.sentinel.instance, vif) - self.vif_driver._vif_plugin.unplug.assert_called_once_with( - mock.sentinel.instance, vif) - @mock.patch.object(vif, 'os_vif') @mock.patch.object(vif.os_vif_util, 'nova_to_osvif_instance') @mock.patch.object(vif.os_vif_util, 'nova_to_osvif_vif') diff --git a/nova/tests/unit/virt/hyperv/test_vmops.py b/nova/tests/unit/virt/hyperv/test_vmops.py index 5094ca29e20e..ed2f7c243a0a 100644 --- a/nova/tests/unit/virt/hyperv/test_vmops.py +++ b/nova/tests/unit/virt/hyperv/test_vmops.py @@ -517,8 +517,7 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase): self._vmops._neutron_failed_callback, mock.sentinel.event_name, mock.sentinel.instance) - @mock.patch.object(vmops.utils, 'is_neutron') - def test_get_neutron_events(self, mock_is_neutron): + def test_get_neutron_events(self): network_info = [{'id': mock.sentinel.vif_id1, 'active': True}, {'id': mock.sentinel.vif_id2, 'active': False}, {'id': mock.sentinel.vif_id3}] @@ -526,16 +525,13 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase): events = self._vmops._get_neutron_events(network_info) self.assertEqual([('network-vif-plugged', mock.sentinel.vif_id2)], events) - mock_is_neutron.assert_called_once_with() - @mock.patch.object(vmops.utils, 'is_neutron') - def test_get_neutron_events_no_timeout(self, mock_is_neutron): + def test_get_neutron_events_no_timeout(self): self.flags(vif_plugging_timeout=0) network_info = [{'id': mock.sentinel.vif_id1, 'active': True}] events = self._vmops._get_neutron_events(network_info) self.assertEqual([], events) - mock_is_neutron.assert_called_once_with() @mock.patch.object(vmops.VMOps, '_attach_pci_devices') @mock.patch.object(vmops.VMOps, '_requires_secure_boot') diff --git a/nova/virt/hyperv/vif.py b/nova/virt/hyperv/vif.py index 4b21bda7491a..5cff9cbaade4 100644 --- a/nova/virt/hyperv/vif.py +++ b/nova/virt/hyperv/vif.py @@ -14,8 +14,6 @@ # License for the specific language governing permissions and limitations # under the License. -import abc - import os_vif from os_win import utilsfactory @@ -28,55 +26,15 @@ from nova.network import os_vif_util CONF = nova.conf.CONF -class HyperVBaseVIFPlugin(object): - @abc.abstractmethod - def plug(self, instance, vif): - pass - - @abc.abstractmethod - def unplug(self, instance, vif): - pass - - -class HyperVNeutronVIFPlugin(HyperVBaseVIFPlugin): - """Neutron VIF plugin.""" - - def plug(self, instance, vif): - # Neutron takes care of plugging the port - pass - - def unplug(self, instance, vif): - # Neutron takes care of unplugging the port - pass - - -class HyperVNovaNetworkVIFPlugin(HyperVBaseVIFPlugin): - """Nova network VIF plugin.""" - - def __init__(self): - self._netutils = utilsfactory.get_networkutils() - - def plug(self, instance, vif): - self._netutils.connect_vnic_to_vswitch(CONF.hyperv.vswitch_name, - vif['id']) - - def unplug(self, instance, vif): - # TODO(alepilotti) Not implemented - pass - - class HyperVVIFDriver(object): def __init__(self): self._netutils = utilsfactory.get_networkutils() - if nova.network.is_neutron(): - self._vif_plugin = HyperVNeutronVIFPlugin() - else: - self._vif_plugin = HyperVNovaNetworkVIFPlugin() def plug(self, instance, vif): vif_type = vif['type'] if vif_type == model.VIF_TYPE_HYPERV: - self._vif_plugin.plug(instance, vif) + # neutron takes care of plugging the port + pass elif vif_type == model.VIF_TYPE_OVS: vif = os_vif_util.nova_to_osvif_vif(vif) instance = os_vif_util.nova_to_osvif_instance(instance) @@ -94,7 +52,8 @@ class HyperVVIFDriver(object): def unplug(self, instance, vif): vif_type = vif['type'] if vif_type == model.VIF_TYPE_HYPERV: - self._vif_plugin.unplug(instance, vif) + # neutron takes care of unplugging the port + pass elif vif_type == model.VIF_TYPE_OVS: vif = os_vif_util.nova_to_osvif_vif(vif) instance = os_vif_util.nova_to_osvif_instance(instance) diff --git a/nova/virt/hyperv/vmops.py b/nova/virt/hyperv/vmops.py index cecf28d64977..356e6fc07eb6 100644 --- a/nova/virt/hyperv/vmops.py +++ b/nova/virt/hyperv/vmops.py @@ -41,7 +41,6 @@ from nova import exception from nova.i18n import _ from nova import objects from nova.objects import fields -from nova import utils from nova.virt import configdrive from nova.virt import hardware from nova.virt.hyperv import block_device_manager @@ -345,11 +344,11 @@ class VMOps(object): # already up will not undergo that transition, and for # anything that might be stale (cache-wise) assume it's # already up so we don't block on it. - if utils.is_neutron() and CONF.vif_plugging_timeout: + if CONF.vif_plugging_timeout: return [('network-vif-plugged', vif['id']) for vif in network_info if vif.get('active') is False] - else: - return [] + + return [] def create_instance(self, instance, network_info, root_device, block_device_info, vm_gen, image_meta):