def compare_vf_mac(pf_name, exp_vf_mac): """ Compare the current vf's mac address with exp_vf_mac :param pf_name: The PF's :param exp_vf_mac: The expected vf's mac address :raise: TestFail if not match """ logging.debug("VF's mac should be %s.", exp_vf_mac) vf_mac_act = utils_sriov.get_vf_mac(pf_name, is_admin=False) if exp_vf_mac != vf_mac_act: test.fail("MAC address changed from '%s' to '%s' after reattaching " "vf." % (exp_vf_mac, vf_mac_act))
def compare_vf_mac(pf_name, exp_vf_mac): """ Compare the current vf's mac address with exp_vf_mac :param pf_name: The PF's :param exp_vf_mac: The expected vf's mac address """ vf_mac_act = utils_sriov.get_vf_mac(pf_name, is_admin=False) if exp_vf_mac != vf_mac_act: logging.error("MAC address changed from '%s' to '%s' after " "reattaching vf.", exp_vf_mac, vf_mac_act) else: logging.debug("VF's mac is still %s.", exp_vf_mac)
def test_hotplug_hostdev_device_with_teaming(): default_vf_mac = utils_sriov.get_vf_mac(pf_name) utils_sriov.set_vf_mac(pf_name, mac_addr) logging.info("Attach the bridge interface.") brg_iface_xml = create_bridge_iface_xml(vm, mac_addr, params) virsh.attach_device(vm_name, brg_iface_xml, debug=True, ignore_status=False) # Wait for 10s before attaching the hostdev device time.sleep(10) logging.info("Attach the hostdev device.") hostdev_dev = libvirt.create_hostdev_xml(vf_pci, teaming=hostdev_teaming_dict) virsh.attach_device(vm_name, hostdev_dev.xml, debug=True, ignore_status=False) vm_session = vm.wait_for_serial_login(timeout=240) ping_ip = get_ping_dest(vm_session, mac_addr) check_vm_network_accessed(vm_session, ping_dest=ping_ip, tcpdump_iface=bridge_name, tcpdump_status_error=True) logging.info("Detach the hostdev device.") virsh.detach_device(vm_name, hostdev_dev.xml, wait_remove_event=True, debug=True, ignore_status=False) logging.debug("Recover vf's mac to %s.", default_vf_mac) utils_sriov.set_vf_mac(pf_name, default_vf_mac) check_hostdev = vm_xml.VMXML.new_from_dumpxml(vm_name)\ .devices.by_device_tag('hostdev') if check_hostdev: test.fail("The hostdev device exists after detaching %s." % check_hostdev) libvirt_vfio.check_vfio_pci(vf_pci, status_error=True) check_vm_network_accessed(vm_session, 2, ping_dest=ping_ip, tcpdump_iface=bridge_name, tcpdump_status_error=False)
def test_vf(): """ Detach/Reattach a vf when it is used in guest 1) Detach/reattach the device 2) Add the device to VM 3) Start the VM 4) Check driver of the device 5) Detach/reattach the device again """ logging.info("Initialize the vfs.") sriov_base.setup_vf(pf_pci, params) vf_pci = utils_sriov.get_vf_pci_id(pf_pci) pf_name = utils_sriov.get_pf_info_by_pci(pf_pci).get('iface') vf_mac = utils_sriov.get_vf_mac(pf_name, is_admin=False) logging.debug("VF's mac: %s.", vf_mac) logging.info("Check the vf's driver, it should not be vfio-pci.") dev_name = utils_sriov.get_device_name(vf_pci) check_driver_from_xml(dev_name) logging.info("Detach and reattach the device and check vf's mac.") nodedev_test(dev_name, no_reset=True) utils_misc.wait_for( lambda: libvirt_vfio.check_vfio_pci(vf_pci, True, True), 10, 5) compare_vf_mac(pf_name, vf_mac) logging.info("Cold-plug the device into the VM.") add_hostdev_iface(vm, vf_pci) vm.start() check_hostdev_iface(vm.name) logging.info("Check the device info. It should be vfio-pci.") check_driver_from_xml(dev_name, status_error=True) nodedev_test(dev_name, True) logging.info("Destroy the vm, and check the vf's mac is recovered.") vm.destroy(gracefully=False) compare_vf_mac(pf_name, vf_mac)