def _enable_interfaces(self, index, vfs, cfg): vpath = self.ovs_properties.get("vpath", "/usr/local") vf = self.networks[vfs[0]] port_num = vf.get('port_num', 0) vpci = PciAddress.parse_address(vf['vpci'].strip(), multi_line=True) # Generate the vpci for the interfaces slot = index + port_num + 10 vf['vpci'] = \ "{}:{}:{:02x}.{}".format(vpci.domain, vpci.bus, slot, vpci.function) Libvirt.add_ovs_interface(vpath, port_num, vf['vpci'], vf['mac'], str(cfg))
def _enable_interfaces(self, index, idx, vfs, cfg): vf_spoofchk = "ip link set {0} vf 0 spoofchk off" vf = self.networks[vfs[0]] vpci = PciAddress(vf['vpci'].strip()) # Generate the vpci for the interfaces slot = index + idx + 10 vf['vpci'] = \ "{}:{}:{:02x}.{}".format(vpci.domain, vpci.bus, slot, vpci.function) Libvirt.add_sriov_interfaces(vf['vpci'], vf['vf_pci']['vf_pci'], vf['mac'], str(cfg)) self.connection.execute("ifconfig %s up" % vf['interface']) self.connection.execute(vf_spoofchk.format(vf['interface']))
def undeploy(self): """don't need to undeploy""" if not self.vm_deploy: return # Todo: NFVi undeploy (sriov, vswitch, ovs etc) based on the config. for vm in self.vm_names: Libvirt.check_if_vm_exists_and_delete(vm, self.connection) # Bind nics back to kernel for ports in self.networks.values(): # enable VFs for given... build_vfs = "echo 0 > /sys/bus/pci/devices/{0}/sriov_numvfs" self.connection.execute(build_vfs.format(ports.get('phy_port')))
def test_virsh_destroy_vm(self): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "a", "")) ssh.return_value = ssh_mock result = Libvirt.virsh_destroy_vm("vm_0", ssh_mock) self.assertIsNone(result)
def test_check_if_vm_exists_and_delete(self): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "a", "")) ssh.return_value = ssh_mock result = Libvirt.check_if_vm_exists_and_delete("vm_0", ssh_mock) self.assertIsNone(result)
def test_update_interrupts_hugepages_perf(self): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "a", "")) ssh.return_value = ssh_mock status = Libvirt.update_interrupts_hugepages_perf(ssh_mock) self.assertIsNone(status)
def test_pin_vcpu_for_perf(self, mock_update_interrupts_hugepages_perf, mock_CpuSysCores): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "a", "")) ssh.return_value = ssh_mock status = Libvirt.pin_vcpu_for_perf(ssh_mock, "vm_0", 4) self.assertIsNotNone(status)
def test_create_snapshot_qemu(self): result = "/var/lib/libvirt/images/0.qcow2" with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "a", "")) ssh.return_value = ssh_mock image = Libvirt.create_snapshot_qemu(ssh_mock, "0", "ubuntu.img") self.assertEqual(image, result)
def test_build_vm_xml(self, mock_open, mock_write_file, mock_create_snapshot_qemu): result = [4] with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "a", "")) ssh.return_value = ssh_mock mock_create_snapshot_qemu.return_value = "0.img" status = Libvirt.build_vm_xml(ssh_mock, {}, "test", "vm_0", 0) self.assertEqual(status[0], result[0])
def undeploy(self): if not self.vm_deploy: return # Cleanup the ovs installation... self.cleanup_ovs_dpdk_env() # Bind nics back to kernel bind_cmd = "{dpdk_nic_bind} --force -b {driver} {port}" for key, port in self.networks.items(): vpci = port.get("phy_port") phy_driver = port.get("driver") self.connection.execute( bind_cmd.format(dpdk_nic_bind=self.dpdk_nic_bind, driver=phy_driver, port=vpci)) # Todo: NFVi undeploy (sriov, vswitch, ovs etc) based on the config. for vm in self.vm_names: Libvirt.check_if_vm_exists_and_delete(vm, self.connection)
def setup_sriov_context(self): nodes = [] # 1 : modprobe host_driver with num_vfs self.configure_nics_for_sriov() for index, (key, vnf) in enumerate(OrderedDict(self.servers).items()): cfg = '/tmp/vm_sriov_%s.xml' % str(index) vm_name = "vm_%s" % str(index) # 1. Check and delete VM if already exists Libvirt.check_if_vm_exists_and_delete(vm_name, self.connection) _, mac = Libvirt.build_vm_xml(self.connection, self.vm_flavor, cfg, vm_name, index) # 2: Cleanup already available VMs for idx, (vkey, vfs) in enumerate( OrderedDict(vnf["network_ports"]).items()): if vkey == "mgmt": continue self._enable_interfaces(index, idx, vfs, cfg) # copy xml to target... self.connection.put(cfg, cfg) # NOTE: launch through libvirt LOG.info("virsh create ...") Libvirt.virsh_create_vm(self.connection, cfg) self.vm_names.append(vm_name) # build vnf node details nodes.append( self.vnf_node.generate_vnf_instance(self.vm_flavor, self.networks, self.host_mgmt.get('ip'), key, vnf, mac)) return nodes
def test_pin_vcpu_for_perf(self, mock_update_interrupts_hugepages_perf, mock_get_numa_nodes): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "a", "")) ssh.return_value = ssh_mock mock_get_numa_nodes.return_value = { '1': [18, 19, 20, 21], '0': [0, 1, 2, 3] } status = Libvirt.pin_vcpu_for_perf(ssh_mock, "vm_0", 4) self.assertIsNone(status)
def setup_ovs_dpdk_context(self): nodes = [] self.configure_nics_for_ovs_dpdk() for index, (key, vnf) in enumerate(OrderedDict(self.servers).items()): cfg = '/tmp/vm_ovs_%d.xml' % index vm_name = "vm_%d" % index # 1. Check and delete VM if already exists Libvirt.check_if_vm_exists_and_delete(vm_name, self.connection) vcpu, mac = Libvirt.build_vm_xml(self.connection, self.vm_flavor, cfg, vm_name, index) # 2: Cleanup already available VMs for idx, (vkey, vfs) in enumerate( OrderedDict(vnf["network_ports"]).items()): if vkey == "mgmt": continue self._enable_interfaces(index, vfs, cfg) # copy xml to target... self.connection.put(cfg, cfg) # FIXME: launch through libvirt LOG.info("virsh create ...") Libvirt.virsh_create_vm(self.connection, cfg) # 5: Tunning for better performace Libvirt.pin_vcpu_for_perf(self.connection, vm_name, vcpu) self.vm_names.append(vm_name) # build vnf node details nodes.append( self.vnf_node.generate_vnf_instance(self.vm_flavor, self.networks, self.host_mgmt.get('ip'), key, vnf, mac)) return nodes
def test_add_interface_address(self, mock_et): pci_address = PciAddress.parse_address("0000:00:04.0", multi_line=True) result = Libvirt.add_interface_address("<interface/>", pci_address) self.assertIsNotNone(result)
def test_get_numa_nodes(self): result = Libvirt.get_numa_nodes() self.assertIsNotNone(result)
def test_split_cpu_list(self): result = Libvirt.split_cpu_list("1,2,3") self.assertEqual(result, [1, 2, 3])
def test_add_sriov_interfaces(self, mock_et, mock_add_interface_address): pci_address = PciAddress.parse_address("0000:00:04.0", multi_line=True) result = Libvirt.add_sriov_interfaces("0000:00:05.0", "0000:00:04.0", "00:00:00:00:00:01", "xml") self.assertIsNone(result)