diff --git a/qemu/tests/file_copy_stress.py b/qemu/tests/file_copy_stress.py index 1b1f524526afe62c365b1f3ee219425c3db80ea0..70bedea05ce149b930966798b3043dc511d9daa8 100644 --- a/qemu/tests/file_copy_stress.py +++ b/qemu/tests/file_copy_stress.py @@ -1,13 +1,12 @@ import time import logging -from autotest.client.shared import error - +from virttest import error_context from virttest import utils_misc from virttest import utils_test -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Transfer a file back and forth between host and guest. @@ -26,14 +25,15 @@ def run(test, params, env): vm = env.get_vm(params["main_vm"]) vm.verify_alive() - error.context("Login to guest", logging.info) + error_context.context("Login to guest", logging.info) session = vm.wait_for_login(timeout=login_timeout) scp_sessions = int(params.get("scp_para_sessions", 1)) try: stress_timeout = float(params.get("stress_timeout", "3600")) - error.context("Do file transfer between host and guest", logging.info) + error_context.context("Do file transfer between host and guest", + logging.info) start_time = time.time() stop_time = start_time + stress_timeout # here when set a run flag, when other case call this case as a diff --git a/qemu/tests/fio_perf.py b/qemu/tests/fio_perf.py index 52828ab1999395b55a8c6825d67bf20f0da972ca..e05a50632683a1048d00e9e67f2fee07bf53db8a 100644 --- a/qemu/tests/fio_perf.py +++ b/qemu/tests/fio_perf.py @@ -4,10 +4,7 @@ import time import threading import logging -from autotest.client import utils - from avocado.utils import process -from avocado.core import exceptions from virttest import utils_misc, utils_test from virttest import data_dir @@ -64,7 +61,7 @@ def get_version(session, result_file, kvm_ver_chk_cmd, guest_ver_cmd, type, driv :param timeout: Timeout in seconds """ - kvm_ver = utils.system_output(kvm_ver_chk_cmd) + kvm_ver = process.system_output(kvm_ver_chk_cmd) host_ver = os.uname()[2] result_file.write("### kvm-userspace-ver : %s\n" % kvm_ver) @@ -207,7 +204,7 @@ def run(test, params, env): (s, o) = session.cmd_status_output(online_disk_run, timeout=cmd_timeout) if s: - raise exceptions.TestFail("Failed to online disk: %s" % o) + test.fail("Failed to online disk: %s" % o) # format disk if format == "True": session.cmd(pre_cmd, cmd_timeout) @@ -239,7 +236,7 @@ def run(test, params, env): (s, o) = session.cmd_status_output(drop_cache, timeout=cmd_timeout) if s: - raise exceptions.TestFail("Failed to free memory: %s" % o) + test.fail("Failed to free memory: %s" % o) cpu_file = os.path.join(data_dir.get_tmp_dir(), "cpus") io_exits_b = int(process.system_output("cat /sys/kernel/debug/kvm/exits")) fio_t = threading.Thread(target=fio_thread) diff --git a/qemu/tests/flag_check.py b/qemu/tests/flag_check.py index 28de630fa0e27dbca36c9ae2c003cd3b1cd78f20..9e99e74639f924974522c3527689db74e1864eb0 100644 --- a/qemu/tests/flag_check.py +++ b/qemu/tests/flag_check.py @@ -2,14 +2,16 @@ import re import logging import os.path -from autotest.client.shared import utils, error +from avocado.utils import download +from avocado.utils import process +from virttest import error_context from virttest import utils_misc from virttest import data_dir from virttest import virt_vm -@error.context_aware +@error_context.context_aware def run(test, params, env): """ flag_check test: @@ -83,7 +85,7 @@ def run(test, params, env): """ qemu_binary = utils_misc.get_qemu_binary(params) cmd = qemu_binary + params.get("query_cmd", " -cpu ?") - output = utils.system_output(cmd) + output = process.system_output(cmd) flags_re = re.compile(params.get("pattern", "flags:(.*)")) flag_list = flags_re.search(output) flags = [] @@ -131,15 +133,17 @@ def run(test, params, env): dump_file = params.get("dump_file") default_dump_path = os.path.join(data_dir.get_deps_dir(), "cpuid") dump_path = params.get("dump_path", default_dump_path) - cpuinfo_file = utils.unmap_url(dump_path, dump_file, dump_path) + dump_file_path = os.path.join(dump_path, dump_file) + cpuinfo_file = os.path.join(default_dump_path, dump_file) + download.get_file(dump_file_path, dump_file) host_flags = utils_misc.get_cpu_flags() vm = env.get_vm(params["main_vm"]) guest_cpumodel = vm.cpuinfo.model extra_flags = params.get("cpu_model_flags", " ") - error.context("Boot guest with -cpu %s,%s" % - (guest_cpumodel, extra_flags), logging.info) + error_context.context("Boot guest with -cpu %s,%s" % + (guest_cpumodel, extra_flags), logging.info) if params.get("start_vm") == "no" and "unknown,check" in extra_flags: params["start_vm"] = "yes" @@ -151,7 +155,7 @@ def run(test, params, env): except virt_vm.VMCreateError as detail: output = str(detail) if params["qemu_output"] not in output: - raise error.TestFail("no qemu output: %s" % params["qemu_output"]) + test.fail("no qemu output: %s" % params["qemu_output"]) else: vm.verify_alive() timeout = float(params.get("login_timeout", 240)) @@ -163,10 +167,12 @@ def run(test, params, env): qemu_model = host_cpumodel[0] else: qemu_model = guest_cpumodel - error.context("Get model %s support flags" % qemu_model, logging.info) + error_context.context("Get model %s support flags" % qemu_model, + logging.info) # Get flags for every reg from model's info - models_info = utils.system_output("cat %s" % cpuinfo_file).split("x86") + models_info = process.system_output( + "cat %s" % cpuinfo_file).split("x86") model_info = qemu_model_info(models_info, qemu_model) reg_list = params.get("reg_list", "feature_edx ").split() model_support_flags = " " @@ -178,10 +184,10 @@ def run(test, params, env): model_support_flags = set(map(utils_misc.Flag, model_support_flags.split())) - error.context("Get guest flags", logging.info) + error_context.context("Get guest flags", logging.info) guest_flags = get_guest_cpuflags(session) - error.context("Get expected flag list", logging.info) + error_context.context("Get expected flag list", logging.info) # out_flags is definded in dump file, but not in guest out_flags = params.get("out_flags", " ").split() @@ -208,7 +214,7 @@ def run(test, params, env): lack_flags = set(expected_flags | check_flags) - host_flags if "check" in extra_flags and "unknown" not in extra_flags: - error.context("Check lack flag in host", logging.info) + error_context.context("Check lack flag in host", logging.info) process_output = vm.process.get_output() miss_warn = [] if lack_flags: @@ -216,17 +222,18 @@ def run(test, params, env): if flag not in process_output: miss_warn.extend(flag.split()) if miss_warn: - raise error.TestFail("no warning for lack flag %s" % miss_warn) + test.fail("no warning for lack flag %s" % miss_warn) - error.context("Compare guest flags with expected flags", logging.info) + error_context.context("Compare guest flags with expected flags", + logging.info) all_support_flags = get_all_support_flags() missing_flags = expected_flags - guest_flags unexpect_flags = (guest_flags - expected_flags - all_support_flags - option_flags) if missing_flags or unexpect_flags: - raise error.TestFail("missing flags:\n %s\n" - "more flags than expected:\n %s\n" - "expected flags:\n %s\n" - "guest flags:\n %s\n" - % (missing_flags, unexpect_flags, expected_flags, - guest_flags)) + test.fail("missing flags:\n %s\n" + "more flags than expected:\n %s\n" + "expected flags:\n %s\n" + "guest flags:\n %s\n" + % (missing_flags, unexpect_flags, expected_flags, + guest_flags)) diff --git a/qemu/tests/floppy.py b/qemu/tests/floppy.py index fc6df4d55d63875e49af596f8cbbe47f85f7946d..6fbc239416a39a90e954da3749e00b51637d2310 100644 --- a/qemu/tests/floppy.py +++ b/qemu/tests/floppy.py @@ -4,21 +4,17 @@ import os import sys import re -try: - import aexpect -except ImportError: - from virttest import aexpect +import aexpect -from autotest.client import utils -from autotest.client.shared import error -from autotest.client.shared.syncdata import SyncData +from avocado.utils import process from virttest import data_dir from virttest import env_process +from virttest import error_context from virttest.utils_test.qemu import migration -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Test virtual floppy of guest: @@ -48,17 +44,17 @@ def run(test, params, env): :return: path to new floppy file. """ - error.context("creating test floppy", logging.info) + error_context.context("creating test floppy", logging.info) floppy = params["floppy_name"] if not os.path.isabs(floppy): floppy = os.path.join(data_dir.get_data_dir(), floppy) if prepare: - utils.run("dd if=/dev/zero of=%s bs=512 count=2880" % floppy) + process.run("dd if=/dev/zero of=%s bs=512 count=2880" % floppy) return floppy def cleanup_floppy(path): """ Removes created floppy """ - error.context("cleaning up temp floppy images", logging.info) + error_context.context("cleaning up temp floppy images", logging.info) os.remove("%s" % path) def lazy_copy(vm, dst_path, check_path, copy_timeout=None, dsize=None): @@ -126,27 +122,27 @@ def run(test, params, env): else: time.sleep(20) - error.context("Formating floppy disk before using it") + error_context.context("Formating floppy disk before using it") format_cmd = params["format_floppy_cmd"] self.session.cmd(format_cmd, timeout=120) logging.info("Floppy disk formatted successfully") if self.dest_dir: - error.context("Mounting floppy") + error_context.context("Mounting floppy") self.session.cmd("mount %s %s" % (guest_floppy_path, self.dest_dir)) - error.context("Testing floppy") + error_context.context("Testing floppy") self.session.cmd(params["test_floppy_cmd"]) - error.context("Copying file to the floppy") + error_context.context("Copying file to the floppy") md5_cmd = params.get("md5_cmd") if md5_cmd: md5_source = self.session.cmd("%s %s" % (md5_cmd, source_file)) try: md5_source = md5_source.split(" ")[0] except IndexError: - error.TestError("Failed to get md5 from source file," - " output: '%s'" % md5_source) + test.error("Failed to get md5 from source file," + " output: '%s'" % md5_source) else: md5_source = None @@ -155,16 +151,17 @@ def run(test, params, env): logging.info("Succeed to copy file '%s' into floppy disk" % source_file) - error.context("Checking if the file is unchanged after copy") + error_context.context("Checking if the file is unchanged " + "after copy") if md5_cmd: md5_dest = self.session.cmd("%s %s" % (md5_cmd, dest_file)) try: md5_dest = md5_dest.split(" ")[0] except IndexError: - error.TestError("Failed to get md5 from dest file," - " output: '%s'" % md5_dest) + test.error("Failed to get md5 from dest file," + " output: '%s'" % md5_dest) if md5_source != md5_dest: - raise error.TestFail("File changed after copy to floppy") + test.fail("File changed after copy to floppy") else: md5_dest = None self.session.cmd("%s %s %s" % (params["diff_file_cmd"], @@ -180,7 +177,8 @@ def run(test, params, env): class Multihost(MiniSubtest): def test(self): - error.context("Preparing migration env and floppies.", logging.info) + error_context.context("Preparing migration env and floppies.", + logging.info) mig_protocol = params.get("mig_protocol", "tcp") self.mig_type = migration.MultihostMigration if mig_protocol == "fd": @@ -219,6 +217,8 @@ def run(test, params, env): class test_multihost_write(Multihost): def test(self): + from autotest.client.shared.syncdata import SyncData + super(test_multihost_write, self).test() copy_timeout = int(params.get("copy_timeout", 480)) @@ -243,7 +243,8 @@ def run(test, params, env): # If mount_dir specified, treat guest as a Linux OS # Some Linux distribution does not load floppy at boot # and Windows needs time to load and init floppy driver - error.context("Prepare floppy for writing.", logging.info) + error_context.context("Prepare floppy for writing.", + logging.info) if self.mount_dir: lsmod = session.cmd("lsmod") if 'floppy' not in lsmod: @@ -253,13 +254,13 @@ def run(test, params, env): session.cmd(format_floppy_cmd) - error.context("Mount and copy data.", logging.info) + error_context.context("Mount and copy data.", logging.info) if self.mount_dir: session.cmd("mount %s %s" % (guest_floppy_path, self.mount_dir), timeout=30) - error.context("File copying test.", logging.info) + error_context.context("File copying test.", logging.info) pid = lazy_copy(vm, src_file, check_copy_path, copy_timeout) @@ -273,34 +274,35 @@ def run(test, params, env): if not self.is_src: # Starts in destination vm = env.get_vm(self.vms[0]) session = vm.wait_for_login(timeout=login_timeout) - error.context("Wait for copy finishing.", logging.info) + error_context.context("Wait for copy finishing.", logging.info) status = session.cmd_status("kill %s" % pid, timeout=copy_timeout) if status != 0: - raise error.TestFail("Copy process was terminatted with" - " error code %s" % (status)) + test.fail("Copy process was terminatted with" + " error code %s" % (status)) session.cmd_status("kill -s SIGINT %s" % (pid), timeout=copy_timeout) - error.context("Check floppy file checksum.", logging.info) + error_context.context("Check floppy file checksum.", + logging.info) md5_cmd = params.get("md5_cmd", "md5sum") if md5_cmd: md5_floppy = session.cmd("%s %s" % (md5_cmd, src_file)) try: md5_floppy = md5_floppy.split(" ")[0] except IndexError: - error.TestError("Failed to get md5 from source file," - " output: '%s'" % md5_floppy) + test.error("Failed to get md5 from source file," + " output: '%s'" % md5_floppy) md5_check = session.cmd("%s %s" % (md5_cmd, check_copy_path)) try: md5_check = md5_check.split(" ")[0] except IndexError: - error.TestError("Failed to get md5 from dst file," - " output: '%s'" % md5_floppy) + test.error("Failed to get md5 from dst file," + " output: '%s'" % md5_floppy) if md5_check != md5_floppy: - raise error.TestFail("There is mistake in copying, " - "it is possible to check file on vm.") + test.fail("There is mistake in copying, " + "it is possible to check file on vm.") session.cmd("rm -f %s" % (src_file)) session.cmd("rm -f %s" % (check_copy_path)) @@ -314,6 +316,8 @@ def run(test, params, env): class test_multihost_eject(Multihost): def test(self): + from autotest.client.shared.syncdata import SyncData + super(test_multihost_eject, self).test() self.mount_dir = params.get("mount_dir", None) @@ -344,7 +348,8 @@ def run(test, params, env): # If mount_dir specified, treat guest as a Linux OS # Some Linux distribution does not load floppy at boot # and Windows needs time to load and init floppy driver - error.context("Prepare floppy for writing.", logging.info) + error_context.context("Prepare floppy for writing.", + logging.info) if self.mount_dir: # If linux lsmod = session.cmd("lsmod") if 'floppy' not in lsmod: @@ -353,7 +358,7 @@ def run(test, params, env): time.sleep(20) if floppy not in vm.monitor.info("block"): - raise error.TestFail("Wrong floppy image is placed in vm.") + test.fail("Wrong floppy image is placed in vm.") try: session.cmd(format_floppy_cmd) @@ -363,7 +368,7 @@ def run(test, params, env): " Trying a second time as a workaround") session.cmd(format_floppy_cmd) - error.context("Check floppy") + error_context.context("Check floppy") if self.mount_dir: # If linux session.cmd("mount %s %s" % (guest_floppy_path, self.mount_dir), timeout=30) @@ -381,23 +386,23 @@ def run(test, params, env): output = session.cmd("type %s" % (filepath)) written = "test \n\n" if output != written: - raise error.TestFail("Data read from the floppy differs" - "from the data written to it." - " EXPECTED: %s GOT: %s" % - (repr(written), repr(output))) + test.fail("Data read from the floppy differs" + "from the data written to it." + " EXPECTED: %s GOT: %s" % + (repr(written), repr(output))) - error.context("Change floppy.") + error_context.context("Change floppy.") vm.monitor.cmd("eject floppy0") vm.monitor.cmd("change floppy %s" % (second_floppy)) session.cmd(format_floppy_cmd) - error.context("Mount and copy data") + error_context.context("Mount and copy data") if self.mount_dir: # If linux session.cmd("mount %s %s" % (guest_floppy_path, self.mount_dir), timeout=30) if second_floppy not in vm.monitor.info("block"): - raise error.TestFail("Wrong floppy image is placed in vm.") + test.fail("Wrong floppy image is placed in vm.") sync = SyncData(self.mig.master_id(), self.mig.hostid, self.mig.hosts, sync_id, self.mig.sync_server) @@ -421,10 +426,10 @@ def run(test, params, env): output = session.cmd("type %s" % (filepath)) written = "test \n\n" if output != written: - raise error.TestFail("Data read from the floppy differs" - "from the data written to it." - " EXPECTED: %s GOT: %s" % - (repr(written), repr(output))) + test.fail("Data read from the floppy differs" + "from the data written to it." + " EXPECTED: %s GOT: %s" % + (repr(written), repr(output))) self.mig._hosts_barrier(self.mig.hosts, self.mig.hosts, 'finish_floppy_test', login_timeout) @@ -437,5 +442,5 @@ def run(test, params, env): tests_group = locals()[test_type] tests_group() else: - raise error.TestFail("Test group '%s' is not defined in" - " migration_with_dst_problem test" % test_type) + test.fail("Test group '%s' is not defined in" + " migration_with_dst_problem test" % test_type) diff --git a/qemu/tests/flow_caches_stress_test.py b/qemu/tests/flow_caches_stress_test.py index ca03658c07962fdc6c86160e9d4ea2eb7e1d7a5d..7dcbe30bbe88cbb3e06f44977c43e40994cdcce2 100644 --- a/qemu/tests/flow_caches_stress_test.py +++ b/qemu/tests/flow_caches_stress_test.py @@ -1,8 +1,8 @@ import logging -from autotest.client import utils -from autotest.client.shared import error +from avocado.utils import process +from virttest import error_context from virttest import utils_netperf from virttest import utils_net from virttest import env_process @@ -12,7 +12,7 @@ from virttest import utils_test # This decorator makes the test function aware of context strings -@error.context_aware +@error_context.context_aware def run(test, params, env): """ QEMU flow caches stress test test @@ -33,13 +33,13 @@ def run(test, params, env): :param env: Dictionary with test environment. """ msg = "Make sure nf_conntrack is disabled in host and guest." - error.context(msg, logging.info) - if "nf_conntrack" in utils.system_output("lsmod"): + error_context.context(msg, logging.info) + if "nf_conntrack" in process.system_output("lsmod"): err = "nf_conntrack load in host, skip this case" - raise error.TestNAError(err) + test.cancel(err) params["start_vm"] = "yes" - error.context("Boot up guest", logging.info) + error_context.context("Boot up guest", logging.info) env_process.preprocess_vm(test, params, env, params["main_vm"]) vm = env.get_vm(params["main_vm"]) vm.verify_alive() @@ -48,7 +48,7 @@ def run(test, params, env): session = vm.wait_for_login(timeout=timeout) if "nf_conntrack" in session.cmd_output("lsmod"): msg = "Unload nf_conntrack module in guest." - error.context(msg, logging.info) + error_context.context(msg, logging.info) black_str = "#disable nf_conntrack\\nblacklist nf_conntrack\\n" \ "blacklist nf_conntrack_ipv6\\nblacklist xt_conntrack\\n" \ "blacklist nf_conntrack_ftp\\nblacklist xt_state\\n" \ @@ -59,7 +59,7 @@ def run(test, params, env): session = vm.reboot(session, timeout=timeout) if "nf_conntrack" in session.cmd_output("lsmod"): err = "Fail to unload nf_conntrack module in guest." - error.TestError(err) + test.error(err) netperf_link = utils_misc.get_path(data_dir.get_deps_dir("netperf"), params["netperf_link"]) @@ -91,14 +91,15 @@ def run(test, params, env): compile_option_server = params.get("compile_option_server", "") if int(params.get("queues", 1)) > 1 and params.get("os_type") == "linux": - error.context("Enable multi queues support in guest.", logging.info) + error_context.context("Enable multi queues support in guest.", + logging.info) guest_mac = vm.get_mac_address() ifname = utils_net.get_linux_ifname(session, guest_mac) cmd = "ethtool -L %s combined %s" % (ifname, params.get("queues")) status, out = session.cmd_status_output(cmd) msg = "Fail to enable multi queues support in guest." msg += "Command %s fail output: %s" % (cmd, out) - error.TestError(msg) + test.error(msg) if params.get("os_type") == "linux": session.cmd("iptables -F", ignore_all_errors=True) @@ -110,7 +111,7 @@ def run(test, params, env): g_client_path = win_netperf_path g_md5sum = win_netperf_md5sum - error.context("Setup netperf in guest and host", logging.info) + error_context.context("Setup netperf in guest and host", logging.info) netperf_client = utils_netperf.NetperfClient(netperf_client_ip, g_client_path, g_md5sum, g_client_link, @@ -132,12 +133,12 @@ def run(test, params, env): status_test_command=status_test_command, compile_option=compile_option_server) try: - error.base_context("Run netperf test between host and guest.") - error.context("Start netserver in host.", logging.info) + error_context.base_context("Run netperf test between host and guest.") + error_context.context("Start netserver in host.", logging.info) netperf_server.start() - error.context("Start Netperf in guest for %ss." % netperf_timeout, - logging.info) + error_context.context("Start Netperf in guest for %ss." + % netperf_timeout, logging.info) test_option = "-t TCP_CRR -l %s -- -b 10 -D" % netperf_timeout netperf_client.bg_start(netperf_server_ip, test_option, client_num) diff --git a/qemu/tests/format_disk.py b/qemu/tests/format_disk.py index c184515160ae00ccd70a94ae0659ee8dc2f347a9..62bf60aaf37dfa7a053f594a8a7421d7b1f31094 100644 --- a/qemu/tests/format_disk.py +++ b/qemu/tests/format_disk.py @@ -3,12 +3,11 @@ import re 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): """ Format guest disk: @@ -29,7 +28,7 @@ def run(test, params, env): vm = env.get_vm(params["main_vm"]) vm.verify_alive() - error.context("Login to the guest", logging.info) + error_context.context("Login to the guest", logging.info) session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) cmd_timeout = int(params.get("cmd_timeout", 360)) @@ -45,45 +44,45 @@ def run(test, params, env): drive_id = "" drive_path = utils_misc.get_linux_drive_path(session, drive_id) if not drive_path: - raise error.TestError("Failed to get '%s' drive path" % drive_name) + test.error("Failed to get '%s' drive path" % drive_name) # Create a partition on disk create_partition_cmd = params.get("create_partition_cmd") if create_partition_cmd: has_dispart = re.findall("diskpart", create_partition_cmd, re.I) if (params.get("os_type") == 'windows' and has_dispart): - error.context("Get disk list in guest") + error_context.context("Get disk list in guest") list_disk_cmd = params.get("list_disk_cmd") status, output = session.cmd_status_output(list_disk_cmd, timeout=cmd_timeout) for i in re.findall("Disk*.(\d+)\s+Offline", output): - error.context("Set disk '%s' to online status" % i, - logging.info) + error_context.context("Set disk '%s' to online status" % i, + logging.info) set_online_cmd = params.get("set_online_cmd") % i status, output = session.cmd_status_output(set_online_cmd, timeout=cmd_timeout) if status != 0: - raise error.TestFail("Can not set disk online %s" % output) + test.fail("Can not set disk online %s" % output) - error.context("Create partition on disk", logging.info) + error_context.context("Create partition on disk", logging.info) status, output = session.cmd_status_output(create_partition_cmd, timeout=cmd_timeout) if status != 0: - raise error.TestFail( - "Failed to create partition with error: %s" % output) + test.fail("Failed to create partition with error: %s" % output) format_cmd = params.get("format_cmd", "").format(drive_path) if format_cmd: - error.context("Format the disk with cmd '%s'" % format_cmd, - logging.info) + error_context.context("Format the disk with cmd '%s'" % format_cmd, + logging.info) status, output = session.cmd_status_output(format_cmd, timeout=cmd_timeout) if status != 0: - raise error.TestFail("Failed to format with error: %s" % output) + test.fail("Failed to format with error: %s" % output) mount_cmd = params.get("mount_cmd", "").format(drive_path) if mount_cmd: - error.context("Mount the disk with cmd '%s'" % mount_cmd, logging.info) + error_context.context("Mount the disk with cmd '%s'" % mount_cmd, + logging.info) status, output = session.cmd_status_output(mount_cmd, timeout=cmd_timeout) if status != 0: @@ -91,11 +90,12 @@ def run(test, params, env): device_list = session.cmd_output_safe(show_dev_cmd) logging.debug("The devices which will be mounted are: %s" % device_list) - raise error.TestFail("Failed to mount with error: %s" % output) + test.fail("Failed to mount with error: %s" % output) testfile_name = params.get("testfile_name") if testfile_name: - error.context("Write some random string to test file", logging.info) + error_context.context("Write some random string to test file", + logging.info) ranstr = utils_misc.generate_random_string(100) writefile_cmd = params["writefile_cmd"] @@ -103,30 +103,31 @@ def run(test, params, env): status, output = session.cmd_status_output(writefile_cmd, timeout=cmd_timeout) if status != 0: - raise error.TestFail("Write to file error: %s" % output) + test.fail("Write to file error: %s" % output) - error.context("Read in the file to see whether content has changed", - logging.info) + error_context.context("Read in the file to see whether " + "content has changed", logging.info) md5chk_cmd = params.get("md5chk_cmd") if md5chk_cmd: status, output = session.cmd_status_output(md5chk_cmd, timeout=cmd_timeout) if status != 0: - raise error.TestFail("Check file md5sum error.") + test.fail("Check file md5sum error.") readfile_cmd = params["readfile_cmd"] readfile_cmd = readfile_cmd % testfile_name status, output = session.cmd_status_output(readfile_cmd, timeout=cmd_timeout) if status != 0: - raise error.TestFail("Read file error: %s" % output) + test.fail("Read file error: %s" % output) if output.strip() != ranstr: - raise error.TestFail("The content written to file has changed, " - "from: %s, to: %s" % (ranstr, output.strip())) + test.fail("The content written to file has changed, " + "from: %s, to: %s" % (ranstr, output.strip())) umount_cmd = params.get("umount_cmd", "").format(drive_path) if umount_cmd: - error.context("Unmounting disk(s) after file write/read operation") + error_context.context("Unmounting disk(s) after file " + "write/read operation") status, output = session.cmd_status_output(umount_cmd, timeout=cmd_timeout) if status != 0: @@ -134,12 +135,13 @@ def run(test, params, env): "show_mount_cmd", "").format(drive_path) mount_list = session.cmd_output_safe(show_mount_cmd) logging.debug("The mounted devices are: %s" % mount_list) - raise error.TestFail("Failed to umount with error: %s" % output) + test.fail("Failed to umount with error: %s" % output) output = "" try: output = session.cmd("dmesg -c") - error.context("Checking if there are I/O error messages in dmesg") + error_context.context("Checking if there are I/O error " + "messages in dmesg") except aexpect.ShellCmdError: pass @@ -155,6 +157,6 @@ def run(test, params, env): logging.error(e_msg) for line in io_error_msg: logging.error(line) - raise error.TestFail(e_msg) + test.fail(e_msg) session.close() diff --git a/qemu/tests/fullscreen_setup.py b/qemu/tests/fullscreen_setup.py index 07e5efca41e5de493a8eb6b2d06bba342be9e245..97f88d400faab7b57aee0a987fd0b90148f26233 100644 --- a/qemu/tests/fullscreen_setup.py +++ b/qemu/tests/fullscreen_setup.py @@ -8,8 +8,6 @@ the same setup will result in them having the same resolution. """ import logging -from autotest.client.shared import error - from virttest import utils_spice @@ -92,7 +90,7 @@ def run(test, params, env): logging.info("Current Resolution of Guest: " + currentGuestRes) if (newClientResolution == currentGuestRes): - raise error.TestFail("Client resolution is same as guest resolution!") + test.fail("Client resolution is same as guest resolution!") # Start vdagent daemon utils_spice.start_vdagent(guest_root_session, test_timeout) diff --git a/qemu/tests/getfd.py b/qemu/tests/getfd.py index ba61ef69542e00707db9706a695446f6eba1db26..a51221be08ff879fcae73109d929b8d981decd5b 100644 --- a/qemu/tests/getfd.py +++ b/qemu/tests/getfd.py @@ -1,5 +1,4 @@ import os -from autotest.client.shared import error def run(test, params, env): @@ -38,7 +37,7 @@ def run(test, params, env): pid = vm.get_pid() if pid is None: - raise error.TestError("Fail to get process id for VM") + test.error("Fail to get process id for VM") # directory for storing temporary files fdfiles_dir = os.path.join(test.tmpdir, 'fdfiles') @@ -55,11 +54,11 @@ def run(test, params, env): os.close(fd) # getfd is supposed to generate no output if response: - raise error.TestError("getfd returned error: %s" % response) + test.error("getfd returned error: %s" % response) # check if qemu process has a copy of the fd if not has_fd(pid, path): - raise error.TestError("QEMU process does not seem to have a file " - "descriptor pointing to file %s" % path) + test.error("QEMU process does not seem to have a file " + "descriptor pointing to file %s" % path) # clean up files for n in range(nofiles): diff --git a/qemu/tests/gluster_boot_snap_boot.py b/qemu/tests/gluster_boot_snap_boot.py index debc4a8973af9013e9fa8bed46105ef9e22d451d..9f314e0d9094099f7bea2c7a6846f1e4b01dd946 100644 --- a/qemu/tests/gluster_boot_snap_boot.py +++ b/qemu/tests/gluster_boot_snap_boot.py @@ -1,13 +1,12 @@ import logging -from autotest.client.shared import error - from virttest import env_process +from virttest import error_context from virttest import qemu_storage from virttest import data_dir -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Run an gluster test. @@ -30,13 +29,13 @@ def run(test, params, env): params['image_format_backing_file_snapshot'] = params.get("image_format") params['image_name_snapshot'] = params.get("image_name") + "-snap" - error.context("boot guest over glusterfs", logging.info) + error_context.context("boot guest over glusterfs", logging.info) vm = env.get_vm(params["main_vm"]) vm.verify_alive() vm.wait_for_login(timeout=timeout) - error.context("shutdown VM", logging.info) + error_context.context("shutdown VM", logging.info) vm.destroy() - error.context("create snapshot of vm disk", logging.info) + error_context.context("create snapshot of vm disk", logging.info) snapshot_params = params.object_params("snapshot") diff --git a/qemu/tests/gluster_create_images.py b/qemu/tests/gluster_create_images.py index 68a900c59e11fbdf6faa08ef1f8d2770975f911e..55ee10a4997a7005203b68715e1b4aa2d00d935a 100644 --- a/qemu/tests/gluster_create_images.py +++ b/qemu/tests/gluster_create_images.py @@ -1,9 +1,8 @@ -from autotest.client.shared import error - from virttest import env_process +from virttest import error_context -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Run an gluster test. @@ -19,7 +18,7 @@ def run(test, params, env): :param params: Dictionary with test parameters. :param env: Dictionary with the test environment. """ - error.context("Create gluster fs image") + error_context.context("Create gluster fs image") gluster_params = params.object_params("gluster") image_name = gluster_params.get("image_name") diff --git a/qemu/tests/guest_memory_dump_analysis.py b/qemu/tests/guest_memory_dump_analysis.py index f10639935d099caf98e26bab53c617b1e1e2e0b7..5f15d0a1875e9944d8452f4d451298e8c2e9a823 100644 --- a/qemu/tests/guest_memory_dump_analysis.py +++ b/qemu/tests/guest_memory_dump_analysis.py @@ -16,7 +16,6 @@ import threading from aexpect import ShellCmdError -from autotest.client.shared import error REQ_GUEST_MEM = 4096 # exact size of guest RAM required REQ_GUEST_ARCH = "x86_64" # the only supported guest arch @@ -51,13 +50,13 @@ def run(test, params, env): """ mem_size = vm.get_memory_size() if (mem_size != REQ_GUEST_MEM): - raise error.TestError("the guest must have %d MB RAM exactly " - "(current: %d MB)" % (REQ_GUEST_MEM, - mem_size)) + test.error("the guest must have %d MB RAM exactly " + "(current: %d MB)" % (REQ_GUEST_MEM, + mem_size)) arch = session.cmd("uname -m").rstrip() if (arch != REQ_GUEST_ARCH): - raise error.TestError("this test only supports %s guests " - "(current: %s)" % (REQ_GUEST_ARCH, arch)) + test.error("this test only supports %s guests " + "(current: %s)" % (REQ_GUEST_ARCH, arch)) def install_kernel_debuginfo(vm, session, login_timeout): """ @@ -93,8 +92,7 @@ def run(test, params, env): try: guest_kernel = session.cmd("uname -r").rstrip() except ShellCmdError, details: - raise error.TestError("guest uname command failed: %s" % - details) + test.error("guest uname command failed: %s" % details) return session.cmd("yum -y install --enablerepo='*debuginfo' " "kernel-debuginfo-%s" % guest_kernel, timeout=LONG_TIMEOUT) @@ -142,8 +140,8 @@ def run(test, params, env): logging.debug("%s", output) df_megs = int(string.split(output)[10]) if (df_megs < REQ_GUEST_DF): - raise error.TestError("insufficient free disk space: %d < %d" % - (df_megs, REQ_GUEST_DF)) + test.error("insufficient free disk space: %d < %d" % + (df_megs, REQ_GUEST_DF)) def dump_and_compress(qmp_monitor, vmcore_host): """ @@ -263,7 +261,7 @@ def run(test, params, env): logging.debug("%s", output) if (string.find(output, "crash:") >= 0 or string.find(output, "WARNING:") >= 0): - raise error.TestFail("vmcore corrupt") + test.fail("vmcore corrupt") vm = env.get_vm(params["main_vm"]) vm.verify_alive() @@ -272,7 +270,7 @@ def run(test, params, env): if qmp_monitor: qmp_monitor = qmp_monitor[0] else: - raise error.TestError('Could not find a QMP monitor, aborting test') + test.error('Could not find a QMP monitor, aborting test') login_timeout = int(params.get("login_timeout", 240)) session = vm.wait_for_login(timeout=login_timeout)