未验证 提交 67525eef 编写于 作者: L Longxiang Lyu 提交者: GitHub

Merge pull request #2044 from hellohellenmao/1786420

New case of check_reports_end_offset
- 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"
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))
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册