示例#1
0
    def test_at_memory_to_vm_with_iface(dev_type):
        """
        hotplug memory device to vm with an interface

        1) Start vm and check the locked memory
        2) Hotplug memory device and check the locked memory

        :param dev_type: interface type
        """
        vm.start()
        vm.wait_for_serial_login(timeout=240).close()
        new_vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)

        # MEMLOCK value is guest memory + 1G(for the passthrough device)
        expr_memlock = normalize_mem_size(
            new_vmxml.get_current_mem(),
            new_vmxml.get_current_mem_unit()) + 1073741824
        if not check_soft_memlock(expr_memlock):
            test.fail("Unalbe to get correct MEMLOCK after VM startup!")

        logging.info("Hotplug memory device.")
        mem_dict = eval(params.get('mem_dict', '{}'))
        memxml = Memory()
        memxml.setup_attrs(**mem_dict)
        virsh.attach_device(vm_name, memxml.xml, **VIRSH_ARGS)
        expr_memlock += normalize_mem_size(
            mem_dict['target']['size'], mem_dict['target']['size_unit'])
        if not check_soft_memlock(expr_memlock):
            test.fail("Unalbe to get correct MEMLOCK after attaching a memory "
                      "device!")
示例#2
0
    def setup_test_xml_check(case):
        """
        Set up xml check related cases

        :param case: test case
        """
        if case == 'smbios':
            # Edit guest XML with smbios /sysinfo /idmap /metadata and memory device
            vmxml_attrs = {k.replace('vmxml_', ''): int(v) if v.isdigit() else v
                           for k, v in params.items() if k.startswith('vmxml_')}

            vmxml_attrs.update({
                'sysinfo': eval(params.get('sysinfo_attrs', '{}')),
                'os': eval(params.get('os_attrs', '{}')),
                'idmap': eval(params.get('idmap_attrs', '{}')),
                'cpu': eval(params.get('cpu_attrs', '{}'))
            })
            vmxml.setup_attrs(**vmxml_attrs)

            # Setup mem device
            memxml_attrs = eval(params.get('memxml_attrs', '{}'))
            memxml = Memory()
            memxml.setup_attrs(**memxml_attrs)
            vmxml.add_device(memxml)

            # Finish setting up vmxml
            vmxml.sync()
            logging.debug(virsh.dumpxml(vm_name).stdout_text)
示例#3
0
def setup_test_mem_nvdimm(vm, params, test):
    """
    Setup steps for nvdimm device

    :param vm:  VM object
    :param params: dict, test parameters
    :param test: test object
    """
    # Change the disk of the vm
    libvirt.set_vm_disk(vm, params)
    if vm.is_alive():
        vm.destroy(gracefully=False)

    nfs_mount_dir = params.get('nfs_mount_dir')
    nvdimm_file_size = params.get('nvdimm_file_size')
    process.run("truncate -s {} {}/nvdimm".format(nvdimm_file_size,
                                                  nfs_mount_dir),
                shell=True)
    vm_attrs = eval(params.get('vm_attrs', '{}'))
    guest_xml = vm_xml.VMXML.new_from_inactive_dumpxml(vm.name)
    # At first remove all existing memory devices
    remove_devices(guest_xml, '/devices/memory', 'nvdimm', test)
    guest_xml.setup_attrs(**vm_attrs)
    mem_device_attrs = eval(params.get('mem_device_attrs', '{}'))
    dimm_device = Memory()
    dimm_device.setup_attrs(**mem_device_attrs)
    guest_xml.add_device(dimm_device)
    guest_xml.sync()

    vm.start()
    vm_session = vm.wait_for_serial_login(timeout=240)
    create_file_within_nvdimm_disk(vm_session, params.get("test_file_content"))
    vm_session.close()
示例#4
0
    def test_at_iface_and_memory(dev_type):
        """
        hotplug an interface and memory devices

        1) Start vm and check the default locked memory
        2) Hotplug an interface and check the locked memory
        3) Hotplug 2 memory devices and check the locked memory
        4) Hot-unplug a memory device and check the locked memory

        :param dev_type: interface type
        """
        vm.start()
        vm.wait_for_serial_login(timeout=240).close()
        expr_memlock = 67108864
        if not check_soft_memlock(expr_memlock):
            test.fail("Unalbe to get correct default!")

        interface_base.attach_iface_device(vm_name, dev_type, params)

        new_vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
        # MEMLOCK value is guest memory + 1G(for the passthrough device)
        expr_memlock = normalize_mem_size(
            new_vmxml.get_current_mem(),
            new_vmxml.get_current_mem_unit()) + 1073741824
        if not check_soft_memlock(expr_memlock):
            test.fail("Unalbe to get correct MEMLOCK after VM startup!")

        logging.info("Hotplug memory devices.")
        for mem_attrs in ['mem_dict1', 'mem_dict2']:
            mem_dict = eval(params.get(mem_attrs, '{}'))
            memxml = Memory()
            memxml.setup_attrs(**mem_dict)
            virsh.attach_device(vm_name, memxml.xml, **VIRSH_ARGS)
            expr_memlock += normalize_mem_size(
                mem_dict['target']['size'], mem_dict['target']['size_unit'])
            if not check_soft_memlock(expr_memlock):
                test.fail("Unalbe to get correct MEMLOCK after attaching a "
                          "memory device!")

        logging.info("Detach a memory device and check memlock.")
        memxml = vm_xml.VMXML.new_from_dumpxml(vm_name).get_devices('memory')[-1]
        cmd_result = virsh.detach_device(vm_name, memxml.xml,
                                         wait_for_event=True,
                                         debug=True)
        if cmd_result.exit_status:
            libvirt.check_result(cmd_result, 'unplug of device was rejected')
            if not check_soft_memlock(expr_memlock):
                test.fail("Detaching mem failed, MEMLOCK should not change!")
        else:
            if not check_soft_memlock(expr_memlock):
                test.fail("Unalbe to get correct MEMLOCK after detaching a "
                          "memory device!")
示例#5
0
    def run_test_dimm(case):
        """
        Multi-operation for dimm devices

        :param case: test case
        """
        vm_attrs = eval(params.get('vm_attrs', '{}'))
        vmxml.setup_attrs(**vm_attrs)

        # Start a guest with 3 dimm device
        dimm_devices_attrs = [
            eval(v) for k, v in params.items() if k.startswith('dimm_device_')
        ]
        for attrs in dimm_devices_attrs:
            dimm_device = Memory()
            dimm_device.setup_attrs(**attrs)
            logging.debug(dimm_device)
            vmxml.add_device(dimm_device)

        vmxml.sync()
        logging.debug(virsh.dumpxml(vm_name).stdout_text)
        vm.start()
        # Check qemu cmd line for amount of dimm device
        dimm_device_num = len(dimm_devices_attrs)
        qemu_cmd = 'pgrep -a qemu'
        qemu_cmd_output = process.run(qemu_cmd, verbose=True).stdout_text
        qemu_cmd_num = len(re.findall("-device.*?pc-dimm", qemu_cmd_output))
        if qemu_cmd_num != dimm_device_num:
            test.fail('The amount of dimm device in qemu command line does not'
                      ' match vmxml, expect %d, but get %d' %
                      (dimm_device_num, qemu_cmd_num))

        # Attach a mem device
        at_dimm_device_attrs = eval(params.get('at_dimm_device'))
        at_dim_device = Memory()
        at_dim_device.setup_attrs(**at_dimm_device_attrs)
        virsh.attach_device(vm_name, at_dim_device.xml, **VIRSH_ARGS)

        # Managedsave guest and restore
        virsh.managedsave(vm_name, **VIRSH_ARGS)
        virsh.start(vm_name, **VIRSH_ARGS)

        # Check qemu cmd line for attached dimm device
        new_qemu_cmd_output = process.run(qemu_cmd, verbose=True).stdout_text
        new_qemu_cmd_num = len(
            re.findall("-device.*?pc-dimm", new_qemu_cmd_output))
        if new_qemu_cmd_num != dimm_device_num + 1:
            test.fail('The amount of dimm device in qemu command line does not'
                      ' match vmxml, expect %d, but get %d' %
                      (dimm_device_num + 1, new_qemu_cmd_num))
        libvirt.check_qemu_cmd_line(qemu_check)
    def setup_test_virtio_mem():
        """
        Setup vmxml for test
        """
        set_num_huge_pages = params.get("set_num_huge_pages")
        if set_num_huge_pages:
            utils_memory.set_num_huge_pages(int(set_num_huge_pages))

        libvirt_vmxml.remove_vm_devices_by_type(vm, 'memory')
        vm_attrs = eval(params.get('vm_attrs', '{}'))
        vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
        vmxml.setup_attrs(**vm_attrs)
        vmxml.sync()
        mem_device_attrs = eval(params.get('mem_device_attrs', '{}'))
        mem_device = Memory()
        mem_device.setup_attrs(**mem_device_attrs)

        virsh.attach_device(vm_name,
                            mem_device.xml,
                            flagstr='--config',
                            debug=True,
                            ignore_status=False)
示例#7
0
    def run_test_virtio_mem():
        """
        Attach a virtio-mem device
        """
        mem_device_attrs = eval(params.get('mem_device_attrs', '{}'))
        mem_device = Memory()
        mem_device.setup_attrs(**mem_device_attrs)

        test.log.info("TEST_STEP1: Attach a virtio-mem device.")
        options = '' if vm.is_alive() else '--config'
        virsh.attach_device(vm_name,
                            mem_device.xml,
                            flagstr=options,
                            debug=True,
                            ignore_status=False)

        if not vm.is_alive():
            vm.start()
            vm.wait_for_login().close()

        test.log.info("TEST_STEP2: Check requested and current size.")
        vmxml_cur = vm_xml.VMXML.new_from_dumpxml(vm_name)
        test.log.debug("Current VM XML: %s.", vmxml_cur)
        mem_dev = vmxml_cur.devices.by_device_tag("memory")[0]
        expr_requested_size = mem_device_attrs['target']['requested_size']
        for check_item in ['requested_size', 'current_size']:
            if getattr(mem_dev.target, check_item) != expr_requested_size:
                test.fail("Incorrect %s! It should be %s, but got %s." %
                          (check_item, expr_requested_size,
                           getattr(mem_dev.target, check_item)))

        test.log.info("TEST_STEP3: Check VM memory.")
        memory_gap = vmxml_cur.get_memory() - vmxml_cur.get_current_mem()
        virtio_mem_gap = mem_dev.target.get_size() - \
            mem_dev.target.get_current_size()
        if memory_gap != virtio_mem_gap:
            test.fail("Size of memory - currentMemory(%s) should be equal to "
                      "virtio-mem size - current(%s)." %
                      (memory_gap, virtio_mem_gap))
示例#8
0
    def run_test_audit_size(case):
        """
        Audit memory size with memory hot-plug/unplug operations

        :param case: test case
        """
        numa_node_size = int(params.get('numa_node_size'))
        at_size = int(params.get('at_size'))
        current_mem = int(params.get('vmxml_current_mem'))
        audit_cmd = params.get('audit_cmd')
        dominfo_check_0 = params.get('dominfo_check_0') % (
            numa_node_size * 2, current_mem)
        dominfo_check_1 = params.get('dominfo_check_1') % (
            numa_node_size * 2 + at_size, current_mem + at_size
        )
        ausearch_check_1 = params.get('ausearch_check_1') % (
            0, numa_node_size * 2,
            numa_node_size * 2, numa_node_size * 2 + at_size
        )
        ausearch_check_2 = params.get('ausearch_check_2') % (
            numa_node_size * 2 + at_size, numa_node_size * 2 + at_size
        )
        dominfo_check_3 = dominfo_check_0
        ausearch_check_3 = params.get('ausearch_check_3') % (
            numa_node_size * 2 + at_size, numa_node_size * 2
        )

        # Start vm and wait for vm to bootup
        vm.start()
        vm.wait_for_login().close()
        logging.debug('Vmxml after started:\n%s',
                      virsh.dumpxml(vm_name).stdout_text)

        # Check dominfo before hotplug mem device
        dominfo = virsh.dominfo(vm_name, **VIRSH_ARGS)
        libvirt.check_result(dominfo, expected_match=dominfo_check_0)

        # Prepare dimm memory devices to be attached
        dimm_devices = []
        for i in (0, 1):
            dimm_device = Memory()
            dimm_device_attrs = eval(
                params.get('dimm_device_%d_attrs' % i, '{}'))
            dimm_device.setup_attrs(**dimm_device_attrs)
            dimm_devices.append(dimm_device)

        def check_dominfo_and_ausearch(dominfo_check, ausearch_check):
            """
            Check output of virsh dominfo and ausearch command

            :param dominfo_check: patterns to search in dominfo output
            :param ausearch_check: patterns to search in ausearch output
            """
            if dominfo_check:
                dominfo = virsh.dominfo(vm_name, **VIRSH_ARGS)
                libvirt.check_result(dominfo, expected_match=dominfo_check)
            if ausearch_check:
                ausearch_result = process.run(audit_cmd,
                                              verbose=True, shell=True)
                libvirt.check_result(ausearch_result,
                                     expected_match=ausearch_check)

        # Hotplug dimm device to guest
        virsh.attach_device(vm_name, dimm_devices[1].xml, **VIRSH_ARGS)
        check_dominfo_and_ausearch(dominfo_check_1, ausearch_check_1)

        # Hotplug dimm device with size 0 G, should fail with error message
        at_result = virsh.attach_device(vm_name, dimm_devices[0].xml,
                                        debug=True)
        libvirt.check_result(at_result, error_msg)
        check_dominfo_and_ausearch(None, ausearch_check_2)

        # HotUnplug the dimm device
        virsh.detach_device(vm_name, dimm_devices[1].xml, **VIRSH_ARGS)
        check_dominfo_and_ausearch(dominfo_check_3, ausearch_check_3)