From eab2b1fbb3124b2e57598f14786d9d88db774d9e Mon Sep 17 00:00:00 2001 From: Haotong Chen Date: Tue, 6 Nov 2018 14:36:51 +0800 Subject: [PATCH] added a test checks thin write in qemu-img commit Signed-off-by: Haotong Chen --- .../cfg/thin_write_in_qemu_img_commit.cfg | 18 +++++ qemu/tests/thin_write_in_qemu_img_commit.py | 66 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 qemu/tests/cfg/thin_write_in_qemu_img_commit.cfg create mode 100644 qemu/tests/thin_write_in_qemu_img_commit.py diff --git a/qemu/tests/cfg/thin_write_in_qemu_img_commit.cfg b/qemu/tests/cfg/thin_write_in_qemu_img_commit.cfg new file mode 100644 index 00000000..4f2568ba --- /dev/null +++ b/qemu/tests/cfg/thin_write_in_qemu_img_commit.cfg @@ -0,0 +1,18 @@ +- thin_write_in_qemu_img_commit: + only qcow2 + virt_test_type = qemu + type = thin_write_in_qemu_img_commit + kill_vm = yes + start_vm = no + force_create_image = no + create_image = yes + remove_image = yes + images = "base" + image_chain = "base sn" + image_name_base = "images/base" + image_size_base = 1G + image_name_sn = "images/sn" + # set size to "", so during snapshot creation + # the cmdline will not have speicfed size option + image_size_sn = "" + write_size = 64K diff --git a/qemu/tests/thin_write_in_qemu_img_commit.py b/qemu/tests/thin_write_in_qemu_img_commit.py new file mode 100644 index 00000000..4e6e874d --- /dev/null +++ b/qemu/tests/thin_write_in_qemu_img_commit.py @@ -0,0 +1,66 @@ +import logging +import json + +from virttest import data_dir +from virttest import utils_numeric +from virttest.qemu_io import QemuIOSystem +from virttest.qemu_storage import QemuImg + +from qemu.tests.qemu_disk_img import QemuImgTest +from qemu.tests.qemu_disk_img import generate_base_snapshot_pair + + +def run(test, params, env): + """ + Check thin write in qemu-img commit. + + 1) write 0x1 into the entire base image through qemu-io + 2) create a external snapshot sn of the base + 3) write specific length zeros at the beginning of the snapshot + 4) commit sn back to base + 5) make sure the zeros have been committed into the base image + + :param test: Qemu test object + :param params: Dictionary with the test parameters + :param env: Dictionary with test environment. + """ + def _get_image_object(tag): + """Get QemuImg object by tag.""" + img_param = params.object_params(tag) + return QemuImg(img_param, img_root_dir, tag) + + def _create_external_snapshot(tag): + """Create an external snapshot based on tag.""" + logging.info("Create external snapshot %s." % tag) + qit = QemuImgTest(test, params, env, snapshot) + qit.create_snapshot() + + def _qemu_io(img, cmd): + """Run qemu-io cmd to a given img.""" + logging.info("Run qemu-io %s" % img.image_filename) + q = QemuIOSystem(test, params, img.image_filename) + q.cmd_output(cmd, 120) + + def _verify_map_output(output): + """"Verify qemu map output.""" + expected = { + "length": int(utils_numeric.normalize_data_size( + params["write_size"], "B")), + "start": 0, "depth": 0, "zero": True, "data": False} + if expected not in json.loads(output.stdout_text): + test.fail("Commit failed, data from 0 to %s are not zero" % + params["write_size"]) + + gen = generate_base_snapshot_pair(params["image_chain"]) + img_root_dir = data_dir.get_data_dir() + base, snapshot = next(gen) + + img_base = _get_image_object(base) + _qemu_io(img_base, 'write -P 1 0 %s' % params["image_size_base"]) + + _create_external_snapshot(snapshot) + img_sn = _get_image_object(snapshot) + _qemu_io(img_sn, 'write -z 0 %s' % params["write_size"]) + + img_sn.commit() + _verify_map_output(img_base.map(output="json")) -- GitLab