未验证 提交 c1b0252f 编写于 作者: X Xu Han 提交者: GitHub

Merge pull request #1287 from luckyh/replace-autotest-qemu-p3

[qemu] Replace autotest modules - de
import logging
import re
from autotest.client.shared import error
from virttest import error_context
from virttest import env_process
@error.context_aware
@error_context.context_aware
def run(test, params, env):
"""
Device bit check test:
......@@ -45,8 +44,8 @@ def run(test, params, env):
else:
properties = default_value
error.context("Boot up guest with properites: %s value as: %s"
% (str(options), properties), logging.info)
error_context.context("Boot up guest with properites: %s value as: %s"
% (str(options), properties), logging.info)
vm_name = params["main_vm"]
params["start_vm"] = 'yes'
env_process.preprocess_vm(test, params, env, vm_name)
......@@ -57,27 +56,26 @@ def run(test, params, env):
qtree_info = vm.monitor.info("qtree")
dev_info = re.findall(dev_pattern, qtree_info, re.S)
if not dev_info:
raise error.TestError("Can't get device info from qtree result.")
test.error("Can't get device info from qtree result.")
for index, option in enumerate(options):
option_regex = "%s\s+=\s+(\w+)" % option
option_value = re.findall(option_regex, dev_info[0], re.M)
if not option_value:
logging.debug("dev info in qtree: %s" % dev_info[0])
raise error.TestError("Can't get the property info from qtree"
" result")
test.error("Can't get the property info from qtree result")
if option_value[0] not in convert_dict[properties[index]]:
msg = "'%s' value get '%s', " % (option, option_value)
msg += "expect value '%s'" % convert_dict[properties[index]]
logging.debug(msg)
raise error.TestFail("Properity bit for %s is wrong." % option)
test.fail("Properity bit for %s is wrong." % option)
logging.info("Properity bit in qtree is right for %s." % option)
if params.get("check_in_guest", "yes") == "yes":
pci_info = session.cmd_output("lspci")
pci_n = re.findall(pci_id_pattern, pci_info)
if not pci_n:
raise error.TestError("Can't get the pci id for device")
test.error("Can't get the pci id for device")
cmd = "cat /sys/bus/pci/devices/0000:%s/" % pci_n[0]
cmd += "virtio*/features"
bitstr = session.cmd_output(cmd)
......@@ -87,8 +85,8 @@ def run(test, params, env):
msg = "bit string in guest: %s" % bitstr
msg += "expect bit string: %s" % properties[index]
logging.debug(msg)
raise error.TestFail("Properity bit for %s is wrong"
" inside guest." % option)
test.fail("Properity bit for %s is wrong"
" inside guest." % option)
logging.info("Properity bit in qtree is right for %s"
" in guest." % option)
session.close()
......
import re
import logging
from virttest import utils_misc
# Make it work under both autotest-framework and avocado-framework
try:
from avocado.core import exceptions
except ImportError:
from autotest.client.shared import error as exceptions
try:
from virttest import error_context
except ImportError:
from autotest.client.shared import error as error_context
from virttest import error_context
from virttest import utils_misc
@error_context.context_aware
......@@ -48,7 +39,7 @@ def run(test, params, env):
status = utils_misc.wait_for(lambda: disable_win_service(session, scname),
timeout=cmd_timeout)
if not status:
raise exceptions.TestFail("Turn off updates service failed.")
test.fail("Turn off updates service failed.")
session = vm.reboot(session)
finally:
session.close()
import os
import logging
from autotest.client.shared import error, utils
from avocado.utils import process
from virttest import error_context
from virttest import utils_misc
from virttest import storage
from virttest import qemu_storage
......@@ -65,7 +66,7 @@ class DriveMirror(block_copy.BlockCopy):
image_file = storage.get_image_filename(params, self.data_dir)
return self.vm.get_block({"file": image_file})
@error.context_aware
@error_context.context_aware
def check_node_name(self):
"""
Check node name as set, after block job complete.
......@@ -76,11 +77,10 @@ class DriveMirror(block_copy.BlockCopy):
node_name_exp = self.params["node_name"]
node_name = info.get("node-name", "")
if node_name != node_name_exp:
raise error.TestFail(
"node-name is: %s, while set value is: %s" %
(node_name, node_name_exp))
self.test.fail("node-name is: %s, while set value is: %s" %
(node_name, node_name_exp))
@error.context_aware
@error_context.context_aware
def start(self):
"""
start block device mirroring job;
......@@ -101,15 +101,15 @@ class DriveMirror(block_copy.BlockCopy):
"buf-size": buf_size})
if 'node_name' in params:
args.update({"node-name": params.get("node_name")})
error.context("Start to mirror block device", logging.info)
error_context.context("Start to mirror block device", logging.info)
self.vm.block_mirror(device, target_image, full_copy,
**args)
if not self.get_status():
raise error.TestFail("No active mirroring job found")
self.test.fail("No active mirroring job found")
if params.get("image_type") != "iscsi":
self.trash_files.append(target_image)
@error.context_aware
@error_context.context_aware
def reopen(self):
"""
reopen target image, then check if image file of the device is
......@@ -118,7 +118,7 @@ class DriveMirror(block_copy.BlockCopy):
params = self.parser_test_args()
target_format = params["image_format"]
timeout = params["reopen_timeout"]
error.context("reopen new target image", logging.info)
error_context.context("reopen new target image", logging.info)
if self.vm.monitor.protocol == "qmp":
self.vm.monitor.clear_event("BLOCK_JOB_COMPLETED")
self.vm.block_reopen(self.device, self.target_image, target_format)
......@@ -141,7 +141,7 @@ class DriveMirror(block_copy.BlockCopy):
params["image_format"],
self.target_image,
params["image_size"])
utils.system(cmd)
process.system(cmd)
image = qemu_storage.Iscsidev(params, self.data_dir,
params["target_image"])
image.cleanup()
......
import logging
from autotest.client.shared import utils
from autotest.client.shared import error
from avocado.utils import process
from virttest import error_context
from virttest import utils_misc
from qemu.tests import drive_mirror
@error.context_aware
@error_context.context_aware
def run_drive_mirror_cancel(test, params, env):
"""
Test block mirroring functionality
......@@ -19,15 +23,16 @@ def run_drive_mirror_cancel(test, params, env):
mirror_test = drive_mirror.DriveMirror(test, params, env, tag)
try:
mirror_test.start()
error.context("Block network connection with iptables", logging.info)
utils.run(params["start_firewall_cmd"])
bg = utils.InterruptedThread(mirror_test.cancel,)
error_context.context("Block network connection with iptables",
logging.info)
process.run(params["start_firewall_cmd"])
bg = utils_misc.InterruptedThread(mirror_test.cancel)
bg.start()
job = mirror_test.get_status()
if job.get("type", "0") != "mirror":
raise error.TestFail("Job cancel immediacatly")
error.context("Cleanup rules in iptables", logging.info)
utils.run(params["stop_firewall_cmd"])
test.fail("Job cancel immediacatly")
error_context.context("Cleanup rules in iptables", logging.info)
process.run(params["stop_firewall_cmd"])
bg.join(timeout=int(params["cancel_timeout"]))
finally:
mirror_test.vm.destroy()
......
import logging
from autotest.client.shared import error
from virttest import data_dir
from virttest import env_process
from virttest import error_context
from virttest import qemu_storage
from qemu.tests import drive_mirror
@error.context_aware
@error_context.context_aware
def run(test, params, env):
"""
Test block mirroring functionality
......@@ -37,8 +36,8 @@ def run(test, params, env):
mirror_test.action_after_reopen()
device_id = mirror_test.vm.get_block({"file": target_image})
if device_id != mirror_test.device:
raise error.TestError("Mirrored image not being used by guest")
error.context("Compare fully mirrored images", logging.info)
test.error("Mirrored image not being used by guest")
error_context.context("Compare fully mirrored images", logging.info)
qemu_img.compare_images(source_image, target_image, force_share=True)
mirror_test.vm.resume()
if params.get("boot_target_image", "no") == "yes":
......
import logging
from autotest.client.shared import error
from virttest import env_process
from virttest import error_context
from qemu.tests import drive_mirror_stress
......@@ -12,15 +11,15 @@ class DriveMirrorPowerdown(drive_mirror_stress.DriveMirrorStress):
def __init__(self, test, params, env, tag):
super(DriveMirrorPowerdown, self).__init__(test, params, env, tag)
@error.context_aware
@error_context.context_aware
def powerdown(self):
"""
power down guest via quit qemu;
"""
error.context("powerdown vm", logging.info)
error_context.context("powerdown vm", logging.info)
return self.vm.destroy()
@error.context_aware
@error_context.context_aware
def powerup(self):
"""
bootup guest with target image;
......@@ -28,7 +27,7 @@ class DriveMirrorPowerdown(drive_mirror_stress.DriveMirrorStress):
params = self.parser_test_args()
vm_name = params['main_vm']
logging.info("Target image: %s" % self.target_image)
error.context("powerup vm with target image", logging.info)
error_context.context("powerup vm with target image", logging.info)
env_process.preprocess_vm(self.test, params, self.env, vm_name)
vm = self.env.get_vm(vm_name)
vm.verify_alive()
......
import logging
import time
import random
from autotest.client.shared import error
from autotest.client.shared import utils
from avocado.utils import process
from virttest import error_context
from qemu.tests import drive_mirror
......@@ -11,26 +14,27 @@ class DriveMirrorSimple(drive_mirror.DriveMirror):
def __init__(self, test, params, env, tag):
super(DriveMirrorSimple, self).__init__(test, params, env, tag)
@error.context_aware
@error_context.context_aware
def query_status(self):
"""
query running block mirroring job info;
"""
error.context("query job status", logging.info)
error_context.context("query job status", logging.info)
if not self.get_status():
raise error.TestFail("No active job")
self.test.fail("No active job")
@error.context_aware
@error_context.context_aware
def readonly_target(self):
error.context("Set readonly bit on target image", logging.info)
error_context.context("Set readonly bit on target image", logging.info)
cmd = "chattr +i %s" % self.target_image
return utils.system(cmd)
return process.system(cmd)
@error.context_aware
@error_context.context_aware
def clear_readonly_bit(self):
error.context("Clear readonly bit on target image", logging.info)
error_context.context("Clear readonly bit on target image",
logging.info)
cmd = "chattr -i %s" % self.target_image
return utils.system(cmd)
return process.system(cmd)
def run(test, params, env):
......@@ -59,7 +63,7 @@ def run(test, params, env):
if params.get("negative_test") == "yes":
keywords = params.get("error_key_words", "Could not open")
if simple_test.get_status():
raise error.TestFail("Block job not cancel as expect")
test.fail("Block job not cancel as expect")
if keywords not in str(detail):
raise
simple_test.action_before_steady()
......
import re
import time
import logging
from virttest import utils_misc
from virttest import utils_test
from virttest import error_context
from autotest.client.shared import utils
from avocado.core import exceptions
@error_context.context_aware
......@@ -62,7 +61,7 @@ def run(test, params, env):
session, bg_stress_test)
session.sendline(bg_stress_test)
else:
stress_thread = utils.InterruptedThread(
stress_thread = utils_misc.InterruptedThread(
utils_test.run_virt_sub_test, (test, params, env),
{"sub_type": bg_stress_test})
stress_thread.start()
......@@ -77,14 +76,13 @@ def run(test, params, env):
if not utils_misc.wait_for(lambda: check_bg_running(target_process),
120, 0, 1):
raise exceptions.TestFail("Backgroud test %s is not "
"alive!" % bg_stress_test)
test.fail("Backgroud test %s is not alive!" % bg_stress_test)
if params.get("set_bg_stress_flag", "no") == "yes":
logging.info("Wait %s test start" % bg_stress_test)
if not utils_misc.wait_for(lambda: env.get(bg_stress_run_flag),
wait_time, 0, 0.5):
err = "Fail to start %s test" % bg_stress_test
raise exceptions.TestError(err)
test.error(err)
env["bg_status"] = 1
return stress_thread
......
import logging
import time
from autotest.client.shared import error
from virttest import error_context
from virttest import utils_misc
@error.context_aware
@error_context.context_aware
def run(test, params, env):
"""
change a removable media:
......@@ -42,55 +41,56 @@ def run(test, params, env):
device_name = vm.get_block(p_dict)
if device_name is None:
msg = "Fail to get device using image %s" % orig_img_name
raise error.TestFail(msg)
error.context("Eject original device.")
test.fail(msg)
error_context.context("Eject original device.")
eject_cmd = "eject device=%s" % device_name
vm.monitor.send_args_cmd(eject_cmd)
logging.info("Wait until device is ejected")
time.sleep(10)
blocks_info = vm.monitor.info("block")
if orig_img_name in str(blocks_info):
raise error.TestFail("Fail to eject cdrom %s. " % orig_img_name)
test.fail("Fail to eject cdrom %s. " % orig_img_name)
error.context("Eject original device for second time")
error_context.context("Eject original device for second time")
vm.monitor.send_args_cmd(eject_cmd)
new_img_name = params.get("new_img_name")
error.context("Insert new image to device.")
error_context.context("Insert new image to device.")
change_cmd = "change device=%s,target=%s" % (device_name, new_img_name)
vm.monitor.send_args_cmd(change_cmd)
logging.info("Wait until device changed")
time.sleep(10)
blocks_info = vm.monitor.info("block")
if new_img_name not in str(blocks_info):
raise error.TestFail("Fail to chang cdrom to %s." % new_img_name)
test.fail("Fail to chang cdrom to %s." % new_img_name)
if qmp_used:
eject_cmd = "eject device=%s, force=True" % device_name
else:
eject_cmd = "eject device=%s" % device_name
error.context("Eject device after add new image by change command")
error_context.context("Eject device after add new image by change command")
vm.monitor.send_args_cmd(eject_cmd)
logging.info("Wait until new image is ejected")
time.sleep(10)
blocks_info = vm.monitor.info("block")
if new_img_name in str(blocks_info):
raise error.TestFail("Fail to eject cdrom %s." % orig_img_name)
test.fail("Fail to eject cdrom %s." % orig_img_name)
error.context("Insert %s to device %s" % (orig_img_name, device_name))
error_context.context("Insert %s to device %s"
% (orig_img_name, device_name))
change_cmd = "change device=%s,target=%s" % (device_name, orig_img_name)
vm.monitor.send_args_cmd(change_cmd)
logging.info("Wait until device changed")
time.sleep(10)
blocks_info = vm.monitor.info("block")
if orig_img_name not in str(blocks_info):
raise error.TestFail("Fail to change cdrom to %s." % orig_img_name)
test.fail("Fail to change cdrom to %s." % orig_img_name)
error.context("Try to eject non-removable device")
error_context.context("Try to eject non-removable device")
p_dict = {"removable": False}
device_name = vm.get_block(p_dict)
if device_name is None:
raise error.TestFail("Could not find non-removable device")
test.fail("Could not find non-removable device")
if params.get("force_eject", "no") == "yes":
if not qmp_used:
eject_cmd = "eject -f %s " % device_name
......@@ -102,12 +102,12 @@ def run(test, params, env):
vm.monitor.send_args_cmd(eject_cmd)
except Exception, e:
if "is not removable" not in str(e):
raise error.TestFail(e)
test.fail(e)
logging.debug("Catch exception message: %s" % e)
logging.info("Wait until device is ejected")
time.sleep(10)
blocks_info = vm.monitor.info("block")
if device_name not in str(blocks_info):
raise error.TestFail("Could remove non-removable device!")
test.fail("Could remove non-removable device!")
session.close()
import logging
import re
from autotest.client.shared import error
from virttest import env_process
from virttest import error_context
from virttest import utils_misc
@error.context_aware
@error_context.context_aware
def run(test, params, env):
"""
enforce quit test:
......@@ -42,14 +41,14 @@ def run(test, params, env):
force_quit = True
if "enforce" not in extra_flags:
raise error.TestError("pls add 'enforce' params to the cmd line")
test.error("pls add 'enforce' params to the cmd line")
msg_unavailable = params.get("msg_unavailable", "").split(":")
msg_unknow = params.get("msg_unknow", "not found")
try:
error.context("boot guest with -cpu %s,%s" %
(guest_cpumodel, extra_flags),
logging.info)
error_context.context("boot guest with -cpu %s,%s" %
(guest_cpumodel, extra_flags),
logging.info)
params["start_vm"] = "yes"
env_process.preprocess_vm(test, params, env, params.get("main_vm"))
except Exception, err:
......@@ -60,10 +59,9 @@ def run(test, params, env):
if tmp_flag or msg_unknow in str(err):
logging.info("unavailable host feature, guest force quit")
else:
raise error.TestFail("guest quit with error\n%s" % str(err))
test.fail("guest quit with error\n%s" % str(err))
vm = env.get_vm(params["main_vm"])
if force_quit:
if not vm.is_dead():
raise error.TestFail("guest didn't enforce quit"
" while flag lacked in host")
test.fail("guest didn't enforce quit while flag lacked in host")
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册