提交 636ebc41 编写于 作者: S suqinhuang 提交者: GitHub

Merge pull request #726 from pingl2016/convert_case

Add cases for subcommand convert of qemu-img
......@@ -26,8 +26,9 @@
image_convert = "image1"
convert_name_image1 = "images/image1_to_qcow2"
convert_format_image1 = "qcow2"
option_verified = "format"
variants:
- default:
- @default:
- compressed:
convert_compressed = yes
- preallocation_mode:
......@@ -51,6 +52,7 @@
no Host_RHEL.m7.u0 Host_RHEL.m7.u1
preallocated = full
- cluster_size:
option_verified += " csize"
variants:
- cluster_size_512:
cluster_size = 512
......@@ -60,26 +62,53 @@
cluster_size = 2M
- compat:
no Host_RHEL.m5, Host_RHEL.m6
option_verified += " compat"
variants:
- compat_0.10:
compat = 0.10
variants:
- default:
- lazy_refcounts_off:
lazy_refcounts = off
- compat_1.1:
compat = 1.1
variants:
- @default:
- lazy_refcounts_on:
only compat_1.1
lazy_refcounts = on
option_verified += " lcounts"
- lazy_refcounts_off:
option_verified += " lcounts"
lazy_refcounts = off
- cluster_size:
option_verified += " csize"
variants:
- default:
- lazy_refcounts_on:
lazy_refcounts = on
- lazy_refcounts_off:
lazy_refcounts = off
- cluster_size_512:
cluster_size = 512
- cluster_size_2k:
cluster_size = 2k
- cluster_size_2M:
cluster_size = 2M
- fully_allocated:
no Host_RHEL.m5, Host_RHEL.m6
option_verified += " sparse_size"
sparse_size = 0
- cache_mode:
variants:
- none:
cache_mode = none
- wirteback:
cache_mode = writeback
- unsafe:
cache_mode = unsafe
- directsync:
cache_mode = directsync
- writethrough:
cache_mode = writethrough
- base_to_raw:
option_verified = "format"
image_convert = "image1"
convert_name_image1 = "images/image1_to_raw"
convert_format_image1 = "raw"
- snapshot_to_qcow2:
option_verified = "format"
image_convert = "sn1"
image_chain += " sn1"
image_name_sn1 = "images/sn1"
......@@ -94,7 +123,7 @@
image_name_sn1 = "images/sn1"
image_format_sn1 = "qcow2"
variants:
- default:
- @default:
- cache_mode:
variants:
- none:
......@@ -115,7 +144,7 @@
image_format_sn1 = "qcow2"
guest_file_name_sn1 = "${tmp_dir}/sn1"
variants:
- default:
- @default:
- backing_chain:
backing_chain = yes
- snapshot:
......
......@@ -64,6 +64,17 @@
#cluster_size set cluster size used in qemu-img -o cluster_size=, default is 64k.
cluster_size = 2048
no Host_RHEL.m5
- show_progress:
command_result_pattern = "\(\d+\.\d+/100%\)"
variants:
- show_progress_on:
show_progress = on
check_output = stdout
- show_progress_off:
show_progress = off
qemu_img_options = cluster_size
cluster_size = 512
check_output = stderr
- to_raw:
dest_image_format = raw
- to_qed:
......
......@@ -9,6 +9,8 @@ from virttest import data_dir
from virttest import env_process
from virttest import storage
from virttest import qemu_storage
from virttest import utils_test
from virttest import utils_misc
class QemuImgTest(qemu_storage.QemuImg):
......@@ -129,6 +131,38 @@ class QemuImgTest(qemu_storage.QemuImg):
error.context("get image file ('%s')" % self.image_filename)
return super(QemuImgTest, self).info()
@error.context_aware
def verify_info(self, params=None):
"""
verify option is applied to image file correctly
"""
error.context("verify option of converted image", logging.info)
image_filename = storage.get_image_filename(params, self.data_dir)
info = utils_test.get_image_info(image_filename)
avalue = evalue = ""
for option in params.objects("option_verified"):
avalue = info.get(option)
if option == "format":
evalue = params.get("image_format")
elif option == "lcounts":
if params.get("lazy_refcounts") == "on":
evalue = "true"
elif params.get("lazy_refcounts") == "off":
evalue = "false"
elif option == "csize":
csize = params.get("cluster_size")
evalue = int(float(utils_misc.normalize_data_size(csize, "B")))
elif option == "sparse_size":
if info.get("dsize") < info.get("vsize"):
avalue = info.get("dsize")
evalue = info.get("vsize")
else:
evalue = params.get(option)
if avalue is not None and avalue != evalue:
msg = "Get wrong %s from image %s!" % (option, image_filename)
msg += "Expect: %s, actual: %s" % (evalue, avalue)
raise error.TestFail(msg)
@error.context_aware
def clean(self):
error.context("clean up useless images")
......
......@@ -58,6 +58,7 @@ def run(test, params, env):
raise error.TestError("Fail to save tmp file")
convert_test.destroy_vm()
n_params = convert_test.convert()
convert_test.verify_info(n_params)
convert_test.start_vm(n_params)
# check md5sum after conversion
......
import re
import os
import time
import re
import logging
import commands
import shutil
......@@ -177,6 +178,42 @@ def run(test, params, env):
cluster_size=params.get("image_cluster_size"))
remove(img)
def send_signal(timeout=360):
"""
send signal "SIGUSR1" to qemu-img without the option -p
to report progress
"""
logging.info("Send signal to qemu-img")
end_time = time.time() + timeout
while time.time() < end_time:
time.sleep(1)
status = utils.system("kill -SIGUSR1 `pidof qemu-img`",
ignore_status=True)
if status == 0:
return None
logging.info("Fail to get pid of qemu-img")
def check_command_output(CmdResult):
"""
Check standard error or standard output of command
: param CmdResult: a list of CmdResult objects
"""
logging.info("Check result of command")
check_output = params.get("check_output", "exit_status")
if not hasattr(CmdResult, check_output):
raise error.TestError("Unknown check output '%s'" % check_output)
output = getattr(CmdResult, check_output)
if check_output == "exit_status" and output == 0:
return None
if check_output == "exit_status" and output != 0:
err_msg = "Get nonzero exit status(%d) '%s'"
raise error.TestFail(err_msg % (output, CmdResult.command))
pattern = params.get("command_result_pattern")
if not re.findall(pattern, output):
err_msg = "Fail to get expected result!"
err_msg += "Output: %s, expected pattern: %s" % (output, pattern)
raise error.TestFail(err_msg)
def _convert(cmd, output_fmt, img_name, output_filename,
fmt=None, compressed="no", encrypted="no"):
"""
......@@ -195,6 +232,9 @@ def run(test, params, env):
cmd += " -c"
if encrypted == "yes":
cmd += " -e"
show_progress = params.get("show_progress", "")
if show_progress == "on":
cmd += " -p"
if fmt:
cmd += " -f %s" % fmt
cmd += " -O %s" % output_fmt
......@@ -210,7 +250,10 @@ def run(test, params, env):
msg = "Converting '%s' from format '%s'" % (img_name, fmt)
msg += " to '%s'" % output_fmt
error.context(msg, logging.info)
utils.system(cmd)
if show_progress == "off":
bg = utils.InterruptedThread(send_signal)
bg.start()
check_command_output(utils.run(cmd, ignore_status=True))
def convert_test(cmd):
"""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册