Merge "libvirt: remove unused get_connection parameter from VIF driver"

This commit is contained in:
Jenkins 2014-12-18 19:00:27 +00:00 committed by Gerrit Code Review
commit 6513d27d31
3 changed files with 40 additions and 53 deletions

View File

@ -25,7 +25,6 @@ from nova.network import model as network_model
from nova import objects
from nova.pci import utils as pci_utils
from nova import test
from nova.tests.unit.virt.libvirt import fakelibvirt
from nova import utils
from nova.virt.libvirt import config as vconfig
from nova.virt.libvirt import vif
@ -288,14 +287,6 @@ class LibvirtVifTestCase(test.NoDBTestCase):
self.stubs.Set(utils, 'execute', fake_execute)
def _get_conn(self, uri="qemu:///session", ver=None):
def __inner():
if ver is None:
return fakelibvirt.Connection(uri, False)
else:
return fakelibvirt.Connection(uri, False, ver)
return __inner
def _get_node(self, xml):
doc = etree.fromstring(xml)
ret = doc.findall('./devices/interface')
@ -423,7 +414,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
virt_type='kvm',
group='libvirt')
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
xml = self._get_instance_xml(d, self.vif_bridge)
self._assertModel(xml)
@ -432,7 +423,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
virt_type='kvm',
group='libvirt')
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
xml = self._get_instance_xml(d, self.vif_bridge)
self._assertModel(xml, network_model.VIF_MODEL_VIRTIO)
@ -442,7 +433,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
virt_type=virt,
group='libvirt')
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
supported = (network_model.VIF_MODEL_NE2K_PCI,
network_model.VIF_MODEL_PCNET,
network_model.VIF_MODEL_RTL8139,
@ -459,7 +450,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
virt_type='kvm',
group='libvirt')
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
image_meta = {'properties': {'hw_vif_model': 'acme'}}
self.assertRaises(exception.UnsupportedHardware,
self._get_instance_xml,
@ -474,7 +465,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
group='libvirt')
for vif_obj in vif_objs:
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
if libvirt_version is not None:
d.libvirt_version = libvirt_version
@ -529,12 +520,12 @@ class LibvirtVifTestCase(test.NoDBTestCase):
virt_type='xen',
group='libvirt')
d = vif.LibvirtGenericVIFDriver(self._get_conn("xen:///system"))
d = vif.LibvirtGenericVIFDriver()
xml = self._get_instance_xml(d, self.vif_bridge)
self._assertModel(xml)
def test_generic_driver_none(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
self.assertRaises(exception.NovaException,
self._get_instance_xml,
d,
@ -547,7 +538,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
self.vif_bridge, br_want, 1)
def test_generic_driver_bridge(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
self._check_bridge_driver(d,
self.vif_bridge,
self.vif_bridge['network']['bridge'])
@ -562,7 +553,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
self.assertEqual(script, "")
def test_unplug_ivs_ethernet(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
with mock.patch.object(linux_net, 'delete_ivs_vif_port') as delete:
delete.side_effect = processutils.ProcessExecutionError
d.unplug_ivs_ethernet(None, self.vif_ovs)
@ -599,7 +590,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
mock.patch.object(linux_net, '_create_veth_pair'),
mock.patch.object(linux_net, 'create_ovs_vif_port')
) as (device_exists, execute, _create_veth_pair, create_ovs_vif_port):
d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010))
d = vif.LibvirtGenericVIFDriver()
d.plug_ovs_hybrid(self.instance, self.vif_ovs)
device_exists.assert_has_calls(calls['device_exists'])
_create_veth_pair.assert_has_calls(calls['_create_veth_pair'])
@ -623,7 +614,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
mock.patch.object(utils, 'execute'),
mock.patch.object(linux_net, 'delete_ovs_vif_port')
) as (device_exists, execute, delete_ovs_vif_port):
d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010))
d = vif.LibvirtGenericVIFDriver()
d.unplug_ovs_hybrid(None, self.vif_ovs)
device_exists.assert_has_calls(calls['device_exists'])
execute.assert_has_calls(calls['execute'])
@ -660,13 +651,13 @@ class LibvirtVifTestCase(test.NoDBTestCase):
mock_execute.assert_has_calls(calls['execute'])
def test_plug_hw_veb(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010))
d = vif.LibvirtGenericVIFDriver()
self._test_hw_veb_op(
d.plug_hw_veb,
self.vif_macvtap['details'][network_model.VIF_DETAILS_VLAN])
def test_unplug_hw_veb(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010))
d = vif.LibvirtGenericVIFDriver()
self._test_hw_veb_op(d.unplug_hw_veb, 0)
def test_unplug_ovs_hybrid_bridge_does_not_exist(self):
@ -679,7 +670,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
return_value=False),
mock.patch.object(linux_net, 'delete_ovs_vif_port')
) as (device_exists, delete_ovs_vif_port):
d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010))
d = vif.LibvirtGenericVIFDriver()
d.unplug_ovs_hybrid(None, self.vif_ovs)
device_exists.assert_has_calls(calls['device_exists'])
delete_ovs_vif_port.assert_has_calls(calls['delete_ovs_vif_port'])
@ -715,7 +706,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
mock.patch.object(linux_net, '_create_veth_pair'),
mock.patch.object(linux_net, 'create_ivs_vif_port')
) as (device_exists, execute, _create_veth_pair, create_ivs_vif_port):
d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010))
d = vif.LibvirtGenericVIFDriver()
d.plug_ivs_hybrid(self.instance, self.vif_ivs)
device_exists.assert_has_calls(calls['device_exists'])
_create_veth_pair.assert_has_calls(calls['_create_veth_pair'])
@ -736,19 +727,19 @@ class LibvirtVifTestCase(test.NoDBTestCase):
mock.patch.object(utils, 'execute'),
mock.patch.object(linux_net, 'delete_ivs_vif_port')
) as (execute, delete_ivs_vif_port):
d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010))
d = vif.LibvirtGenericVIFDriver()
d.unplug_ivs_hybrid(None, self.vif_ivs)
execute.assert_has_calls(calls['execute'])
delete_ivs_vif_port.assert_has_calls(calls['delete_ivs_vif_port'])
def test_unplug_ivs_hybrid_bridge_does_not_exist(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010))
d = vif.LibvirtGenericVIFDriver()
with mock.patch.object(utils, 'execute') as execute:
execute.side_effect = processutils.ProcessExecutionError
d.unplug_ivs_hybrid(None, self.vif_ivs)
def test_unplug_iovisor(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010))
d = vif.LibvirtGenericVIFDriver()
with mock.patch.object(utils, 'execute') as execute:
execute.side_effect = processutils.ProcessExecutionError
mynetwork = network_model.Network(id='network-id-xxx-yyy-zzz',
@ -761,7 +752,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
@mock.patch('nova.network.linux_net.device_exists')
def test_plug_iovisor(self, device_exists):
device_exists.return_value = True
d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010))
d = vif.LibvirtGenericVIFDriver()
with mock.patch.object(utils, 'execute') as execute:
execute.side_effect = processutils.ProcessExecutionError
instance = {
@ -772,7 +763,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
d.plug_iovisor(instance, self.vif_ivs)
def test_unplug_mlnx_with_details(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010))
d = vif.LibvirtGenericVIFDriver()
with mock.patch.object(utils, 'execute') as execute:
execute.side_effect = processutils.ProcessExecutionError
d.unplug_mlnx_direct(None, self.vif_mlnx_net)
@ -782,7 +773,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
run_as_root=True)
def test_plug_mlnx_with_details(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010))
d = vif.LibvirtGenericVIFDriver()
with mock.patch.object(utils, 'execute') as execute:
d.plug_mlnx_direct(self.instance, self.vif_mlnx_net)
execute.assert_called_once_with('ebrctl', 'add-port',
@ -794,7 +785,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
run_as_root=True)
def test_plug_mlnx_no_physical_network(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010))
d = vif.LibvirtGenericVIFDriver()
with mock.patch.object(utils, 'execute') as execute:
self.assertRaises(exception.NovaException,
d.plug_mlnx_direct,
@ -803,7 +794,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
self.assertEqual(0, execute.call_count)
def test_ivs_ethernet_driver(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010))
d = vif.LibvirtGenericVIFDriver()
self._check_ivs_ethernet_driver(d,
self.vif_ivs,
"tap")
@ -833,21 +824,21 @@ class LibvirtVifTestCase(test.NoDBTestCase):
self.assertTrue(iface_id_found)
def test_generic_ovs_virtualport_driver(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9011))
d = vif.LibvirtGenericVIFDriver()
want_iface_id = self.vif_ovs['ovs_interfaceid']
self._check_ovs_virtualport_driver(d,
self.vif_ovs,
want_iface_id)
def test_generic_ivs_virtualport_driver(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9011))
d = vif.LibvirtGenericVIFDriver()
want_iface_id = self.vif_ivs['ovs_interfaceid']
self._check_ivs_virtualport_driver(d,
self.vif_ivs,
want_iface_id)
def test_ivs_plug_with_nova_firewall(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
br_want = "qbr" + self.vif_ivs['id']
br_want = br_want[:network_model.NIC_NAME_LEN]
xml = self._get_instance_xml(d, self.vif_ivs)
@ -856,7 +847,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
self.vif_ivs, br_want, 1)
def test_ivs_plug_with_port_filter_direct_no_nova_firewall(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
br_want = "qbr" + self.vif_ivs_filter_hybrid['id']
br_want = br_want[:network_model.NIC_NAME_LEN]
self.flags(firewall_driver="nova.virt.firewall.NoopFirewallDriver")
@ -866,7 +857,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
self.vif_ivs_filter_hybrid, br_want, 0)
def test_ivs_plug_with_port_filter_hybrid_no_nova_firewall(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
br_want = self.vif_ivs_filter_direct['devname']
self.flags(firewall_driver="nova.virt.firewall.NoopFirewallDriver")
xml = self._get_instance_xml(d, self.vif_ivs_filter_direct)
@ -875,7 +866,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
self.vif_ivs_filter_direct, br_want, 0)
def test_hybrid_plug_without_nova_firewall(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
br_want = "qbr" + self.vif_ovs_hybrid['id']
br_want = br_want[:network_model.NIC_NAME_LEN]
self.flags(firewall_driver="nova.virt.firewall.NoopFirewallDriver")
@ -885,7 +876,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
self.vif_ovs_hybrid, br_want, 0)
def test_direct_plug_with_port_filter_cap_no_nova_firewall(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
br_want = self.vif_midonet['devname']
xml = self._get_instance_xml(d, self.vif_ovs_filter_cap)
node = self._get_node(xml)
@ -900,7 +891,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
vif, br_want, 1)
def test_generic_hybrid_driver(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
br_want = "qbr" + self.vif_ovs['id']
br_want = br_want[:network_model.NIC_NAME_LEN]
self._check_neutron_hybrid_driver(d,
@ -908,7 +899,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
br_want)
def test_ivs_hybrid_driver(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
br_want = "qbr" + self.vif_ivs['id']
br_want = br_want[:network_model.NIC_NAME_LEN]
self._check_neutron_hybrid_driver(d,
@ -916,7 +907,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
br_want)
def test_mlnx_direct_vif_driver(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
xml = self._get_instance_xml(d,
self.vif_mlnx)
node = self._get_node(xml)
@ -929,7 +920,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
self._assertModel(xml, network_model.VIF_MODEL_VIRTIO)
def test_midonet_ethernet_vif_driver(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
self.flags(firewall_driver="nova.virt.firewall.NoopFirewallDriver")
br_want = self.vif_midonet['devname']
xml = self._get_instance_xml(d, self.vif_midonet)
@ -938,7 +929,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
self.vif_midonet, br_want)
def test_generic_8021qbh_driver(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
xml = self._get_instance_xml(d, self.vif_8021qbh)
node = self._get_node(xml)
self._assertTypeAndPciEquals(node, "hostdev", self.vif_8021qbh)
@ -957,7 +948,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
self.assertTrue(profile_id_found)
def test_hw_veb_driver(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
xml = self._get_instance_xml(d, self.vif_hw_veb)
node = self._get_node(xml)
self._assertTypeAndPciEquals(node, "hostdev", self.vif_hw_veb)
@ -969,7 +960,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
@mock.patch.object(pci_utils, 'get_ifname_by_pci_address',
return_value='eth1')
def test_hw_veb_driver_macvtap(self, mock_get_ifname):
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
xml = self._get_instance_xml(d, self.vif_macvtap)
node = self._get_node(xml)
self.assertEqual(node.get("type"), "direct")
@ -982,7 +973,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
self.assertIsNone(vlan)
def test_generic_iovisor_driver(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
self.flags(firewall_driver="nova.virt.firewall.NoopFirewallDriver")
br_want = self.vif_ivs['devname']
xml = self._get_instance_xml(d, self.vif_ivs)
@ -991,7 +982,7 @@ class LibvirtVifTestCase(test.NoDBTestCase):
self.vif_ivs, br_want)
def test_generic_8021qbg_driver(self):
d = vif.LibvirtGenericVIFDriver(self._get_conn())
d = vif.LibvirtGenericVIFDriver()
xml = self._get_instance_xml(d, self.vif_8021qbg)
node = self._get_node(xml)

View File

@ -394,8 +394,7 @@ class LibvirtDriver(driver.ComputeDriver):
self.virtapi,
get_connection=self._get_connection)
self.vif_driver = libvirt_vif.LibvirtGenericVIFDriver(
self._get_connection)
self.vif_driver = libvirt_vif.LibvirtGenericVIFDriver()
self.volume_drivers = driver.driver_dict_from_config(
CONF.libvirt.volume_drivers, self)

View File

@ -82,9 +82,6 @@ def is_vif_model_valid_for_virt(virt_type, vif_model):
class LibvirtGenericVIFDriver(object):
"""Generic VIF driver for libvirt networking."""
def __init__(self, get_connection):
self.get_connection = get_connection
def _normalize_vif_type(self, vif_type):
return vif_type.replace('2.1q', '2q')