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 <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane 2019-11-25 11:01:08 +00:00
parent 913679d7e3
commit 5ecfa67408
4 changed files with 11 additions and 92 deletions

View File

@ -25,50 +25,17 @@ from nova.virt.hyperv import vif
CONF = nova.conf.CONF 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): class HyperVVIFDriverTestCase(test_base.HyperVBaseTestCase):
def setUp(self): def setUp(self):
super(HyperVVIFDriverTestCase, self).setUp() super(HyperVVIFDriverTestCase, self).setUp()
self.vif_driver = vif.HyperVVIFDriver() self.vif_driver = vif.HyperVVIFDriver()
self.vif_driver._netutils = mock.MagicMock() 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): def test_plug(self):
vif = {'type': model.VIF_TYPE_HYPERV} 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.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')
@mock.patch.object(vif.os_vif_util, 'nova_to_osvif_instance') @mock.patch.object(vif.os_vif_util, 'nova_to_osvif_instance')
@mock.patch.object(vif.os_vif_util, 'nova_to_osvif_vif') @mock.patch.object(vif.os_vif_util, 'nova_to_osvif_vif')
@ -95,11 +62,9 @@ class HyperVVIFDriverTestCase(test_base.HyperVBaseTestCase):
def test_unplug(self): def test_unplug(self):
vif = {'type': model.VIF_TYPE_HYPERV} 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.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')
@mock.patch.object(vif.os_vif_util, 'nova_to_osvif_instance') @mock.patch.object(vif.os_vif_util, 'nova_to_osvif_instance')
@mock.patch.object(vif.os_vif_util, 'nova_to_osvif_vif') @mock.patch.object(vif.os_vif_util, 'nova_to_osvif_vif')

View File

@ -517,8 +517,7 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
self._vmops._neutron_failed_callback, self._vmops._neutron_failed_callback,
mock.sentinel.event_name, mock.sentinel.instance) mock.sentinel.event_name, mock.sentinel.instance)
@mock.patch.object(vmops.utils, 'is_neutron') def test_get_neutron_events(self):
def test_get_neutron_events(self, mock_is_neutron):
network_info = [{'id': mock.sentinel.vif_id1, 'active': True}, network_info = [{'id': mock.sentinel.vif_id1, 'active': True},
{'id': mock.sentinel.vif_id2, 'active': False}, {'id': mock.sentinel.vif_id2, 'active': False},
{'id': mock.sentinel.vif_id3}] {'id': mock.sentinel.vif_id3}]
@ -526,16 +525,13 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
events = self._vmops._get_neutron_events(network_info) events = self._vmops._get_neutron_events(network_info)
self.assertEqual([('network-vif-plugged', mock.sentinel.vif_id2)], self.assertEqual([('network-vif-plugged', mock.sentinel.vif_id2)],
events) events)
mock_is_neutron.assert_called_once_with()
@mock.patch.object(vmops.utils, 'is_neutron') def test_get_neutron_events_no_timeout(self):
def test_get_neutron_events_no_timeout(self, mock_is_neutron):
self.flags(vif_plugging_timeout=0) self.flags(vif_plugging_timeout=0)
network_info = [{'id': mock.sentinel.vif_id1, 'active': True}] network_info = [{'id': mock.sentinel.vif_id1, 'active': True}]
events = self._vmops._get_neutron_events(network_info) events = self._vmops._get_neutron_events(network_info)
self.assertEqual([], events) self.assertEqual([], events)
mock_is_neutron.assert_called_once_with()
@mock.patch.object(vmops.VMOps, '_attach_pci_devices') @mock.patch.object(vmops.VMOps, '_attach_pci_devices')
@mock.patch.object(vmops.VMOps, '_requires_secure_boot') @mock.patch.object(vmops.VMOps, '_requires_secure_boot')

View File

@ -14,8 +14,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import abc
import os_vif import os_vif
from os_win import utilsfactory from os_win import utilsfactory
@ -28,55 +26,15 @@ from nova.network import os_vif_util
CONF = nova.conf.CONF 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): class HyperVVIFDriver(object):
def __init__(self): def __init__(self):
self._netutils = utilsfactory.get_networkutils() self._netutils = utilsfactory.get_networkutils()
if nova.network.is_neutron():
self._vif_plugin = HyperVNeutronVIFPlugin()
else:
self._vif_plugin = HyperVNovaNetworkVIFPlugin()
def plug(self, instance, vif): def plug(self, instance, vif):
vif_type = vif['type'] vif_type = vif['type']
if vif_type == model.VIF_TYPE_HYPERV: 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: elif vif_type == model.VIF_TYPE_OVS:
vif = os_vif_util.nova_to_osvif_vif(vif) vif = os_vif_util.nova_to_osvif_vif(vif)
instance = os_vif_util.nova_to_osvif_instance(instance) instance = os_vif_util.nova_to_osvif_instance(instance)
@ -94,7 +52,8 @@ class HyperVVIFDriver(object):
def unplug(self, instance, vif): def unplug(self, instance, vif):
vif_type = vif['type'] vif_type = vif['type']
if vif_type == model.VIF_TYPE_HYPERV: 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: elif vif_type == model.VIF_TYPE_OVS:
vif = os_vif_util.nova_to_osvif_vif(vif) vif = os_vif_util.nova_to_osvif_vif(vif)
instance = os_vif_util.nova_to_osvif_instance(instance) instance = os_vif_util.nova_to_osvif_instance(instance)

View File

@ -41,7 +41,6 @@ from nova import exception
from nova.i18n import _ from nova.i18n import _
from nova import objects from nova import objects
from nova.objects import fields from nova.objects import fields
from nova import utils
from nova.virt import configdrive from nova.virt import configdrive
from nova.virt import hardware from nova.virt import hardware
from nova.virt.hyperv import block_device_manager from nova.virt.hyperv import block_device_manager
@ -345,10 +344,10 @@ class VMOps(object):
# already up will not undergo that transition, and for # already up will not undergo that transition, and for
# anything that might be stale (cache-wise) assume it's # anything that might be stale (cache-wise) assume it's
# already up so we don't block on it. # 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']) return [('network-vif-plugged', vif['id'])
for vif in network_info if vif.get('active') is False] for vif in network_info if vif.get('active') is False]
else:
return [] return []
def create_instance(self, instance, network_info, root_device, def create_instance(self, instance, network_info, root_device,