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

Merge pull request #1284 from hereischen/2-drop-auotest

[generic] Replace autotest modules - bcdef
import time
import logging
from autotest.client.shared import error
from virttest import error_context
from virttest import utils_test
@error.context_aware
@error_context.context_aware
def run(test, params, env):
"""
Qemu reboot test:
......@@ -23,7 +22,7 @@ def run(test, params, env):
timeout = float(params.get("login_timeout", 240))
vms = env.get_all_vms()
for vm in vms:
error.context("Try to log into guest '%s'." % vm.name, logging.info)
error_context.context("Try to log into guest '%s'." % vm.name, logging.info)
session = vm.wait_for_login(timeout=timeout)
session.close()
......@@ -34,7 +33,7 @@ def run(test, params, env):
session.close()
if params.get("reboot_method"):
for vm in vms:
error.context("Reboot guest '%s'." % vm.name, logging.info)
error_context.context("Reboot guest '%s'." % vm.name, logging.info)
if params["reboot_method"] == "system_reset":
time.sleep(int(params.get("sleep_before_reset", 10)))
# Reboot the VM
......
......@@ -3,8 +3,6 @@ import time
import tempfile
import os
from autotest.client.shared import error
from virttest import qemu_storage
from virttest import data_dir
from virttest import utils_misc
......@@ -77,7 +75,7 @@ def run(test, params, env):
time_elapsed = int(time.time() - start_time)
info = "after %s s, %d load/save cycles" % (time_elapsed, cycles + 1)
if not successful_login:
raise error.TestFail("Can't log on '%s' %s" % (vm.name, info))
test.fail("Can't log on '%s' %s" % (vm.name, info))
else:
logging.info("Test ended %s", info)
......@@ -85,7 +83,7 @@ def run(test, params, env):
vm.destroy()
floppy_info = floppy.snapshot_list()
if floppy_info == floppy_orig_info:
raise error.TestFail("savevm didn't create snapshot in floppy."
" original snapshot list is: %s"
" now snapshot list is: %s"
% (floppy_orig_info, floppy_info))
test.fail("savevm didn't create snapshot in floppy."
" original snapshot list is: %s"
" now snapshot list is: %s"
% (floppy_orig_info, floppy_info))
from autotest.client.shared import error
from virttest import installer
......@@ -30,5 +28,5 @@ def run(test, params, env):
minor_failure_reasons.append(reason)
if minor_failure:
raise error.TestWarn("Minor (worked around) failures during build "
"test: %s" % ", ".join(minor_failure_reasons))
test.error("Minor (worked around) failures during build "
"test: %s" % ", ".join(minor_failure_reasons))
import logging
import os
from autotest.client.shared import error
from virttest import error_context
from virttest import utils_test
from virttest import data_dir
@error.context_aware
@error_context.context_aware
def run(test, params, env):
"""
Verify if guests using kvm-clock as the time source have a sane clock
......@@ -32,7 +31,7 @@ def run(test, params, env):
dest_name = "/tmp/clock_getres.c"
if not os.path.isfile(source_name):
raise error.TestError("Could not find %s" % source_name)
test.error("Could not find %s" % source_name)
vm.copy_files_to(source_name, dest_name)
session.cmd("gcc -lrt -o %s %s" % (getres_cmd, dest_name))
......@@ -41,6 +40,6 @@ def run(test, params, env):
logging.info("PASS: Guest reported appropriate clock resolution")
sub_test = params.get("sub_test")
if sub_test:
error.context("Run sub test '%s' after checking"
" clock resolution" % sub_test, logging.info)
error_context.context("Run sub test '%s' after checking"
" clock resolution" % sub_test, logging.info)
utils_test.run_virt_sub_test(test, params, env, sub_test)
"""
Configurable on-guest dd test.
:author: Lukas Doktor <ldoktor@redhat.com>
:copyright: 2012 Red Hat, Inc.
"""
......@@ -7,11 +8,11 @@ import logging
import aexpect
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):
"""
Executes dd with defined parameters and checks the return number and output
......@@ -21,7 +22,7 @@ def run(test, params, env):
2). run dd command in guest with special params(eg. oflag, bs and so on)
3). check command exit stauts and output
"""
def _get_file(filename, select):
def _get_file(filename, select, test=test):
""" Picks the actual file based on select value """
if filename == "NULL":
return "/dev/null"
......@@ -36,7 +37,7 @@ def run(test, params, env):
drive_path = utils_misc.get_linux_drive_path(session, drive_id)
if drive_path:
return drive_path
raise error.TestError("Failed to get '%s' drive path" % filename)
test.error("Failed to get '%s' drive path" % filename)
else:
# get all matching filenames
try:
......@@ -51,12 +52,12 @@ def run(test, params, env):
err = ("Incorrect cfg: dd_select out of the range (disks=%s,"
" select=%s)" % (disks, select))
logging.error(err)
raise error.TestError(err)
test.error(err)
vm = env.get_vm(params['main_vm'])
timeout = int(params.get("login_timeout", 360))
error.context("Wait guest boot up", logging.info)
error_context.context("Wait guest boot up", logging.info)
session = vm.wait_for_login(timeout=timeout)
dd_if = params.get("dd_if")
......@@ -96,28 +97,25 @@ def run(test, params, env):
dd_cmd += " seek=%s" % dd_seek
logging.info("Using '%s' cmd", dd_cmd)
error.context("Execute dd in guest", logging.info)
error_context.context("Execute dd in guest", logging.info)
try:
(stat, out) = session.cmd_status_output(dd_cmd, timeout=dd_timeout)
except aexpect.ShellTimeoutError:
err = ("dd command timed-out (cmd='%s', timeout=%d)"
% (dd_cmd, dd_timeout))
logging.error(err)
raise error.TestFail(err)
test.fail(err)
except aexpect.ShellCmdError, details:
stat = details.status
out = details.output
error.context("Check command exit status and output", logging.info)
error_context.context("Check command exit status and output", logging.info)
logging.debug("Returned dd_status: %s\nReturned output:\n%s", stat, out)
if stat != dd_stat:
err = ("Return code doesn't match (expected=%s, actual=%s)\n"
"Output:\n%s" % (dd_stat, stat, out))
logging.error(err)
raise error.TestFail(err)
test.fail(err)
if dd_output not in out:
err = ("Output doesn't match:\nExpected:\n%s\nActual:\n%s"
% (dd_output, out))
raise error.TestFail(err)
test.fail(err)
logging.info("dd test succeeded.")
return
import logging
from autotest.client.shared import error
from virttest import utils_test
from virttest import error_context
from virttest import qemu_storage
......@@ -33,4 +31,4 @@ def run(test, params, env):
if actual_compat != ver_to:
err_msg = "Fail to downgrade qcow2 image version!"
err_msg += "Actual: %s, expect: %s" % (actual_compat, ver_to)
raise error.TestFail(err_msg)
test.fail(err_msg)
import os
from autotest.client import utils
from autotest.client.shared import error
from avocado.utils import process
from virttest import data_dir
......@@ -14,6 +13,6 @@ def run(test, params, env):
dropin_path = os.path.join(data_dir.get_root_dir(), "dropin",
dropin_path)
try:
utils.system(dropin_path)
except error.CmdError:
raise error.TestFail("Drop in test %s failed" % dropin_path)
process.system(dropin_path)
except process.CmdError:
test.fail("Drop in test %s failed" % dropin_path)
......@@ -2,16 +2,15 @@ import logging
import re
import aexpect
from autotest.client.shared import error
from autotest.client import utils
from avocado.utils import crypto, process
from virttest import utils_net
from virttest import utils_misc
from virttest import remote
from virttest import error_context
@error.context_aware
@error_context.context_aware
def run(test, params, env):
"""
Test offload functions of ethernet device using ethtool
......@@ -70,7 +69,7 @@ def run(test, params, env):
"""
txt = "Set offload status for device "
txt += "'%s': %s" % (ethname, str(status))
error.context(txt, logging.info)
error_context.context(txt, logging.info)
cmd = "ethtool -K %s " % ethname
cmd += " ".join([o + ' ' + s for o, s in status.items()])
......@@ -91,17 +90,17 @@ def run(test, params, env):
return True
def ethtool_save_params(session):
error.context("Saving ethtool configuration", logging.info)
error_context.context("Saving ethtool configuration", logging.info)
return ethtool_get(session)
def ethtool_restore_params(session, status):
error.context("Restoring ethtool configuration", logging.info)
error_context.context("Restoring ethtool configuration", logging.info)
ethtool_set(session, status)
def compare_md5sum(name):
txt = "Comparing md5sum of the files on guest and host"
error.context(txt, logging.info)
host_result = utils.hash_file(name, method="md5")
error_context.context(txt, logging.info)
host_result = crypto.hash_file(name, method="md5")
try:
o = session.cmd_output("md5sum %s" % name)
guest_result = re.findall("\w+", o)[0]
......@@ -125,7 +124,7 @@ def run(test, params, env):
(filename, params.get("filesize")))
failure = (False, "Failed to create file using dd, cmd: %s" % dd_cmd)
txt = "Creating file in source host, cmd: %s" % dd_cmd
error.context(txt, logging.info)
error_context.context(txt, logging.info)
ethname = utils_net.get_linux_ifname(session,
vm.get_mac_address(0))
tcpdump_cmd = "tcpdump -lep -i %s -s 0 tcp -vv port ssh" % ethname
......@@ -140,26 +139,27 @@ def run(test, params, env):
tcpdump_cmd += " and dst %s" % guest_ip
copy_files_func = vm.copy_files_to
try:
utils.system(dd_cmd)
except error.CmdError, e:
process.system(dd_cmd)
except process.CmdError, e:
return failure
# only capture the new tcp port after offload setup
original_tcp_ports = re.findall("tcp.*:(\d+).*%s" % guest_ip,
utils.system_output("/bin/netstat -nap"))
original_tcp_ports = re.findall(
"tcp.*:(\d+).*%s" % guest_ip,
process.system_output("/bin/netstat -nap"))
for i in original_tcp_ports:
tcpdump_cmd += " and not port %s" % i
txt = "Listening traffic using command: %s" % tcpdump_cmd
error.context(txt, logging.info)
error_context.context(txt, logging.info)
sess.sendline(tcpdump_cmd)
if not utils_misc.wait_for(
lambda: session.cmd_status("pgrep tcpdump") == 0, 30):
return (False, "Tcpdump process wasn't launched")
txt = "Transferring file %s from %s" % (filename, src)
error.context(txt, logging.info)
error_context.context(txt, logging.info)
try:
copy_files_func(filename, filename)
except remote.SCPError, e:
......@@ -194,7 +194,7 @@ def run(test, params, env):
if not s:
logging.error(o)
return False
error.context("Check if contained large frame", logging.info)
error_context.context("Check if contained large frame", logging.info)
# MTU: default IPv4 MTU is 1500 Bytes, ethernet header is 14 Bytes
return (status == "on") ^ (len([i for i in re.findall(
"length (\d*):", o) if int(i) > mtu]) == 0)
......@@ -208,26 +208,26 @@ def run(test, params, env):
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
error.context("Log into a guest.", logging.info)
error_context.context("Log into a guest.", logging.info)
login_timeout = int(params.get("login_timeout", 360))
session = vm.wait_for_login(timeout=login_timeout)
# Let's just error the test if we identify that there's no ethtool
# installed
error.context("Check whether ethtool installed in guest.")
error_context.context("Check whether ethtool installed in guest.")
session.cmd("ethtool -h")
mtu = 1514
pretest_status = {}
filename = "/tmp/ethtool.dd"
guest_ip = vm.get_address()
error.context("Try to get ethernet device name in guest.")
error_context.context("Try to get ethernet device name in guest.")
ethname = utils_net.get_linux_ifname(session, vm.get_mac_address(0))
supported_features = params.get("supported_features")
if supported_features:
supported_features = supported_features.split()
else:
raise error.TestError("No supported features set on the parameters")
test.error("No supported features set on the parameters")
test_matrix = {
# type:(callback, (dependence), (exclude)
......@@ -254,7 +254,7 @@ def run(test, params, env):
failed_tests.append(e_msg)
txt = "Run callback function %s" % callback.func_name
error.context(txt, logging.info)
error_context.context(txt, logging.info)
# Some older kernel versions split packets by GSO
# before tcpdump can capture the big packet, which
......@@ -270,14 +270,14 @@ def run(test, params, env):
logging.error(e_msg)
failed_tests.append(e_msg)
txt = "Run callback function %s" % callback.func_name
error.context(txt, logging.info)
error_context.context(txt, logging.info)
if not callback(status="off"):
e_msg = "Callback failed after disabling %s" % f_type
logging.error(e_msg)
failed_tests.append(e_msg)
if failed_tests:
raise error.TestFail("Failed tests: %s" % failed_tests)
test.fail("Failed tests: %s" % failed_tests)
finally:
try:
......
from autotest.client.shared import error
def run(test, params, env):
"""
Raise TestFail exception (should trigger FAIL in simple harness).
"""
raise error.TestFail("Fail test is failing!")
test.fail("Fail test is failing!")
import logging
from autotest.client.shared import error
from virttest import error_context
@error.context_aware
@error_context.context_aware
def run(test, params, env):
"""
Fileup disk test:
......@@ -30,7 +30,8 @@ def run(test, params, env):
number = 0
try:
error.context("Start filling the disk in %s" % fill_dir, logging.info)
error_context.context("Start filling the disk in %s" % fill_dir,
logging.info)
cmd = params.get("fillup_cmd")
while not filled:
# As we want to test the backing file, so bypass the cache
......@@ -41,10 +42,10 @@ def run(test, params, env):
logging.debug("Successfully filled up the disk")
filled = True
elif s != 0:
raise error.TestFail("Command dd failed to execute: %s" % o)
test.fail("Command dd failed to execute: %s" % o)
number += 1
finally:
error.context("Cleaning the temporary files...", logging.info)
error_context.context("Cleaning the temporary files...", logging.info)
try:
clean_cmd = params.get("clean_cmd") % fill_dir
session2.cmd(clean_cmd, ignore_all_errors=True)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册