Use new location for nova network utilities
The 'device_exists' method moved from nova.network.linux_net to nova.network.utils in Ieac8621217c42f8b2d08dbc58c2025262f325e1e The 'set_device_mtu' and 'delete_net_dev' moved in I9872056c440a706b89dd51d3b9f2418951723efa The 'detach_volume' method has user context passed to it as of I751fcb7532679905c4279744919c6cce84a11eb4. The 'lxd_mock' fixture has also been updated to work with recent changes to oslotest for autospec. Change-Id: Iac52d616517a55984b13d3762c88c66a64292ef5
This commit is contained in:
parent
47afcf108a
commit
f571c64283
|
@ -17,6 +17,7 @@ import mock
|
|||
|
||||
from nova import context
|
||||
from nova.tests.unit import fake_instance
|
||||
from pylxd.deprecated import api
|
||||
|
||||
|
||||
class MockConf(mock.Mock):
|
||||
|
@ -60,13 +61,15 @@ class MockInstance(mock.Mock):
|
|||
|
||||
|
||||
def lxd_mock(*args, **kwargs):
|
||||
mock_api = mock.Mock(spec=api.API)
|
||||
default = {
|
||||
'profile_list.return_value': ['fake_profile'],
|
||||
'container_list.return_value': ['mock-instance-1', 'mock-instance-2'],
|
||||
'host_ping.return_value': True,
|
||||
}
|
||||
default.update(kwargs)
|
||||
return mock.Mock(*args, **default)
|
||||
mock_api.configure_mock(**default)
|
||||
return mock_api
|
||||
|
||||
|
||||
def annotated_data(*args):
|
||||
|
|
|
@ -921,7 +921,8 @@ class LXDDriverTest(test.NoDBTestCase):
|
|||
|
||||
driver.brick_get_connector = mock.MagicMock()
|
||||
driver.brick_get_connector_properties = mock.MagicMock()
|
||||
lxd_driver.detach_volume(connection_info, instance, mountpoint, None)
|
||||
lxd_driver.detach_volume(ctx, connection_info, instance,
|
||||
mountpoint, None)
|
||||
|
||||
lxd_driver.client.profiles.get.assert_called_once_with(instance.name)
|
||||
|
||||
|
|
|
@ -203,12 +203,12 @@ class LXDGenericVifDriverTest(test.NoDBTestCase):
|
|||
_post_plug_wiring.assert_called_with(INSTANCE, TAP_VIF)
|
||||
|
||||
@mock.patch.object(vif, '_post_unplug_wiring')
|
||||
@mock.patch('nova.virt.lxd.vif.linux_net')
|
||||
@mock.patch('nova.virt.lxd.vif.network_utils')
|
||||
@mock.patch('nova.virt.lxd.vif.os_vif')
|
||||
def test_unplug_tap(self, os_vif, linux_net, _post_unplug_wiring):
|
||||
def test_unplug_tap(self, os_vif, network_utils, _post_unplug_wiring):
|
||||
self.vif_driver.unplug(INSTANCE, TAP_VIF)
|
||||
os_vif.plug.assert_not_called()
|
||||
linux_net.delete_net_dev.assert_called_with('tapda5cc4bf-f1')
|
||||
network_utils.delete_net_dev.assert_called_with('tapda5cc4bf-f1')
|
||||
_post_unplug_wiring.assert_called_with(INSTANCE, TAP_VIF)
|
||||
|
||||
|
||||
|
@ -221,15 +221,17 @@ class PostPlugTest(test.NoDBTestCase):
|
|||
@mock.patch('nova.virt.lxd.vif._create_veth_pair')
|
||||
@mock.patch('nova.virt.lxd.vif._add_bridge_port')
|
||||
@mock.patch('nova.virt.lxd.vif.linux_net')
|
||||
@mock.patch('nova.virt.lxd.vif.network_utils')
|
||||
def test_post_plug_ovs_hybrid(self,
|
||||
network_utils,
|
||||
linux_net,
|
||||
add_bridge_port,
|
||||
create_veth_pair):
|
||||
linux_net.device_exists.return_value = False
|
||||
network_utils.device_exists.return_value = False
|
||||
|
||||
vif._post_plug_wiring(INSTANCE, OVS_HYBRID_VIF)
|
||||
|
||||
linux_net.device_exists.assert_called_with('tapda5cc4bf-f1')
|
||||
network_utils.device_exists.assert_called_with('tapda5cc4bf-f1')
|
||||
create_veth_pair.assert_called_with('tapda5cc4bf-f1',
|
||||
'tinda5cc4bf-f1',
|
||||
1000)
|
||||
|
@ -239,16 +241,18 @@ class PostPlugTest(test.NoDBTestCase):
|
|||
@mock.patch('nova.virt.lxd.vif._create_veth_pair')
|
||||
@mock.patch('nova.virt.lxd.vif._add_bridge_port')
|
||||
@mock.patch('nova.virt.lxd.vif.linux_net')
|
||||
@mock.patch('nova.virt.lxd.vif.network_utils')
|
||||
def test_post_plug_ovs(self,
|
||||
network_utils,
|
||||
linux_net,
|
||||
add_bridge_port,
|
||||
create_veth_pair):
|
||||
|
||||
linux_net.device_exists.return_value = False
|
||||
network_utils.device_exists.return_value = False
|
||||
|
||||
vif._post_plug_wiring(INSTANCE, OVS_VIF)
|
||||
|
||||
linux_net.device_exists.assert_called_with('tapda5cc4bf-f1')
|
||||
network_utils.device_exists.assert_called_with('tapda5cc4bf-f1')
|
||||
create_veth_pair.assert_called_with('tapda5cc4bf-f1',
|
||||
'tinda5cc4bf-f1',
|
||||
1000)
|
||||
|
@ -265,15 +269,17 @@ class PostPlugTest(test.NoDBTestCase):
|
|||
@mock.patch('nova.virt.lxd.vif._create_veth_pair')
|
||||
@mock.patch('nova.virt.lxd.vif._add_bridge_port')
|
||||
@mock.patch('nova.virt.lxd.vif.linux_net')
|
||||
@mock.patch('nova.virt.lxd.vif.network_utils')
|
||||
def test_post_plug_bridge(self,
|
||||
network_utils,
|
||||
linux_net,
|
||||
add_bridge_port,
|
||||
create_veth_pair):
|
||||
linux_net.device_exists.return_value = False
|
||||
network_utils.device_exists.return_value = False
|
||||
|
||||
vif._post_plug_wiring(INSTANCE, LB_VIF)
|
||||
|
||||
linux_net.device_exists.assert_called_with('tapda5cc4bf-f1')
|
||||
network_utils.device_exists.assert_called_with('tapda5cc4bf-f1')
|
||||
create_veth_pair.assert_called_with('tapda5cc4bf-f1',
|
||||
'tinda5cc4bf-f1',
|
||||
1000)
|
||||
|
@ -282,25 +288,25 @@ class PostPlugTest(test.NoDBTestCase):
|
|||
|
||||
@mock.patch('nova.virt.lxd.vif._create_veth_pair')
|
||||
@mock.patch('nova.virt.lxd.vif._add_bridge_port')
|
||||
@mock.patch('nova.virt.lxd.vif.linux_net')
|
||||
@mock.patch('nova.virt.lxd.vif.network_utils')
|
||||
def test_post_plug_tap(self,
|
||||
linux_net,
|
||||
network_utils,
|
||||
add_bridge_port,
|
||||
create_veth_pair):
|
||||
linux_net.device_exists.return_value = False
|
||||
network_utils.device_exists.return_value = False
|
||||
|
||||
vif._post_plug_wiring(INSTANCE, TAP_VIF)
|
||||
|
||||
linux_net.device_exists.assert_not_called()
|
||||
network_utils.device_exists.assert_not_called()
|
||||
|
||||
|
||||
class PostUnplugTest(test.NoDBTestCase):
|
||||
"""Tests for post unplug operations"""
|
||||
|
||||
@mock.patch('nova.virt.lxd.vif.linux_net')
|
||||
def test_post_unplug_ovs_hybrid(self, linux_net):
|
||||
@mock.patch('nova.virt.lxd.vif.network_utils')
|
||||
def test_post_unplug_ovs_hybrid(self, network_utils):
|
||||
vif._post_unplug_wiring(INSTANCE, OVS_HYBRID_VIF)
|
||||
linux_net.delete_net_dev.assert_called_with('tapda5cc4bf-f1')
|
||||
network_utils.delete_net_dev.assert_called_with('tapda5cc4bf-f1')
|
||||
|
||||
@mock.patch('nova.virt.lxd.vif.linux_net')
|
||||
def test_post_unplug_ovs(self, linux_net):
|
||||
|
@ -309,10 +315,10 @@ class PostUnplugTest(test.NoDBTestCase):
|
|||
'tapda5cc4bf-f1',
|
||||
True)
|
||||
|
||||
@mock.patch('nova.virt.lxd.vif.linux_net')
|
||||
def test_post_unplug_bridge(self, linux_net):
|
||||
@mock.patch('nova.virt.lxd.vif.network_utils')
|
||||
def test_post_unplug_bridge(self, network_utils):
|
||||
vif._post_unplug_wiring(INSTANCE, LB_VIF)
|
||||
linux_net.delete_net_dev.assert_called_with('tapda5cc4bf-f1')
|
||||
network_utils.delete_net_dev.assert_called_with('tapda5cc4bf-f1')
|
||||
|
||||
|
||||
class MiscHelpersTest(test.NoDBTestCase):
|
||||
|
|
|
@ -734,7 +734,7 @@ class LXDDriver(driver.ComputeDriver):
|
|||
profile.config.update({'raw.apparmor': 'mount fstype=ext4,'})
|
||||
profile.save()
|
||||
|
||||
def detach_volume(self, connection_info, instance, mountpoint,
|
||||
def detach_volume(self, context, connection_info, instance, mountpoint,
|
||||
encryption=None):
|
||||
"""Detach block device from a nova instance.
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ from nova import utils
|
|||
from nova.network import linux_net
|
||||
from nova.network import model as network_model
|
||||
from nova.network import os_vif_util
|
||||
from nova.network import utils as network_utils
|
||||
|
||||
import os_vif
|
||||
|
||||
|
@ -47,14 +48,14 @@ def _create_veth_pair(dev1_name, dev2_name, mtu=None):
|
|||
deleting any previous devices with those names.
|
||||
"""
|
||||
for dev in [dev1_name, dev2_name]:
|
||||
linux_net.delete_net_dev(dev)
|
||||
network_utils.delete_net_dev(dev)
|
||||
|
||||
utils.execute('ip', 'link', 'add', dev1_name, 'type', 'veth', 'peer',
|
||||
'name', dev2_name, run_as_root=True)
|
||||
|
||||
for dev in [dev1_name, dev2_name]:
|
||||
utils.execute('ip', 'link', 'set', dev, 'up', run_as_root=True)
|
||||
linux_net._set_device_mtu(dev, mtu)
|
||||
network_utils.set_device_mtu(dev, mtu)
|
||||
|
||||
|
||||
def _add_bridge_port(bridge, dev):
|
||||
|
@ -116,7 +117,7 @@ def _post_plug_wiring_veth_and_bridge(instance, vif):
|
|||
mtu = network.get_meta('mtu') if network else None
|
||||
v1_name = get_vif_devname(vif)
|
||||
v2_name = get_vif_internal_devname(vif)
|
||||
if not linux_net.device_exists(v1_name):
|
||||
if not network_utils.device_exists(v1_name):
|
||||
_create_veth_pair(v1_name, v2_name, mtu)
|
||||
if _is_ovs_vif_port(vif):
|
||||
# NOTE(jamespage): wire tap device directly to ovs bridge
|
||||
|
@ -130,7 +131,7 @@ def _post_plug_wiring_veth_and_bridge(instance, vif):
|
|||
# NOTE(jamespage): wire tap device linux bridge
|
||||
_add_bridge_port(config['bridge'], v1_name)
|
||||
else:
|
||||
linux_net._set_device_mtu(v1_name, mtu)
|
||||
network_utils.set_device_mtu(v1_name, mtu)
|
||||
|
||||
|
||||
POST_PLUG_WIRING = {
|
||||
|
@ -168,7 +169,7 @@ def _post_unplug_wiring_delete_veth(instance, vif):
|
|||
linux_net.delete_ovs_vif_port(vif['network']['bridge'],
|
||||
v1_name, True)
|
||||
else:
|
||||
linux_net.delete_net_dev(v1_name)
|
||||
network_utils.delete_net_dev(v1_name)
|
||||
except processutils.ProcessExecutionError:
|
||||
LOG.exception("Failed to delete veth for vif",
|
||||
vif=vif)
|
||||
|
@ -252,16 +253,16 @@ class LXDGenericVifDriver(object):
|
|||
# NOTE(jamespage): For nova-lxd this is really a veth pair
|
||||
# so that a) security rules get applied on the host
|
||||
# and b) that the container can still be wired.
|
||||
if not linux_net.device_exists(v1_name):
|
||||
if not network_utils.device_exists(v1_name):
|
||||
_create_veth_pair(v1_name, v2_name, mtu)
|
||||
else:
|
||||
linux_net._set_device_mtu(v1_name, mtu)
|
||||
network_utils.set_device_mtu(v1_name, mtu)
|
||||
|
||||
def unplug_tap(self, instance, vif):
|
||||
"""Unplug a VIF_TYPE_TAP virtual interface."""
|
||||
dev = get_vif_devname(vif)
|
||||
try:
|
||||
linux_net.delete_net_dev(dev)
|
||||
network_utils.delete_net_dev(dev)
|
||||
except processutils.ProcessExecutionError:
|
||||
LOG.exception("Failed while unplugging vif",
|
||||
instance=instance)
|
||||
|
|
Loading…
Reference in New Issue