コード例 #1
0
def get_blkio_parameter(test, params, cgstop):
    """
    Get the blkio parameters

    :param test: the test handle
    :param params: the parameter dictionary
    :param cgstop: the status of cgconfig
    """
    vm_name = params.get("main_vm")
    options = params.get("options")

    result = virsh.blkiotune(vm_name, options=options)
    status = result.exit_status

    # Check status_error
    status_error = params.get("status_error", "no")

    if status_error == "yes":
        if status:
            logging.info("It's an expected %s", result.stderr)
        else:
            if cgstop:
                test.fail("Unexpected return code %d" % status)
            else:
                logging.info("Control groups stopped, thus expected success")
    elif status_error == "no":
        if status:
            test.fail(result.stderr)
        else:
            logging.info(result.stdout)
コード例 #2
0
def get_blkio_parameter(test, params, cgstop):
    """
    Get the blkio parameters

    :param test: the test handle
    :param params: the parameter dictionary
    :param cgstop: the status of cgconfig
    """
    vm_name = params.get("main_vm")
    options = params.get("options")

    result = virsh.blkiotune(vm_name, options=options)
    status = result.exit_status

    # Check status_error
    status_error = params.get("status_error", "no")

    if status_error == "yes":
        if status:
            logging.info("It's an expected %s", result.stderr)
        else:
            if cgstop:
                test.fail("Unexpected return code %d" % status)
            else:
                logging.info("Control groups stopped, thus expected success")
    elif status_error == "no":
        if status:
            test.fail(result.stderr)
        else:
            logging.info(result.stdout)
コード例 #3
0
def set_blkio_parameter(test, params, cgstop):
    """
    Set the blkio parameters

    :param test: the test handle
    :param params: the parameter dictionary
    :param cgstop: the status of cgconfig
    """
    vm_name = params.get("main_vm")
    weight = params.get("blkio_weight")
    device_weights = params.get("blkio_device_weights")
    options = params.get("options")

    result = virsh.blkiotune(vm_name,
                             weight,
                             device_weights,
                             options=options,
                             debug=True)
    status = result.exit_status

    # Check status_error
    status_error = params.get("status_error", "no")

    if status_error == "yes":
        if status:
            logging.info("It's an expected %s", result.stderr)
        else:
            if cgstop:
                test.fail("Unexpected return code %d" % status)
            else:
                logging.info("Control groups stopped, thus expected success")
    elif status_error == "no":
        is_cfq = params.get('iosche_for_test') == 'cfq'
        if status and not is_cfq and device_weights:
            logging.info(
                "Set/get device weight is only supported for cfq."
                " It's an expected %s", result.stderr)
        elif status:
            test.fail(result.stderr)
        else:
            if check_blkiotune(test, params):
                logging.info(result.stdout)
            else:
                test.fail("The 'weight' or/and 'device-weights' are"
                          " inconsistent with blkiotune XML or/and"
                          " blkio.weight and blkio.weight_device"
                          " value from cgroup blkio controller")

    # Start Vm if needed
    validate_vm_not_start = "yes" == params.get("validate_vm_not_start", "no")
    if validate_vm_not_start:
        result = virsh.start(vm_name, debug=True)
        vm_not_start_error_msg = params.get("vm_not_start_error_msg")
        if vm_not_start_error_msg not in result.stderr_text:
            test.fail("can not find error message: %s" %
                      vm_not_start_error_msg)
コード例 #4
0
def set_blkio_parameter(test, params, cgstop):
    """
    Set the blkio parameters

    :param test: the test handle
    :param params: the parameter dictionary
    :param cgstop: the status of cgconfig
    """
    vm_name = params.get("main_vm")
    weight = params.get("blkio_weight")
    device_weights = params.get("blkio_device_weights")
    options = params.get("options")

    result = virsh.blkiotune(vm_name, weight, device_weights, options=options)
    status = result.exit_status

    # Check status_error
    status_error = params.get("status_error", "no")

    if status_error == "yes":
        if status:
            logging.info("It's an expected %s", result.stderr)
        else:
            if cgstop:
                test.fail("Unexpected return code %d" % status)
            else:
                logging.info("Control groups stopped, thus expected success")
    elif status_error == "no":
        if status:
            test.fail(result.stderr)
        else:
            if check_blkiotune(test, params):
                logging.info(result.stdout)
            else:
                test.fail("The 'weight' or/and 'device-weights' are"
                          " inconsistent with blkiotune XML or/and"
                          " blkio.weight and blkio.weight_device"
                          " value from cgroup blkio controller")
コード例 #5
0
def set_blkio_parameter(test, params, cgstop):
    """
    Set the blkio parameters

    :param test: the test handle
    :param params: the parameter dictionary
    :param cgstop: the status of cgconfig
    """
    vm_name = params.get("main_vm")
    weight = params.get("blkio_weight")
    device_weights = params.get("blkio_device_weights")
    options = params.get("options")

    result = virsh.blkiotune(vm_name, weight, device_weights, options)
    status = result.exit_status

    # Check status_error
    status_error = params.get("status_error", "no")

    if status_error == "yes":
        if status:
            logging.info("It's an expected %s", result.stderr)
        else:
            if cgstop:
                test.fail("Unexpected return code %d" % status)
            else:
                logging.info("Control groups stopped, thus expected success")
    elif status_error == "no":
        if status:
            test.fail(result.stderr)
        else:
            if check_blkiotune(test, params):
                logging.info(result.stdout)
            else:
                test.fail("The 'weight' or/and 'device-weights' are"
                          " inconsistent with blkiotune XML or/and"
                          " blkio.weight and blkio.weight_device"
                          " value from cgroup blkio controller")
コード例 #6
0
def check_blkiotune(test, params):
    """
    To compare weight and device-weights value with guest XML
    configuration, virsh blkiotune output and corresponding
    blkio.weight and blkio.weight_device value from cgroup.

    :param test: the test handle
    :param params: the parameter dictionary
    """
    vm_name = params.get("main_vm")
    vm = params.get("vm")
    options = params.get("options", None)
    weight = params.get("blkio_weight", "")
    cgconfig = params.get("cgconfig", "on")
    device_weights = params.get("blkio_device_weights", "")
    result = virsh.blkiotune(vm_name)
    dicts = {}
    # Parsing command output and putting them into python dictionary.
    cmd_output = result.stdout.strip().splitlines()
    for l in cmd_output:
        k, v = l.split(':')
        dicts[k.strip()] = v.strip()

    logging.debug(dicts)

    virt_xml_obj = libvirt_xml.vm_xml.VMXML(virsh_instance=virsh)

    # To change a running guest with 'config' option, which will affect
    # next boot, if don't shutdown the guest, we need to run virsh dumpxml
    # with 'inactive' option to get guest XML changes.
    if options == "config" and vm and vm.is_alive():
        blkio_params = virt_xml_obj.get_blkio_params(vm_name, "--inactive")
    else:
        blkio_params = virt_xml_obj.get_blkio_params(vm_name)

    device_weights_from_xml = ""
    weight_from_cgroup = ""
    device_weight_from_cgroup = ""

    weight_from_xml = blkio_params.get("weight", "")
    device_weights_path_from_xml = blkio_params.get("device_weights_path")
    device_weights_weight_from_xml = blkio_params.get("device_weights_weight")
    weight_from_cmd_output = dicts['weight']
    device_weights_from_cmd_output = dicts['device_weight']

    # To get guest corresponding blkio.weight and blkio.weight_device value
    # from blkio controller of the cgroup.
    if cgconfig == "on" and vm.is_alive():
        blkio_params_from_cgroup = get_blkio_params_from_cgroup(test, params)
        weight_from_cgroup = blkio_params_from_cgroup.get('weight')
        device_weight_from_cgroup = \
            blkio_params_from_cgroup.get('weight_device')

    # The device-weights is a single string listing, in the format
    # of /path/to/device,weight
    if device_weights_path_from_xml and device_weights_weight_from_xml:
        device_weights_from_xml = device_weights_path_from_xml + "," + \
                                  device_weights_weight_from_xml

    if device_weights:
        dev = device_weights.split(',')[0]
        (major, minor) = get_dev_major_minor(dev)
        device_weights_tmp = str(major) + ":" + str(
            minor) + "," + device_weights.split(',')[1]

    # To check specified weight and device_weight value with virsh command
    # output and/or blkio.weight and blkio.weight_device value from blkio
    # controller of the cgroup.
    if vm.is_alive() and options != "config":
        if (weight and weight != weight_from_cmd_output
                or weight and weight != weight_from_cgroup):
            logging.error("To expect weight %s: %s", weight,
                          weight_from_cmd_output)
            return False
        if (device_weights and device_weights != device_weights_from_cmd_output
                or device_weights
                and device_weights_tmp != device_weight_from_cgroup):
            # The value 0 to remove that device from per-device listings.
            if (device_weights.split(',')[-1] == '0'
                    and not device_weights_from_cmd_output):
                return True
            else:
                logging.error("To expect device_weights %s: %s",
                              device_weights, device_weights_from_cmd_output)
                return False
    else:
        if weight and weight != weight_from_xml:
            logging.error("To expect weight %s: %s", weight, weight_from_xml)
            return False
        if (device_weights and device_weights_from_xml
                and device_weights != device_weights_from_xml):
            logging.error("To expect device_weights %s: %s", device_weights,
                          device_weights_from_xml)
            return False

    return True
コード例 #7
0
def check_blkiotune(test, params):
    """
    To compare weight and device-weights value with guest XML
    configuration, virsh blkiotune output and corresponding
    blkio.weight and blkio.weight_device value from cgroup.

    :param test: the test handle
    :params: the parameter dictionary
    """
    vm_name = params.get("main_vm")
    vm = params.get("vm")
    options = params.get("options", None)
    weight = params.get("blkio_weight", "")
    cgconfig = params.get("cgconfig", "on")
    device_weights = params.get("blkio_device_weights", "")
    result = virsh.blkiotune(vm_name)
    dicts = {}
    # Parsing command output and putting them into python dictionary.
    cmd_output = result.stdout.strip().splitlines()
    for l in cmd_output:
        k, v = l.split(':')
        dicts[k.strip()] = v.strip()

    logging.debug(dicts)

    virt_xml_obj = libvirt_xml.vm_xml.VMXML(virsh_instance=virsh)

    # To change a running guest with 'config' option, which will affect
    # next boot, if don't shutdown the guest, we need to run virsh dumpxml
    # with 'inactive' option to get guest XML changes.
    if options == "config" and vm and vm.is_alive():
        blkio_params = virt_xml_obj.get_blkio_params(vm_name, "--inactive")
    else:
        blkio_params = virt_xml_obj.get_blkio_params(vm_name)

    device_weights_from_xml = ""
    weight_from_cgroup = ""
    device_weight_from_cgroup = ""

    weight_from_xml = blkio_params.get("weight", "")
    device_weights_path_from_xml = blkio_params.get("device_weights_path")
    device_weights_weight_from_xml = blkio_params.get("device_weights_weight")
    weight_from_cmd_output = dicts['weight']
    device_weights_from_cmd_output = dicts['device_weight']

    # To get guest corresponding blkio.weight and blkio.weight_device value
    # from blkio controller of the cgroup.
    if cgconfig == "on" and vm.is_alive():
        blkio_params_from_cgroup = get_blkio_params_from_cgroup(test, params)
        weight_from_cgroup = blkio_params_from_cgroup.get('weight')
        device_weight_from_cgroup = \
            blkio_params_from_cgroup.get('weight_device')

    # The device-weights is a single string listing, in the format
    # of /path/to/device,weight
    if device_weights_path_from_xml and device_weights_weight_from_xml:
        device_weights_from_xml = device_weights_path_from_xml + "," + \
                                  device_weights_weight_from_xml

    if device_weights:
        dev = device_weights.split(',')[0]
        (major, minor) = get_dev_major_minor(dev)
        device_weights_tmp = str(major) + ":" + str(minor) + "," + device_weights.split(',')[1]

    # To check specified weight and device_weight value with virsh command
    # output and/or blkio.weight and blkio.weight_device value from blkio
    # controller of the cgroup.
    if vm.is_alive() and options != "config":
        if (weight and weight != weight_from_cmd_output or weight and weight != weight_from_cgroup):
            logging.error("To expect weight %s: %s",
                          weight, weight_from_cmd_output)
            return False
        if (device_weights and device_weights != device_weights_from_cmd_output or device_weights and
                device_weights_tmp != device_weight_from_cgroup):
            # The value 0 to remove that device from per-device listings.
            if (device_weights.split(',')[-1] == '0' and not device_weights_from_cmd_output):
                return True
            else:
                logging.error("To expect device_weights %s: %s",
                              device_weights, device_weights_from_cmd_output)
                return False
    else:
        if weight and weight != weight_from_xml:
            logging.error("To expect weight %s: %s", weight, weight_from_xml)
            return False
        if (device_weights and device_weights_from_xml and device_weights != device_weights_from_xml):
            logging.error("To expect device_weights %s: %s",
                          device_weights, device_weights_from_xml)
            return False

    return True