def test_hw_veb_driver_macvtap(self, mock_get_ifname): d = vif.LibvirtGenericVIFDriver() xml = self._get_instance_xml(d, self.vif_macvtap) node = self._get_node(xml) self.assertEqual(node.get("type"), "direct") self._assertTypeEquals(node, "direct", "source", "dev", "eth1") self._assertTypeEquals(node, "direct", "source", "mode", "passthrough") self._assertMacEquals(node, self.vif_macvtap) vlan = node.find("vlan") self.assertIsNone(vlan)
def test_unplug_mlnx_with_details(self): d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010)) with mock.patch.object(utils, 'execute') as execute: execute.side_effect = processutils.ProcessExecutionError d.unplug_mlnx_direct(None, self.vif_mlnx_net) execute.assert_called_once_with('ebrctl', 'del-port', 'fake_phy_network', 'ca:fe:de:ad:be:ef', run_as_root=True)
def test_generic_driver_none(self): def get_connection(): return fakelibvirt.Connection("qemu:///session", False) d = vif.LibvirtGenericVIFDriver(get_connection) self.assertRaises(exception.NovaException, self._get_instance_xml, d, self.net_bridge, self.mapping_none)
def test_mlnx_direct_vif_driver(self): d = vif.LibvirtGenericVIFDriver(self._get_conn()) xml = self._get_instance_xml(d, self.vif_mlnx) node = self._get_node(xml) self.assertEqual(node.get("type"), "direct") self._assertTypeEquals(node, "direct", "source", "dev", "eth-xxx-yyy-zzz") self._assertTypeEquals(node, "direct", "source", "mode", "passthrough") self._assertMacEquals(node, self.vif_mlnx) self._assertModel(xml, network_model.VIF_MODEL_VIRTIO)
def test_plug_iovisor(self): d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010)) with mock.patch.object(utils, 'execute') as execute: execute.side_effect = processutils.ProcessExecutionError instance = { 'name': 'instance-name', 'uuid': 'instance-uuid', 'project_id': 'myproject' } d.plug_iovisor(instance, self.vif_ivs)
def test_model_kvm_bogus(self): self.flags(use_virtio_for_bridges=True, virt_type='kvm', group='libvirt') d = vif.LibvirtGenericVIFDriver(self._get_conn()) image_meta = {'properties': {'hw_vif_model': 'acme'}} self.assertRaises(exception.UnsupportedHardware, self._get_instance_xml, d, self.vif_bridge, image_meta)
def test_unplug_iovisor(self): d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010)) with mock.patch.object(utils, 'execute') as execute: execute.side_effect = processutils.ProcessExecutionError mynetwork = network_model.Network(id='network-id-xxx-yyy-zzz', label='mylabel') myvif = network_model.VIF(id='vif-xxx-yyy-zzz', address='ca:fe:de:ad:be:ef', network=mynetwork) d.unplug_iovisor(None, myvif)
def test_model_kvm_bogus(self): self.flags(libvirt_use_virtio_for_bridges=True, libvirt_type='kvm') def get_connection(): return fakelibvirt.Connection("qemu:///session", False) d = vif.LibvirtGenericVIFDriver(get_connection) image_meta = {'properties': {'hw_vif_model': 'acme'}} self.assertRaises(exception.UnsupportedHardware, self._get_instance_xml, d, self.net_bridge, self.mapping_bridge, image_meta)
def test_generic_ovs_virtualport_driver(self): def get_connection(): return fakelibvirt.Connection("qemu:///session", False, 9011) d = vif.LibvirtGenericVIFDriver(get_connection) want_iface_id = self.mapping_ovs['ovs_interfaceid'] self._check_ovs_virtualport_driver(d, self.net_ovs, self.mapping_ovs, want_iface_id)
def test_plug_iovisor(self, device_exists): device_exists.return_value = True d = vif.LibvirtGenericVIFDriver() with mock.patch.object(utils, 'execute') as execute: execute.side_effect = processutils.ProcessExecutionError instance = { 'name': 'instance-name', 'uuid': 'instance-uuid', 'project_id': 'myproject' } d.plug_iovisor(instance, self.vif_ivs)
def test_plug_mlnx_with_details(self): d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010)) 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', 'ca:fe:de:ad:be:ef', 'instance-uuid', 'fake_phy_network', 'mlnx_direct', 'eth-xxx-yyy-zzz', run_as_root=True)
def test_model_kvm_custom(self): self.flags(use_virtio_for_bridges=True, virt_type='kvm', group='libvirt') d = vif.LibvirtGenericVIFDriver(self._get_conn()) image_meta = {'properties': {'hw_vif_model': network_model.VIF_MODEL_E1000}} xml = self._get_instance_xml(d, self.vif_bridge, image_meta) self._assertModel(xml, network_model.VIF_MODEL_E1000)
def test_model_qemu(self): self.flags(libvirt_use_virtio_for_bridges=True, libvirt_type='qemu') d = vif.LibvirtGenericVIFDriver(self._get_conn()) xml = self._get_instance_xml(d, self.net_bridge, self.mapping_bridge) doc = etree.fromstring(xml) ret = doc.findall('./devices/interface/bandwidth') self.assertEqual(len(ret), 1) self._assertModel(xml, "virtio", "qemu")
def test_unplug_ovs_hybrid_bridge_does_not_exist(self): calls = { 'device_exists': [mock.call('qbrvif-xxx-yyy')], 'delete_ovs_vif_port': [mock.call('br0', 'qvovif-xxx-yyy')] } with contextlib.nested( mock.patch.object(linux_net, 'device_exists', 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.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'])
def test_model_kvm_qemu_custom(self): for virt in ('kvm', 'qemu'): self.flags(use_virtio_for_bridges=True, virt_type=virt, group='libvirt') d = vif.LibvirtGenericVIFDriver(self._get_conn()) supported = (network_model.VIF_MODEL_NE2K_PCI, network_model.VIF_MODEL_PCNET, network_model.VIF_MODEL_RTL8139, network_model.VIF_MODEL_E1000, network_model.VIF_MODEL_SPAPR_VLAN) for model in supported: image_meta = {'properties': {'hw_vif_model': model}} xml = self._get_instance_xml(d, self.vif_bridge, image_meta) self._assertModel(xml, model)
def test_unplug_ovs_hybrid(self): calls = { 'device_exists': [mock.call('qbrvif-xxx-yyy'), mock.call('qvovif-xxx-yyy')], 'execute': [ mock.call('brctl', 'delif', 'qbrvif-xxx-yyy', 'qvbvif-xxx-yyy', run_as_root=True), mock.call('ip', 'link', 'set', 'qbrvif-xxx-yyy', 'down', run_as_root=True), mock.call('brctl', 'delbr', 'qbrvif-xxx-yyy', run_as_root=True), mock.call('ovs-vsctl', '--timeout=120', 'del-port', 'br0', 'qvovif-xxx-yyy', run_as_root=True), mock.call('ip', 'link', 'delete', 'qvovif-xxx-yyy', run_as_root=True, check_exit_code=[0, 2, 254]) ] } with contextlib.nested( mock.patch.object(linux_net, 'device_exists', return_value=True), mock.patch.object(utils, 'execute'), mock.patch.object( linux_net, 'delete_ivs_vif_port')) as (device_exists, execute, delete_ivs_vif_port): d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010)) d.unplug_ovs_hybrid(None, self.vif_ovs) device_exists.assert_has_calls(calls['device_exists']) execute.assert_has_calls(calls['execute']) delete_ivs_vif_port.assert_has_calls([])
def test_generic_8021qbg_driver(self): def get_connection(): return fakelibvirt.Connection("qemu:///session", False) d = vif.LibvirtGenericVIFDriver(get_connection) xml = self._get_instance_xml(d, self.net_8021, self.mapping_8021qbg) doc = etree.fromstring(xml) print xml ret = doc.findall('./devices/interface') self.assertEqual(len(ret), 1) node = ret[0] self.assertEqual(node.get("type"), "direct") br_name = node.find("source").get("dev") self.assertEqual(br_name, "eth0") mac = node.find("mac").get("address") self.assertEqual(mac, self.mapping_8021qbg['mac']) vp = node.find("virtualport") self.assertEqual(vp.get("type"), "802.1Qbg") manager_id_found = False type_id_found = False typeversion_id_found = False instance_id_found = False for p_elem in vp.findall("parameters"): wantparams = self.mapping_8021qbg['qbg_params'] manager_id = p_elem.get("managerid", None) type_id = p_elem.get("typeid", None) typeversion_id = p_elem.get("typeidversion", None) instance_id = p_elem.get("instanceid", None) if manager_id: self.assertEqual(manager_id, wantparams['managerid']) manager_id_found = True if type_id: self.assertEqual(type_id, wantparams['typeid']) type_id_found = True if typeversion_id: self.assertEqual(typeversion_id, wantparams['typeidversion']) typeversion_id_found = True if instance_id: self.assertEqual(instance_id, wantparams['instanceid']) instance_id_found = True self.assertTrue(manager_id_found) self.assertTrue(type_id_found) self.assertTrue(typeversion_id_found) self.assertTrue(instance_id_found)
def test_generic_8021qbh_driver(self): d = vif.LibvirtGenericVIFDriver(self._get_conn()) xml = self._get_instance_xml(d, self.vif_8021qbh) node = self._get_node(xml) self._assertTypeEquals(node, "direct", "source", "dev", "eth0") self._assertMacEquals(node, self.vif_8021qbh) vp = node.find("virtualport") self.assertEqual(vp.get("type"), "802.1Qbh") profile_id_found = False for p_elem in vp.findall("parameters"): wantparams = self.vif_8021qbh['qbh_params'] profile_id = p_elem.get("profileid", None) if profile_id: self.assertEqual(profile_id, wantparams['profileid']) profile_id_found = True self.assertTrue(profile_id_found)
def test_model_qemu(self): self.flags(libvirt_use_virtio_for_bridges=True, libvirt_type='qemu') def get_connection(): return fakelibvirt.Connection("qemu:///session", False) d = vif.LibvirtGenericVIFDriver(get_connection) xml = self._get_instance_xml(d, self.net_bridge, self.mapping_bridge) doc = etree.fromstring(xml) ret = doc.findall('./devices/interface') self.assertEqual(len(ret), 1) node = ret[0] model = node.find("model").get("type") self.assertEqual(model, "virtio") driver = node.find("driver").get("name") self.assertEqual(driver, "qemu")
def test_unplug_ivs_hybrid(self): calls = { 'execute': [mock.call('brctl', 'delif', 'qbrvif-xxx-yyy', 'qvbvif-xxx-yyy', run_as_root=True), mock.call('ip', 'link', 'set', 'qbrvif-xxx-yyy', 'down', run_as_root=True), mock.call('brctl', 'delbr', 'qbrvif-xxx-yyy', run_as_root=True)], 'delete_ivs_vif_port': [mock.call('qvovif-xxx-yyy')] } with contextlib.nested( 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.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_generic_8021qbh_driver(self): d = vif.LibvirtGenericVIFDriver(self._get_conn()) xml = self._get_instance_xml(d, self.vif_8021qbh) node = self._get_node(xml) self._assertTypeAndPciEquals(node, "hostdev", self.vif_8021qbh) self._assertMacEquals(node, self.vif_8021qbh) vp = node.find("virtualport") self.assertEqual(vp.get("type"), "802.1Qbh") profile_id_found = False for p_elem in vp.findall("parameters"): details = self.vif_8021qbh["details"] profile_id = p_elem.get("profileid", None) if profile_id: self.assertEqual(profile_id, details[network_model.VIF_DETAILS_PROFILEID]) profile_id_found = True self.assertTrue(profile_id_found)
def test_model_xen(self): self.flags(libvirt_use_virtio_for_bridges=True, libvirt_type='xen') def get_connection(): return fakelibvirt.Connection("xen:///system", False) d = vif.LibvirtGenericVIFDriver(get_connection) xml = self._get_instance_xml(d, self.net_bridge, self.mapping_bridge) doc = etree.fromstring(xml) ret = doc.findall('./devices/interface') self.assertEqual(len(ret), 1) node = ret[0] ret = node.findall("model") self.assertEqual(len(ret), 0) ret = node.findall("driver") self.assertEqual(len(ret), 0)
def test_model_kvm_custom(self): self.flags(libvirt_use_virtio_for_bridges=True, libvirt_type='kvm') def get_connection(): return fakelibvirt.Connection("qemu:///session", False) d = vif.LibvirtGenericVIFDriver(get_connection) image_meta = {'properties': {'hw_vif_model': 'e1000'}} xml = self._get_instance_xml(d, self.net_bridge, self.mapping_bridge, image_meta) doc = etree.fromstring(xml) ret = doc.findall('./devices/interface') self.assertEqual(len(ret), 1) node = ret[0] model = node.find("model").get("type") self.assertEqual(model, "e1000") ret = node.findall("driver") self.assertEqual(len(ret), 0)
def test_generic_8021qbg_driver(self): d = vif.LibvirtGenericVIFDriver(self._get_conn()) xml = self._get_instance_xml(d, self.vif_8021qbg) node = self._get_node(xml) self._assertTypeEquals(node, "direct", "source", "dev", "eth0") self._assertMacEquals(node, self.vif_8021qbg) vp = node.find("virtualport") self.assertEqual(vp.get("type"), "802.1Qbg") manager_id_found = False type_id_found = False typeversion_id_found = False instance_id_found = False for p_elem in vp.findall("parameters"): wantparams = self.vif_8021qbg['qbg_params'] manager_id = p_elem.get("managerid", None) type_id = p_elem.get("typeid", None) typeversion_id = p_elem.get("typeidversion", None) instance_id = p_elem.get("instanceid", None) if manager_id: self.assertEqual(manager_id, wantparams['managerid']) manager_id_found = True if type_id: self.assertEqual(type_id, wantparams['typeid']) type_id_found = True if typeversion_id: self.assertEqual(typeversion_id, wantparams['typeidversion']) typeversion_id_found = True if instance_id: self.assertEqual(instance_id, wantparams['instanceid']) instance_id_found = True self.assertTrue(manager_id_found) self.assertTrue(type_id_found) self.assertTrue(typeversion_id_found) self.assertTrue(instance_id_found)
def test_plug_ovs_hybrid(self): calls = { 'device_exists': [mock.call('qbrvif-xxx-yyy'), mock.call('qvovif-xxx-yyy')], '_create_veth_pair': [mock.call('qvbvif-xxx-yyy', 'qvovif-xxx-yyy')], 'execute': [mock.call('brctl', 'addbr', 'qbrvif-xxx-yyy', run_as_root=True), mock.call('brctl', 'setfd', 'qbrvif-xxx-yyy', 0, run_as_root=True), mock.call('brctl', 'stp', 'qbrvif-xxx-yyy', 'off', run_as_root=True), mock.call('tee', ('/sys/class/net/qbrvif-xxx-yyy' '/bridge/multicast_snooping'), process_input='0', run_as_root=True, check_exit_code=[0, 1]), mock.call('ip', 'link', 'set', 'qbrvif-xxx-yyy', 'up', run_as_root=True), mock.call('brctl', 'addif', 'qbrvif-xxx-yyy', 'qvbvif-xxx-yyy', run_as_root=True)], 'create_ovs_vif_port': [mock.call('br0', 'qvovif-xxx-yyy', 'aaa-bbb-ccc', 'ca:fe:de:ad:be:ef', 'instance-uuid')] } with contextlib.nested( mock.patch.object(linux_net, 'device_exists', return_value=False), mock.patch.object(utils, 'execute'), 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.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']) execute.assert_has_calls(calls['execute']) create_ovs_vif_port.assert_has_calls(calls['create_ovs_vif_port'])
except qcexp.NeutronClientException as e: print >> sys.stderr, e exit(1) port_id = port['port']['id'] instance = {'uuid': vm_uuid} network = {'bridge': 'br-int'} class VeryDangerousHack(network_model.VIF): def __init__(self, port_id, mac_addr, network): super(VeryDangerousHack, self).__init__( id=port_id, address=mac_addr, network=network, type=network_model.VIF_TYPE_OVS, # details={'ovs_hybrid_plug': False, 'port_filter': False}, active=True) vif = VeryDangerousHack(port_id, mac_addr, network) # For ML2 plugin driver = vif_driver.LibvirtGenericVIFDriver({}) driver.plug(instance, vif) br_name = driver.get_br_name(port_id) print br_name, port_name, port_id, net_name, nw_id
def test_ivs_hybrid_driver(self): d = vif.LibvirtGenericVIFDriver(self._get_conn()) br_want = "qbr" + self.vif_ivs['id'] br_want = br_want[:network_model.NIC_NAME_LEN] self._check_neutron_hybrid_driver(d, self.vif_ivs, br_want)
def test_generic_ivs_virtualport_driver(self): d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9011)) want_iface_id = self.vif_ivs['ovs_interfaceid'] self._check_ivs_virtualport_driver(d, self.vif_ivs, want_iface_id)
def test_ivs_ethernet_driver(self): d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010)) self._check_ivs_ethernet_driver(d, self.vif_ivs, "tap")
def test_unplug_ivs_hybrid_bridge_does_not_exist(self): d = vif.LibvirtGenericVIFDriver(self._get_conn(ver=9010)) with mock.patch.object(utils, 'execute') as execute: execute.side_effect = processutils.ProcessExecutionError d.unplug_ivs_hybrid(None, self.vif_ivs)