Merge "Rename network.utils to network.linux_utils."
This commit is contained in:
commit
d2166ed072
|
@ -37,7 +37,7 @@ import six
|
|||
import nova.conf
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova.network import utils as net_utils
|
||||
from nova.network import linux_utils as linux_net_utils
|
||||
from nova import objects
|
||||
from nova.pci import utils as pci_utils
|
||||
from nova import utils
|
||||
|
@ -932,7 +932,7 @@ def get_dhcp_opts(context, network_ref, fixedips):
|
|||
|
||||
|
||||
def release_dhcp(dev, address, mac_address):
|
||||
if net_utils.device_exists(dev):
|
||||
if linux_net_utils.device_exists(dev):
|
||||
try:
|
||||
utils.execute('dhcp_release', dev, address, mac_address,
|
||||
run_as_root=True)
|
||||
|
@ -1244,7 +1244,7 @@ def delete_ivs_vif_port(dev):
|
|||
|
||||
|
||||
def create_tap_dev(dev, mac_address=None, multiqueue=False):
|
||||
if not net_utils.device_exists(dev):
|
||||
if not linux_net_utils.device_exists(dev):
|
||||
try:
|
||||
# First, try with 'ip'
|
||||
cmd = ('ip', 'tuntap', 'add', dev, 'mode', 'tap')
|
||||
|
@ -1269,22 +1269,22 @@ def create_tap_dev(dev, mac_address=None, multiqueue=False):
|
|||
|
||||
|
||||
def create_fp_dev(dev, sockpath, sockmode):
|
||||
if not net_utils.device_exists(dev):
|
||||
if not linux_net_utils.device_exists(dev):
|
||||
utils.execute('fp-vdev', 'add', dev, '--sockpath', sockpath,
|
||||
'--sockmode', sockmode, run_as_root=True)
|
||||
net_utils.set_device_mtu(dev)
|
||||
linux_net_utils.set_device_mtu(dev)
|
||||
utils.execute('ip', 'link', 'set', dev, 'up', run_as_root=True,
|
||||
check_exit_code=[0, 2, 254])
|
||||
|
||||
|
||||
def delete_fp_dev(dev):
|
||||
if net_utils.device_exists(dev):
|
||||
if linux_net_utils.device_exists(dev):
|
||||
utils.execute('fp-vdev', 'del', dev, run_as_root=True)
|
||||
|
||||
|
||||
def delete_bridge_dev(dev):
|
||||
"""Delete a network bridge."""
|
||||
if net_utils.device_exists(dev):
|
||||
if linux_net_utils.device_exists(dev):
|
||||
try:
|
||||
utils.execute('ip', 'link', 'set', dev, 'down', run_as_root=True)
|
||||
utils.execute('brctl', 'delbr', dev, run_as_root=True)
|
||||
|
@ -1411,7 +1411,7 @@ class LinuxBridgeInterfaceDriver(LinuxNetInterfaceDriver):
|
|||
"""Create a vlan unless it already exists."""
|
||||
if interface is None:
|
||||
interface = 'vlan%s' % vlan_num
|
||||
if not net_utils.device_exists(interface):
|
||||
if not linux_net_utils.device_exists(interface):
|
||||
LOG.debug('Starting VLAN interface %s', interface)
|
||||
_execute('ip', 'link', 'add', 'link', bridge_interface,
|
||||
'name', interface, 'type', 'vlan',
|
||||
|
@ -1427,7 +1427,7 @@ class LinuxBridgeInterfaceDriver(LinuxNetInterfaceDriver):
|
|||
check_exit_code=[0, 2, 254])
|
||||
# NOTE(vish): set mtu every time to ensure that changes to mtu get
|
||||
# propagated
|
||||
net_utils.set_device_mtu(interface, mtu)
|
||||
linux_net_utils.set_device_mtu(interface, mtu)
|
||||
return interface
|
||||
|
||||
@staticmethod
|
||||
|
@ -1435,7 +1435,7 @@ class LinuxBridgeInterfaceDriver(LinuxNetInterfaceDriver):
|
|||
def remove_vlan(vlan_num):
|
||||
"""Delete a vlan."""
|
||||
vlan_interface = 'vlan%s' % vlan_num
|
||||
net_utils.delete_net_dev(vlan_interface)
|
||||
linux_net_utils.delete_net_dev(vlan_interface)
|
||||
|
||||
@staticmethod
|
||||
@utils.synchronized('lock_bridge', external=True)
|
||||
|
@ -1456,7 +1456,7 @@ class LinuxBridgeInterfaceDriver(LinuxNetInterfaceDriver):
|
|||
interface onto the bridge and reset the default gateway if necessary.
|
||||
|
||||
"""
|
||||
if not net_utils.device_exists(bridge):
|
||||
if not linux_net_utils.device_exists(bridge):
|
||||
LOG.debug('Starting Bridge %s', bridge)
|
||||
out, err = _execute('brctl', 'addbr', bridge,
|
||||
check_exit_code=False, run_as_root=True)
|
||||
|
@ -1542,7 +1542,7 @@ class LinuxBridgeInterfaceDriver(LinuxNetInterfaceDriver):
|
|||
@utils.synchronized('lock_bridge', external=True)
|
||||
def remove_bridge(bridge, gateway=True, filtering=True):
|
||||
"""Delete a bridge."""
|
||||
if not net_utils.device_exists(bridge):
|
||||
if not linux_net_utils.device_exists(bridge):
|
||||
return
|
||||
else:
|
||||
if filtering:
|
||||
|
@ -1696,7 +1696,7 @@ class LinuxOVSInterfaceDriver(LinuxNetInterfaceDriver):
|
|||
|
||||
def plug(self, network, mac_address, gateway=True):
|
||||
dev = self.get_dev(network)
|
||||
if not net_utils.device_exists(dev):
|
||||
if not linux_net_utils.device_exists(dev):
|
||||
bridge = CONF.linuxnet_ovs_integration_bridge
|
||||
_ovs_vsctl(['--', '--may-exist', 'add-port', bridge, dev,
|
||||
'--', 'set', 'Interface', dev, 'type=internal',
|
||||
|
@ -1708,7 +1708,7 @@ class LinuxOVSInterfaceDriver(LinuxNetInterfaceDriver):
|
|||
'external-ids:attached-mac=%s' % mac_address])
|
||||
_execute('ip', 'link', 'set', dev, 'address', mac_address,
|
||||
run_as_root=True)
|
||||
net_utils.set_device_mtu(dev, network.get('mtu'))
|
||||
linux_net_utils.set_device_mtu(dev, network.get('mtu'))
|
||||
_execute('ip', 'link', 'set', dev, 'up', run_as_root=True)
|
||||
if not gateway:
|
||||
# If we weren't instructed to act as a gateway then add the
|
||||
|
@ -1769,7 +1769,7 @@ class NeutronLinuxBridgeInterfaceDriver(LinuxNetInterfaceDriver):
|
|||
|
||||
create_tap_dev(dev, mac_address)
|
||||
|
||||
if not net_utils.device_exists(bridge):
|
||||
if not linux_net_utils.device_exists(bridge):
|
||||
LOG.debug("Starting bridge %s ", bridge)
|
||||
utils.execute('brctl', 'addbr', bridge, run_as_root=True)
|
||||
utils.execute('brctl', 'setfd', bridge, str(0), run_as_root=True)
|
||||
|
@ -1789,10 +1789,10 @@ class NeutronLinuxBridgeInterfaceDriver(LinuxNetInterfaceDriver):
|
|||
|
||||
def unplug(self, network):
|
||||
dev = self.get_dev(network)
|
||||
if not net_utils.device_exists(dev):
|
||||
if not linux_net_utils.device_exists(dev):
|
||||
return None
|
||||
else:
|
||||
net_utils.delete_net_dev(dev)
|
||||
linux_net_utils.delete_net_dev(dev)
|
||||
return dev
|
||||
|
||||
def get_dev(self, network):
|
||||
|
|
|
@ -32,7 +32,7 @@ from nova import db
|
|||
from nova import exception
|
||||
from nova.network import driver
|
||||
from nova.network import linux_net
|
||||
from nova.network import utils as net_utils
|
||||
from nova.network import linux_utils as linux_net_utils
|
||||
from nova import objects
|
||||
from nova import test
|
||||
from nova.tests import uuidsentinel as uuids
|
||||
|
@ -610,7 +610,7 @@ class LinuxNetworkTestCase(test.NoDBTestCase):
|
|||
"share_address": False}, "fakemac")
|
||||
self.assertEqual(2, mock_add_rule.call_count)
|
||||
|
||||
@mock.patch('nova.network.utils.device_exists')
|
||||
@mock.patch('nova.network.linux_utils.device_exists')
|
||||
@mock.patch.object(utils, 'execute')
|
||||
def test_linux_ovs_driver_plug_exception(self, mock_execute,
|
||||
mock_device_exists):
|
||||
|
@ -1141,7 +1141,8 @@ class LinuxNetworkTestCase(test.NoDBTestCase):
|
|||
]
|
||||
}
|
||||
with test.nested(
|
||||
mock.patch('nova.network.utils.device_exists', return_value=True),
|
||||
mock.patch('nova.network.linux_utils.device_exists',
|
||||
return_value=True),
|
||||
mock.patch.object(linux_net, '_execute', return_value=('', '')),
|
||||
mock.patch.object(netifaces, 'ifaddresses')
|
||||
) as (device_exists, _execute, ifaddresses):
|
||||
|
@ -1160,7 +1161,8 @@ class LinuxNetworkTestCase(test.NoDBTestCase):
|
|||
return ('', '')
|
||||
|
||||
with test.nested(
|
||||
mock.patch('nova.network.utils.device_exists', return_value=True),
|
||||
mock.patch('nova.network.linux_utils.device_exists',
|
||||
return_value=True),
|
||||
mock.patch.object(linux_net, '_execute', fake_execute)
|
||||
) as (device_exists, _):
|
||||
driver = linux_net.LinuxBridgeInterfaceDriver()
|
||||
|
@ -1177,7 +1179,8 @@ class LinuxNetworkTestCase(test.NoDBTestCase):
|
|||
return ('', '')
|
||||
|
||||
with test.nested(
|
||||
mock.patch('nova.network.utils.device_exists', return_value=False),
|
||||
mock.patch('nova.network.linux_utils.device_exists',
|
||||
return_value=False),
|
||||
mock.patch.object(linux_net, '_execute', fake_execute)
|
||||
) as (device_exists, _):
|
||||
driver = linux_net.LinuxBridgeInterfaceDriver()
|
||||
|
@ -1186,7 +1189,7 @@ class LinuxNetworkTestCase(test.NoDBTestCase):
|
|||
|
||||
def _create_veth_pair(self, calls):
|
||||
with mock.patch.object(utils, 'execute', return_value=('', '')) as ex:
|
||||
net_utils.create_veth_pair('fake-dev1', 'fake-dev2')
|
||||
linux_net_utils.create_veth_pair('fake-dev1', 'fake-dev2')
|
||||
ex.assert_has_calls(calls)
|
||||
|
||||
def test_create_veth_pair(self):
|
||||
|
@ -1298,8 +1301,8 @@ class LinuxNetworkTestCase(test.NoDBTestCase):
|
|||
self.assertEqual(expected_execute_args, mock_execute.mock_calls)
|
||||
|
||||
@mock.patch.object(linux_net, '_execute')
|
||||
@mock.patch('nova.network.utils.device_exists', return_value=False)
|
||||
@mock.patch('nova.network.utils.set_device_mtu')
|
||||
@mock.patch('nova.network.linux_utils.device_exists', return_value=False)
|
||||
@mock.patch('nova.network.linux_utils.set_device_mtu')
|
||||
def test_ensure_vlan(self, mock_set_device_mtu, mock_device_exists,
|
||||
mock_execute):
|
||||
interface = linux_net.LinuxBridgeInterfaceDriver.ensure_vlan(
|
||||
|
@ -1319,8 +1322,8 @@ class LinuxNetworkTestCase(test.NoDBTestCase):
|
|||
mock_set_device_mtu.assert_called_once_with('vlan_name', 'MTU')
|
||||
|
||||
@mock.patch.object(linux_net, '_execute')
|
||||
@mock.patch('nova.network.utils.device_exists', return_value=True)
|
||||
@mock.patch('nova.network.utils.set_device_mtu')
|
||||
@mock.patch('nova.network.linux_utils.device_exists', return_value=True)
|
||||
@mock.patch('nova.network.linux_utils.set_device_mtu')
|
||||
def test_ensure_vlan_device_exists(self, mock_set_device_mtu,
|
||||
mock_device_exists, mock_execute):
|
||||
interface = linux_net.LinuxBridgeInterfaceDriver.ensure_vlan(1, 'eth0')
|
||||
|
|
|
@ -1917,11 +1917,11 @@ class VlanNetworkTestCase(test.TestCase):
|
|||
'DE:AD:BE:EF:00:00',
|
||||
run_as_root=True)
|
||||
|
||||
@mock.patch('nova.network.utils.device_exists', return_value=True)
|
||||
@mock.patch('nova.network.linux_utils.device_exists', return_value=True)
|
||||
def test_deallocate_fixed_with_dhcp(self, mock_dev_exists):
|
||||
self._deallocate_fixed_with_dhcp(mock_dev_exists)
|
||||
|
||||
@mock.patch('nova.network.utils.device_exists', return_value=False)
|
||||
@mock.patch('nova.network.linux_utils.device_exists', return_value=False)
|
||||
def test_deallocate_fixed_without_dhcp(self, mock_dev_exists):
|
||||
self._deallocate_fixed_with_dhcp(mock_dev_exists)
|
||||
|
||||
|
|
|
@ -957,9 +957,9 @@ class LibvirtVifTestCase(test.NoDBTestCase):
|
|||
|
||||
def test_plug_ivs_hybrid(self):
|
||||
with test.nested(
|
||||
mock.patch('nova.network.utils.device_exists',
|
||||
mock.patch('nova.network.linux_utils.device_exists',
|
||||
return_value=False),
|
||||
mock.patch('nova.network.utils.create_veth_pair'),
|
||||
mock.patch('nova.network.linux_utils.create_veth_pair'),
|
||||
mock.patch.object(linux_net, 'create_ivs_vif_port'),
|
||||
mock.patch.object(os.path, 'exists', return_value=True),
|
||||
mock.patch('nova.privsep.libvirt.disable_multicast_snooping'),
|
||||
|
@ -1042,7 +1042,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
|
|||
d = vif.LibvirtGenericVIFDriver()
|
||||
d.unplug(self.instance, self.vif_iovisor)
|
||||
|
||||
@mock.patch('nova.network.utils.device_exists')
|
||||
@mock.patch('nova.network.linux_utils.device_exists')
|
||||
@mock.patch('nova.privsep.libvirt.plug_plumgrid_vif')
|
||||
def test_plug_iovisor(self, mock_plug, device_exists):
|
||||
device_exists.return_value = True
|
||||
|
@ -1234,7 +1234,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
|
|||
self._assertTypeAndMacEquals(node, "ethernet", "target", "dev",
|
||||
self.vif_tap, br_want)
|
||||
|
||||
@mock.patch('nova.network.utils.device_exists')
|
||||
@mock.patch('nova.network.linux_utils.device_exists')
|
||||
def test_plug_tap(self, device_exists):
|
||||
device_exists.return_value = True
|
||||
d = vif.LibvirtGenericVIFDriver()
|
||||
|
|
|
@ -31,9 +31,9 @@ import nova.conf
|
|||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova.network import linux_net
|
||||
from nova.network import linux_utils as linux_net_utils
|
||||
from nova.network import model as network_model
|
||||
from nova.network import os_vif_util
|
||||
from nova.network import utils as net_utils
|
||||
from nova import objects
|
||||
from nova import profiler
|
||||
from nova import utils
|
||||
|
@ -591,16 +591,16 @@ class LibvirtGenericVIFDriver(object):
|
|||
br_name = self.get_br_name(vif['id'])
|
||||
v1_name, v2_name = self.get_veth_pair_names(vif['id'])
|
||||
|
||||
if not net_utils.device_exists(br_name):
|
||||
if not linux_net_utils.device_exists(br_name):
|
||||
nova.privsep.libvirt.add_bridge(br_name)
|
||||
nova.privsep.libvirt.zero_bridge_forward_delay(br_name)
|
||||
nova.privsep.libvirt.disable_bridge_stp(br_name)
|
||||
nova.privsep.libvirt.disable_multicast_snooping(br_name)
|
||||
nova.privsep.libvirt.disable_ipv6(br_name)
|
||||
|
||||
if not net_utils.device_exists(v2_name):
|
||||
if not linux_net_utils.device_exists(v2_name):
|
||||
mtu = vif['network'].get_meta('mtu')
|
||||
net_utils.create_veth_pair(v1_name, v2_name, mtu)
|
||||
linux_net_utils.create_veth_pair(v1_name, v2_name, mtu)
|
||||
nova.privsep.libvirt.toggle_interface(br_name, 'up')
|
||||
nova.privsep.libvirt.bridge_add_interface(br_name, v1_name)
|
||||
linux_net.create_ivs_vif_port(v2_name, iface_id,
|
||||
|
@ -701,7 +701,7 @@ class LibvirtGenericVIFDriver(object):
|
|||
linux_net.create_tap_dev(dev, mac)
|
||||
network = vif.get('network')
|
||||
mtu = network.get_meta('mtu') if network else None
|
||||
net_utils.set_device_mtu(dev, mtu)
|
||||
linux_net_utils.set_device_mtu(dev, mtu)
|
||||
|
||||
def plug_vhostuser(self, instance, vif):
|
||||
pass
|
||||
|
@ -864,7 +864,7 @@ class LibvirtGenericVIFDriver(object):
|
|||
port_id = vif['id']
|
||||
try:
|
||||
nova.privsep.libvirt.unplug_midonet_vif(port_id)
|
||||
net_utils.delete_net_dev(dev)
|
||||
linux_net_utils.delete_net_dev(dev)
|
||||
except processutils.ProcessExecutionError:
|
||||
LOG.exception(_("Failed while unplugging vif"), instance=instance)
|
||||
|
||||
|
@ -872,7 +872,7 @@ class LibvirtGenericVIFDriver(object):
|
|||
"""Unplug a VIF_TYPE_TAP virtual interface."""
|
||||
dev = self.get_vif_devname(vif)
|
||||
try:
|
||||
net_utils.delete_net_dev(dev)
|
||||
linux_net_utils.delete_net_dev(dev)
|
||||
except processutils.ProcessExecutionError:
|
||||
LOG.exception(_("Failed while unplugging vif"), instance=instance)
|
||||
|
||||
|
@ -885,7 +885,7 @@ class LibvirtGenericVIFDriver(object):
|
|||
dev = self.get_vif_devname(vif)
|
||||
try:
|
||||
nova.privsep.libvirt.unplug_plumgrid_vif(dev)
|
||||
net_utils.delete_net_dev(dev)
|
||||
linux_net_utils.delete_net_dev(dev)
|
||||
except processutils.ProcessExecutionError:
|
||||
LOG.exception(_("Failed while unplugging vif"), instance=instance)
|
||||
|
||||
|
@ -901,7 +901,7 @@ class LibvirtGenericVIFDriver(object):
|
|||
port_id = vif['id']
|
||||
try:
|
||||
nova.privsep.libvirt.unplug_contrail_vif(port_id)
|
||||
net_utils.delete_net_dev(dev)
|
||||
linux_net_utils.delete_net_dev(dev)
|
||||
except processutils.ProcessExecutionError:
|
||||
LOG.exception(_("Failed while unplugging vif"), instance=instance)
|
||||
|
||||
|
|
Loading…
Reference in New Issue