Beispiel #1
0
def run(test, params, env):
    """
    'qemu-img' snapshot functions test:

    Params:
    :param test: Qemu test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.

    Test steps:
    1. save file md5sum before create snapshot.
    2. create snapshot and check the result.
    3. change tmp file before apply snapshot.
    4. apply snapshot.
    5. check md5sum after apply snapshot.
    """

    base_image = params.get("images", "image1").split()[0]
    params.update({
        "image_name_%s" % base_image: params["image_name"],
        "image_format_%s" % base_image: params["image_format"]
    })
    t_file = params["guest_file_name"]
    snapshot_test = qemu_disk_img.QemuImgTest(test, params, env, base_image)

    logging.info("Step1. save file md5sum before create snapshot.")
    snapshot_test.start_vm(params)
    md5 = snapshot_test.save_file(t_file)
    if not md5:
        raise exceptions.TestError("Fail to save tmp file.")
    snapshot_test.destroy_vm()

    logging.info("Step2. create snapshot and check the result.")
    snapshot_tag = snapshot_test.snapshot_create()
    output = snapshot_test.snapshot_list()
    if snapshot_tag not in output:
        raise exceptions.TestFail("Snapshot created failed or missed;"
                                  "snapshot list is: \n%s" % output)

    logging.info("Step3. change tmp file before apply snapshot")
    snapshot_test.start_vm(params)
    change_md5 = snapshot_test.save_file(t_file)
    if not change_md5 or change_md5 == md5:
        raise exceptions.TestError("Fail to change tmp file.")
    snapshot_test.destroy_vm()

    logging.info("Step4. apply snapshot.")
    snapshot_test.snapshot_apply()
    snapshot_test.snapshot_del()

    logging.info("Step5. check md5sum after apply snapshot.")
    snapshot_test.start_vm(params)
    ret = snapshot_test.check_file(t_file, md5)
    if not ret:
        raise exceptions.TestError(
            "image content changed after apply snapshot")

    snapshot_test.clean()
Beispiel #2
0
    def check_cluster_size(parttern, expect, csize_set):
        cfail = 0
        fail_log = ""
        image_name = params.get("images")
        status_error = "yes" == params.get("status_error", "no")
        image_params = params.object_params(image_name)
        image = qemu_disk_img.QemuImgTest(test, image_params, env,
                                          image_name)

        filename, result = image.create(image_params, ignore_errors=True)

        if status_error:
            if result.exit_status == 0:
                logging.error("Return success with invalid Cluster size: %s"
                              % csize_set)
                logging.error("%s.\n" % result)
                cfail += 1
        else:
            output = image.info()
            error.context("Check the cluster size from output", logging.info)
            cluster_size = re.findall(parttern, output)
            if cluster_size:
                if cluster_size[0] != expect:
                    logging.error("Cluster size mismatch")
                    logging.error("Cluster size report by command: %s"
                                  % cluster_size)
                    logging.error("Cluster size expect: %s" % expect)
                    cfail += 1
                    fail_log += "Cluster size mismatch when set it to "
                    fail_log += "%s.\n" % csize_set
            else:
                logging.error("Can not get the cluster size from command: %s"
                              % output)
                cfail += 1
                fail_log += "Can not get the cluster size from command:"
                fail_log += " %s\n" % output

        return cfail, fail_log
Beispiel #3
0
    def check_cluster_size(parttern, expect, csize_set):
        cfail = 0
        fail_log = ""
        image_name = params.get("images")
        status_error = "yes" == params.get("status_error", "no")
        image_params = params.object_params(image_name)
        image = qemu_disk_img.QemuImgTest(test, image_params, env, image_name)

        filename, result = image.create(image_params, ignore_errors=True)

        if status_error:
            if result.exit_status == 0:
                logging.error(
                    "Create image sucessfully with invalid size: %s" %
                    csize_set)
                cfail += 1
                fail_log += "Succeed in creating image unexpectedly.\n"
        else:
            output = image.info()
            error_context.context("Check the cluster size from output",
                                  logging.info)
            cluster_size = re.findall(parttern, output)
            if cluster_size:
                if cluster_size[0] != expect:
                    logging.error("Cluster size %s is not expected value %s" %
                                  (cluster_size, expect))
                    cfail += 1
                    fail_log += "Cluster size mismatch the specified value "
                    fail_log += "%s.\n" % csize_set
            else:
                logging.error("Can not get the cluster size from command: %s" %
                              output)
                cfail += 1
                fail_log += "Can not get the cluster size from command:"
                fail_log += " %s\n" % output

        return cfail, fail_log