Example #1
0
    def test_blockjob_raw():
        """
        Do blockjob with raw option.

        1) Prepare a running guest.
        2) Do blockcopy.
        3) Do blockjob with raw option twice and check cur value is changing
        4) Execute with --pivot and check raw option return empty
        """
        options = params.get('option_value', '')
        # Confirm blockcopy not finished.
        if not libvirt.check_blockjob(vm_name, dev, "progress", "100"):
            res_1 = virsh.blockjob(vm_name,
                                   dev,
                                   options=options,
                                   debug=True,
                                   ignore_status=False)
            cur1 = libvirt_misc.convert_to_dict(res_1.stdout_text.strip(),
                                                pattern=r'(\S+)=(\S+)')['cur']
            time.sleep(1)
            res_2 = virsh.blockjob(vm_name,
                                   dev,
                                   options=options,
                                   debug=True,
                                   ignore_status=False)
            cur2 = libvirt_misc.convert_to_dict(res_2.stdout_text.strip(),
                                                pattern=r'(\S+)=(\S+)')['cur']
            LOG.debug('cur1 is %s , cur2 is %s', cur1, cur2)

            if int(cur1) >= int(cur2):
                test.fail('Two times cur value is not changed according'
                          ' to the progress of blockcopy.')

            # Abort job and check abort success.
            if utils_misc.wait_for(
                    lambda: libvirt.check_blockjob(vm_name, dev, "progress",
                                                   "100"), 100):
                virsh.blockjob(vm_name,
                               dev,
                               options=' --pivot',
                               debug=True,
                               ignore_status=False)
            else:
                test.fail("Blockjob timeout in 100 sec.")
            # Check no output after abort.
            result = virsh.blockjob(vm_name,
                                    dev,
                                    options=options,
                                    debug=True,
                                    ignore_status=False)
            if result.stdout_text.strip():
                test.fail("Not return empty after pivot, but get:%s",
                          result.stdout_text.strip())
        else:
            test.error(
                'Blockcopy finished too fast, unable to check raw result,\
             Please consider to reduce bandwith value to retest this case.')
Example #2
0
def get_vm_iface_info(vm_session):
    """
    Get VM's interface info using 'ethtool' command

    :param vm_session: VM's session
    :return: Dict, vm's interface infomation
    """
    vm_iface = get_vm_iface(vm_session)
    cmd = 'ethtool -i %s' % vm_iface
    output_str = vm_session.cmd_output(cmd).strip()
    if_info = libvirt_misc.convert_to_dict(output_str,
                                           pattern=r'(\S+): +(\S+)')
    logging.debug("VM interface info: %s.", if_info)
    return if_info
Example #3
0
def subtest_no_any_option(test):
    """
    Run virsh nodecpustats and check result

    :param test: test object
    :raises: test.fail if command checking fails
    """
    option = ''
    status, output = run_nodecpustats(option)
    if not status:
        actual_value = libvirt_misc.convert_to_dict(output.stdout,
                                                    r"^(\w+)\s*:\s+(\d+)")
        virsh_check_nodecpustats(test, actual_value)
    else:
        test.fail("Command 'virsh nodecpustats %s'" " not succeeded" % option)
Example #4
0
def get_vcpupin_dict(vm_name, vcpu=None, options=None):
    """
    Change vcpupin command output to a dict

    :param vm_name: vm name
    :param vcpu: str, vcpu id to get vcpupin value
    :param options: option for vcpupin command
    :return: new dict
    """

    ret = virsh.vcpupin(vm_name,
                        vcpu=vcpu,
                        options=options,
                        debug=True,
                        ignore_status=False)
    return libvirt_misc.convert_to_dict(ret.stdout.strip(), r'(\d+) +(\S+)')
Example #5
0
def subtest_percentage_option(test):
    """
    Run virsh nodecpustats --percent and check result

    :param test: test object
    :raises: test.fail if command checking fails
    """
    # Test the total cpus to get the stats in percentage
    option = "--percent"
    status, output = run_nodecpustats(option)
    if not status:
        actual_value = libvirt_misc.convert_to_dict(output.stdout,
                                                    r"^(\w+)\s*:\s+(\d+.\d+)")
        virsh_check_nodecpustats_percentage(test, actual_value)
    else:
        test.fail("Command 'virsh nodecpustats %s'" " not succeeded" % option)
Example #6
0
def subtest_cpu_percentage_option(test, cpu, with_cpu_option=True):
    """
    Run virsh nodecpustats --cpu xxx --percent and check result

    :param test: test object
    :param cpu: a specified host cpu
    :param with_cpu_option: True, use '--cpu', otherwise, does not
    :raises: test.fail if command checking fails
    """
    option = "--cpu %s --percent" % cpu if with_cpu_option else " %s --percent" % cpu
    status, output = run_nodecpustats(option)
    if not status:
        actual_value = libvirt_misc.convert_to_dict(output.stdout,
                                                    r"^(\w+)\s*:\s+(\d+.\d+)")
        virsh_check_nodecpustats_percentage(test, actual_value)
    else:
        test.fail("Command 'virsh nodecpustats %s'" " not succeeded" % option)
def run_func(func_name, vm_name, pattern=r'(\d+) +(\S+)'):
    ret = func_name(vm_name, ignore_status=False, debug=True)
    return libvirt_misc.convert_to_dict(ret.stdout_text, pattern)