def test_vf_hotplug():
        """
        Hot-plug VF to VM

        """
        logging.info("Preparing a running guest...")
        libvirt_vmxml.remove_vm_devices_by_type(vm, 'interface')
        vm.start()
        vm_session = vm.wait_for_serial_login(timeout=180)

        logging.info("Attaching VF to the guest...")
        mac_addr = utils_net.generate_mac_address_simple()
        iface_dict = eval(
            params.get('iface_dict', '{"hostdev_addr": "%s"}') %
            utils_sriov.pci_to_addr(vf_pci))
        iface = interface.Interface("hostdev")
        iface.xml = libvirt.modify_vm_iface(vm.name, "get_xml", iface_dict)
        virsh.attach_device(vm_name,
                            iface.xml,
                            debug=True,
                            ignore_status=False)

        logging.info("Checking VF in the guest...")
        vm_iface_types = [
            iface.get_type_name() for iface in vm_xml.VMXML.new_from_dumpxml(
                vm_name).devices.by_device_tag("interface")
        ]
        if 'hostdev' not in vm_iface_types:
            test.fail('Unable to get hostdev interface!')
        if cmd_in_vm:
            if not utils_misc.wait_for(
                    lambda: not vm_session.cmd_status(cmd_in_vm), 30, 10):
                test.fail("Can not get the Virtual Function info on vm!")
        vm_session.close()
示例#2
0
 def test_hotplug_vdpa_to_vm_with_hostdev_iface():
     """
     Hotplug the vDPA device to the vm when the VF is in use
     """
     vf_pci = get_vdpa_vf_pci(dev_name)
     iface_args = eval(iface_dict % utils_sriov.pci_to_addr(vf_pci))
     iface_args2 = eval(iface_dict2)
     exec_test(vm, test_scenario, iface_type, iface_args, iface_type2,
               iface_args2)
示例#3
0
 def test_coldplug_vdpa_vf():
     """
     Start the VM with a vDPA device and the VF
     """
     iface_args = eval(iface_dict)
     vf_pci = get_vdpa_vf_pci(dev_name)
     iface_args2 = eval(iface_dict2 % utils_sriov.pci_to_addr(vf_pci))
     exec_test(vm, test_scenario, iface_type, iface_args, iface_type2,
               iface_args2)
 def create_vf_pool():
     """
     Create VF pool
     """
     net_hostdev_dict = {
         "net_name": params.get("net_name"),
         "net_forward": params.get("net_forward"),
         "vf_list_attrs": "[%s]" % utils_sriov.pci_to_addr(vf_pci)
     }
     libvirt_network.create_or_del_network(net_hostdev_dict)
示例#5
0
def add_hostdev_iface(vm, vf_pci):
    """
    Add hostdev device to VM

    :param vm: VM object
    :param vf_pci: PCI ID of a VF
    """
    libvirt_vmxml.remove_vm_devices_by_type(vm, 'interface')
    iface_dict = {"type": "hostdev", "managed": "yes",
                  "hostdev_addr": str(utils_sriov.pci_to_addr(vf_pci))}
    libvirt.modify_vm_iface(vm.name, "update_iface", iface_dict)
def get_hostdev_dict(vf_pci, params):
    """
    Get the updated hostdev dict

    :param vf_pci: VF's pci
    :param params: the parameters dict
    :return: The updated hostdev dict
    """
    pci_to_addr = utils_sriov.pci_to_addr(vf_pci)
    if params.get('hostdev_iface_dict'):
        return eval(params.get('hostdev_iface_dict') % pci_to_addr)
    else:
        del pci_to_addr['type']
        return eval(params.get('hostdev_dict') % pci_to_addr)
    def test_duplicated_cust_alias():
        """
        Hotplug hostdev interface with duplicate custom alias
        """
        vm.cleanup_serial_console()
        vm.create_serial_console()
        vm.wait_for_serial_login(timeout=240).close()
        alias_name = 'ua-' + str(uuid.uuid4())
        hostdev_dict = eval(
            params.get('hostdev_iface_dict') %
            (utils_sriov.pci_to_addr(vf_pci), alias_name))
        exec_test(vm, hostdev_dict, params)

        host_dev = vm_xml.VMXML.new_from_dumpxml(vm.name)\
            .devices.by_device_tag("interface")[0]
        test.log.info("TEST_STEP3: Hotplug another hostdev interface with the"
                      "same alias name")
        vf2_pci = utils_sriov.get_vf_pci_id(pf_pci, vf_index=1)
        hostdev_dict['hostdev_address']['attrs'] = utils_sriov.pci_to_addr(
            vf2_pci)
        host_dev2 = interface_base.create_iface('hostdev', hostdev_dict)
        result = virsh.attach_device(vm_name, host_dev2.xml, debug=True)
        libvirt.check_exit_status(result, True)

        test.log.info("TEST_STEP4: Detach the first hostdev interface.")
        virsh.detach_device(vm_name,
                            host_dev.xml,
                            wait_for_event=True,
                            debug=True,
                            ignore_status=False)

        test.log.info("TEST_STEP5: Attach the second hostdev interface again.")
        virsh.attach_device(vm_name,
                            host_dev2.xml,
                            debug=True,
                            ignore_status=False)
        check_points.comp_hostdev_xml(vm, "interface", hostdev_dict)
示例#8
0
 def setup_hostdev():
     """
     Setup test environment for hostdev
     """
     pf_pci = utils_sriov.get_pf_pci()
     sriov_base.setup_vf(pf_pci, params)
     vf_pci = utils_misc.wait_for(lambda: utils_sriov.get_vf_pci_id(pf_pci),
                                  30, 5)
     pci_to_addr = utils_sriov.pci_to_addr(vf_pci)
     if params.get('iface_dict'):
         params.update({'iface_dict': params.get('iface_dict') % pci_to_addr})
     elif params.get('hostdev_dict'):
         del pci_to_addr['type']
         params.update(
             {'hostdev_dict': params.get('hostdev_dict') % pci_to_addr})
示例#9
0
 def test_at_dt():
     """
     Test attach-detach interfaces
     """
     options = '' if vm.is_alive() else '--config'
     iface_dict = eval(params.get('iface_dict')
                       % utils_sriov.pci_to_addr(vf_pci))
     iface = interface_base.create_iface('hostdev', iface_dict)
     result = virsh.attach_device(vm_name, iface.xml,
                                  flagstr=options, debug=True)
     if not start_vm:
         result = virsh.start(vm.name, debug=True)
     libvirt.check_exit_status(result, status_error)
     if error_msg:
         libvirt.check_result(result, error_msg)
示例#10
0
    def test_device_hotplug():
        """
        Hotplug/unplug VF with managed='no'

        1) Prepare a running guest
        2) Check the driver of vf on host
        3) Prepare a xml with "managed=no"and attach to guest
        4) Detach the device from host
        5) Check the driver of vf on host
        6) Attach the device to guest
        7) Check the interface of the guest
        8) Detach the device from guest and check the driver
        9) Reattach the device to the host and check the driver
        """
        libvirt_vmxml.remove_vm_devices_by_type(vm, 'interface')
        start_vm(vm)
        libvirt_vfio.check_vfio_pci(vf_pci, status_error=True)
        mac_addr = utils_net.generate_mac_address_simple()
        iface_dict = eval(
            params.get('iface_dict', '{"hostdev_addr": "%s"}') %
            utils_sriov.pci_to_addr(vf_pci))
        iface = interface.Interface("hostdev")
        iface.xml = libvirt.modify_vm_iface(vm.name, "get_xml", iface_dict)
        res = virsh.attach_device(vm_name, iface.xml, debug=True)
        libvirt.check_exit_status(res, True)
        virsh.nodedev_detach(dev_name, debug=True, ignore_status=False)
        libvirt_vfio.check_vfio_pci(vf_pci)
        virsh.attach_device(vm_name,
                            iface.xml,
                            debug=True,
                            ignore_status=False)

        check_vm_iface_managed(vm_name, iface_dict)
        vm.wait_for_serial_login().close()
        virsh.detach_device(vm_name,
                            iface.xml,
                            wait_remove_event=True,
                            debug=True,
                            ignore_status=False)
        libvirt_vfio.check_vfio_pci(vf_pci)
        virsh.nodedev_reattach(dev_name, debug=True, ignore_status=False)
        libvirt_vfio.check_vfio_pci(vf_pci, status_error=True)