nova-net: Copy shared utils from nova-net module
This will allow us to remove the linux_net module in its entirety shortly. Change-Id: I46ca734f83a509b1a11d83a28039588899dd21d1 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
parent
9b321e41f6
commit
656c18eaf2
|
@ -25,7 +25,6 @@ from oslo_utils.fixture import uuidsentinel as uuids
|
|||
import six
|
||||
|
||||
from nova import exception
|
||||
from nova.network import linux_net
|
||||
from nova.network import model as network_model
|
||||
from nova import objects
|
||||
from nova.pci import utils as pci_utils
|
||||
|
@ -1000,13 +999,13 @@ class LibvirtVifTestCase(test.NoDBTestCase):
|
|||
d = vif.LibvirtGenericVIFDriver()
|
||||
self._test_hw_veb_op(d.unplug, 0)
|
||||
|
||||
@mock.patch('nova.network.linux_net.set_vf_trusted')
|
||||
@mock.patch('nova.virt.libvirt.vif.set_vf_trusted')
|
||||
def test_plug_hw_veb_trusted(self, mset_vf_trusted):
|
||||
d = vif.LibvirtGenericVIFDriver()
|
||||
d.plug(self.instance, self.vif_hw_veb_trusted)
|
||||
mset_vf_trusted.assert_called_once_with('0000:0a:00.1', True)
|
||||
|
||||
@mock.patch('nova.network.linux_net.set_vf_trusted')
|
||||
@mock.patch('nova.virt.libvirt.vif.set_vf_trusted')
|
||||
def test_unplug_hw_veb_trusted(self, mset_vf_trusted):
|
||||
d = vif.LibvirtGenericVIFDriver()
|
||||
d.unplug(self.instance, self.vif_hw_veb_trusted)
|
||||
|
@ -1186,13 +1185,13 @@ class LibvirtVifTestCase(test.NoDBTestCase):
|
|||
self.assertIn('macvtap_mode', six.text_type(e))
|
||||
self.assertIn('physical_interface', six.text_type(e))
|
||||
|
||||
@mock.patch.object(linux_net.LinuxBridgeInterfaceDriver, 'ensure_vlan')
|
||||
@mock.patch('nova.virt.libvirt.vif.ensure_vlan')
|
||||
def test_macvtap_plug_vlan(self, ensure_vlan_mock):
|
||||
d = vif.LibvirtGenericVIFDriver()
|
||||
d.plug(self.instance, self.vif_macvtap_vlan)
|
||||
ensure_vlan_mock.assert_called_once_with(1, 'eth0', interface='eth0.1')
|
||||
|
||||
@mock.patch.object(linux_net.LinuxBridgeInterfaceDriver, 'ensure_vlan')
|
||||
@mock.patch('nova.virt.libvirt.vif.ensure_vlan')
|
||||
def test_macvtap_plug_flat(self, ensure_vlan_mock):
|
||||
d = vif.LibvirtGenericVIFDriver()
|
||||
d.plug(self.instance, self.vif_macvtap_flat)
|
||||
|
|
|
@ -31,7 +31,6 @@ from oslo_utils import strutils
|
|||
import nova.conf
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova.network import linux_net
|
||||
from nova.network import model as network_model
|
||||
from nova.network import os_vif_util
|
||||
from nova import objects
|
||||
|
@ -115,6 +114,42 @@ def set_vf_interface_vlan(pci_addr, mac_addr, vlan=0):
|
|||
port_state=port_state)
|
||||
|
||||
|
||||
def set_vf_trusted(pci_addr, trusted):
|
||||
"""Configures the VF to be trusted or not
|
||||
|
||||
:param pci_addr: PCI slot of the device
|
||||
:param trusted: Boolean value to indicate whether to
|
||||
enable/disable 'trusted' capability
|
||||
"""
|
||||
pf_ifname = pci_utils.get_ifname_by_pci_address(pci_addr,
|
||||
pf_interface=True)
|
||||
vf_num = pci_utils.get_vf_num_by_pci_address(pci_addr)
|
||||
nova.privsep.linux_net.set_device_trust(
|
||||
pf_ifname, vf_num, trusted)
|
||||
|
||||
|
||||
@utils.synchronized('lock_vlan', external=True)
|
||||
def ensure_vlan(vlan_num, bridge_interface, mac_address=None, mtu=None,
|
||||
interface=None):
|
||||
"""Create a vlan unless it already exists."""
|
||||
if interface is None:
|
||||
interface = 'vlan%s' % vlan_num
|
||||
if not nova.privsep.linux_net.device_exists(interface):
|
||||
LOG.debug('Starting VLAN interface %s', interface)
|
||||
nova.privsep.linux_net.add_vlan(bridge_interface, interface,
|
||||
vlan_num)
|
||||
# (danwent) the bridge will inherit this address, so we want to
|
||||
# make sure it is the value set from the NetworkManager
|
||||
if mac_address:
|
||||
nova.privsep.linux_net.set_device_macaddr(
|
||||
interface, mac_address)
|
||||
nova.privsep.linux_net.set_device_enabled(interface)
|
||||
# NOTE(vish): set mtu every time to ensure that changes to mtu get
|
||||
# propagated
|
||||
nova.privsep.linux_net.set_device_mtu(interface, mtu)
|
||||
return interface
|
||||
|
||||
|
||||
@profiler.trace_cls("vif_driver")
|
||||
class LibvirtGenericVIFDriver(object):
|
||||
"""Generic VIF driver for libvirt networking."""
|
||||
|
@ -629,7 +664,7 @@ class LibvirtGenericVIFDriver(object):
|
|||
trusted = strutils.bool_from_string(
|
||||
vif['profile'].get('trusted', "False"))
|
||||
if trusted:
|
||||
linux_net.set_vf_trusted(vif['profile']['pci_slot'], True)
|
||||
set_vf_trusted(vif['profile']['pci_slot'], True)
|
||||
|
||||
def plug_macvtap(self, instance, vif):
|
||||
vif_details = vif['details']
|
||||
|
@ -638,8 +673,7 @@ class LibvirtGenericVIFDriver(object):
|
|||
vlan_name = vif_details.get(
|
||||
network_model.VIF_DETAILS_MACVTAP_SOURCE)
|
||||
phys_if = vif_details.get(network_model.VIF_DETAILS_PHYS_INTERFACE)
|
||||
linux_net.LinuxBridgeInterfaceDriver.ensure_vlan(
|
||||
vlan, phys_if, interface=vlan_name)
|
||||
ensure_vlan(vlan, phys_if, interface=vlan_name)
|
||||
|
||||
def plug_midonet(self, instance, vif):
|
||||
"""Plug into MidoNet's network port
|
||||
|
@ -762,7 +796,7 @@ class LibvirtGenericVIFDriver(object):
|
|||
mac_addr='00:00:00:00:00:00')
|
||||
elif vif['vnic_type'] == network_model.VNIC_TYPE_DIRECT:
|
||||
if "trusted" in vif['profile']:
|
||||
linux_net.set_vf_trusted(vif['profile']['pci_slot'], False)
|
||||
set_vf_trusted(vif['profile']['pci_slot'], False)
|
||||
|
||||
def unplug_midonet(self, instance, vif):
|
||||
"""Unplug from MidoNet network port
|
||||
|
|
Loading…
Reference in New Issue