提交 93ad2aad 编写于 作者: H Haotong Chen

added two qemu-img resize tests

1. Verify qemu-img resize increase on raw format.
2. Verify qemu-img resize shrink on raw format.
Signed-off-by: NHaotong Chen <hachen@redhat.com>
上级 c208f8c0
- resize_raw_img:
only raw
virt_test_type = qemu
kill_vm = yes
start_vm = no
force_create_image = no
type = resize_raw_img
images = "test"
image_format_test = raw
image_name_test = images/test
variants:
- increase_size:
# These two params must be provided to calculate size changes.
# You can change size_changes based on your cases.
image_size_test = 10G
size_changes = "+1G"
- shrink_size:
required_qemu = [2.12.0, )
image_size_test = 10G
size_changes = "-2G"
import json
import logging
from virttest import data_dir
from virttest import error_context
from virttest import utils_numeric
from virttest.qemu_storage import QemuImg
@error_context.context_aware
def run(test, params, env):
"""
A 'qemu-img' resize test.
1.create a raw image
2.change the raw image size * n
3.verify resize * n
:param test: Qemu test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment.
"""
def _sum_size_changes(size_changes):
"""
Sum the list of size changes.
:param size_changes: list of size changes
"""
res = []
for change in size_changes:
s = int(utils_numeric.normalize_data_size(change, "B")
) * (-1 if '-' in change else 1)
res.append(s)
return sum(res)
def _verify_resize(img_size, expected_size):
"""Verify the image size is as expected after resize."""
logging.info("Verify the size of %s is %s." %
(img.image_filename, expected_size))
if img_size != expected_size:
test.fail("Got image virtual size: %s, should be: %s." %
(img_size, expected_size))
def _resize(size_changes):
"""Resize the image and verify its size."""
for idx, size in enumerate(size_changes):
logging.info("Resize the raw image %s %s." % (img.image_filename,
size))
shrink = True if "-" in size else False
img.resize(size, shrink=shrink)
img_size = json.loads(img.info(output="json"))["virtual-size"]
expected_size = (int(utils_numeric.normalize_data_size(
params["image_size_test"], "B")) +
_sum_size_changes(size_changes[:idx + 1]))
_verify_resize(img_size, expected_size)
img_param = params.object_params('test')
img = QemuImg(img_param, data_dir.get_data_dir(), 'test')
size_changes = params["size_changes"].split()
logging.info("Create a raw image %s." % img.image_filename)
img.create(img_param)
_resize(size_changes)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册