diff --git a/qemu/tests/cfg/check_reports_end_offset.cfg b/qemu/tests/cfg/check_reports_end_offset.cfg new file mode 100755 index 0000000000000000000000000000000000000000..fa53a9c955e5f52d011fe1f1a4f5fdab323c834c --- /dev/null +++ b/qemu/tests/cfg/check_reports_end_offset.cfg @@ -0,0 +1,13 @@ +- check_reports_end_offset: + only qcow2 + virt_test_type = qemu + type = check_reports_end_offset + start_vm = no + create_image = yes + remove_image = yes + images = "report" + image_name_report = "images/report" + image_size_report = 20G + image_end_offset = 262144 + human_key = "Image end offset" + json_key = "image-end-offset" diff --git a/qemu/tests/check_reports_end_offset.py b/qemu/tests/check_reports_end_offset.py new file mode 100755 index 0000000000000000000000000000000000000000..91f3f45d667d9adbd06b047715239433a4bf845f --- /dev/null +++ b/qemu/tests/check_reports_end_offset.py @@ -0,0 +1,49 @@ +import logging +import re +import json + +from virttest import data_dir +from virttest.qemu_storage import QemuImg + + +def run(test, params, env): + """ + 'qemu-img check' should report the end offset of the image. + 1. Create a test qcow2 image. + 2. Check there is image end offset and the value with both "humam" + and "json" output. + :param test: Qemu test object. + :param params: Dictionary with the test parameters. + :param env: Dictionary with test environment. + """ + + def _check_result(key, offset, output): + """Check the keywords and the value from the output.""" + if key not in output or int(offset) != int(output[key]): + test.fail("The keyword/value is no correct. Check please.") + + report = params["images"] + root_dir = data_dir.get_data_dir() + report = QemuImg(params.object_params(report), root_dir, report) + offset = params["image_end_offset"] + human_key = params["human_key"] + json_key = params["json_key"] + + logging.info("Create the test image file.") + report.create(report.params) + + # 'qemu-img check' the image and check the output info. + check_result = report.check(report.params, root_dir, + output="human").stdout.decode() + if not check_result: + test.error("There is no output of check command, check please.") + logging.debug("The check output with human output format: %s", check_result) + result_dict = dict(re.findall(r'(.+):\s(.+)', check_result)) + _check_result(human_key, offset, result_dict) + + check_result = report.check(report.params, root_dir, + output="json").stdout.decode() + if not check_result: + test.error("There is no output of check command, check please.") + logging.debug("The check output with json output format: %s", check_result) + _check_result(json_key, offset, json.loads(check_result))