提交 7666da44 编写于 作者: X Xu Han 提交者: GitHub

Merge pull request #762 from xiywang/live_commit

block_commit: Add test case 'Basic block commit test' to block commit
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()
import time
import logging
from autotest.client.shared import error
from autotest.client import utils
from virttest import utils_misc
from virttest import utils_test
from virttest import error_context
from qemu.tests import blk_stream
class BlockStreamStress(blk_stream.BlockStream):
def __init__(self, test, params, env, tag):
super(BlockStreamStress, self).__init__(test, params, env, tag)
def parser_test_args(self):
"""
set default values and check core commands has configured;
"""
params = super(BlockStreamStress, self).parser_test_args()
for param in ["start_cmd", "stop_cmd", "check_cmd"]:
if not params.get(param):
raise error.TestFail("%s not configured,please check your"
"configuration at first")
return params
@error.context_aware
def install_stress_app(self):
params = self.parser_test_args()
session = self.get_session()
if session.cmd_status(params.get("app_check_cmd", "true")) == 0:
return True
error.context("install stress app in guest", logging.info)
link = params.get("download_link")
md5sum = params.get("pkg_md5sum")
tmp_dir = params.get("tmp_dir")
install_cmd = params.get("install_cmd")
config_cmd = params.get("config_cmd")
logging.info("Fetch package: %s" % link)
pkg = utils.unmap_url_cache(self.test.tmpdir, link, md5sum)
self.vm.copy_files_to(pkg, tmp_dir)
logging.info("Install app: %s" % install_cmd)
s, o = session.cmd_status_output(install_cmd, timeout=300)
if s != 0:
raise error.TestError("Fail to install stress app(%s)" % o)
logging.info("Configure app: %s" % config_cmd)
s, o = session.cmd_status_output(config_cmd, timeout=300)
if s != 0:
raise error.TestError("Fail to conifg stress app(%s)" % o)
@error.context_aware
@error_context.context_aware
def load_stress(self):
"""
load IO/CPU/Memoery stress in guest;
"""
params = self.parser_test_args()
self.install_stress_app()
cmd = params.get("start_cmd")
session = self.get_session()
error.context("Load stress in guest(%s)" % cmd, logging.info)
session.sendline(cmd)
if not self.app_runing():
raise error.TestFail("stress app( %s) isn't running" % cmd)
error_context.context("launch stress app in guest", logging.info)
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")
# sleep 10s to ensure heavyload.exe make guest under heayload really;
time.sleep(10)
return None
@error.context_aware
@error_context.context_aware
def unload_stress(self):
"""
stop stress app
"""
error.context("stop stress app in guest", logging.info)
params = self.parser_test_args()
def _unload_stress():
session = self.get_session()
cmd = params.get("stop_cmd")
cmd = self.params.get("stop_cmd")
session.sendline(cmd)
if not self.app_runing():
return True
return False
session.close()
return self.app_running()
stoped = utils_misc.wait_for(_unload_stress, first=2.0,
text="wait stress app quit",
step=1.0, timeout=params["wait_timeout"])
if not stoped:
raise error.TestFail("stress app is still running")
error_context.context("stop stress app in guest", logging.info)
stopped = utils_misc.wait_for(_unload_stress, first=2.0,
text="wait stress app quit",
step=1.0, timeout=120)
if not stopped:
logging.warn("stress app is still running")
def app_runing(self):
def app_running(self):
"""
check stress app really run in background;
"""
session = self.get_session()
params = self.parser_test_args()
cmd = params.get("check_cmd")
cmd = self.params.get("check_cmd")
status = session.cmd_status(cmd, timeout=120)
session.close()
return status == 0
......
# 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"
......@@ -85,15 +85,7 @@
absolute_path = no
- with_stress:
type = block_stream_stress
download_link = http://weather.ou.edu/~apw/projects/stress/stress-1.0.4.tar.gz
pkg_md5sum = a607afa695a511765b40993a64c6e2f4
install_cmd = "tar -xzvf ${tmp_dir}/stress-1.0.4.tar.gz -C ./ && cd stress-1.0.4 && ./configure --prefix=/usr && make && make install "
config_cmd = ""
app_check_cmd = "stress --help"
before_start = "load_stress"
start_cmd = "stress --cpu 4 --io 4 --vm 2 --vm-bytes 256M --quiet &"
check_cmd = 'pidof -s stress'
stop_cmd = "killall -g stress"
after_finished = "unload_stress reboot verify_alive"
variants:
- @default:
......
......@@ -108,30 +108,22 @@
reopen_timeout = 600
variants:
- heavyload:
download_link = http://weather.ou.edu/~apw/projects/stress/stress-1.0.4.tar.gz
pkg_md5sum = a607afa695a511765b40993a64c6e2f4
install_cmd = "tar -xzvf ${tmp_dir}/stress-1.0.4.tar.gz -C ./ && cd stress-1.0.4 && ./configure --prefix=/usr && make && make install "
config_cmd = ""
app_check_cmd = "stress --help"
start_cmd = "stress --cpu 4 --io 4 --vm 2 --vm-bytes 256M --quiet &"
check_cmd = 'pidof -s stress'
stop_cmd = "killall -g stress"
variants:
- stress:
before_start = "load_stress"
when_steady = "reopen"
after_reopen = "reboot verify_alive"
after_reopen = "unload_stress reboot verify_alive"
- stop:
before_start = "load_stress"
before_steady = "stop"
when_steady = "reopen resume"
after_reopen = "reboot verify_alive"
after_reopen = "unload_stress reboot verify_alive"
- check_steady:
before_start = "load_stress"
when_steady = "verify_steady"
#seconds to verify offset not decrease when guest in steady status
hold_on_timeout = 300
after_reopen = "reboot verify_alive"
after_reopen = "unload_stress reboot verify_alive"
- dd:
app_check_cmd = "dd --help"
start_cmd = "dd if=/dev/urandom of=/tmp/dd.img bs=4k count=500000"
......
import time
import logging
from autotest.client.shared import error
from autotest.client import utils
from virttest import utils_misc
from virttest import utils_test
from virttest import error_context
from qemu.tests import drive_mirror
class DriveMirrorStress(drive_mirror.DriveMirror):
def __init__(self, test, params, env, tag):
super(DriveMirrorStress, self).__init__(test, params, env, tag)
@error.context_aware
def install_stress_app(self):
params = self.parser_test_args()
session = self.get_session()
if session.cmd_status(params.get("app_check_cmd", "true")) == 0:
return True
error.context("install stress app in guest", logging.info)
link = params.get("download_link")
md5sum = params.get("pkg_md5sum")
tmp_dir = params.get("tmp_dir")
install_cmd = params.get("install_cmd")
config_cmd = params.get("config_cmd")
logging.info("Fetch package: %s" % link)
pkg = utils.unmap_url_cache(self.test.tmpdir, link, md5sum)
self.vm.copy_files_to(pkg, tmp_dir)
logging.info("Install app: %s" % install_cmd)
s, o = session.cmd_status_output(install_cmd, timeout=300)
if s != 0:
raise error.TestError("Fail to install stress app(%s)" % o)
logging.info("Configure app: %s" % config_cmd)
s, o = session.cmd_status_output(config_cmd, timeout=300)
if s != 0:
raise error.TestError("Fail to conifg stress app(%s)" % o)
@error.context_aware
def load_stress(self):
"""
load IO/CPU/Memory stress in guest;
"""
params = self.parser_test_args()
self.install_stress_app()
cmd = params.get("start_cmd")
session = self.get_session()
error.context("launch stress app in guest", logging.info)
session.sendline(cmd)
logging.info("Start command: %s" % cmd)
running = utils_misc.wait_for(self.app_runing, timeout=150, step=5)
if not running:
raise error.TestFail("stress app isn't running")
error_context.context("launch stress app in guest", logging.info)
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")
# sleep 10s to ensure heavyload.exe make guest under heayload really;
time.sleep(10)
return None
@error.context_aware
def unload_stress(self):
"""
stop stress app
"""
def _unload_stress():
params = self.parser_test_args()
session = self.get_session()
cmd = params.get("stop_cmd")
cmd = self.params.get("stop_cmd")
session.sendline(cmd)
if not self.app_runing():
return True
return False
session.close()
return self.app_running()
error.context("stop stress app in guest", logging.info)
utils_misc.wait_for(_unload_stress, first=2.0,
text="wait stress app quit", step=1.0, timeout=120)
error_context.context("stop stress app in guest", logging.info)
stopped = utils_misc.wait_for(_unload_stress, first=2.0,
text="wait stress app quit",
step=1.0, timeout=120)
if not stopped:
logging.warn("stress app is still running")
def app_runing(self):
def app_running(self):
"""
check stress app really run in background;
"""
session = self.get_session()
params = self.parser_test_args()
cmd = params.get("check_cmd")
cmd = self.params.get("check_cmd")
status = session.cmd_status(cmd, timeout=120)
session.close()
return status == 0
@error.context_aware
def verify_steady(self):
"""
verify offset not decreased, after block mirror job in steady status;
"""
error.context("verify offset not decreased", logging.info)
error_context.context("verify offset not decreased", logging.info)
params = self.parser_test_args()
timeout = int(params.get("hold_on_timeout", 600))
offset = self.get_status()["offset"]
......@@ -98,7 +68,7 @@ class DriveMirrorStress(drive_mirror.DriveMirror):
if _offset < offset:
msg = "offset decreased, offset last: %s" % offset
msg += "offset now: %s" % _offset
raise error.TestFail(msg)
self.test.fail(msg)
offset = _offset
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册