Example #1
0
def run(test, params, env):
    """
    1. convert source image to target image.
    2. compare source image with target image.
    4. check strace output that `O_DIRECT` is off for `open`.
    6. compare with source cache mode `none`.
    7. check strace output that `O_DIRECT` is on.
    """
    def compare_images(source, target, source_cache_mode=None):
        ret = source.compare_to(target, source_cache_mode=source_cache_mode)
        if ret.exit_status == 0:
            logging.debug("images are identical")
        elif ret.exit_status == 1:
            test.fail("images differ")
        else:
            logging.error(ret.stdout_text)
            test.error("error in image comparison")

    logging.debug("check if strace is available")
    try:
        path.find_command("strace")
    except path.CmdNotFoundError as detail:
        raise test.cancel(str(detail))

    root_dir = data_dir.get_data_dir()
    strace_events = params["strace_event"].split()
    source, target = params["images"].split()
    source_params = params.object_params(source)
    source = qemu_storage.QemuImg(source_params, root_dir, source)
    source.create(source_params)
    target_params = params.object_params(target)
    target = qemu_storage.QemuImg(target_params, root_dir, target)

    logging.debug("Convert image from %s to %s", source.tag, target.tag)
    try:
        source.convert(source_params, root_dir)
    except process.CmdError as detail:
        test.cancel(str(detail))

    strace_output_file = os.path.join(test.debugdir, "compare.log")
    with strace(source, strace_events, strace_output_file):
        compare_images(source, target)
    fail_msg = "'O_DIRECT' is presented in system calls %s" % strace_events
    if check_flag(strace_output_file, source.image_filename, "O_DIRECT"):
        test.fail(fail_msg)
    if check_flag(strace_output_file, target.image_filename, "O_DIRECT"):
        test.fail(fail_msg)

    strace_output_file = os.path.join(test.debugdir, "compare_bypass.log")
    with strace(source, strace_events, strace_output_file):
        compare_images(source, target, source_cache_mode="none")
    fail_msg = "'O_DIRECT' is not presented in system calls %s" % strace_events
    if not check_flag(strace_output_file, source.image_filename, "O_DIRECT"):
        test.fail(fail_msg)
    if not check_flag(strace_output_file, target.image_filename, "O_DIRECT"):
        test.fail(fail_msg)
    params["remove_image"] = "yes"
def run(test, params, env):
    """
    1. convert image with both default cache mode.
    2. check strace output that `O_DIRECT` is off for `open`.
    3. convert image with cache mode `none` for both source and dest images.
    4. check strace output that `O_DIRECT` is on for `open`.
    """

    find_strace()

    root_dir = data_dir.get_data_dir()
    strace_events = params["strace_event"].split()
    image = params["images"]
    image_params = params.object_params(image)
    image = qemu_storage.QemuImg(image_params, root_dir, image)
    convert_target1, convert_target2 = params["convert_target"].split()

    strace_output_file = os.path.join(test.debugdir,
                                      "convert_to_%s.log" % convert_target1)
    image_params["convert_target"] = convert_target1
    logging.debug("Convert image from %s to %s, strace log: %s", image.tag,
                  convert_target1, strace_output_file)

    with strace(image, strace_events, strace_output_file):
        fail_on((process.CmdError, ))(image.convert)(image_params, root_dir)

    convert_target1_filename = storage.get_image_filename(
        params.object_params(convert_target1), root_dir)
    fail_msg = "'O_DIRECT' is presented in system calls %s" % strace_events
    if check_flag(strace_output_file, image.image_filename, "O_DIRECT"):
        test.fail(fail_msg)
    if check_flag(strace_output_file, convert_target1_filename, "O_DIRECT"):
        test.fail(fail_msg)

    strace_output_file = os.path.join(test.debugdir,
                                      "convert_to_%s.log" % convert_target2)
    image_params["convert_target"] = convert_target2
    logging.debug(("Convert image from %s to %s with cache mode "
                   "'none', strace log: %s"), image.tag, convert_target2,
                  strace_output_file)

    with strace(image, strace_events, strace_output_file):
        fail_on((process.CmdError, ))(image.convert)(image_params,
                                                     root_dir,
                                                     cache_mode="none",
                                                     source_cache_mode="none")

    convert_target2_filename = storage.get_image_filename(
        params.object_params(convert_target2), root_dir)
    fail_msg = "'O_DIRECT' is not presented in system calls %s" % strace_events
    if not check_flag(strace_output_file, image.image_filename, "O_DIRECT"):
        test.fail(fail_msg)
    if not check_flag(strace_output_file, convert_target2_filename,
                      "O_DIRECT"):
        test.fail(fail_msg)
    params["images"] += params["convert_target"]
Example #3
0
def run(test, params, env):
    """
    1. create snapshot base->sn
    2. write to snapshot sn
    3. commit sn to base with default cache mode.
    4. check strace output that `O_DIRECT` is off for `open`.
    5. write to snapshot sn
    6. commit sn to base with cache=none.
    7. check strace output that `O_DIRECT` is on.
    """
    img_utils.find_strace()

    root_dir = data_dir.get_data_dir()
    trace_events = params["trace_events"].split()
    sync_bin = params.get("sync_bin", "sync")
    images = params["images"].split()
    params["image_name_%s" % images[0]] = params["image_name"]
    params["image_format_%s" % images[0]] = params["image_format"]

    base, sn = (qemu_storage.QemuImg(params.object_params(tag), root_dir, tag)
                for tag in images)
    try:
        sn.create(sn.params)
        vm = img_utils.boot_vm_with_images(test, params, env, (sn.tag, ))
    except (process.CmdError, virt_vm.VMCreateError) as detail:
        test.fail(str(detail))

    guest_file = params["guest_tmp_filename"]
    logging.debug("Create tmp file %s in image %s", guest_file,
                  sn.image_filename)
    img_utils.save_random_file_to_vm(vm, guest_file, 2048 * 100, sync_bin)
    vm.destroy()

    strace_log = os.path.join(test.debugdir, "commit.log")
    logging.debug("commit snapshot, strace log %s", strace_log)
    with img_utils.strace(sn, trace_events, strace_log):
        fail_on((process.CmdError, ))(sn.commit)()
    fail_msg = "'O_DIRECT' is presented in system calls %s" % trace_events
    if img_utils.check_flag(strace_log, base.image_filename, "O_DIRECT"):
        test.fail(fail_msg)
    if img_utils.check_flag(strace_log, sn.image_filename, "O_DIRECT"):
        test.fail(fail_msg)

    strace_log = os.path.join(test.debugdir, "commit_bypass.log")
    logging.debug("commit snapshot with cache 'none', strace log: %s",
                  strace_log)
    with img_utils.strace(sn, trace_events, strace_log):
        fail_on((process.CmdError, ))(sn.commit)(cache_mode="none")
    fail_msg = "'O_DIRECT' is missing in system calls %s" % trace_events
    if not img_utils.check_flag(strace_log, base.image_filename, "O_DIRECT"):
        test.fail(fail_msg)
    if not img_utils.check_flag(strace_log, sn.image_filename, "O_DIRECT"):
        test.fail(fail_msg)
def run(test, params, env):
    """
    qemu-img supports 'discard' for raw block target images.

    1. Create source image via dd with all zero.
    2. Modprobe a 1G scsi_debug disk with writesame_16 mode.
    3. Trace the system calls while converting the zero image to the
       scsi_debug block device, then check whether 'fallocate' system call
       results work in the log.
    :param test: Qemu test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    def _check_output(strace_event, strace_output, match_str):
        """Check whether the value is good in the output file."""
        logging.debug("Check the output file '%s'.", strace_output)
        with open(strace_output) as fd:
            m = re.findall(match_str + r', \d+, \d+', fd.read())
            if not m:
                test.fail("The result of system call '%s' is not right, "
                          "check '%s' for more details." %
                          (strace_event, strace_output))
            last_lst = m[-1].split(',')
            sum_size = int(last_lst[-1]) + int(last_lst[-2])
            # get the source image size in byte unit
            byte_image_size = int(
                utils_numeric.normalize_data_size(image_size, "B"))
            if sum_size != byte_image_size:
                test.fail(
                    "The target allocated size '%s' is different from the source image size, "
                    "check '%s' for more details." %
                    (str(sum_size), strace_output))

    src_image = params["images"]
    image_size = params["image_size_test"]
    root_dir = data_dir.get_data_dir()
    source = QemuImg(params.object_params(src_image), root_dir, src_image)
    strace_event = params["strace_event"]
    strace_events = strace_event.split()
    strace_output_file = os.path.join(test.debugdir, "convert_to_block.log")

    source.create(source.params)
    # Generate the target scsi block file.
    tgt_disk = process.system_output("lsscsi | grep '%s' | awk '{print $NF}'" %
                                     params["scsi_mod"],
                                     shell=True).decode()
    params["image_name_target"] = tgt_disk

    logging.debug(
        "Convert from %s to %s with cache mode none, strace log: %s.",
        source.image_filename, tgt_disk, strace_output_file)
    with strace(source, strace_events, strace_output_file, trace_child=True):
        fail_on((process.CmdError, ))(source.convert)(
            params.object_params(src_image), root_dir, cache_mode="none")

    _check_output(strace_event, strace_output_file, "FALLOC_FL_PUNCH_HOLE")
Example #5
0
 def check_fallocate_syscall(trace_event):
     """
     check whether invoke fallocate system call
     when creating an image with preallocation=falloc
     """
     strace_log = os.path.join(test.debugdir, "fallocate.log")
     with img_utils.strace(img_stg, trace_event.split(), strace_log, True):
         fail_on((process.CmdError,))(img_stg.create)(image_stg_params)
     with open(strace_log) as fd:
         if trace_event not in fd.read():
             test.fail("Not invoked fallocate system call when "
                       "creating an image with preallocation=falloc")
def run(test, params, env):
    """
    qemu-img supports 'discard' for raw block target images.

    1. Create source image via dd with all zero.
    2. Modprobe a 1G scsi_debug disk with writesame_16 mode.
    3. Trace the system calls while converting the zero image to the
       scsi_debug block device, then check whether 'fallocate' system call
       works in the log.
    :param test: Qemu test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    def check_output(strace_event, strace_output, match_str):
        """Check whether the value is good in the output file."""
        logging.debug("Check the output file '%s'.", strace_output)
        with open(strace_output) as fd:
            if match_str not in fd.read():
                test.fail("The system call of '%s' is not right, "
                          "check '%s' for more details." %
                          (strace_event, strace_output))

    src_image = params["images"]
    root_dir = data_dir.get_data_dir()
    source = QemuImg(params.object_params(src_image), root_dir, src_image)
    strace_event = params["strace_event"]
    strace_events = strace_event.split()
    strace_output_file = os.path.join(test.debugdir, "convert_to_block.log")

    source.create(source.params)
    # Generate the target scsi block file.
    tgt_disk = process.system_output("lsscsi | grep '%s' | awk '{print $NF}'" %
                                     params["scsi_mod"],
                                     shell=True).decode()
    params["image_name_target"] = tgt_disk

    logging.debug(
        "Convert from %s to %s with cache mode none, strace log: %s.",
        source.image_filename, tgt_disk, strace_output_file)
    with strace(source, strace_events, strace_output_file, trace_child=True):
        fail_on((process.CmdError, ))(source.convert)(
            params.object_params(src_image), root_dir, cache_mode="none")

    check_output(strace_event, strace_output_file,
                 "FALLOC_FL_PUNCH_HOLE, 0, 1073741824")
Example #7
0
def run(test, params, env):
    """
    qemu-img uses larger output buffer for "none" cache mode.
    1. Create 100M source image with random data via 'dd'.
    2. Trace the system calls while converting the source image to the
       a qcow2 target image, and check the maxim result of pwrite/pwrite64
       should be 2M.
    :param test: Qemu test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    src_image = params["images"]
    tgt_image = params["convert_target"]
    root_dir = data_dir.get_data_dir()
    source = QemuImg(params.object_params(src_image), root_dir, src_image)
    strace_event = params["strace_event"]
    strace_events = strace_event.split()
    strace_output_file = os.path.join(test.debugdir, "convert_with_none.log")
    src_filename = source.image_filename
    process.run("dd if=/dev/urandom of=%s bs=1M count=100" % src_filename)
    logging.debug(
        "Convert from %s to %s with cache mode none, strace log: "
        "%s.", src_filename, tgt_image, strace_output_file)
    with strace(source, strace_events, strace_output_file, trace_child=True):
        fail_on((process.CmdError, ))(source.convert)(
            params.object_params(src_image), root_dir, cache_mode="none")

    logging.debug("Check whether the max size of %s syscall is 2M in %s.",
                  strace_event, strace_output_file)
    with open(strace_output_file) as fd:
        for line in fd.readlines():
            if int(line.split()[-1]) == 2097152:
                break
        else:
            test.fail("The max size of '%s' is not 2M, check '%s' please.",
                      strace_event, strace_output_file)

    params["images"] += " " + tgt_image
Example #8
0
def run(test, params, env):
    """
    check if qemu-img rebase could bypass host cache.
    1) create snapshot chain image1 -> sn1 -> sn2
    2) rebase sn2 to image1 and check the open syscall that no flag O_DIRECT
    3) create snapshot chain image1 -> sn1 -> sn2
    4) rebase sn2 to image1 with cache mode 'none' and check flag O_DIRECT
    is on.
    """
    def remove_snapshots():
        """Remove snapshots created."""
        while snapshots:
            snapshot = snapshots.pop()
            snapshot.remove()

    def parse_snapshot_chain(target):
        """Parse snapshot chain."""
        image_chain = params["image_chain"].split()
        for snapshot in image_chain[1:]:
            target.send(snapshot)

    @coroutine
    def create_snapshot(target):
        """Create snapshot."""
        while True:
            snapshot = yield
            logging.debug("create image %s", snapshot)
            snapshot_params = params.object_params(snapshot)
            snapshot = qemu_storage.QemuImg(snapshot_params, root_dir, snapshot)
            fail_on((process.CmdError,))(snapshot.create)(snapshot.params)
            snapshots.append(snapshot)
            target.send(snapshot)

    @coroutine
    def save_file_to_snapshot():
        """Save temporary file to snapshot."""
        sync_bin = params.get("sync_bin", "sync")
        while True:
            snapshot = yield
            logging.debug("boot vm from image %s", snapshot.tag)
            vm = img_utils.boot_vm_with_images(test, params, env,
                                               images=(snapshot.tag,),
                                               vm_name="VM_%s" % snapshot.tag)
            guest_file = params["guest_tmp_filename"] % snapshot.tag
            logging.debug("create tmp file %s in %s", guest_file, snapshot.tag)
            img_utils.save_random_file_to_vm(vm, guest_file, 2048, sync_bin)
            vm.destroy()

    img_utils.find_strace()
    base = params["image_chain"].split()[0]
    params["image_name_%s" % base] = params["image_name"]
    params["image_format_%s" % base] = params["image_format"]
    root_dir = data_dir.get_data_dir()
    base = qemu_storage.QemuImg(params.object_params(base), root_dir, base)
    trace_events = params["trace_event"].split()

    snapshots = []
    parse_snapshot_chain(create_snapshot(save_file_to_snapshot()))

    strace_log = os.path.join(test.debugdir, "rebase.log")
    top = snapshots[-1]
    logging.debug("rebase snapshot %s to %s", top.tag, base.tag)
    with img_utils.strace(top, trace_events, strace_log):
        top.base_tag = base.tag
        fail_on((process.CmdError))(top.rebase)(params)

    fail_msg = "'O_DIRECT' is presented in %s with file %s"
    for image in [base] + snapshots:
        if img_utils.check_flag(strace_log, image.image_filename, "O_DIRECT"):
            test.fail(fail_msg % (trace_events, image.image_filename))

    remove_snapshots()
    parse_snapshot_chain(create_snapshot(save_file_to_snapshot()))

    strace_log = os.path.join(test.debugdir, "rebase_bypass.log")
    top = snapshots[-1]
    logging.debug("rebase snapshot %s to %s in cache mode 'none'",
                  top.tag, base.tag)
    with img_utils.strace(top, trace_events, strace_log):
        top.base_tag = base.tag
        fail_on((process.CmdError))(top.rebase)(params,
                                                cache_mode="none",
                                                source_cache_mode="none")

    fail_msg = "'O_DIRECT' is missing in %s with file %s"
    for image in [base] + snapshots:
        if not img_utils.check_flag(strace_log,
                                    image.image_filename, "O_DIRECT"):
            test.fail(fail_msg % (trace_events, image.image_filename))

    remove_snapshots()