提交 c2a3cb42 编写于 作者: X Xu Tian 提交者: GitHub

Merge pull request #756 from xutian/fix_mem_pause

Update test case to make memory hotplug/unplug when VM is paused
......@@ -15,6 +15,7 @@
no RHEL.5 RHEL.6
no Windows..i386
no WinXP Win2000 Win2003 WinVista
sub_test_wait_time = 0
variants numa_nodes:
- one:
guest_numa_nodes = "node0"
......@@ -112,6 +113,7 @@
reboot_method = system_reset
sleep_before_reset = 0
- guest_reboot:
sub_test_wait_time = 2
sub_type = boot
reboot_method = shell
kill_vm_on_error = yes
......@@ -131,9 +133,11 @@
only after
- pause_vm:
sub_type = stop_continue
pause_time = 120
pause_time = 300
wait_resume_timeout = "${pause_time}"
sub_test_wait_time = 60
- stress:
sub_test_wait_time = 60
Windows:
timeout = 600
autostress = yes
......
import logging
from virttest.utils_test import BackgroundTest
from virttest.utils_test import run_virt_sub_test
from virttest.utils_test.qemu import MemoryHotplugTest
......@@ -18,6 +19,7 @@ except ImportError:
class MemoryHotplugSimple(MemoryHotplugTest):
def run_sub_test(self):
""" Run virt sub test before/after hotplug/unplug memory device"""
if self.params.get("sub_type"):
step = ("Run sub test '%s' %s %s memory device" %
(self.params["sub_test"],
......@@ -28,13 +30,18 @@ class MemoryHotplugSimple(MemoryHotplugTest):
run_virt_sub_test(*args)
def run_background_test(self):
"""Run virt sub test in backgroup"""
wait_time = float(self.params.get("sub_test_wait_time", 0))
args = (self.test, self.params, self.env, self.params["sub_type"])
bg_test = BackgroundTest(run_virt_sub_test, args)
bg_test.start()
wait_for(bg_test.is_alive, first=10, step=3, timeout=100)
wait_for(bg_test.is_alive, first=wait_time, step=3, timeout=240)
return bg_test
def restore_memory(self, pre_vm, post_vm):
"""
Compare pre_vm and post_vm, restore VM memory devices.
"""
mem_devs_post = set(post_vm.params.objects("mem_devs"))
mem_devs_origin = set(pre_vm.params.objects("mem_devs"))
if mem_devs_post == mem_devs_origin:
......@@ -56,35 +63,50 @@ class MemoryHotplugSimple(MemoryHotplugTest):
devices = filter(None, map(vm.devices.get_by_qid, dev_ids))
return [_[0] for _ in devices]
def unplug_memory(self, vm, target_mem):
"""Unplug the target memory, if the memory not exists,
hotplug it, then unplug it
"""
devs = self.get_mem_by_name(vm, target_mem)
if not devs and self.params.get("strict_check") != "yes":
self.hotplug_memory(vm, target_mem)
return super(MemoryHotplugSimple, self).unplug_memory(vm, target_mem)
def start_test(self):
operation = self.params["operation"]
target_mem = self.params["target_mem"]
stage = self.params.get("stage", "before")
sub_test_runner = (
stage == 'during' and [
self.run_background_test] or [
self.run_sub_test])[0]
func = getattr(self, "%s_memory" % operation)
if not callable(func):
raise exceptions.TestError(
"Unsupported memory operation '%s'" %
operation)
vm = self.env.get_vm(self.params["main_vm"])
try:
if stage != "after":
sub_test = sub_test_runner()
func(vm, target_mem)
self.check_memory(vm)
else:
func(vm, target_mem)
self.check_memory(vm)
sub_test = sub_test_runner()
if stage == "during":
sub_test.join(timeout=3600)
vm = self.env.get_vm(self.params["main_vm"])
if self.params.get("stage") == "before":
self.run_sub_test()
# If unplug memory not exits and test in instrcit then hotplug it
if operation == "unplug":
devs = self.get_mem_by_name(vm, target_mem)
if not devs and self.params.get("strict") != "yes":
self.hotplug_memory(vm, target_mem)
func_name = "%s_memory" % operation
func = getattr(self, func_name)
if self.params.get("stage") == "during":
sub_test = self.run_background_test()
func(vm, target_mem)
self.check_memory(vm)
if self.params.get("stage") == "during":
test_timeout = float(self.params.get("sub_test_timeout", 3600))
sub_test.join(timeout=test_timeout)
if self.params.get("stage") == "after":
self.run_sub_test()
self.restore_memory(vm, self.env.get_vm(self.params['main_vm']))
vm.reboot()
finally:
try:
self.restore_memory(
vm, self.env.get_vm(
self.params['main_vm']))
except Exception, details:
logging.warn("Error happen when restore vm: %s" % details)
self.close_sessions()
vm = self.env.get_vm(self.params["main_vm"])
vm.verify_alive()
vm.reboot()
@step_engine.context_aware
......
import time
import logging
from autotest.client.shared import error
......@@ -63,7 +64,7 @@ def run(test, params, env):
logging.error(msg)
raise error.TestFail(msg)
session.close()
time.sleep(float(params.get("pause_time", 0)))
error.base_context("Resume the VM", logging.info)
vm.resume()
error.context("Verify the status of VM is 'running'", logging.info)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册