diff --git a/qemu/tests/time_manage.py b/qemu/tests/time_manage.py index a6e04f6558593962f485fab92eeaed4c11ac3700..67e2c7c4f8cecd1827631485ff2fe3248b82e55e 100644 --- a/qemu/tests/time_manage.py +++ b/qemu/tests/time_manage.py @@ -2,14 +2,12 @@ import logging import time import aexpect - -from autotest.client.shared import error - from virttest import utils_test from virttest import env_process +from virttest import error_context -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Time manage test: @@ -78,7 +76,8 @@ def run(test, params, env): logging.info("Guest #%d booted up successfully", num) # Check whether all previous shell sessions are responsive - error.context("checking responsiveness of the booted guest") + error_context.context("checking responsiveness of the booted" + " guest") for se in sessions: se.cmd(params["alive_test_cmd"]) num += 1 @@ -93,7 +92,7 @@ def run(test, params, env): se = vm.reboot(se, timeout=timeout) # Remember the current changed session sessions[vmid] = se - error.context("checking responsiveness of guest") + error_context.context("checking responsiveness of guest") se.cmd(params["alive_test_cmd"]) if itr == 0: (ht0, gt0) = utils_test.get_time(se, time_command, diff --git a/qemu/tests/timedrift.py b/qemu/tests/timedrift.py index 88ec82e8e1b112d66d968cdd071c2847728d1a6c..106b4d4245075be95e130d9caf031a14635fdb14 100644 --- a/qemu/tests/timedrift.py +++ b/qemu/tests/timedrift.py @@ -3,11 +3,8 @@ import time import commands import aexpect - from virttest import utils_test -from autotest.client.shared import error - def run(test, params, env): """ @@ -199,7 +196,7 @@ def run(test, params, env): # Fail the test if necessary if abs(drift) > drift_threshold: - raise error.TestFail("Time drift too large: %.2f%%" % drift) + test.fail("Time drift too large: %.2f%%" % drift) if abs(drift_total) > drift_threshold_after_rest: - raise error.TestFail("Time drift too large after rest period: %.2f%%" - % drift_total) + test.fail("Time drift too large after rest period: %.2f%%" + % drift_total) diff --git a/qemu/tests/timedrift_adjust_time.py b/qemu/tests/timedrift_adjust_time.py index 3560735e7023c5293920897c0e2884b2408e4a21..5a3fa6778a3adca7bac6ba7d150e26bb441cfca1 100644 --- a/qemu/tests/timedrift_adjust_time.py +++ b/qemu/tests/timedrift_adjust_time.py @@ -2,11 +2,10 @@ import re import time import logging -from autotest.client.shared import error -from autotest.client.shared import utils - +from avocado.utils import process from virttest import env_process from virttest import test_setup +from virttest import error_context from generic.tests.guest_suspend import GuestSuspendBaseTest @@ -89,12 +88,12 @@ class TimedriftTest(object): timeout = int(self.params.get("execute_timeout", 360)) ret = session.cmd_output(cmd, timeout=timeout) else: - ret = utils.system_output(cmd) + ret = process.system_output(cmd, shell=True) target = session and "guest" or "host" logging.debug("(%s) Execute command('%s')" % (target, cmd)) return ret - @error.context_aware + @error_context.context_aware def sync_host_time(self): """ calibrate system time via ntp server, if session is not None, @@ -104,7 +103,7 @@ class TimedriftTest(object): :return: ntpdate command output; :rtype: str """ - error.context("Sync host time from ntp server", logging.info) + error_context.context("Sync host time from ntp server", logging.info) cmd = self.params["sync_host_time_cmd"] return self.execute(cmd, None) @@ -119,7 +118,8 @@ class TimedriftTest(object): guest_timestr = session.cmd_output( guest_epoch_time_cmd, timeout=120) - host_timestr = utils.system_output(host_epoch_time_cmd) + host_timestr = process.system_output(host_epoch_time_cmd, + shell=True) epoch_host, epoch_guest = map(lambda x: re.findall(regex, x)[0], [host_timestr, guest_timestr]) except IndexError: @@ -127,7 +127,7 @@ class TimedriftTest(object): "Guest Time: %s" % guest_timestr) return map(float, [epoch_host, epoch_guest]) - @error.context_aware + @error_context.context_aware def verify_clock_source(self, session): """ Verify guest used expected clocksource; @@ -135,18 +135,18 @@ class TimedriftTest(object): :param session: ShellSession object; :raise: error.TestFail Exception """ - error.context("Verify guest clock resource", logging.info) + error_context.context("Verify guest clock resource", logging.info) read_clock_source_cmd = self.params["read_clock_source_cmd"] real_clock_source = session.cmd_output(read_clock_source_cmd) expect_clock_source = self.params["clock_source"] if expect_clock_source not in real_clock_source: - raise error.TestFail("Expect clock source: " + - expect_clock_source + - "Real clock source: %s" % real_clock_source) + self.test.fail("Expect clock source: " + + expect_clock_source + + "Real clock source: %s" % real_clock_source) - @error.context_aware + @error_context.context_aware def cleanup(self): - error.context("Cleanup after test", logging.info) + error_context.context("Cleanup after test", logging.info) self.close_sessions() self.cleanup_private_network() @@ -160,7 +160,7 @@ class BackwardtimeTest(TimedriftTest): def __init__(self, test, params, env): super(BackwardtimeTest, self).__init__(test, params, env) - @error.context_aware + @error_context.context_aware def set_time(self, nsec, session=None): """ Change host/guest time, if session is not None, backword guest time, @@ -171,11 +171,11 @@ class BackwardtimeTest(TimedriftTest): """ target = session and "guest" or "host" step = "Forward %s time %s seconds" % (target, nsec) - error.context(step, logging.info) + error_context.context(step, logging.info) cmd = self.params.get("set_%s_time_cmd" % target) return self.execute(cmd, session) - @error.context_aware + @error_context.context_aware def check_drift_after_adjust_time(self, session): """ Verify host/guest system/hardware clock drift after change @@ -187,7 +187,7 @@ class BackwardtimeTest(TimedriftTest): target = self.params.get("set_host_time_cmd") and "host" or "guest" step_info = "Check time difference between host and guest" step_info += " after forward %s time" % target - error.context(step_info, logging.info) + error_context.context(step_info, logging.info) tolerance = float(self.params["tolerance"]) timeout = float(self.params.get("workaround_timeout", 1.0)) expect_difference = float(self.params["time_difference"]) @@ -202,9 +202,9 @@ class BackwardtimeTest(TimedriftTest): err_msg = "Unexcept time difference between host and guest after" err_msg += " testing.(actual difference: %s)" % real_difference err_msg += " except difference: %s)" % expect_difference - raise error.TestFail(err_msg) + self.test.fail(err_msg) - @error.context_aware + @error_context.context_aware def check_dirft_before_adjust_time(self, session): """ Verify host/guest system/hardware clock drift before change @@ -216,7 +216,7 @@ class BackwardtimeTest(TimedriftTest): target = self.params.get("set_host_time_cmd") and "host" or "guest" step_info = "Check time difference between host and guest" step_info += " before forward %s time" % target - error.context(step_info, logging.info) + error_context.context(step_info, logging.info) tolerance = float(self.params.get("tolerance", 6)) host_epoch_time, guest_epoch_time = self.get_epoch_seconds(session) real_difference = abs(host_epoch_time - guest_epoch_time) @@ -225,7 +225,7 @@ class BackwardtimeTest(TimedriftTest): logging.info("Guest epoch time: %s" % guest_epoch_time) err_msg = "Unexcept time difference (%s) " % real_difference err_msg += " between host and guest before testing." - raise error.TestFail(err_msg) + self.test.fail(err_msg) def pre_test(self): """ @@ -264,7 +264,7 @@ class BackwardtimeTest(TimedriftTest): self.cleanup() -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Time drift after change host/guest sysclock test: @@ -291,7 +291,7 @@ def run(test, params, env): def __init__(self, test, params, env): super(TestReboot, self).__init__(test, params, env) - @error.context_aware + @error_context.context_aware def reboot(self): vm = self.get_vm() session = self.get_session(vm) @@ -300,7 +300,7 @@ def run(test, params, env): self.set_time(seconds_to_forward) if self.params.get("set_guest_time_cmd"): self.set_time(seconds_to_forward, session=session) - error.context("Reboot guest", logging.info) + error_context.context("Reboot guest", logging.info) vm.reboot(session=session, method="shell") def run(self): @@ -318,18 +318,18 @@ def run(test, params, env): def __init__(self, test, params, env): super(TestPauseresume, self).__init__(test, params, env) - @error.context_aware + @error_context.context_aware def pause_resume(self): vm = self.get_vm() sleep_seconds = float(params.get("sleep_seconds", 1800)) - error.context("Pause guest %s seconds" % sleep_seconds, - logging.info) + error_context.context("Pause guest %s seconds" % sleep_seconds, + logging.info) vm.pause() seconds_to_forward = int(self.params.get("seconds_to_forward", 0)) if seconds_to_forward: self.set_time(seconds_to_forward) time.sleep(sleep_seconds) - error.context("Resume guest", logging.info) + error_context.context("Resume guest", logging.info) vm.resume() def run(self): @@ -363,11 +363,11 @@ def run(test, params, env): self.open_sessions.append(session) return session - @error.context_aware + @error_context.context_aware def action_during_suspend(self, **args): sleep_seconds = float(self.params.get("sleep_seconds", 1800)) - error.context("Sleep %s seconds before resume" % sleep_seconds, - logging.info) + error_context.context("Sleep %s seconds before resume" % + sleep_seconds, logging.info) seconds_to_forward = int(self.params.get("seconds_to_forward", 0)) if seconds_to_forward: self.set_time(seconds_to_forward) @@ -375,7 +375,7 @@ def run(test, params, env): def suspend_resume(self): vm = self.get_vm() - GuestSuspendBaseTest.__init__(self, params, vm) + GuestSuspendBaseTest.__init__(self, test, params, vm) if self.params.get("guest_suspend_type") == "mem": self.guest_suspend_mem(self.params) else: diff --git a/qemu/tests/timedrift_check_when_crash.py b/qemu/tests/timedrift_check_when_crash.py index 6e8b2c68a4f41ea1df750ca9bc42dc730c1ef45f..0fef9cb579563ef72a04907080d29957b5b9b5ed 100644 --- a/qemu/tests/timedrift_check_when_crash.py +++ b/qemu/tests/timedrift_check_when_crash.py @@ -1,13 +1,14 @@ import logging import time import re -from autotest.client.shared import error -from autotest.client.shared import utils + +from avocado.utils import process from virttest.env_process import preprocess from virttest.virt_vm import VMDeadKernelCrashError +from virttest import error_context -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Time clock offset check when guest crash/bsod test: @@ -29,10 +30,10 @@ def run(test, params, env): sleep_time = float(params.get("sleep_time", 1800)) deviation = float(params.get("deviation", 5)) - error.context("sync host time with ntp server", logging.info) - utils.system("ntpdate %s" % ntp_server) + error_context.context("sync host time with ntp server", logging.info) + process.system("ntpdate %s" % ntp_server) - error.context("start guest", logging.info) + error_context.context("start guest", logging.info) params["start_vm"] = "yes" preprocess(test, params, env) vm = env.get_vm(params["main_vm"]) @@ -40,10 +41,10 @@ def run(test, params, env): timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) - error.context("sync time in guest", logging.info) + error_context.context("sync time in guest", logging.info) session.cmd(ntp_cmd) - error.context("inject nmi interrupt in vm", logging.info) + error_context.context("inject nmi interrupt in vm", logging.info) target, cmd = re.split("\s*:\s*", nmi_cmd) if target == "monitor": vm.monitor.send_args_cmd(cmd) @@ -54,9 +55,9 @@ def run(test, params, env): except Exception: pass else: - raise error.TestFail("Guest OS still alive ...") + test.fail("Guest OS still alive ...") - error.context("sleep %s seconds" % sleep_time, logging.info) + error_context.context("sleep %s seconds" % sleep_time, logging.info) time.sleep(sleep_time) # Autotest parses serial output and could raise VMDeadKernelCrash # we generated using sysrq. Ignore one "BUG:" line @@ -66,10 +67,10 @@ def run(test, params, env): details = str(details) if (re.findall(r"Trigger a crash\s.*BUG:", details, re.M) and details.count("BUG:") != 1): - raise error.TestFail("Got multiple kernel crashes. Please " - "note that one of them was " - "intentionally generated by sysrq in " - "this test.\n%s" % details) + test.fail("Got multiple kernel crashes. Please " + "note that one of them was " + "intentionally generated by sysrq in " + "this test.\n%s" % details) end_time = time.time() + timeout while time.time() < end_time: try: @@ -78,19 +79,19 @@ def run(test, params, env): details = str(details) if (re.findall(r"Trigger a crash\s.*BUG:", details, re.M) and details.count("BUG:") != 1): - raise error.TestFail("Got multiple kernel crashes. " - "Please note that one of them was " - "intentionally generated by sysrq " - "in this test.\n%s" % details) + test.fail("Got multiple kernel crashes. " + "Please note that one of them was " + "intentionally generated by sysrq " + "in this test.\n%s" % details) else: break - error.context("check time offset via ntp", logging.info) + error_context.context("check time offset via ntp", logging.info) output = session.cmd_output(ntp_query_cmd) try: offset = re.findall(r"[+-](\d+\.\d+)", output, re.M)[-1] except IndexError: offset = 0.0 if float(offset) > deviation: - raise error.TestFail("Unacceptable offset '%s', " % offset + - "deviation '%s'" % deviation) + test.fail("Unacceptable offset '%s', " % offset + + "deviation '%s'" % deviation) diff --git a/qemu/tests/timedrift_check_with_syscall.py b/qemu/tests/timedrift_check_with_syscall.py index 6f779216c3ebfc5c4253f62c234f88379e056b92..7fde6cb9ca8f64ca2478912d96673a156352b7c8 100644 --- a/qemu/tests/timedrift_check_with_syscall.py +++ b/qemu/tests/timedrift_check_with_syscall.py @@ -2,13 +2,11 @@ import os import logging import aexpect - -from autotest.client.shared import error - from virttest import data_dir +from virttest import error_context -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Time clock offset check test (only for Linux guest): @@ -34,19 +32,19 @@ def run(test, params, env): src_dir = os.path.join(data_dir.get_deps_dir(), 'timedrift') src_file = os.path.join(src_dir, "clktest.c") dst_file = os.path.join(tmp_dir, "clktest.c") - error.context("transfer '%s' to guest('%s')" % (src_file, dst_file), - logging.info) + error_context.context("transfer '%s' to guest('%s')" % + (src_file, dst_file), logging.info) vm.copy_files_to(src_file, tmp_dir, timeout=120) build_cmd = params.get("build_cmd", "gcc -lrt clktest.c -o clktest") - error.context("build binary file 'clktest'", logging.info) + error_context.context("build binary file 'clktest'", logging.info) session.cmd(build_cmd) - error.context("check clock offset via `clktest`", logging.info) + error_context.context("check clock offset via `clktest`", logging.info) logging.info("set check timeout to %s seconds", check_timeout) try: session.cmd_output(test_cmd, timeout=check_timeout) except aexpect.ShellTimeoutError, msg: if 'Interval is' in msg.output: - raise error.TestFail(msg.output) + test.fail(msg.output) pass diff --git a/qemu/tests/timedrift_monotonicity.py b/qemu/tests/timedrift_monotonicity.py index 4e447b56728dd49d238d0187adb74636d5335739..46c347e07983785a5a6375ea47e1d7f197455a70 100644 --- a/qemu/tests/timedrift_monotonicity.py +++ b/qemu/tests/timedrift_monotonicity.py @@ -4,10 +4,8 @@ import time import re import shutil -from autotest.client.shared import error -from autotest.client.shared import utils - from virttest import utils_test +from virttest import utils_misc def run(test, params, env): @@ -66,7 +64,7 @@ def run(test, params, env): try: # take time logging.info("Start take guest time") - bg = utils.InterruptedThread(get_time, (cmd, test_time, session1)) + bg = utils_misc.InterruptedThread(get_time, (cmd, test_time, session1)) bg.start() # migration @@ -77,7 +75,7 @@ def run(test, params, env): logging.info("Logging in after migration...") session2 = vm.wait_for_login(timeout=timeout) if not session2: - raise error.TestFail("Could not log in after migration") + test.fail("Could not log in after migration") logging.info("Logged in after migration") # linger a while @@ -92,8 +90,8 @@ def run(test, params, env): for line in myfile: if "time went backwards" in line: myfile.close() - raise error.TestFail("Failed Time Monotonicity testing, " - "Please check log %s" % host_path) + test.fail("Failed Time Monotonicity testing, " + "Please check log %s" % host_path) finally: session1.close() # remove flags add for this test. diff --git a/qemu/tests/timedrift_no_net.py b/qemu/tests/timedrift_no_net.py index 25ac0ff7663b99933ee9f767e967bff3f5e97b6f..984aacbb4f65d1157718ecb62e2dd479c6e7562e 100644 --- a/qemu/tests/timedrift_no_net.py +++ b/qemu/tests/timedrift_no_net.py @@ -1,27 +1,27 @@ import logging import time -from autotest.client.shared import error -from autotest.client import utils - +from avocado.utils import path, process from virttest import utils_test +from virttest import error_context from generic.tests.guest_suspend import GuestSuspendBaseTest class GuestSuspendSerialConsole(GuestSuspendBaseTest): - def __init__(self, params, vm, session): - super(GuestSuspendSerialConsole, self).__init__(params, vm) + def __init__(self, test, params, vm, session): + super(GuestSuspendSerialConsole, self).__init__(test, params, vm) def _get_session(self): self.vm.verify_alive() session = self.vm.wait_for_serial_login(timeout=self.login_timeout) return session - @error.context_aware + @error_context.context_aware def action_during_suspend(self, **args): - error.context("Sleep a while before resuming guest", logging.info) + error_context.context("Sleep a while before resuming guest", + logging.info) time.sleep(float(self.params.get("wait_timeout", "1800"))) if self.os_type == "windows": @@ -31,31 +31,31 @@ class GuestSuspendSerialConsole(GuestSuspendBaseTest): time.sleep(50) -def subw_guest_suspend(params, vm, session): - gs = GuestSuspendSerialConsole(params, vm, session) +def subw_guest_suspend(test, params, vm, session): + gs = GuestSuspendSerialConsole(test, params, vm, session) suspend_type = params.get("guest_suspend_type") if suspend_type == gs.SUSPEND_TYPE_MEM: - error.context("Suspend vm to mem", logging.info) + error_context.context("Suspend vm to mem", logging.info) gs.guest_suspend_mem(params) elif suspend_type == gs.SUSPEND_TYPE_DISK: - error.context("Suspend vm to disk", logging.info) + error_context.context("Suspend vm to disk", logging.info) gs.guest_suspend_disk(params) else: - raise error.TestError("Unknown guest suspend type, Check your" - " 'guest_suspend_type' config.") + test.error("Unknown guest suspend type, Check your" + " 'guest_suspend_type' config.") -def subw_guest_pause_resume(params, vm, session): +def subw_guest_pause_resume(test, params, vm, session): vm.monitor.cmd("stop") if not vm.monitor.verify_status("paused"): - raise error.TestError("VM is not paused Current status: %s" % - vm.monitor.get_status()) + test.error("VM is not paused Current status: %s" % + vm.monitor.get_status()) time.sleep(float(params.get("wait_timeout", "1800"))) vm.monitor.cmd("cont") if not vm.monitor.verify_status("running"): - raise error.TestError("VM is not running. Current status: %s" % - vm.monitor.get_status()) + test.error("VM is not running. Current status: %s" % + vm.monitor.get_status()) def time_diff(host_guest_time_before, @@ -77,7 +77,7 @@ def time_diff(host_guest_time_before, return before_diff - after_diff -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Test suspend commands in qemu guest agent. @@ -108,26 +108,27 @@ def run(test, params, env): vm_name = params.get("vms") vm = env.get_vm(vm_name) - error.context("Check if ntp utils are host in system.", logging.info) + error_context.context("Check if ntp utils are host in system.", + logging.info) try: - utils.find_command("ntpdate") - except ValueError: - error.context("Install ntp utils `%s`." % (ntputil_install), - logging.info) - utils.run(ntputil_install) - error.context("Sync host machine with clock server %s" % (clock_server), - logging.info) - utils.run("ntpdate %s" % (clock_server)) - error.context("Check clock source on guest VM", logging.info) + path.find_command("ntpdate") + except path.CmdNotFoundError: + error_context.context("Install ntp utils `%s`." % (ntputil_install), + logging.info) + process.run(ntputil_install, shell=True) + error_context.context("Sync host machine with clock server %s" % + (clock_server), logging.info) + process.run("ntpdate %s" % (clock_server)) + error_context.context("Check clock source on guest VM", logging.info) session = vm.wait_for_serial_login(timeout=login_timeout) out = session.cmd_output("cat /sys/devices/system/clocksource/" "clocksource0/current_clocksource") if guest_clock_source not in out: - raise error.TestFail("Clock source %s missing in guest clock " - "sources %s." % (guest_clock_source, out)) + test.fail("Clock source %s missing in guest clock " + "sources %s." % (guest_clock_source, out)) - error.context("Get clock from host and guest VM using `date`", - logging.info) + error_context.context("Get clock from host and guest VM using `date`", + logging.info) before_date = utils_test.get_time(session, date_time_command, date_time_filter_re, @@ -135,8 +136,8 @@ def run(test, params, env): logging.debug("date: host time=%ss guest time=%ss", *before_date) - error.context("Get clock from host and guest VM using `hwclock`", - logging.info) + error_context.context("Get clock from host and guest VM using `hwclock`", + logging.info) before_hwclock = utils_test.get_time(session, hwclock_time_command, hwclock_time_filter_re, @@ -149,12 +150,12 @@ def run(test, params, env): if sub_work in globals(): # Try to find sub work function. globals()[sub_work](params, vm, session) else: - raise error.TestNAError("Unable to found subwork %s in %s test file." % - (sub_work, __file__)) + test.cancel("Unable to found subwork %s in %s test file." % + (sub_work, __file__)) session = vm.wait_for_serial_login(timeout=login_timeout) - error.context("Get clock from host and guest VM using `date`", - logging.info) + error_context.context("Get clock from host and guest VM using `date`", + logging.info) after_date = utils_test.get_time(session, date_time_command, date_time_filter_re, @@ -162,8 +163,8 @@ def run(test, params, env): logging.debug("date: host time=%ss guest time=%ss", *after_date) - error.context("Get clock from host and guest VM using `hwclock`", - logging.info) + error_context.context("Get clock from host and guest VM using `hwclock`", + logging.info) after_hwclock = utils_test.get_time(session, hwclock_time_command, hwclock_time_filter_re, @@ -175,25 +176,25 @@ def run(test, params, env): date_diff = time_diff(before_date, after_date) hwclock_diff = time_diff(before_hwclock, after_hwclock) if date_diff > tolerance and hwclock_diff > tolerance: - raise error.TestFail("hwclock %ss and date %ss difference is " - "'guest_diff_time != host_diff_time'" - " out of tolerance %ss" % (hwclock_diff, - date_diff, - tolerance)) + test.fail("hwclock %ss and date %ss difference is " + "'guest_diff_time != host_diff_time'" + " out of tolerance %ss" % (hwclock_diff, + date_diff, + tolerance)) elif date_diff > tolerance: - raise error.TestFail("date %ss difference is " - "'guest_diff_time != host_diff_time'" - " out of tolerance %ss" % (date_diff, - tolerance)) + test.fail("date %ss difference is " + "'guest_diff_time != host_diff_time'" + " out of tolerance %ss" % (date_diff, + tolerance)) elif hwclock_diff > tolerance: - raise error.TestFail("hwclock %ss difference is " - "'guest_diff_time != host_diff_time'" - " out of tolerance %ss" % (hwclock_diff, - tolerance)) + test.fail("hwclock %ss difference is " + "'guest_diff_time != host_diff_time'" + " out of tolerance %ss" % (hwclock_diff, + tolerance)) elif test_type == "guest_pause_resume": date_diff = time_diff(before_date, after_date) if date_diff > tolerance: - raise error.TestFail("date %ss difference is" - "'guest_time_after-guest_time_before'" - " out of tolerance %ss" % (date_diff, - tolerance)) + test.fail("date %ss difference is" + "'guest_time_after-guest_time_before'" + " out of tolerance %ss" % (date_diff, + tolerance)) diff --git a/qemu/tests/timedrift_no_net_win.py b/qemu/tests/timedrift_no_net_win.py index 694732c30b56ff9a873ede7d1a920bab0e32484c..2950131efc7be6766df3dfc150fcaba0420b490d 100644 --- a/qemu/tests/timedrift_no_net_win.py +++ b/qemu/tests/timedrift_no_net_win.py @@ -1,22 +1,22 @@ import logging import time -from autotest.client.shared import error -from autotest.client import utils - +from avocado.utils import path, process from virttest import utils_test +from virttest import error_context from generic.tests.guest_suspend import GuestSuspendBaseTest class GuestSuspendSerialConsole(GuestSuspendBaseTest): - def __init__(self, params, vm, session): - super(GuestSuspendSerialConsole, self).__init__(params, vm) + def __init__(self, test, params, vm, session): + super(GuestSuspendSerialConsole, self).__init__(test, params, vm) - @error.context_aware + @error_context.context_aware def action_during_suspend(self, **args): - error.context("Sleep a while before resuming guest", logging.info) + error_context.context("Sleep a while before resuming guest", + logging.info) time.sleep(float(self.params.get("wait_timeout", "1800"))) if self.os_type == "windows": @@ -26,31 +26,31 @@ class GuestSuspendSerialConsole(GuestSuspendBaseTest): time.sleep(50) -def subw_guest_suspend(params, vm, session): - gs = GuestSuspendSerialConsole(params, vm, session) +def subw_guest_suspend(test, params, vm, session): + gs = GuestSuspendSerialConsole(test, params, vm, session) suspend_type = params.get("guest_suspend_type") if suspend_type == gs.SUSPEND_TYPE_MEM: - error.context("Suspend vm to mem", logging.info) + error_context.context("Suspend vm to mem", logging.info) gs.guest_suspend_mem(params) elif suspend_type == gs.SUSPEND_TYPE_DISK: - error.context("Suspend vm to disk", logging.info) + error_context.context("Suspend vm to disk", logging.info) gs.guest_suspend_disk(params) else: - raise error.TestError("Unknown guest suspend type, Check your" - " 'guest_suspend_type' config.") + test.error("Unknown guest suspend type, Check your" + " 'guest_suspend_type' config.") -def subw_guest_pause_resume(params, vm, session): +def subw_guest_pause_resume(test, params, vm, session): vm.monitor.cmd("stop") if not vm.monitor.verify_status("paused"): - raise error.TestError("VM is not paused Current status: %s" % - vm.monitor.get_status()) + test.error("VM is not paused Current status: %s" % + vm.monitor.get_status()) time.sleep(float(params.get("wait_timeout", "1800"))) vm.monitor.cmd("cont") if not vm.monitor.verify_status("running"): - raise error.TestError("VM is not running. Current status: %s" % - vm.monitor.get_status()) + test.error("VM is not running. Current status: %s" % + vm.monitor.get_status()) def time_diff(host_guest_time_before, @@ -91,7 +91,7 @@ def time_diff_host_guest(host_guest_time_before, return (host_diff, guest_diff) -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Test suspend commands in qemu guest agent. @@ -117,20 +117,21 @@ def run(test, params, env): vm_name = params.get("vms") vm = env.get_vm(vm_name) - error.context("Check if ntp utils are host in system.", logging.info) + error_context.context("Check if ntp utils are host in system.", + logging.info) try: - utils.find_command("ntpdate") - except ValueError: - error.context("Install ntp utils `%s`." % (ntputil_install), - logging.info) - utils.run(ntputil_install) - error.context("Sync host machine with clock server %s" % (clock_server), - logging.info) - utils.run("ntpdate %s" % (clock_server)) + path.find_command("ntpdate") + except path.CmdNotFoundError: + error_context.context("Install ntp utils `%s`." % (ntputil_install), + logging.info) + process.run(ntputil_install, shell=True) + error_context.context("Sync host machine with clock server %s" % + (clock_server), logging.info) + process.run("ntpdate %s" % (clock_server)) session = vm.wait_for_login(timeout=login_timeout) - error.context("Get clock from host and guest VM using `date`", - logging.info) + error_context.context("Get clock from host and guest VM using `date`", + logging.info) before_date = utils_test.get_time(session, date_time_command, @@ -144,13 +145,13 @@ def run(test, params, env): if sub_work in globals(): # Try to find sub work function. globals()[sub_work](params, vm, session) else: - raise error.TestNAError("Unable to found subwork %s in %s test file." % - (sub_work, __file__)) + test.cancel("Unable to found subwork %s in %s test file." % + (sub_work, __file__)) vm = env.get_vm(vm_name) session = vm.wait_for_login(timeout=login_timeout) - error.context("Get clock from host and guest VM using `date`", - logging.info) + error_context.context("Get clock from host and guest VM using `date`", + logging.info) after_date = utils_test.get_time(session, date_time_command, date_time_filter_re, @@ -161,14 +162,14 @@ def run(test, params, env): if test_type == 'guest_suspend': date_diff = time_diff(before_date, after_date) if date_diff > tolerance: - raise error.TestFail("date %ss difference is" - "'guest_diff_time != host_diff_time'" - " out of tolerance %ss" % (date_diff[1], - tolerance)) + test.fail("date %ss difference is" + "'guest_diff_time != host_diff_time'" + " out of tolerance %ss" % (date_diff[1], + tolerance)) elif test_type == "guest_pause_resume": date_diff = time_diff_host_guest(before_date, after_date) if date_diff[1] > tolerance: - raise error.TestFail("date %ss difference is " - "'guest_time_after-guest_time_before'" - " out of tolerance %ss" % (date_diff[1], - tolerance)) + test.fail("date %ss difference is " + "'guest_time_after-guest_time_before'" + " out of tolerance %ss" % (date_diff[1], + tolerance)) diff --git a/qemu/tests/timedrift_with_cpu_offline.py b/qemu/tests/timedrift_with_cpu_offline.py index 305a675e8c4eb0551484708bb9b36103e71ee6d6..6d343ff6e748d65e0a75290d6f014dddb743bb8d 100644 --- a/qemu/tests/timedrift_with_cpu_offline.py +++ b/qemu/tests/timedrift_with_cpu_offline.py @@ -1,12 +1,11 @@ import logging import time -from autotest.client.shared import error - from virttest import utils_test +from virttest import error_context -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Time drift test with vm's cpu offline/online: @@ -52,29 +51,29 @@ def run(test, params, env): try: # Get time before set cpu offline # (ht stands for host time, gt stands for guest time) - error.context("get time before set cpu offline") + error_context.context("get time before set cpu offline") (ht0, gt0) = utils_test.get_time(session, time_command, time_filter_re, time_format) # Check cpu number - error.context("check guest cpu number") + error_context.context("check guest cpu number") smp = int(params.get("smp")) if smp < 2: - raise error.TestError("The guest only has %d vcpu," - "unsupport cpu offline" % smp) + test.error("The guest only has %d vcpu," + "unsupport cpu offline" % smp) # Set cpu offline - error.context("set cpu offline ") + error_context.context("set cpu offline ") offline_cpu_cmd = params.get("offline_cpu_cmd") s, o = session.cmd_status_output(offline_cpu_cmd) if s != 0: logging.error(o) - raise error.TestError("Failed set guest cpu offline") + test.error("Failed set guest cpu offline") # Sleep for a while after set cpu offline time.sleep(stop_time) # Get time after set cpu offline - error.context("get time after set cpu offline") + error_context.context("get time after set cpu offline") (ht1, gt1) = utils_test.get_time(session, time_command, time_filter_re, time_format) # Report results @@ -85,17 +84,17 @@ def run(test, params, env): logging.info("Guest duration: %.2f", guest_delta) logging.info("Drift: %.2f%%", drift) if abs(drift) > drift_threshold: - raise error.TestFail("Time drift too large: %.2f%%" % drift) + test.fail("Time drift too large: %.2f%%" % drift) # Set cpu online again - error.context("set cpu online") + error_context.context("set cpu online") online_cpu_cmd = params.get("online_cpu_cmd") s, o = session.cmd_status_output(online_cpu_cmd) if s != 0: logging.error(o) - raise error.TestError("Failed set guest cpu online") + test.error("Failed set guest cpu online") - error.context("get time after set cpu online") + error_context.context("get time after set cpu online") start_time = time.time() while (time.time() - start_time) < test_duration: # Get time delta after set cpu online @@ -111,7 +110,7 @@ def run(test, params, env): logging.info("Drift: %.2f%%", drift) time.sleep(interval_gettime) if abs(drift) > drift_threshold: - raise error.TestFail("Time drift too large: %.2f%%" % drift) + test.fail("Time drift too large: %.2f%%" % drift) finally: session.close() # remove flags add for this test. diff --git a/qemu/tests/timedrift_with_migration.py b/qemu/tests/timedrift_with_migration.py index 45a339bde61252495659bd99ca2697834630de21..a45b5464279b77005f0a32579f44244940e2fa8e 100644 --- a/qemu/tests/timedrift_with_migration.py +++ b/qemu/tests/timedrift_with_migration.py @@ -1,7 +1,5 @@ import logging -from autotest.client.shared import error - from virttest import utils_test @@ -78,8 +76,8 @@ def run(test, params, env): (i + 1), drift) # Fail if necessary if drift > drift_threshold_single: - raise error.TestFail("Time drift too large at iteration %d: " - "%.2f seconds" % (i + 1, drift)) + test.fail("Time drift too large at iteration %d: " + "%.2f seconds" % (i + 1, drift)) # Get final time (ht1, gt1) = utils_test.get_time(session, time_command, @@ -107,5 +105,5 @@ def run(test, params, env): # Fail if necessary if drift > drift_threshold: - raise error.TestFail("Time drift too large after %d migrations: " - "%.2f seconds" % (migration_iterations, drift)) + test.fail("Time drift too large after %d migrations: " + "%.2f seconds" % (migration_iterations, drift)) diff --git a/qemu/tests/timedrift_with_reboot.py b/qemu/tests/timedrift_with_reboot.py index 7231bd39c35a2e33afd79ffa9231a0e4ad42bdaa..a8b163302bb7edfcee9765c40fa6aa1ed77328ee 100644 --- a/qemu/tests/timedrift_with_reboot.py +++ b/qemu/tests/timedrift_with_reboot.py @@ -1,7 +1,5 @@ import logging -from autotest.client.shared import error - from virttest import utils_test @@ -73,8 +71,8 @@ def run(test, params, env): (i + 1), drift) # Fail if necessary if drift > drift_threshold_single: - raise error.TestFail("Time drift too large at iteration %d: " - "%.2f seconds" % (i + 1, drift)) + test.fail("Time drift too large at iteration %d: " + "%.2f seconds" % (i + 1, drift)) # Get final time (ht1, gt1) = utils_test.get_time(session, time_command, @@ -102,5 +100,5 @@ def run(test, params, env): # Fail if necessary if drift > drift_threshold: - raise error.TestFail("Time drift too large after %d reboots: " - "%.2f seconds" % (reboot_iterations, drift)) + test.fail("Time drift too large after %d reboots: " + "%.2f seconds" % (reboot_iterations, drift)) diff --git a/qemu/tests/timedrift_with_stop.py b/qemu/tests/timedrift_with_stop.py index 61dea3c3926fac682e4bcacf33184e08531762ee..de51b3fb5e769a026fbaee1944c441231a1ab08f 100644 --- a/qemu/tests/timedrift_with_stop.py +++ b/qemu/tests/timedrift_with_stop.py @@ -3,8 +3,6 @@ import time import os import signal -from autotest.client.shared import error - from virttest import utils_test @@ -105,8 +103,8 @@ def run(test, params, env): (i + 1), drift) # Fail if necessary if drift > drift_threshold_single: - raise error.TestFail("Time drift too large at iteration %d: " - "%.2f seconds" % (i + 1, drift)) + test.fail("Time drift too large at iteration %d: " + "%.2f seconds" % (i + 1, drift)) # Get final time (ht1, gt1) = utils_test.get_time(session, time_command, @@ -140,5 +138,5 @@ def run(test, params, env): # Fail if necessary if drift > drift_threshold: - raise error.TestFail("Time drift too large after %d stops: " - "%.2f seconds" % (stop_iterations, drift)) + test.fail("Time drift too large after %d stops: " + "%.2f seconds" % (stop_iterations, drift)) diff --git a/qemu/tests/timerdevice_boot.py b/qemu/tests/timerdevice_boot.py index 7943cd9296653f43320dd20ef06637a4237aa6d8..3c68b53479f9718aa61df4e7b7fc8938898d174f 100644 --- a/qemu/tests/timerdevice_boot.py +++ b/qemu/tests/timerdevice_boot.py @@ -2,18 +2,17 @@ import logging import re import time -from autotest.client.shared import error -from autotest.client import utils - +from avocado.utils import process from virttest import data_dir from virttest import storage from virttest import utils_disk from virttest import utils_test from virttest import env_process from virttest import funcatexit +from virttest import error_context -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Timer device boot guest: @@ -35,25 +34,26 @@ def run(test, params, env): :param env: Dictionary with the test environment. """ def verify_guest_clock_source(session, expected): - error.context("Check the current clocksource in guest", logging.info) + error_context.context("Check the current clocksource in guest", + logging.info) cmd = "cat /sys/devices/system/clocksource/" cmd += "clocksource0/current_clocksource" if expected not in session.cmd(cmd): - raise error.TestFail( - "Guest didn't use '%s' clocksource" % expected) + test.fail("Guest didn't use '%s' clocksource" % expected) - error.context("Sync the host system time with ntp server", logging.info) - utils.system("ntpdate clock.redhat.com") + error_context.context("Sync the host system time with ntp server", + logging.info) + process.system("ntpdate clock.redhat.com") timerdevice_host_load_cmd = params.get("timerdevice_host_load_cmd") if timerdevice_host_load_cmd: - error.context("Add some load on host", logging.info) - utils.system(timerdevice_host_load_cmd) + error_context.context("Add some load on host", logging.info) + process.system(timerdevice_host_load_cmd, shell=True) host_load_stop_cmd = params["timerdevice_host_load_stop_cmd"] - funcatexit.register(env, params["type"], utils.system, + funcatexit.register(env, params["type"], process.system, host_load_stop_cmd) - error.context("Boot a guest with kvm-clock", logging.info) + error_context.context("Boot a guest with kvm-clock", logging.info) vm = env.get_vm(params["main_vm"]) vm.verify_alive() @@ -66,11 +66,11 @@ def run(test, params, env): verify_guest_clock_source(session, timerdevice_clksource) except Exception: clksrc = timerdevice_clksource - error.context("Shutdown guest") + error_context.context("Shutdown guest") vm.destroy() env.unregister_vm(vm.name) - error.context("Update guest kernel cli to '%s'" % clksrc, - logging.info) + error_context.context("Update guest kernel cli to '%s'" % clksrc, + logging.info) image_filename = storage.get_image_filename(params, data_dir.get_data_dir()) grub_file = params.get("grub_file", "/boot/grub2/grub.cfg") @@ -85,9 +85,9 @@ def run(test, params, env): kernel_cfg = re.findall(kernel_cfg_pattern, kernel_cfg_original)[0] except IndexError, detail: - raise error.TestError("Couldn't find the kernel config, regex" - " pattern is '%s', detail: '%s'" % - (kernel_cfg_pattern, detail)) + test.error("Couldn't find the kernel config, regex" + " pattern is '%s', detail: '%s'" % + (kernel_cfg_pattern, detail)) if "clocksource=" in kernel_cfg: kernel_cfg_new = re.sub("clocksource=.*?\s", @@ -99,7 +99,7 @@ def run(test, params, env): disk_obj.replace_image_file_content(grub_file, kernel_cfg, kernel_cfg_new) - error.context("Boot the guest", logging.info) + error_context.context("Boot the guest", logging.info) vm_name = params["main_vm"] cpu_model_flags = params.get("cpu_model_flags") params["cpu_model_flags"] = cpu_model_flags + ",-kvmclock" @@ -108,15 +108,15 @@ def run(test, params, env): vm.verify_alive() session = vm.wait_for_login(timeout=timeout) - error.context("Check the current clocksource in guest", - logging.info) + error_context.context("Check the current clocksource in guest", + logging.info) verify_guest_clock_source(session, clksrc) - error.context("Kill all ntp related processes") + error_context.context("Kill all ntp related processes") session.cmd("pkill ntp; true") if params.get("timerdevice_file_operation") == "yes": - error.context("Do some file operation on guest", logging.info) + error_context.context("Do some file operation on guest", logging.info) session.cmd("dd if=/dev/zero of=/tmp/timer-test-file bs=1M count=100") return @@ -128,53 +128,55 @@ def run(test, params, env): time_format = params["time_format"] timerdevice_drift_threshold = params.get("timerdevice_drift_threshold", 3) - error.context("Check the system time on guest and host", logging.info) + error_context.context("Check the system time on guest and host", + logging.info) (host_time, guest_time) = utils_test.get_time(session, time_command, time_filter_re, time_format) drift = abs(float(host_time) - float(guest_time)) if drift > timerdevice_drift_threshold: - raise error.TestFail("The guest's system time is different with" - " host's. Host time: '%s', guest time:" - " '%s'" % (host_time, guest_time)) + test.fail("The guest's system time is different with" + " host's. Host time: '%s', guest time:" + " '%s'" % (host_time, guest_time)) get_hw_time_cmd = params.get("get_hw_time_cmd") if get_hw_time_cmd: - error.context( + error_context.context( "Check the hardware time on guest and host", logging.info) - host_time = utils.system_output(get_hw_time_cmd) + host_time = process.system_output(get_hw_time_cmd, shell=True) guest_time = session.cmd(get_hw_time_cmd) drift = abs(float(host_time) - float(guest_time)) if drift > timerdevice_drift_threshold: - raise error.TestFail("The guest's hardware time is different with" - " host's. Host time: '%s', guest time:" - " '%s'" % (host_time, guest_time)) + test.fail("The guest's hardware time is different with" + " host's. Host time: '%s', guest time:" + " '%s'" % (host_time, guest_time)) if params.get("timerdevice_reboot_test") == "yes": sleep_time = params.get("timerdevice_sleep_time") if sleep_time: - error.context("Sleep '%s' secs before reboot" % sleep_time, - logging.info) + error_context.context("Sleep '%s' secs before reboot" % sleep_time, + logging.info) sleep_time = int(sleep_time) time.sleep(sleep_time) session = vm.reboot() - error.context("Check the system time on guest and host", logging.info) + error_context.context("Check the system time on guest and host", + logging.info) (host_time, guest_time) = utils_test.get_time(session, time_command, time_filter_re, time_format) drift = abs(float(host_time) - float(guest_time)) if drift > timerdevice_drift_threshold: - raise error.TestFail("The guest's system time is different with" - " host's. Host time: '%s', guest time:" - " '%s'" % (host_time, guest_time)) + test.fail("The guest's system time is different with" + " host's. Host time: '%s', guest time:" + " '%s'" % (host_time, guest_time)) get_hw_time_cmd = params.get("get_hw_time_cmd") if get_hw_time_cmd: - error.context( + error_context.context( "Check the hardware time on guest and host", logging.info) - host_time = utils.system_output(get_hw_time_cmd) + host_time = process.system_output(get_hw_time_cmd, shell=True) guest_time = session.cmd(get_hw_time_cmd) drift = abs(float(host_time) - float(guest_time)) if drift > timerdevice_drift_threshold: - raise error.TestFail("The guest's hardware time is different with" - " host's. Host time: '%s', guest time:" - " '%s'" % (host_time, guest_time)) + test.fail("The guest's hardware time is different with" + " host's. Host time: '%s', guest time:" + " '%s'" % (host_time, guest_time)) diff --git a/qemu/tests/timerdevice_change_guest_clksource.py b/qemu/tests/timerdevice_change_guest_clksource.py index 47cca84f562fbb9676d9180a42eee9d3f5cb3c7b..820489b4c88eced87e0f7a3cde6a11b36fc36792 100644 --- a/qemu/tests/timerdevice_change_guest_clksource.py +++ b/qemu/tests/timerdevice_change_guest_clksource.py @@ -1,15 +1,14 @@ import logging import re -from autotest.client.shared import error - from virttest import data_dir from virttest import storage from virttest import utils_disk from virttest import env_process +from virttest import error_context -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Timer device check guest after update kernel line without kvmclock: @@ -26,33 +25,34 @@ def run(test, params, env): :param env: Dictionary with the test environment. """ def verify_guest_clock_source(session, expected): - error.context("Check the current clocksource in guest", logging.info) + error_context.context("Check the current clocksource in guest", + logging.info) cmd = "cat /sys/devices/system/clocksource/" cmd += "clocksource0/current_clocksource" if expected not in session.cmd(cmd): - raise error.TestFail( - "Guest didn't use '%s' clocksource" % expected) + test.fail("Guest didn't use '%s' clocksource" % expected) - error.context("Boot a guest with kvm-clock", logging.info) + error_context.context("Boot a guest with kvm-clock", logging.info) vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) - error.context("Check the current clocksource in guest", logging.info) + error_context.context("Check the current clocksource in guest", + logging.info) cmd = "cat /sys/devices/system/clocksource/" cmd += "clocksource0/current_clocksource" if "kvm-clock" not in session.cmd(cmd): grub_file = params.get("grub_file", "/boot/grub2/grub.cfg") if "clocksource=" not in session.cmd("cat %s" % grub_file): - raise error.TestFail("Guest didn't use 'kvm-clock' clocksource") + test.fail("Guest didn't use 'kvm-clock' clocksource") - error.context("Shutdown guest") + error_context.context("Shutdown guest") vm.destroy() env.unregister_vm(vm.name) - error.context("Update guest kernel cli to kvm-clock", - logging.info) + error_context.context("Update guest kernel cli to kvm-clock", + logging.info) image_filename = storage.get_image_filename(params, data_dir.get_data_dir()) kernel_cfg_pattern = params.get("kernel_cfg_pos_reg", @@ -66,16 +66,16 @@ def run(test, params, env): kernel_cfg = re.findall(kernel_cfg_pattern, kernel_cfg_original)[0] except IndexError, detail: - raise error.TestError("Couldn't find the kernel config, regex" - " pattern is '%s', detail: '%s'" % - (kernel_cfg_pattern, detail)) + test.error("Couldn't find the kernel config, regex" + " pattern is '%s', detail: '%s'" % + (kernel_cfg_pattern, detail)) if "clocksource=" in kernel_cfg: kernel_cfg_new = re.sub("clocksource=[a-z\- ]+", " ", kernel_cfg) disk_obj.replace_image_file_content(grub_file, kernel_cfg, kernel_cfg_new) - error.context("Boot the guest", logging.info) + error_context.context("Boot the guest", logging.info) vm_name = params["main_vm"] cpu_model_flags = params.get("cpu_model_flags") params["cpu_model_flags"] = cpu_model_flags + ",-kvmclock" @@ -84,23 +84,24 @@ def run(test, params, env): vm.verify_alive() session = vm.wait_for_login(timeout=timeout) - error.context("Check the available clocksource in guest", logging.info) + error_context.context("Check the available clocksource in guest", + logging.info) cmd = "cat /sys/devices/system/clocksource/" cmd += "clocksource0/available_clocksource" try: available_clksrc_list = session.cmd(cmd).splitlines()[-1].split() available_clksrc_list = [_.strip() for _ in available_clksrc_list] except Exception, detail: - raise error.TestFail("Couldn't get guest available clock source." - " Detail: '%s'" % detail) + test.fail("Couldn't get guest available clock source." + " Detail: '%s'" % detail) try: for clksrc in available_clksrc_list: - error.context("Shutdown guest") + error_context.context("Shutdown guest") vm.destroy() env.unregister_vm(vm.name) - error.context("Update guest kernel cli to '%s'" % clksrc, - logging.info) + error_context.context("Update guest kernel cli to '%s'" % clksrc, + logging.info) image_filename = storage.get_image_filename(params, data_dir.get_data_dir()) grub_file = params.get("grub_file", "/boot/grub2/grub.cfg") @@ -115,9 +116,9 @@ def run(test, params, env): kernel_cfg = re.findall(kernel_cfg_pattern, kernel_cfg_original)[0] except IndexError, detail: - raise error.TestError("Couldn't find the kernel config, regex" - " pattern is '%s', detail: '%s'" % - (kernel_cfg_pattern, detail)) + test.error("Couldn't find the kernel config, regex" + " pattern is '%s', detail: '%s'" % + (kernel_cfg_pattern, detail)) if "clocksource=" in kernel_cfg: kernel_cfg_new = re.sub("clocksource=[a-z \-_]+", @@ -128,7 +129,7 @@ def run(test, params, env): disk_obj.replace_image_file_content(grub_file, kernel_cfg, kernel_cfg_new) - error.context("Boot the guest", logging.info) + error_context.context("Boot the guest", logging.info) if clksrc != "kvm-clock": cpu_model_flags = params.get("cpu_model_flags") if "-kvmclock" not in cpu_model_flags: @@ -139,14 +140,14 @@ def run(test, params, env): vm.verify_alive() session = vm.wait_for_login(timeout=timeout) - error.context("Check the current clocksource in guest", - logging.info) + error_context.context("Check the current clocksource in guest", + logging.info) verify_guest_clock_source(session, clksrc) finally: try: - error.context("Shutdown guest") + error_context.context("Shutdown guest") vm.destroy() - error.context("Restore guest kernel cli", logging.info) + error_context.context("Restore guest kernel cli", logging.info) image_filename = storage.get_image_filename(params, data_dir.get_data_dir()) grub_file = params.get("grub_file", "/boot/grub2/grub.cfg") @@ -159,9 +160,9 @@ def run(test, params, env): kernel_cfg = re.findall(kernel_cfg_pattern, kernel_cfg_original)[0] except IndexError, detail: - raise error.TestError("Couldn't find the kernel config, regex" - " pattern is '%s', detail: '%s'" % - (kernel_cfg_pattern, detail)) + test.error("Couldn't find the kernel config, regex" + " pattern is '%s', detail: '%s'" % + (kernel_cfg_pattern, detail)) if "clocksource=" in kernel_cfg: kernel_cfg_new = re.sub( diff --git a/qemu/tests/timerdevice_clock_drift_with_ntp.py b/qemu/tests/timerdevice_clock_drift_with_ntp.py index a1dbc5e4e5e29283383f1ea6f1fee22008bcd4df..0d70ca76e9c28cadca9376df5c56e0dec5e545b4 100644 --- a/qemu/tests/timerdevice_clock_drift_with_ntp.py +++ b/qemu/tests/timerdevice_clock_drift_with_ntp.py @@ -2,15 +2,13 @@ import logging import os import aexpect - -from autotest.client.shared import error -from autotest.client import utils - +from avocado.utils import process from virttest import data_dir from virttest import utils_misc +from virttest import error_context -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Timer device check clock frequency offset using NTP on CPU starved guest: @@ -38,70 +36,71 @@ def run(test, params, env): except Exception: return False - error.context("Check for an appropriate clocksource on host", logging.info) + error_context.context("Check for an appropriate clocksource on host", + logging.info) host_cmd = "cat /sys/devices/system/clocksource/" host_cmd += "clocksource0/current_clocksource" - if "tsc" not in utils.system_output(host_cmd): - raise error.TestNAError("Host must use 'tsc' clocksource") + if "tsc" not in process.system_output(host_cmd): + test.cancel("Host must use 'tsc' clocksource") - error.context("Boot the guest", logging.info) + error_context.context("Boot the guest", logging.info) vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) sess_guest_load = vm.wait_for_login(timeout=timeout) - error.context("Copy time-warp-test.c to guest", logging.info) + error_context.context("Copy time-warp-test.c to guest", logging.info) src_file_name = os.path.join(data_dir.get_deps_dir(), "tsc_sync", "time-warp-test.c") vm.copy_files_to(src_file_name, "/tmp") - error.context("Compile the time-warp-test.c", logging.info) + error_context.context("Compile the time-warp-test.c", logging.info) cmd = "cd /tmp/;" cmd += " yum install -y popt-devel;" cmd += " rm -f time-warp-test;" cmd += " gcc -Wall -o time-warp-test time-warp-test.c -lrt" sess_guest_load.cmd(cmd) - error.context("Stop ntpd and apply load on guest", logging.info) + error_context.context("Stop ntpd and apply load on guest", logging.info) sess_guest_load.cmd("yum install -y ntp; service ntpd stop") load_cmd = "for ((I=0; I<`grep 'processor id' /proc/cpuinfo| wc -l`; I++));" load_cmd += " do taskset $(( 1 << $I )) /bin/bash -c 'for ((;;)); do X=1; done &';" load_cmd += " done" sess_guest_load.sendline(load_cmd) - error.context("Pin every vcpu to a physical cpu", logging.info) + error_context.context("Pin every vcpu to a physical cpu", logging.info) host_cpu_cnt_cmd = params["host_cpu_cnt_cmd"] - host_cpu_num = utils.system_output(host_cpu_cnt_cmd).strip() + host_cpu_num = process.system_output(host_cpu_cnt_cmd, shell=True).strip() host_cpu_list = (_ for _ in range(int(host_cpu_num))) cpu_pin_list = zip(vm.vcpu_threads, host_cpu_list) if len(cpu_pin_list) < len(vm.vcpu_threads): - raise error.TestNAError("There isn't enough physical cpu to" - " pin all the vcpus") + test.cancel("There isn't enough physical cpu to pin all the vcpus") for vcpu, pcpu in cpu_pin_list: - utils.system("taskset -p %s %s" % (1 << pcpu, vcpu)) + process.system("taskset -p %s %s" % (1 << pcpu, vcpu)) - error.context("Verify each vcpu is pinned on host", logging.info) + error_context.context("Verify each vcpu is pinned on host", logging.info) - error.context("Run time-warp-test", logging.info) + error_context.context("Run time-warp-test", logging.info) session = vm.wait_for_login(timeout=timeout) cmd = "/tmp/time-warp-test > /dev/null &" session.sendline(cmd) - error.context("Start ntpd on guest", logging.info) + error_context.context("Start ntpd on guest", logging.info) cmd = "service ntpd start; sleep 1; echo" session.cmd(cmd) - error.context("Check if the drift file exists on guest", logging.info) + error_context.context("Check if the drift file exists on guest", + logging.info) test_run_timeout = float(params["test_run_timeout"]) try: utils_misc.wait_for(_drift_file_exist, test_run_timeout, step=5) except aexpect.ShellCmdError, detail: - raise error.TestError("Failed to wait for the creation of" - " /var/lib/ntp/drift file. Detail: '%s'" % detail) + test.error("Failed to wait for the creation of" + " /var/lib/ntp/drift file. Detail: '%s'" % detail) - error.context("Verify the drift file content on guest", logging.info) + error_context.context("Verify the drift file content on guest", + logging.info) output = session.cmd("cat /var/lib/ntp/drift") if int(abs(float(output))) > 20: - raise error.TestFail("Failed to check the ntp drift." - " Output: '%s'" % output) + test.fail("Failed to check the ntp drift. Output: '%s'" % output) diff --git a/qemu/tests/timerdevice_clock_drift_with_sleep.py b/qemu/tests/timerdevice_clock_drift_with_sleep.py index 79cc28d3e9a143839700cbd76ef3bf577592979d..492c3179f242167201a77f79431fcba2d57d0141 100644 --- a/qemu/tests/timerdevice_clock_drift_with_sleep.py +++ b/qemu/tests/timerdevice_clock_drift_with_sleep.py @@ -1,16 +1,15 @@ import logging import re -from autotest.client.shared import error -from autotest.client import utils - +from avocado.utils import process from virttest import data_dir from virttest import storage from virttest import utils_disk from virttest import env_process +from virttest import error_context -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Timer device measure clock drift after sleep in guest with kvmclock: @@ -41,33 +40,34 @@ def run(test, params, env): times_list = [_ for _ in times_list if _ > 10.0 or _ < 11.0] if times_list: - raise error.TestFail("Unexpected time drift found:" - " Detail: '%s'" % output) + test.fail("Unexpected time drift found: Detail: '%s'" % output) - error.context("Sync the host system time with ntp server", logging.info) - utils.system("yum install -y ntpdate; ntpdate clock.redhat.com") + error_context.context("Sync the host system time with ntp server", + logging.info) + process.system("yum install -y ntpdate; ntpdate clock.redhat.com", + shell=True) - error.context("Boot the guest", logging.info) + error_context.context("Boot the guest", logging.info) vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) - error.context("Check the clock source currently used on guest", - logging.info) + error_context.context("Check the clock source currently used on guest", + logging.info) cmd = "cat /sys/devices/system/clocksource/" cmd += "clocksource0/current_clocksource" if "kvm-clock" not in session.cmd(cmd): grub_file = params.get("grub_file", "/boot/grub2/grub.cfg") if "clocksource=" not in session.cmd("cat %s" % grub_file): - raise error.TestFail("Guest didn't use 'kvm-clock' clocksource") + test.fail("Guest didn't use 'kvm-clock' clocksource") - error.context("Shutdown guest") + error_context.context("Shutdown guest") vm.destroy() env.unregister_vm(vm.name) - error.context("Update guest kernel cli to kvm-clock", - logging.info) + error_context.context("Update guest kernel cli to kvm-clock", + logging.info) image_filename = storage.get_image_filename(params, data_dir.get_data_dir()) kernel_cfg_pattern = params.get("kernel_cfg_pos_reg", @@ -80,16 +80,16 @@ def run(test, params, env): kernel_cfg = re.findall(kernel_cfg_pattern, kernel_cfg_original)[0] except IndexError, detail: - raise error.TestError("Couldn't find the kernel config, regex" - " pattern is '%s', detail: '%s'" % - (kernel_cfg_pattern, detail)) + test.error("Couldn't find the kernel config, regex" + " pattern is '%s', detail: '%s'" % + (kernel_cfg_pattern, detail)) if "clocksource=" in kernel_cfg: kernel_cfg_new = re.sub(r"clocksource=[a-z\- ]+", " ", kernel_cfg) disk_obj.replace_image_file_content(grub_file, kernel_cfg, kernel_cfg_new) - error.context("Boot the guest", logging.info) + error_context.context("Boot the guest", logging.info) vm_name = params["main_vm"] cpu_model_flags = params.get("cpu_model_flags") params["cpu_model_flags"] = cpu_model_flags + ",-kvmclock" @@ -98,36 +98,35 @@ def run(test, params, env): vm.verify_alive() session = vm.wait_for_login(timeout=timeout) - error.context("Stop auto sync service in guest", logging.info) + error_context.context("Stop auto sync service in guest", logging.info) cmd = "(service chronyd status | grep 'Loaded: loaded')" cmd += " && service chronyd stop" session.cmd_status_output(cmd) - error.context("Sync time from guest to ntpserver", logging.info) + error_context.context("Sync time from guest to ntpserver", logging.info) session.cmd("yum install -y ntpdate; ntpdate clock.redhat.com", timeout=timeout) - error.context("Sleep a while and check the time drift on guest" - " (without any pinned vcpu)", logging.info) + error_context.context("Sleep a while and check the time drift on guest" + " (without any pinned vcpu)", logging.info) verify_elapsed_time() - error.context("Pin every vcpu to physical cpu", logging.info) + error_context.context("Pin every vcpu to physical cpu", logging.info) host_cpu_cnt_cmd = params["host_cpu_cnt_cmd"] - host_cpu_num = utils.system_output(host_cpu_cnt_cmd).strip() + host_cpu_num = process.system_output(host_cpu_cnt_cmd, shell=True).strip() host_cpu_list = (_ for _ in range(int(host_cpu_num))) cpu_pin_list = zip(vm.vcpu_threads, host_cpu_list) if len(cpu_pin_list) < len(vm.vcpu_threads): - raise error.TestNAError("There isn't enough physical cpu to" - " pin all the vcpus") + test.cancel("There isn't enough physical cpu to pin all the vcpus") check_one_cpu_pinned = False for vcpu, pcpu in cpu_pin_list: - utils.system("taskset -p -c %s %s" % (pcpu, vcpu)) + process.system("taskset -p -c %s %s" % (pcpu, vcpu)) if not check_one_cpu_pinned: - error.context("Sleep a while and check the time drift on" - "guest (with one pinned vcpu)", logging.info) + error_context.context("Sleep a while and check the time drift on" + "guest (with one pinned vcpu)", logging.info) verify_elapsed_time() check_one_cpu_pinned = True - error.context("Sleep a while and check the time drift on" - "guest (with all pinned vcpus)", logging.info) + error_context.context("Sleep a while and check the time drift on" + "guest (with all pinned vcpus)", logging.info) verify_elapsed_time() diff --git a/qemu/tests/timerdevice_kvmclock_newer_msrs_support.py b/qemu/tests/timerdevice_kvmclock_newer_msrs_support.py index 2aa77a30e4f4c7b45fc927584f39a91ed710ee07..0be1b9f6d2005d5489fd1e358e266e3b219b360d 100644 --- a/qemu/tests/timerdevice_kvmclock_newer_msrs_support.py +++ b/qemu/tests/timerdevice_kvmclock_newer_msrs_support.py @@ -1,9 +1,7 @@ import re import logging -from autotest.client.shared import error -@error.context_aware def run(test, params, env): """ check kvm-clock using newer msrs test (only for Linux guest): @@ -28,8 +26,8 @@ def run(test, params, env): if current_msrs: current_msrs = set(current_msrs.groups()) if current_msrs != set(msrs): - raise error.TestFail("Except msrs (%s), " % msrs + - "got (%s)" % current_msrs) + test.fail("Except msrs (%s), " % msrs + + "got (%s)" % current_msrs) else: logging.debug(dmesg) - raise error.TestFail("No newer msr available for kvm-clock") + test.fail("No newer msr available for kvm-clock") diff --git a/qemu/tests/timerdevice_tscsync_change_host_clksource.py b/qemu/tests/timerdevice_tscsync_change_host_clksource.py index 43cf327307ae69a9b7030ae2f7df7a24cde122d6..89f895527258b9902b5204a73df9374f91b5ec59 100644 --- a/qemu/tests/timerdevice_tscsync_change_host_clksource.py +++ b/qemu/tests/timerdevice_tscsync_change_host_clksource.py @@ -2,13 +2,12 @@ import logging import os import re -from autotest.client.shared import error -from autotest.client import utils - +from avocado.utils import process from virttest import data_dir +from virttest import error_context -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Timer device check TSC synchronity after change host clocksource: @@ -26,90 +25,89 @@ def run(test, params, env): :param params: Dictionary with test parameters. :param env: Dictionary with the test environment. """ - error.context("Check for an appropriate clocksource on host", logging.info) + error_context.context("Check for an appropriate clocksource on host", + logging.info) host_cmd = "cat /sys/devices/system/clocksource/" host_cmd += "clocksource0/current_clocksource" - if "tsc" not in utils.system_output(host_cmd): - raise error.TestNAError("Host must use 'tsc' clocksource") + if "tsc" not in process.system_output(host_cmd): + test.cancel("Host must use 'tsc' clocksource") - error.context("Boot the guest with one cpu socket", logging.info) + error_context.context("Boot the guest with one cpu socket", logging.info) vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) - error.context("Check the guest is using vsyscall", logging.info) + error_context.context("Check the guest is using vsyscall", logging.info) date_cmd = "strace date 2>&1|egrep 'clock_gettime|gettimeofday'|wc -l" output = session.cmd(date_cmd) if '0' not in output: - raise error.TestFail("Failed to check vsyscall. Output: '%s'" % output) + test.fail("Failed to check vsyscall. Output: '%s'" % output) - error.context("Copy time-warp-test.c to guest", logging.info) + error_context.context("Copy time-warp-test.c to guest", logging.info) src_file_name = os.path.join(data_dir.get_deps_dir(), "tsc_sync", "time-warp-test.c") vm.copy_files_to(src_file_name, "/tmp") - error.context("Compile the time-warp-test.c", logging.info) + error_context.context("Compile the time-warp-test.c", logging.info) cmd = "cd /tmp/;" cmd += " yum install -y popt-devel;" cmd += " rm -f time-warp-test;" cmd += " gcc -Wall -o time-warp-test time-warp-test.c -lrt" session.cmd(cmd) - error.context("Run time-warp-test", logging.info) + error_context.context("Run time-warp-test", logging.info) test_run_timeout = int(params.get("test_run_timeout", 10)) session.sendline("$(sleep %d; pkill time-warp-test) &" % test_run_timeout) cmd = "/tmp/time-warp-test" - _, output = session.cmd_status_output(cmd, timeout=(test_run_timeout + 60)) + output = session.cmd_status_output(cmd, timeout=(test_run_timeout + 60))[1] re_str = "fail:(\d+).*?fail:(\d+).*fail:(\d+)" fail_cnt = re.findall(re_str, output) if not fail_cnt: - raise error.TestError("Could not get correct test output." - " Output: '%s'" % output) + test.error("Could not get correct test output. Output: '%s'" % output) tsc_cnt, tod_cnt, clk_cnt = [int(_) for _ in fail_cnt[-1]] if tsc_cnt or tod_cnt or clk_cnt: msg = output.splitlines()[-5:] - raise error.TestFail("Get error when running time-warp-test." - " Output (last 5 lines): '%s'" % msg) + test.fail("Get error when running time-warp-test." + " Output (last 5 lines): '%s'" % msg) try: - error.context("Switch host to hpet clocksource", logging.info) + error_context.context("Switch host to hpet clocksource", logging.info) cmd = "echo hpet > /sys/devices/system/clocksource/" cmd += "clocksource0/current_clocksource" - utils.system(cmd) + process.system(cmd, shell=True) - error.context("Run time-warp-test after change the host clock source", - logging.info) + error_context.context("Run time-warp-test after change the host" + " clock source", logging.info) cmd = "$(sleep %d; pkill time-warp-test) &" session.sendline(cmd % test_run_timeout) cmd = "/tmp/time-warp-test" - _, output = session.cmd_status_output(cmd, - timeout=(test_run_timeout + 60)) + output = session.cmd_status_output(cmd, + timeout=(test_run_timeout + 60))[1] fail_cnt = re.findall(re_str, output) if not fail_cnt: - raise error.TestError("Could not get correct test output." - " Output: '%s'" % output) + test.error("Could not get correct test output." + " Output: '%s'" % output) tsc_cnt, tod_cnt, clk_cnt = [int(_) for _ in fail_cnt[-1]] if tsc_cnt or tod_cnt or clk_cnt: msg = output.splitlines()[-5:] - raise error.TestFail("Get error when running time-warp-test." - " Output (last 5 lines): '%s'" % msg) + test.fail("Get error when running time-warp-test." + " Output (last 5 lines): '%s'" % msg) output = session.cmd(date_cmd) if "1" not in output: - raise error.TestFail("Failed to check vsyscall." - " Output: '%s'" % output) + test.fail("Failed to check vsyscall. Output: '%s'" % output) finally: - error.context("Restore host to tsc clocksource", logging.info) + error_context.context("Restore host to tsc clocksource", logging.info) cmd = "echo tsc > /sys/devices/system/clocksource/" cmd += "clocksource0/current_clocksource" try: - utils.system(cmd) - except Exception, detail: + process.system(cmd, shell=True) + except Exception as detail: logging.error("Failed to restore host clocksource." "Detail: %s" % detail) diff --git a/qemu/tests/timerdevice_tscsync_longtime.py b/qemu/tests/timerdevice_tscsync_longtime.py index 8571d9642232a7978da4dd6d207d4c05cb51be77..35fae8477398ebf83dd914402ae53921c70670d8 100644 --- a/qemu/tests/timerdevice_tscsync_longtime.py +++ b/qemu/tests/timerdevice_tscsync_longtime.py @@ -2,13 +2,12 @@ import logging import os import re -from autotest.client.shared import error -from autotest.client import utils - +from avocado.utils import process from virttest import data_dir +from virttest import error_context -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Timer device check TSC synchronity for long time test: @@ -24,50 +23,52 @@ def run(test, params, env): :param params: Dictionary with test parameters. :param env: Dictionary with the test environment. """ - error.context("Check for an appropriate clocksource on host", logging.info) + error_context.context("Check for an appropriate clocksource on host", + logging.info) host_cmd = "cat /sys/devices/system/clocksource/" host_cmd += "clocksource0/current_clocksource" - if "tsc" not in utils.system_output(host_cmd): - raise error.TestNAError("Host must use 'tsc' clocksource") + if "tsc" not in process.system_output(host_cmd): + test.cancel("Host must use 'tsc' clocksource") - error.context("Check host has more than one cpu socket", logging.info) + error_context.context("Check host has more than one cpu socket", + logging.info) host_socket_cnt_cmd = params["host_socket_cnt_cmd"] - if utils.system_output(host_socket_cnt_cmd).strip() == "1": - raise error.TestNAError("Host must have more than 1 socket") + if process.system_output(host_socket_cnt_cmd, shell=True).strip() == "1": + test.cancel("Host must have more than 1 socket") - error.context("Boot the guest with one cpu socket", logging.info) + error_context.context("Boot the guest with one cpu socket", logging.info) vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) - error.context("Copy time-warp-test.c to guest", logging.info) + error_context.context("Copy time-warp-test.c to guest", logging.info) src_file_name = os.path.join(data_dir.get_deps_dir(), "tsc_sync", "time-warp-test.c") vm.copy_files_to(src_file_name, "/tmp") - error.context("Compile the time-warp-test.c", logging.info) + error_context.context("Compile the time-warp-test.c", logging.info) cmd = "cd /tmp/;" cmd += " yum install -y popt-devel;" cmd += " rm -f time-warp-test;" cmd += " gcc -Wall -o time-warp-test time-warp-test.c -lrt" session.cmd(cmd) - error.context("Run time-warp-test for minimum 4 hours", logging.info) + error_context.context("Run time-warp-test for minimum 4 hours", + logging.info) test_run_timeout = int(params.get("test_run_timeout", 14400)) session.sendline("$(sleep %d; pkill time-warp-test) &" % test_run_timeout) cmd = "/tmp/time-warp-test" - _, output = session.cmd_status_output(cmd, timeout=(test_run_timeout + 60)) + output = session.cmd_status_output(cmd, timeout=(test_run_timeout + 60))[1] re_str = "fail:(\d+).*?fail:(\d+).*fail:(\d+)" fail_cnt = re.findall(re_str, output) if not fail_cnt: - raise error.TestError("Could not get correct test output." - " Output: '%s'" % output) + test.error("Could not get correct test output. Output: '%s'" % output) tsc_cnt, tod_cnt, clk_cnt = [int(_) for _ in fail_cnt[-1]] if tsc_cnt or tod_cnt or clk_cnt: msg = output.splitlines()[-5:] - raise error.TestFail("Get error when running time-warp-test." - " Output (last 5 lines): '%s'" % msg) + test.fail("Get error when running time-warp-test." + " Output (last 5 lines): '%s'" % msg) diff --git a/qemu/tests/timerdevice_tscwrite.py b/qemu/tests/timerdevice_tscwrite.py index b897d4bb53f99b5272d51fb7a87e6209f7048b47..650de98b6ff7f70c69463f11856b40a3760f523b 100644 --- a/qemu/tests/timerdevice_tscwrite.py +++ b/qemu/tests/timerdevice_tscwrite.py @@ -1,9 +1,10 @@ import logging -from autotest.client.shared import error -from autotest.client import utils +from avocado.utils import process +from virttest import error_context -@error.context_aware + +@error_context.context_aware def run(test, params, env): """ Timer device tscwrite test: @@ -17,32 +18,33 @@ def run(test, params, env): :param params: Dictionary with test parameters. :param env: Dictionary with the test environment. """ - error.context("Check for an appropriate clocksource on host", logging.info) + error_context.context("Check for an appropriate clocksource on host", + logging.info) host_cmd = "cat /sys/devices/system/clocksource/" host_cmd += "clocksource0/current_clocksource" - if "tsc" not in utils.system_output(host_cmd): - raise error.TestNAError("Host must use 'tsc' clocksource") + if "tsc" not in process.system_output(host_cmd): + test.cancel("Host must use 'tsc' clocksource") - error.context("Boot the guest", logging.info) + error_context.context("Boot the guest", logging.info) vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) - error.context("Download and compile the newest msr-tools", logging.info) + error_context.context("Download and compile the newest msr-tools", + logging.info) msr_tools_install_cmd = params["msr_tools_install_cmd"] session.cmd(msr_tools_install_cmd) - error.context("Execute cmd in guest", logging.info) + error_context.context("Execute cmd in guest", logging.info) cmd = "dmesg -c > /dev/null" session.cmd(cmd) date_cmd = "strace date 2>&1 | egrep 'clock_gettime|gettimeofday' | wc -l" output = session.cmd(date_cmd) if '0' not in output: - raise error.TestFail("Test failed before run msr tools." - " Output: '%s'" % output) + test.fail("Test failed before run msr tools. Output: '%s'" % output) msr_tools_cmd = params["msr_tools_cmd"] session.cmd(msr_tools_cmd) @@ -52,5 +54,4 @@ def run(test, params, env): output = session.cmd(date_cmd) if "1" not in output: - raise error.TestFail("Test failed after run msr tools." - " Output: '%s'" % output) + test.fail("Test failed after run msr tools. Output: '%s'" % output) diff --git a/qemu/tests/trace_cmd_boot.py b/qemu/tests/trace_cmd_boot.py index 057d0a0339db15f6db148e374dcec575d5988d9f..758159b074f35ccd645ccf1d7d90f01e6659a487 100644 --- a/qemu/tests/trace_cmd_boot.py +++ b/qemu/tests/trace_cmd_boot.py @@ -3,13 +3,12 @@ import os import signal import logging -from autotest.client import utils -from autotest.client.shared import error - +from avocado.utils import process from virttest import utils_misc +from virttest import error_context -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Qemu reboot test: @@ -30,13 +29,14 @@ def run(test, params, env): """ def find_trace_cmd(): - if utils.system("ps -a | grep trace-cmd", ignore_status=True): + if process.system("ps -a | grep trace-cmd", ignore_status=True, + shell=True): return False else: return True if os.system("which trace-cmd"): - raise error.TestNAError("Please install trace-cmd.") + test.cancel("Please install trace-cmd.") timeout = float(params.get("login_timeout", 240)) vm = env.get_vm(params["main_vm"]) @@ -54,43 +54,42 @@ def run(test, params, env): report_file = os.path.join(test.debugdir, "trace.txt") trace_report_cmd = "trace-cmd report -i %s > %s " % (trace_o, report_file) try: - error.context("Run stress tool on host.", logging.info) - stress_job = utils.BgJob(stress_cmd) + error_context.context("Run stress tool on host.", logging.info) + stress_job = utils_misc.BgJob(stress_cmd) # Reboot the VM for num in xrange(int(params.get("reboot_count", 1))): - error.context("Reboot guest '%s'. Repeat %d" % (vm.name, num + 1), - logging.info) - trace_job = utils.BgJob(trace_cmd) + error_context.context("Reboot guest '%s'. Repeat %d" % + (vm.name, num + 1), logging.info) + trace_job = utils_misc.BgJob(trace_cmd) try: session = vm.reboot(session, reboot_method, 0, timeout) - except Exception, err: + except Exception: txt = "stop the trace-cmd and generate the readable report." - error.context(txt, logging.info) + error_context.context(txt, logging.info) os.kill(trace_job.sp.pid, signal.SIGINT) if not utils_misc.wait_for(lambda: not find_trace_cmd(), 120, 60, 3): logging.warn("trace-cmd could not finish after 120s.") trace_job = None - utils.system(trace_report_cmd) + process.system(trace_report_cmd, shell=True) report_txt = file(report_file).read() txt = "Check whether the trace.txt includes the error log." - error.context(txt, logging.info) + error_context.context(txt, logging.info) if re.findall(re_trace, report_txt, re.S): msg = "Found %s in trace log %s" % (re_trace, report_file) - logging.info(msg) - error.TestFail(msg) + test.fail(msg) else: txt = "stop the trace-cmd and remove the trace.dat file." - error.context(txt, logging.info) + error_context.context(txt, logging.info) os.kill(trace_job.sp.pid, signal.SIGINT) if not utils_misc.wait_for(lambda: not find_trace_cmd(), 120, 60, 3): logging.warn("trace-cmd could not finish after 120s.") trace_job = None - utils.system("rm -rf %s" % trace_o, timeout=60) + process.system("rm -rf %s" % trace_o, timeout=60) finally: if session: session.close() diff --git a/qemu/tests/tracing_exception_injection.py b/qemu/tests/tracing_exception_injection.py index 50cb1724286da1cd95d280d974af86ede6e7bdb2..24f057fe1c7064dd6891bab960dd5cb3a554722c 100644 --- a/qemu/tests/tracing_exception_injection.py +++ b/qemu/tests/tracing_exception_injection.py @@ -1,9 +1,10 @@ import logging -from autotest.client import utils, os_dep -from autotest.client.shared import error +from avocado.utils import process, path +from virttest import error_context -@error.context_aware + +@error_context.context_aware def run(test, params, env): """ Run tracing of exception injection test @@ -16,30 +17,30 @@ def run(test, params, env): :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ - error.context("Get the main VM", logging.info) + error_context.context("Get the main VM", logging.info) vm = env.get_vm(params["main_vm"]) vm.verify_alive() - error.context("Check that kvm_stat works in host", logging.info) - kvm_stat_bin = os_dep.command("kvm_stat") + error_context.context("Check that kvm_stat works in host", logging.info) + kvm_stat_bin = path.find_command("kvm_stat") check_cmd = "%s -1 -f exits" % kvm_stat_bin - host_cmd_output = utils.system_output(check_cmd) + host_cmd_output = process.system_output(check_cmd) if host_cmd_output: if host_cmd_output.split()[1] == '0': - raise error.TestFail("kvm_stat did not provide the expected " - "output: %s" % host_cmd_output) + test.fail("kvm_stat did not provide the expected " + "output: %s" % host_cmd_output) logging.info("kvm_stat provided the expected output") logging.info("Host cmd output '%s'", host_cmd_output) - error.context( + error_context.context( "Check that host allows tracing of exception injection in KVM", logging.info) exec_cmd = "grep kvm:kvm_inj_exception " exec_cmd += " /sys/kernel/debug/tracing/available_events" inj_check_cmd = params.get("injection_check_cmd", exec_cmd) try: - utils.run(inj_check_cmd) - except error.CmdError: + process.run(inj_check_cmd, shell=True) + except process.CmdError: err_msg = "kvm:kvm_inj_exception is not an available event in host" - raise error.TestFail(err_msg) + test.fail(err_msg) logging.info("Host supports tracing of exception injection in KVM") diff --git a/qemu/tests/transfer_file_over_ipv6.py b/qemu/tests/transfer_file_over_ipv6.py index abad55ac721590bbcbfc7c6f5dfcaa32622177ed..036cee9f24f6e836284c2fd591ebdd10a038c790 100644 --- a/qemu/tests/transfer_file_over_ipv6.py +++ b/qemu/tests/transfer_file_over_ipv6.py @@ -2,15 +2,14 @@ import logging import os import re -from autotest.client import utils -from autotest.client.shared import error - +from avocado.utils import crypto, process from virttest import remote from virttest import utils_misc from virttest import utils_net +from virttest import error_context -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Test Step @@ -40,13 +39,12 @@ def run(test, params, env): if session is not None: o = session.cmd_output("ifconfig %s" % ifname) else: - o = utils.system_output("ifconfig %s" % ifname) + o = process.system_output("ifconfig %s" % ifname) ipv6_address_reg = re.compile(r"(fe80::[^\s|/]*)") if o: ipv6_linklocal_address = ipv6_address_reg.findall(o) if not ipv6_linklocal_address: - raise error.TestError("Can't get %s linklocal address" - % ifname) + test.error("Can't get %s linklocal address" % ifname) return ipv6_linklocal_address[0] else: return None @@ -60,7 +58,7 @@ def run(test, params, env): o = session.cmd_output("md5sum %s" % file_name, timeout=timeout) file_md5sum = re.findall("\w+", o)[0] except IndexError: - raise error.TestError("Could not get file md5sum in guest") + test.error("Could not get file md5sum in guest") return file_md5sum sessions = {} @@ -68,7 +66,7 @@ def run(test, params, env): inet_name = {} vms = [] - error.context("Boot vms for test", logging.info) + error_context.context("Boot vms for test", logging.info) for vm_name in params.get("vms", "vm1 vm2").split(): vms.append(env.get_vm(vm_name)) @@ -89,14 +87,14 @@ def run(test, params, env): host_path = os.path.join(test.tmpdir, "tmp-%s" % utils_misc.generate_random_string(8)) logging.info("Test setup: Creating %dMB file on host", filesize) - utils.run(dd_cmd % (host_path, filesize)) + process.run(dd_cmd % (host_path, filesize)) try: - src_md5 = (utils.hash_file(host_path, method="md5")) + src_md5 = (crypto.hash_file(host_path, algorithm="md5")) # transfer data for vm in vms: - error.context("Transfer data from host to %s" % vm.name, - logging.info) + error_context.context("Transfer data from host to %s" % vm.name, + logging.info) remote.copy_files_to(addresses[vm], client, username, password, port, host_path, guest_path, @@ -105,14 +103,14 @@ def run(test, params, env): dst_md5 = get_file_md5sum(guest_path, sessions[vm], timeout=file_md5_check_timeout) if dst_md5 != src_md5: - raise error.TestFail("File changed after transfer host -> %s" - % vm.name) + test.fail("File changed after transfer host -> %s" % vm.name) for vm_src in addresses: for vm_dst in addresses: if vm_src != vm_dst: - error.context("Transferring data from %s to %s" % - (vm_src.name, vm_dst.name), logging.info) + error_context.context("Transferring data from %s to %s" % + (vm_src.name, vm_dst.name), + logging.info) remote.scp_between_remotes(addresses[vm_src], addresses[vm_dst], port, password, password, @@ -124,27 +122,27 @@ def run(test, params, env): dst_md5 = get_file_md5sum(dest_path, sessions[vm_dst], timeout=file_md5_check_timeout) if dst_md5 != src_md5: - raise error.TestFail("File changed transfer %s -> %s" - % (vm_src.name, vm_dst.name)) + test.fail("File changed transfer %s -> %s" + % (vm_src.name, vm_dst.name)) for vm in vms: - error.context("Transfer data from %s to host" % vm.name, - logging.info) + error_context.context("Transfer data from %s to host" % vm.name, + logging.info) remote.copy_files_from(addresses[vm], client, username, password, port, dest_path, host_path, timeout=file_trans_timeout, interface=host_ifname) - error.context("Check whether the file changed after trans", - logging.info) - dst_md5 = (utils.hash_file(host_path, method="md5")) + error_context.context("Check whether the file changed after trans", + logging.info) + dst_md5 = (crypto.hash_file(host_path, algorithm="md5")) if dst_md5 != src_md5: - raise error.TestFail("File changed after transfer (md5sum mismatch)") - utils.system_output("rm -rf %s" % host_path, timeout=timeout) + test.fail("File changed after transfer (md5sum mismatch)") + process.system_output("rm -rf %s" % host_path, timeout=timeout) finally: - utils.system("rm -rf %s" % host_path, timeout=timeout, - ignore_status=True) + process.system("rm -rf %s" % host_path, timeout=timeout, + ignore_status=True) for vm in vms: sessions[vm].cmd("rm -rf %s %s || true" % (guest_path, dest_path), timeout=timeout, ignore_all_errors=True) diff --git a/qemu/tests/tsc_drift.py b/qemu/tests/tsc_drift.py index 09d2e927d9edea2db83517856b9c703c916d32ff..9fcf2a4d88caa2ac04118e0608d6a7be0a0d7289 100644 --- a/qemu/tests/tsc_drift.py +++ b/qemu/tests/tsc_drift.py @@ -4,9 +4,7 @@ import logging import commands import re -from autotest.client.shared import error -from autotest.client import local_host - +from avocado.utils import cpu from virttest import data_dir @@ -46,7 +44,7 @@ def run(test, params, env): else: s, o = session.get_command_status_output(cmd) if s != 0: - raise error.TestError("Fail to get tsc of host, ncpu: %d" % i) + test.error("Fail to get tsc of host, ncpu: %d" % i) o = re.findall("(\d+)", o)[0] return float(o) @@ -58,7 +56,7 @@ def run(test, params, env): if not os.path.exists(tsc_cmd_guest): commands.getoutput("gcc %s" % tsc_freq_path) - ncpu = local_host.LocalHost().get_num_cpu() + ncpu = cpu.online_cpus_count() logging.info("Interval is %s" % interval) logging.info("Determine the TSC frequency in the host") @@ -70,7 +68,7 @@ def run(test, params, env): delta = tsc2 - tsc1 logging.info("Host TSC delta for cpu %s is %s" % (i, delta)) if delta < 0: - raise error.TestError("Host TSC for cpu %s warps %s" % (i, delta)) + test.error("Host TSC for cpu %s warps %s" % (i, delta)) host_freq += delta / ncpu logging.info("Average frequency of host's cpus: %s" % host_freq) @@ -78,11 +76,11 @@ def run(test, params, env): if session.get_command_status("test -x %s" % tsc_cmd_guest): vm.copy_files_to(tsc_freq_path, '/tmp/get_tsc.c') if session.get_command_status("gcc /tmp/get_tsc.c") != 0: - raise error.TestError("Fail to compile program on guest") + test.error("Fail to compile program on guest") s, guest_ncpu = session.get_command_status_output(cpu_chk_cmd) if s != 0: - raise error.TestError("Fail to get cpu number of guest") + test.error("Fail to get cpu number of guest") success = True for i in range(int(guest_ncpu)): @@ -102,7 +100,7 @@ def run(test, params, env): success = False if not success: - raise error.TestFail("TSC drift found for the guest, please check the " - "log for details") + test.fail("TSC drift found for the guest, please check the " + "log for details") session.close()