예제 #1
0
    def test_hotplug_hostdev_iface_to_vm_with_vdpa_dev():
        """
        Hotplug the VF to the vm with the vDPA device
        """
        iface_args = eval(iface_dict)
        iface = interface_base.create_iface(iface_type, iface_args)

        test.log.info("TEST_STEP1: Start the VM with %s device", iface_type)
        virsh.attach_device(vm.name,
                            iface.xml,
                            flagstr='--config',
                            **VIRSH_ARGS)
        vm.start()
        vm.wait_for_serial_login(timeout=240).close()

        test.log.info("TEST_STEP2: Assign the VF to the VM")
        vf_pci = get_vdpa_vf_pci(dev_name)
        result = virsh.attach_interface(vm.name,
                                        option="%s %s --managed" %
                                        (iface_type2, vf_pci),
                                        debug=True,
                                        timeout=20)

        # FIXME: virsh hangs here, need a way to recover the environment
        if result.exit_status == -15:
            utils_misc.safe_kill(vm.get_pid(), signal.SIGKILL)
            test.fail("virsh may hang when attaching the vf while vdpa device "
                      "is in use!")

        libvirt.check_exit_status(result, status_error)
        if error_msg:
            test.log.debug("error_msg: %s", error_msg)
            libvirt.check_result(result, error_msg)
예제 #2
0
    def run_test(dev_type, params, test_obj=None):
        """
        Test the connectivity of vm's interface

        1) Start the vm with a interface
        2) Check the network driver of VM's interface
        3) Check the network connectivity
        4) Destroy the VM
        """
        # Setup Iface device
        vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
        iface_dict = interface_base.parse_iface_dict(params)
        iface_dev = interface_base.create_iface(dev_type, iface_dict)
        libvirt.add_vm_device(vmxml, iface_dev)

        logging.info("Start a VM with a '%s' type interface.", dev_type)
        vm.start()
        vm_session = vm.wait_for_serial_login(timeout=240)
        vm_iface_info = interface_base.get_vm_iface_info(vm_session)
        if params.get('vm_iface_driver'):
            if vm_iface_info.get('driver') != params.get('vm_iface_driver'):
                test.fail("VM iface should be {}, but got {}."
                          .format(params.get('vm_iface_driver'),
                                  vm_iface_info.get('driver')))

        logging.info("Check the network connectivity")
        check_points.check_network_accessibility(
            vm, test_obj=test_obj, **params)
        virsh.destroy(vm.name, **VIRSH_ARGS)
예제 #3
0
    def exec_test(vm,
                  test_scenario,
                  iface_type,
                  iface_args,
                  iface_type2,
                  iface_args2,
                  params=params):
        """
        Execute test

        :param vm: VM object
        :param test_scenario: Test scenario
        :param iface_type: Interface type for the first device
        :param iface_args: Interface attrs for the first device
        :param iface_type2: Interface type for the second device
        :param iface_args2: Interface attrs for the second device
        :param params: Test parameters
        """
        status_error = "yes" == params.get("status_error", "no")
        error_msg = params.get("error_msg")

        opts = '--config'
        test.log.info("TEST_STEP1: Attach a %s device", iface_type)
        iface = interface_base.create_iface(iface_type, iface_args)
        virsh.attach_device(vm.name, iface.xml, flagstr=opts, **VIRSH_ARGS)

        iface2 = interface_base.create_iface(iface_type2, iface_args2)
        if test_scenario.startswith("hotplug"):
            opts = ''
            libvirt_pcicontr.reset_pci_num(vm.name)
            test.log.info("TEST_STEP2: Start VM")
            vm.start()
            vm.wait_for_serial_login(timeout=240).close()
            test.log.info("TEST_STEP3: Attach a %s device.", iface_type2)
            result = virsh.attach_device(vm.name, iface2.xml, debug=True)
        else:
            test.log.info("TEST_STEP2: Attach a %s device.", iface_type2)
            virsh.attach_device(vm.name,
                                iface2.xml,
                                flagstr=opts,
                                **VIRSH_ARGS)
            test.log.info("TEST_STEP3: 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)
예제 #4
0
def create_dev(params, dev_dict):
    """
    Wrapper function for creating a device

    :param params: the parameters dict
    :param hostdev_dict: Dict, attrs of the device
    :return: new created device
    """
    if params.get('hostdev_iface_dict'):
        return interface_base.create_iface('hostdev', dev_dict)
    else:
        return create_hostdev_device(dev_dict)
예제 #5
0
    def setup_at_memory_to_vm_with_iface(dev_type):
        """
        Prepare a vm with max memory, numa, and an interface

        :param dev_type: interface type
        """
        test_env_obj = setup_test(dev_type)
        # Add interface device
        iface_dict = eval(params.get('iface_dict', '{}'))
        iface_dev = interface_base.create_iface(dev_type, iface_dict)
        vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
        libvirt.add_vm_device(vmxml, iface_dev)
        logging.debug("VM xml afater updating ifaces: %s.",
                      vm_xml.VMXML.new_from_dumpxml(vm_name))
        return test_env_obj
예제 #6
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)
예제 #7
0
    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 run_test(dev_type, params, test_obj=None):
        """
        Test domain lifecycle

        1) Start the vm and check network
        2) Destroy and start the VM, and check network
        3) Save and restore, and check network
        4) Suspend and resume, and check network
        5) Reboot the VM and check the network
        """
        # Setup Iface device
        vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
        iface_dict = eval(params.get('iface_dict', '{}'))
        iface_dev = interface_base.create_iface(dev_type, iface_dict)
        libvirt.add_vm_device(vmxml, iface_dev)

        logging.info("Start a VM with a '%s' type interface.", dev_type)
        vm.start()
        vm.wait_for_serial_login(timeout=240).close()
        check_points.check_network_accessibility(vm,
                                                 test_obj=test_obj,
                                                 **params)

        logging.info("Destroy and start the VM.")
        virsh.destroy(vm.name, **VIRSH_ARGS)
        virsh.start(vm.name, **VIRSH_ARGS)
        check_points.check_network_accessibility(vm,
                                                 test_obj=test_obj,
                                                 config_vdpa=True,
                                                 **params)

        logging.info("Save the VM.")
        save_error = "yes" == params.get("save_error", "no")
        save_path = os.path.join(data_dir.get_tmp_dir(), vm.name + '.save')
        res = virsh.save(vm.name, 'sss', debug=True)
        libvirt.check_exit_status(res, expect_error=save_error)
        if not save_error:
            logging.info("Restore vm.")
            virsh.restore(save_path, **VIRSH_ARGS)
            check_points.check_network_accessibility(vm,
                                                     test_obj=test_obj,
                                                     config_vdpa=False,
                                                     **params)

        logging.info("Suspend and resume the vm.")
        virsh.suspend(vm.name, **VIRSH_ARGS)
        if not libvirt.check_vm_state(vm_name, "paused"):
            test.fail("VM should be paused!")
        virsh.resume(vm.name, **VIRSH_ARGS)
        if not libvirt.check_vm_state(vm_name, "running"):
            test.fail("VM should be running!")
        check_points.check_network_accessibility(vm,
                                                 test_obj=test_obj,
                                                 config_vdpa=False,
                                                 **params)

        logging.debug("Reboot VM and check network.")
        virsh.reboot(vm.name, **VIRSH_ARGS)
        check_points.check_network_accessibility(vm,
                                                 test_obj=test_obj,
                                                 config_vdpa=False,
                                                 **params)