提交 de8d9d39 编写于 作者: H Haotong Chen

added a qemu-img map an unaligned image case

Signed-off-by: NHaotong Chen <hachen@redhat.com>
上级 a06914c2
- qemu_img_map_unaligned_image:
only raw
virt_test_type = qemu
type = qemu_img_map_unaligned_image
kill_vm = yes
start_vm = no
images = "test"
image_size_test = 1G
image_name_test = images/unaligned_image
image_format_test = raw
import logging
import random
import json
import string
from avocado.utils import process
from virttest import data_dir
from virttest.qemu_storage import QemuImg
def run(test, params, env):
"""
qemu-img map an unaligned image.
1.create a raw file using truncate
2.write data into the raw file
3.verify the dumped mete-data using qemu-img map
:param test: Qemu test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment
"""
def _generate_random_string(max_len=19):
"""Generate random alphabets string in the range of [1, max_len+1]."""
random_str = ''.join(random.choice(
string.ascii_lowercase) for _ in range(random.randint(1, max_len)))
return random_str, len(random_str)
def _verify_qemu_img_map(output, str_len):
"""Verify qemu-img map's output."""
logging.info("Verify the dumped mete-data of the unaligned image.")
expected = [{"start": 0, "length": str_len, "depth": 0,
"zero": False, "data": True, "offset": 0},
{"start": str_len, "length": 512 - (str_len % 512),
"depth": 0, "zero": True, "data": False,
"offset": str_len}]
res = json.loads(output)
if res != expected:
test.fail("The dumped mete-data of the unaligned "
"image '%s' is not correct." % img.image_filename)
img_param = params.object_params("test")
img = QemuImg(img_param, data_dir.get_data_dir(), "test")
logging.info("Create a new file %s using truncate." % img.image_filename)
process.run("rm -f %s" % img.image_filename)
process.run("truncate -s 1G %s " % img.image_filename)
random_str, str_len = _generate_random_string()
logging.info("Write '%s' into the file %s." % (random_str,
img.image_filename))
process.run("echo -n '%s' > %s" % (random_str, img.image_filename),
shell=True)
res = img.map(output="json")
if res.exit_status != 0:
test.fail("qemu-img map error: %s." % res.stderr_text)
_verify_qemu_img_map(res.stdout_text, str_len)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册