提交 198344f3 编写于 作者: X Xiyue Wang

block_commit: Add test case 'Basic block commit test' to block_commit

Signed-off-by: NXiyue Wang <xiywang@redhat.com>
上级 052a1a18
import logging
from virttest import utils_misc
from qemu.tests import block_copy
class BlockCommit(block_copy.BlockCopy):
def start(self):
"""
start block device committing job;
"""
base_image = self.params["base_image"]
base_image = utils_misc.get_path(self.data_dir, base_image)
top_image = self.params["top_image"]
top_image = utils_misc.get_path(self.data_dir, top_image)
default_speed = self.params.get("default_speed")
backing_file = self.params.get("backing_file", None)
if backing_file is not None:
backing_file = utils_misc.get_path(self.data_dir, backing_file)
if self.vm.monitor.protocol == "qmp":
self.vm.monitor.clear_event("BLOCK_JOB_READY")
self.vm.monitor.clear_event("BLOCK_JOB_COMPLETED")
else:
self.test.cancel("hmp command is not supportable.")
logging.info("start to commit block device")
self.vm.block_commit(self.device, default_speed, base_image, top_image,
backing_file)
status = self.get_status()
if not status:
self.test.fail("no active job found")
logging.info("block commit job running, with limited speed {0} B/s".format(default_speed))
def create_snapshots(self):
"""
create live snapshot_chain, snapshots chain define in $snapshot_chain
"""
image_format = self.params["snapshot_format"]
snapshots = self.params["snapshot_chain"].split()
logging.info("create live snapshots %s" % snapshots)
for snapshot in snapshots:
snapshot = utils_misc.get_path(self.data_dir, snapshot)
image_file = self.get_image_file()
logging.info("snapshot {0}, base {1}".format(snapshot, image_file))
device = self.vm.live_snapshot(image_file, snapshot, image_format)
if device != self.device:
image_file = self.get_image_file()
logging.info("expect file: {0}, opening file: {1}".format(snapshot, image_file))
self.test.fail("create snapshot '%s' failed" % snapshot)
self.trash_files.append(snapshot)
import logging
from virttest import utils_misc
from virttest import utils_test
from qemu.tests import blk_commit
class BlockCommitStress(blk_commit.BlockCommit):
def load_stress(self):
"""
load IO/CPU/Memoery stress in guest
"""
logging.info("launch stress app in guest")
args = (self.test, self.params, self.env, self.params["stress_test"])
bg_test = utils_test.BackgroundTest(utils_test.run_virt_sub_test, args)
bg_test.start()
if not utils_misc.wait_for(bg_test.is_alive, first=10, step=3, timeout=100):
self.test.fail("background test start failed")
if not utils_misc.wait_for(self.app_running, timeout=360, step=5):
self.test.fail("stress app isn't running")
def unload_stress(self):
"""
stop stress app
"""
def _unload_stress():
session = self.get_session()
cmd = self.params.get("stop_cmd")
session.sendline(cmd)
session.close()
return self.app_running()
logging.info("stop stress app in guest")
stopped = utils_misc.wait_for(_unload_stress, first=2.0,
text="wait stress app quit", step=1.0,
timeout=self.params["wait_timeout"])
if not stopped:
logging.warn("stress app is still running")
def app_running(self):
"""
check stress app really run in background
"""
session = self.get_session()
cmd = self.params.get("check_cmd")
status = session.cmd_status(cmd, timeout=120)
session.close()
return status == 0
def verify_backingfile(self):
"""
check no backingfile found after commit job done via qemu-img info;
"""
logging.info("Check image backing-file")
exp_img_file = self.params["expected_image_file"]
exp_img_file = utils_misc.get_path(self.data_dir, exp_img_file)
logging.debug("Expected image file read from config file is '%s'" % exp_img_file)
backingfile = self.get_backingfile("monitor")
if backingfile:
logging.info("Got backing-file: #{0}# by 'info/query block' in #{1}# "
"monitor".format(backingfile, self.vm.monitor.protocol))
if exp_img_file == backingfile:
logging.info("check backing file with monitor passed")
else:
self.test.fail("backing file is different with the expected one. "
"expecting: %s, actual: %s" % (exp_img_file, backingfile))
def run(test, params, env):
"""
block_commit_stress test:
1). load stress in guest
2). create live snapshot base->sn1->sn2->sn3->sn4
3). merge sn3 to sn1(sn3->sn1), the snapshot chain should be base->sn1->sn4
4). commit block device and wait to finished
5). check backing file after commit
6). quit stress app
7). reboot and verify guest can response correctly
:param test: Kvm test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment.
"""
tag = params.get("source_image", "image1")
stress_test = BlockCommitStress(test, params, env, tag)
try:
stress_test.action_before_start()
stress_test.create_snapshots()
stress_test.start()
stress_test.action_after_finished()
finally:
stress_test.clean()
# Below case works stablly on QMP monitor, but have no more test with Human
# monitor, so suggest to use QMP monitor as default qemu monitor run below test
#
- block_commit:
no raw qed vmdk
backup_image_before_testing = yes
restore_image_after_testing = yes
wait_finished = yes
default_speed_image1 = 0
snapshot_chain = "images/sn1 images/sn2 images/sn3 images/sn4"
# If image size increase or limited committing please increase
# wait_timeout to avoid wait for committing finished timeout;
wait_timeout = 3900
snapshot_format = qcow2
kill_vm = yes
alive_check_cmd = dir
tmp_dir = /tmp
base_image = "images/sn1"
top_image = "images/sn3"
expected_image_file = "images/sn1"
variants:
- with_payload:
type = block_commit_stress
variants:
- with_stress:
wait_finished = no
wait_timeout = 120
before_start = "load_stress"
after_finished = "unload_stress verify_backingfile reboot verify_alive"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册