提交 d4767ead 编写于 作者: H Haotong Chen

[generic] Replace autotest modules - np

Signed-off-by: NHaotong Chen <hachen@redhat.com>
上级 fa83fcad
...@@ -5,8 +5,7 @@ import threading ...@@ -5,8 +5,7 @@ import threading
import re import re
import time import time
from autotest.client import utils from avocado.utils import process
from virttest import utils_test from virttest import utils_test
from virttest import utils_misc from virttest import utils_misc
from virttest import utils_net from virttest import utils_net
...@@ -139,7 +138,7 @@ def run(test, params, env): ...@@ -139,7 +138,7 @@ def run(test, params, env):
error_context.context("Change all Bridge NICs MTU to %s" error_context.context("Change all Bridge NICs MTU to %s"
% mtu, logging.info) % mtu, logging.info)
for iface in target_ifaces: for iface in target_ifaces:
utils.run(host_mtu_cmd % (iface, mtu), ignore_status=False) process.run(host_mtu_cmd % (iface, mtu), ignore_status=False)
def _pin_vm_threads(vm, node): def _pin_vm_threads(vm, node):
if node: if node:
...@@ -285,7 +284,8 @@ def run(test, params, env): ...@@ -285,7 +284,8 @@ def run(test, params, env):
if params.get("log_hostinfo_script"): if params.get("log_hostinfo_script"):
src = os.path.join(test.virtdir, params.get("log_hostinfo_script")) src = os.path.join(test.virtdir, params.get("log_hostinfo_script"))
path = os.path.join(test.resultsdir, "systeminfo") path = os.path.join(test.resultsdir, "systeminfo")
utils.system_output("bash %s %s &> %s" % (src, test.resultsdir, path)) process.system_output(
"bash %s %s &> %s" % (src, test.resultsdir, path))
if params.get("log_guestinfo_script") and params.get("log_guestinfo_exec"): if params.get("log_guestinfo_script") and params.get("log_guestinfo_exec"):
src = os.path.join(test.virtdir, params.get("log_guestinfo_script")) src = os.path.join(test.virtdir, params.get("log_guestinfo_script"))
...@@ -449,8 +449,8 @@ def ssh_cmd(session, cmd, timeout=120, ignore_status=False): ...@@ -449,8 +449,8 @@ def ssh_cmd(session, cmd, timeout=120, ignore_status=False):
:param timeout: timeout for the command :param timeout: timeout for the command
""" """
if session == "localhost": if session == "localhost":
o = utils.system_output(cmd, timeout=timeout, o = process.system_output(cmd, timeout=timeout,
ignore_status=ignore_status) ignore_status=ignore_status)
else: else:
o = session.cmd(cmd, timeout=timeout, ignore_all_errors=ignore_status) o = session.cmd(cmd, timeout=timeout, ignore_all_errors=ignore_status)
return o return o
......
import logging import logging
import time import time
from autotest.client.shared import error from avocado.utils import process
from autotest.client import utils
from virttest import utils_misc from virttest import utils_misc
from virttest import utils_test from virttest import utils_test
from virttest import env_process from virttest import env_process
from virttest import error_context
@error.context_aware @error_context.context_aware
def run(test, params, env): def run(test, params, env):
""" """
Try to kill the guest after/during network stress in guest. Try to kill the guest after/during network stress in guest.
...@@ -46,17 +45,17 @@ def run(test, params, env): ...@@ -46,17 +45,17 @@ def run(test, params, env):
modules.remove("") modules.remove("")
return set(modules) return set(modules)
def kill_and_check(vm): def kill_and_check(test, vm):
vm.destroy(gracefully=False) vm.destroy(gracefully=False)
if not vm.wait_until_dead(timeout=60): if not vm.wait_until_dead(timeout=60):
raise error.TestFail("VM is not dead after destroy operation") test.fail("VM is not dead after destroy operation")
logging.info("VM is dead as expected") logging.info("VM is dead as expected")
def netload_kill_problem(session_serial): def netload_kill_problem(test, session_serial):
firewall_flush = params.get("firewall_flush", "service iptables stop") firewall_flush = params.get("firewall_flush", "service iptables stop")
error.context("Stop firewall in guest and host.", logging.info) error_context.context("Stop firewall in guest and host.", logging.info)
try: try:
utils.run(firewall_flush) process.run(firewall_flush)
except Exception: except Exception:
logging.warning("Could not stop firewall in host") logging.warning("Could not stop firewall in host")
...@@ -66,15 +65,16 @@ def run(test, params, env): ...@@ -66,15 +65,16 @@ def run(test, params, env):
logging.warning("Could not stop firewall in guest") logging.warning("Could not stop firewall in guest")
try: try:
bg_stress_test = params.get("background_stress_test", 'netperf_stress') bg_stress_test = params.get("background_stress_test",
error.context("Run subtest %s between host and guest." % bg_stress_test, 'netperf_stress')
logging.info) error_context.context(("Run subtest %s between host and guest." %
bg_stress_test), logging.info)
stress_thread = None stress_thread = None
wait_time = int(params.get("wait_bg_time", 60)) wait_time = int(params.get("wait_bg_time", 60))
bg_stress_run_flag = params.get("bg_stress_run_flag") bg_stress_run_flag = params.get("bg_stress_run_flag")
vm_wait_time = int(params.get("wait_before_kill_vm")) vm_wait_time = int(params.get("wait_before_kill_vm"))
env[bg_stress_run_flag] = False env[bg_stress_run_flag] = False
stress_thread = utils.InterruptedThread( stress_thread = utils_misc.InterruptedThread(
utils_test.run_virt_sub_test, (test, params, env), utils_test.run_virt_sub_test, (test, params, env),
{"sub_type": bg_stress_test}) {"sub_type": bg_stress_test})
stress_thread.start() stress_thread.start()
...@@ -82,37 +82,38 @@ def run(test, params, env): ...@@ -82,37 +82,38 @@ def run(test, params, env):
wait_time, 0, 1, wait_time, 0, 1,
"Wait %s test start" % bg_stress_test): "Wait %s test start" % bg_stress_test):
err = "Fail to start netperf test between guest and host" err = "Fail to start netperf test between guest and host"
raise error.TestError(err) test.error(err)
logging.info("Sleep %ss before killing the VM", vm_wait_time) logging.info("Sleep %ss before killing the VM", vm_wait_time)
time.sleep(vm_wait_time) time.sleep(vm_wait_time)
msg = "During netperf running, Check that we can kill VM with signal 0" msg = "During netperf running, Check that we can kill VM with signal 0"
error.context(msg, logging.info) error_context.context(msg, logging.info)
kill_and_check(vm) kill_and_check(test, vm)
finally: finally:
try: try:
stress_thread.join(60) stress_thread.join(60)
except Exception: except Exception:
pass pass
def netdriver_kill_problem(session_serial): def netdriver_kill_problem(test, session_serial):
times = int(params.get("repeat_times", 10)) times = int(params.get("repeat_times", 10))
modules = get_ethernet_driver(session_serial) modules = get_ethernet_driver(session_serial)
logging.debug("Guest network driver(s): %s" % modules) logging.debug("Guest network driver(s): %s" % modules)
msg = "Repeatedly load/unload network driver(s) for %s times." % times msg = "Repeatedly load/unload network driver(s) for %s times." % times
error.context(msg, logging.info) error_context.context(msg, logging.info)
for i in range(times): for i in range(times):
for module in modules: for module in modules:
error.context("Unload driver %s. Repeat: %s/%s" % (module, error_context.context("Unload driver %s. Repeat: %s/%s" %
i, times)) (module, i, times))
session_serial.cmd_output_safe("rmmod %s" % module) session_serial.cmd_output_safe("rmmod %s" % module)
for module in modules: for module in modules:
error.context("Load driver %s. Repeat: %s/%s" % (module, error_context.context("Load driver %s. Repeat: %s/%s" %
i, times)) (module, i, times))
session_serial.cmd_output_safe("modprobe %s" % module) session_serial.cmd_output_safe("modprobe %s" % module)
error.context("Check that we can kill VM with signal 0.", logging.info) error_context.context("Check that we can kill VM with signal 0.",
kill_and_check(vm) logging.info)
kill_and_check(test, vm)
vm = env.get_vm(params["main_vm"]) vm = env.get_vm(params["main_vm"])
vm.verify_alive() vm.verify_alive()
...@@ -123,9 +124,9 @@ def run(test, params, env): ...@@ -123,9 +124,9 @@ def run(test, params, env):
mode = params.get("mode") mode = params.get("mode")
if mode == "driver": if mode == "driver":
netdriver_kill_problem(session_serial) netdriver_kill_problem(test, session_serial)
elif mode == "load": elif mode == "load":
netload_kill_problem(session_serial) netload_kill_problem(test, session_serial)
env_process.preprocess_vm(test, params, env, params["main_vm"]) env_process.preprocess_vm(test, params, env, params["main_vm"])
vm = env.get_vm(params["main_vm"]) vm = env.get_vm(params["main_vm"])
vm.verify_alive() vm.verify_alive()
......
...@@ -2,9 +2,8 @@ import os ...@@ -2,9 +2,8 @@ import os
import re import re
import logging import logging
from autotest.client import utils from avocado.utils import process
from autotest.client import os_dep from avocado.utils import path as utils_path
from virttest import utils_misc from virttest import utils_misc
from virttest import utils_net from virttest import utils_net
from virttest import env_process from virttest import env_process
...@@ -43,9 +42,9 @@ class NFSCorruptConfig(object): ...@@ -43,9 +42,9 @@ class NFSCorruptConfig(object):
""" """
error_context.context("Finding out commands to handle NFS service", error_context.context("Finding out commands to handle NFS service",
logging.info) logging.info)
service = os_dep.command("service") service = utils_path.find_command("service")
try: try:
systemctl = os_dep.command("systemctl") systemctl = utils_path.find_command("systemctl")
except ValueError: except ValueError:
systemctl = None systemctl = None
...@@ -105,16 +104,16 @@ class NFSCorruptConfig(object): ...@@ -105,16 +104,16 @@ class NFSCorruptConfig(object):
if not self.is_service_active(): if not self.is_service_active():
self.start_service() self.start_service()
utils.run("exportfs %s:%s -o rw,no_root_squash" % process.run("exportfs %s:%s -o rw,no_root_squash" %
(self.nfs_ip, self.nfs_dir)) (self.nfs_ip, self.nfs_dir))
utils.run("mount %s:%s %s -o rw,soft,timeo=30,retrans=1,vers=3" % process.run("mount %s:%s %s -o rw,soft,timeo=30,retrans=1,vers=3" %
(self.nfs_ip, self.nfs_dir, self.mnt_dir)) (self.nfs_ip, self.nfs_dir, self.mnt_dir))
@error_context.context_aware @error_context.context_aware
def cleanup(self, force_stop=False): def cleanup(self, force_stop=False):
error_context.context("Cleaning up test NFS share", logging.info) error_context.context("Cleaning up test NFS share", logging.info)
utils.run("umount %s" % self.mnt_dir) process.run("umount %s" % self.mnt_dir)
utils.run("exportfs -u %s:%s" % (self.nfs_ip, self.nfs_dir)) process.run("exportfs -u %s:%s" % (self.nfs_ip, self.nfs_dir))
if force_stop: if force_stop:
self.stop_service() self.stop_service()
...@@ -122,19 +121,19 @@ class NFSCorruptConfig(object): ...@@ -122,19 +121,19 @@ class NFSCorruptConfig(object):
""" """
Starts the NFS server. Starts the NFS server.
""" """
utils.run(self.start_cmd) process.run(self.start_cmd)
def stop_service(self): def stop_service(self):
""" """
Stops the NFS server. Stops the NFS server.
""" """
utils.run(self.stop_cmd) process.run(self.stop_cmd)
def restart_service(self): def restart_service(self):
""" """
Restarts the NFS server. Restarts the NFS server.
""" """
utils.run(self.restart_cmd) process.run(self.restart_cmd)
def is_service_active(self): def is_service_active(self):
""" """
...@@ -143,7 +142,7 @@ class NFSCorruptConfig(object): ...@@ -143,7 +142,7 @@ class NFSCorruptConfig(object):
:param chk_re: Regular expression that tells whether NFS is running :param chk_re: Regular expression that tells whether NFS is running
or not. or not.
""" """
status = utils.system_output(self.status_cmd, ignore_status=True) status = process.system_output(self.status_cmd, ignore_status=True)
if re.findall(self.chk_re, status): if re.findall(self.chk_re, status):
return True return True
else: else:
...@@ -257,7 +256,7 @@ def run(test, params, env): ...@@ -257,7 +256,7 @@ def run(test, params, env):
cmd += " -j REJECT" cmd += " -j REJECT"
error_context.context("Reject NFS connection on host", logging.info) error_context.context("Reject NFS connection on host", logging.info)
utils.system(cmd) process.system(cmd)
error_context.context("Check if VM status is 'paused'", logging.info) error_context.context("Check if VM status is 'paused'", logging.info)
if not utils_misc.wait_for( if not utils_misc.wait_for(
...@@ -276,7 +275,7 @@ def run(test, params, env): ...@@ -276,7 +275,7 @@ def run(test, params, env):
cmd += " --dport 2049" cmd += " --dport 2049"
cmd += " -j REJECT" cmd += " -j REJECT"
utils.system(cmd) process.system(cmd)
error_context.context("Continue guest", logging.info) error_context.context("Continue guest", logging.info)
vm.resume() vm.resume()
......
...@@ -3,15 +3,14 @@ import os ...@@ -3,15 +3,14 @@ import os
import time import time
import random import random
from autotest.client import utils from avocado.utils import crypto, process
from autotest.client.shared import error
from virttest import utils_misc from virttest import utils_misc
from virttest import utils_net from virttest import utils_net
from virttest import data_dir from virttest import data_dir
from virttest import error_context
@error.context_aware @error_context.context_aware
def run(test, params, env): def run(test, params, env):
""" """
Test nic driver load/unload. Test nic driver load/unload.
...@@ -69,12 +68,12 @@ def run(test, params, env): ...@@ -69,12 +68,12 @@ def run(test, params, env):
rules = params.get("rules") rules = params.get("rules")
if not session.cmd_status("[ -e %s ]" % udev_rules_file): if not session.cmd_status("[ -e %s ]" % udev_rules_file):
if not rules: if not rules:
raise error.TestNAError("You must set udev rules before test") test.cancel("You must set udev rules before test")
rules = rules % vm_mac_address rules = rules % vm_mac_address
session = reset_guest_udevrules(session, udev_rules_file, rules) session = reset_guest_udevrules(session, udev_rules_file, rules)
error.base_context("Test env prepare") error_context.base_context("Test env prepare")
error.context("Get NIC interface name in guest.", logging.info) error_context.context("Get NIC interface name in guest.", logging.info)
ethname = utils_net.get_linux_ifname(session, vm.get_mac_address(0)) ethname = utils_net.get_linux_ifname(session, vm.get_mac_address(0))
# get ethernet driver from '/sys' directory. # get ethernet driver from '/sys' directory.
# ethtool can do the same thing and doesn't care about os type. # ethtool can do the same thing and doesn't care about os type.
...@@ -86,29 +85,29 @@ def run(test, params, env): ...@@ -86,29 +85,29 @@ def run(test, params, env):
sys_path)).strip()) sys_path)).strip())
logging.info("The guest interface %s using driver %s" % (ethname, driver)) logging.info("The guest interface %s using driver %s" % (ethname, driver))
error.context("Host test file prepare, create %dMB file on host" % error_context.context("Host test file prepare, create %dMB file on host" %
filesize, logging.info) filesize, logging.info)
tmp_dir = data_dir.get_tmp_dir() tmp_dir = data_dir.get_tmp_dir()
host_path = os.path.join(tmp_dir, "host_file_%s" % host_path = os.path.join(tmp_dir, "host_file_%s" %
utils_misc.generate_random_string(8)) utils_misc.generate_random_string(8))
guest_path = os.path.join("/home", "guest_file_%s" % guest_path = os.path.join("/home", "guest_file_%s" %
utils_misc.generate_random_string(8)) utils_misc.generate_random_string(8))
cmd = "dd if=/dev/zero of=%s bs=1M count=%d" % (host_path, filesize) cmd = "dd if=/dev/zero of=%s bs=1M count=%d" % (host_path, filesize)
utils.run(cmd) process.run(cmd)
file_checksum = utils.hash_file(host_path, "md5") file_checksum = crypto.hash_file(host_path, "md5")
error.context("Guest test file prepare, Copy file %s from host to guest" error_context.context("Guest test file prepare, Copy file %s from host to "
% host_path, logging.info) "guest" % host_path, logging.info)
vm.copy_files_to(host_path, guest_path, timeout=transfer_timeout) vm.copy_files_to(host_path, guest_path, timeout=transfer_timeout)
if session.cmd_status("md5sum %s | grep %s" % if session.cmd_status("md5sum %s | grep %s" %
(guest_path, file_checksum)): (guest_path, file_checksum)):
raise error.TestNAError("File MD5SUMs changed after copy to guest") test.cancel("File MD5SUMs changed after copy to guest")
logging.info("Test env prepare successfully") logging.info("Test env prepare successfully")
error.base_context("Nic driver load/unload testing", logging.info) error_context.base_context("Nic driver load/unload testing", logging.info)
session_serial = vm.wait_for_serial_login(timeout=timeout) session_serial = vm.wait_for_serial_login(timeout=timeout)
try: try:
error.context("Transfer file between host and guest", logging.info) error_context.context("Transfer file between host and guest", logging.info)
threads = [] threads = []
file_paths = [] file_paths = []
host_file_paths = [] host_file_paths = []
...@@ -116,13 +115,13 @@ def run(test, params, env): ...@@ -116,13 +115,13 @@ def run(test, params, env):
sess_path = os.path.join("/home", "dst-%s" % sess_index) sess_path = os.path.join("/home", "dst-%s" % sess_index)
host_sess_path = os.path.join(tmp_dir, "dst-%s" % sess_index) host_sess_path = os.path.join(tmp_dir, "dst-%s" % sess_index)
thread1 = utils.InterruptedThread(vm.copy_files_to, thread1 = utils_misc.InterruptedThread(
(host_path, sess_path), vm.copy_files_to, (host_path, sess_path),
{"timeout": transfer_timeout}) {"timeout": transfer_timeout})
thread2 = utils.InterruptedThread(vm.copy_files_from, thread2 = utils_misc.InterruptedThread(
(guest_path, host_sess_path), vm.copy_files_from, (guest_path, host_sess_path),
{"timeout": transfer_timeout}) {"timeout": transfer_timeout})
thread1.start() thread1.start()
threads.append(thread1) threads.append(thread1)
thread2.start() thread2.start()
...@@ -133,23 +132,23 @@ def run(test, params, env): ...@@ -133,23 +132,23 @@ def run(test, params, env):
utils_misc.wait_for(lambda: all_threads_alive(threads), 60, 10, 1) utils_misc.wait_for(lambda: all_threads_alive(threads), 60, 10, 1)
time.sleep(5) time.sleep(5)
error.context("Repeatedly unload/load NIC driver during file transfer", error_context.context("Repeatedly unload/load NIC driver during file "
logging.info) "transfer", logging.info)
while not all_threads_done(threads): while not all_threads_done(threads):
error.context("Shutdown the driver for NIC interface.", error_context.context("Shutdown the driver for NIC interface.",
logging.info) logging.info)
session_serial.cmd_output_safe("ifconfig %s down" % ethname) session_serial.cmd_output_safe("ifconfig %s down" % ethname)
error.context("Unload NIC driver.", logging.info) error_context.context("Unload NIC driver.", logging.info)
session_serial.cmd_output_safe("modprobe -r %s" % driver) session_serial.cmd_output_safe("modprobe -r %s" % driver)
error.context("Load NIC driver.", logging.info) error_context.context("Load NIC driver.", logging.info)
session_serial.cmd_output_safe("modprobe %s" % driver) session_serial.cmd_output_safe("modprobe %s" % driver)
error.context("Activate NIC driver.", logging.info) error_context.context("Activate NIC driver.", logging.info)
session_serial.cmd_output_safe("ifconfig %s up" % ethname) session_serial.cmd_output_safe("ifconfig %s up" % ethname)
session_serial.cmd_output_safe("sleep %s" % random.randint(10, 60)) session_serial.cmd_output_safe("sleep %s" % random.randint(10, 60))
# files md5sums check # files md5sums check
error.context("File transfer finished, checking files md5sums", error_context.context("File transfer finished, checking files md5sums",
logging.info) logging.info)
err_info = [] err_info = []
for copied_file in file_paths: for copied_file in file_paths:
if session_serial.cmd_status("md5sum %s | grep %s" % if session_serial.cmd_status("md5sum %s | grep %s" %
...@@ -157,13 +156,12 @@ def run(test, params, env): ...@@ -157,13 +156,12 @@ def run(test, params, env):
err_msg = "Guest file %s md5sum changed" err_msg = "Guest file %s md5sum changed"
err_info.append(err_msg % copied_file) err_info.append(err_msg % copied_file)
for copied_file in host_file_paths: for copied_file in host_file_paths:
if utils.system("md5sum %s | grep %s" % if process.system("md5sum %s | grep %s" %
(copied_file, file_checksum)): (copied_file, file_checksum)):
err_msg = "Host file %s md5sum changed" err_msg = "Host file %s md5sum changed"
err_info.append(err_msg % copied_file) err_info.append(err_msg % copied_file)
if err_info: if err_info:
raise error.TestError("files MD5SUMs changed after copying %s" % test.error("files MD5SUMs changed after copying %s" % err_info)
err_info)
except Exception: except Exception:
for thread in threads: for thread in threads:
thread.join(suppress_exception=True) thread.join(suppress_exception=True)
...@@ -174,7 +172,7 @@ def run(test, params, env): ...@@ -174,7 +172,7 @@ def run(test, params, env):
for copied_file in file_paths: for copied_file in file_paths:
session_serial.cmd("rm -rf %s" % copied_file) session_serial.cmd("rm -rf %s" % copied_file)
for copied_file in host_file_paths: for copied_file in host_file_paths:
utils.system("rm -rf %s" % copied_file) process.system("rm -rf %s" % copied_file)
session_serial.cmd("%s %s" % ("rm -rf", guest_path)) session_serial.cmd("%s %s" % ("rm -rf", guest_path))
os.remove(host_path) os.remove(host_path)
session.close() session.close()
......
...@@ -3,9 +3,7 @@ import time ...@@ -3,9 +3,7 @@ import time
import aexpect import aexpect
from autotest.client.shared import utils from avocado.utils import process
from autotest.client.shared import error
from virttest import remote from virttest import remote
from virttest import utils_test from virttest import utils_test
from virttest.staging import service from virttest.staging import service
...@@ -17,14 +15,15 @@ class NTPTest(object): ...@@ -17,14 +15,15 @@ class NTPTest(object):
This class is for ntpd test This class is for ntpd test
""" """
def __init__(self, params, env): def __init__(self, test, params, env):
""" """
Initialize the object and set a few attributes. Initialize the object and set a few attributes.
""" """
self.test = test
self.server_hostname = None self.server_hostname = None
self.server_ip = params.get("remote_ip") self.server_ip = params.get("remote_ip")
if self.server_ip.count("REMOTE"): if self.server_ip.count("REMOTE"):
raise error.TestNAError("Please set server ip!") self.test.cancel("Please set server ip!")
self.server_user = params.get("remote_user") self.server_user = params.get("remote_user")
self.server_password = params.get("remote_pwd") self.server_password = params.get("remote_pwd")
self.local_clock = params.get("local_clock") self.local_clock = params.get("local_clock")
...@@ -44,7 +43,7 @@ class NTPTest(object): ...@@ -44,7 +43,7 @@ class NTPTest(object):
r"[\$#]\s*$") r"[\$#]\s*$")
self.session = self.vm.wait_for_login() self.session = self.vm.wait_for_login()
except remote.LoginTimeoutError, detail: except remote.LoginTimeoutError, detail:
raise error.TestNAError(str(detail)) self.test.cancel(str(detail))
def close_session(self): def close_session(self):
""" """
...@@ -68,7 +67,7 @@ class NTPTest(object): ...@@ -68,7 +67,7 @@ class NTPTest(object):
cmd = 'echo \'ZONE = "America/New_York"\' > /etc/sysconfig/clock' cmd = 'echo \'ZONE = "America/New_York"\' > /etc/sysconfig/clock'
status = self.server_session.cmd_status(cmd) status = self.server_session.cmd_status(cmd)
if status: if status:
raise error.TestError("set ZONE in server failed.") self.test.error("set ZONE in server failed.")
cmd_ln = 'ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime' cmd_ln = 'ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime'
self.server_session.cmd_status(cmd_ln) self.server_session.cmd_status(cmd_ln)
...@@ -81,7 +80,7 @@ class NTPTest(object): ...@@ -81,7 +80,7 @@ class NTPTest(object):
"/etc/ntp.conf" "/etc/ntp.conf"
% self.local_clock) % self.local_clock)
if status: if status:
raise error.TestError("config local_clock failed.") self.test.error("config local_clock failed.")
# Add host and guest in restrict # Add host and guest in restrict
output = self.server_session.cmd_output("grep '^restrict %s'" output = self.server_session.cmd_output("grep '^restrict %s'"
...@@ -95,7 +94,7 @@ class NTPTest(object): ...@@ -95,7 +94,7 @@ class NTPTest(object):
self.mask, self.mask,
self.restrict_option)) self.restrict_option))
if status: if status:
raise error.TestError("config restrict failed.") self.test.error("config restrict failed.")
# Restart ntpd service # Restart ntpd service
server_run = remote.RemoteRunner(session=self.server_session) server_run = remote.RemoteRunner(session=self.server_session)
...@@ -114,17 +113,17 @@ class NTPTest(object): ...@@ -114,17 +113,17 @@ class NTPTest(object):
# Set the time zone to New_York # Set the time zone to New_York
cmd = ('echo \'ZONE = "America/New_York"\' > /etc/sysconfig/clock;') cmd = ('echo \'ZONE = "America/New_York"\' > /etc/sysconfig/clock;')
try: try:
utils.run(cmd, ignore_status=False) process.run(cmd, ignore_status=False)
except error.CmdError, detail: except process.CmdError, detail:
raise error.TestFail("set Zone on host failed.%s" % detail) self.test.fail("set Zone on host failed.%s" % detail)
cmd_ln = 'ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime' cmd_ln = 'ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime'
utils.run(cmd_ln, ignore_status=True) process.run(cmd_ln, ignore_status=True)
# Check the cpu info of constant_tsc # Check the cpu info of constant_tsc
cmd = "cat /proc/cpuinfo | grep constant_tsc" cmd = "cat /proc/cpuinfo | grep constant_tsc"
result = utils.run(cmd) result = process.run(cmd)
if not result.stdout.strip(): if not result.stdout.strip():
raise error.TestFail("constant_tsc not available in this system!!") self.test.fail("constant_tsc not available in this system!!")
# Stop ntpd to use ntpdate # Stop ntpd to use ntpdate
host_ntpd = service.Factory.create_service("ntpd") host_ntpd = service.Factory.create_service("ntpd")
...@@ -139,22 +138,22 @@ class NTPTest(object): ...@@ -139,22 +138,22 @@ class NTPTest(object):
logging.info("server time: %s" % server_date) logging.info("server time: %s" % server_date)
logging.info("host time: %s" % host_date) logging.info("host time: %s" % host_date)
if not abs(int(server_date) - int(host_date)) < 2: if not abs(int(server_date) - int(host_date)) < 2:
raise error.TestFail("timing by ntpdate on host failed!!") self.test.fail("timing by ntpdate on host failed!!")
# Delete server of local clock # Delete server of local clock
result = utils.run("grep '^server %s' /etc/ntp.conf" % self.local_clock, result = process.run("grep '^server %s' /etc/ntp.conf" %
ignore_status=True) self.local_clock, ignore_status=True)
if result.stdout.strip(): if result.stdout.strip():
utils.run("sed -i '/%s/d' /etc/ntp.conf" % self.local_clock) process.run("sed -i '/%s/d' /etc/ntp.conf" % self.local_clock)
# Check the ntp.conf and add server ip into it # Check the ntp.conf and add server ip into it
cmd = "grep '^server %s' /etc/ntp.conf" % self.server_ip cmd = "grep '^server %s' /etc/ntp.conf" % self.server_ip
result = utils.run(cmd, ignore_status=True) result = process.run(cmd, ignore_status=True)
if not result.stdout.strip(): if not result.stdout.strip():
cmd = "echo 'server %s' >> /etc/ntp.conf" % self.server_ip cmd = "echo 'server %s' >> /etc/ntp.conf" % self.server_ip
try: try:
utils.run(cmd, ignore_status=False) process.run(cmd, ignore_status=False)
except error.CmdError, detail: except process.CmdError, detail:
raise error.TestFail("config /etc/ntp.conf on host failed!!") self.test.fail("config /etc/ntp.conf on host failed!!")
# Start ntpd service # Start ntpd service
host_ntpd.start() host_ntpd.start()
...@@ -188,7 +187,7 @@ class NTPTest(object): ...@@ -188,7 +187,7 @@ class NTPTest(object):
logging.info("server time is : %s" % server_date) logging.info("server time is : %s" % server_date)
logging.info("guest time is : %s " % guest_date) logging.info("guest time is : %s " % guest_date)
if not abs(int(server_date) - int(guest_date)) < 2: if not abs(int(server_date) - int(guest_date)) < 2:
raise error.TestFail("timing by ntpdate on guest failed!!") self.test.fail("timing by ntpdate on guest failed!!")
# Delete server of local clock # Delete server of local clock
output = self.session.cmd_output("grep '%s' /etc/ntp.conf" output = self.session.cmd_output("grep '%s' /etc/ntp.conf"
...@@ -202,7 +201,7 @@ class NTPTest(object): ...@@ -202,7 +201,7 @@ class NTPTest(object):
cmd = "echo 'server %s' >> /etc/ntp.conf" % self.server_ip cmd = "echo 'server %s' >> /etc/ntp.conf" % self.server_ip
status = self.session.cmd_status(cmd) status = self.session.cmd_status(cmd)
if status: if status:
raise error.TestFail("config /etc/ntp.conf on server failed!!") self.test.fail("config /etc/ntp.conf on server failed!!")
# Start the ntpd service # Start the ntpd service
guest_ntpd.start() guest_ntpd.start()
...@@ -219,18 +218,16 @@ class NTPTest(object): ...@@ -219,18 +218,16 @@ class NTPTest(object):
cmd_name = "" cmd_name = ""
if self.server_hostname: if self.server_hostname:
cmd_name = "ntpq -p | grep '^*%s'" % self.server_hostname cmd_name = "ntpq -p | grep '^*%s'" % self.server_hostname
result_ntpq_ip = utils.run(cmd_ip, ignore_status=True) result_ntpq_ip = process.run(cmd_ip, ignore_status=True)
result_ntpq_name = utils.run(cmd_name, ignore_status=True) result_ntpq_name = process.run(cmd_name, ignore_status=True)
if (not result_ntpq_ip.stdout.strip() and if (not result_ntpq_ip.stdout.strip() and
not result_ntpq_name.stdout.strip()): not result_ntpq_name.stdout.strip()):
raise error.TestFail("ntpd setting failed of %s host !!" self.test.fail("ntpd setting failed of %s host !!" % self.vm_name)
% self.vm_name)
# Test on guest # Test on guest
output_ip = self.session.cmd_output(cmd_ip).strip() output_ip = self.session.cmd_output(cmd_ip).strip()
output_name = self.session.cmd_output(cmd_name).strip() output_name = self.session.cmd_output(cmd_name).strip()
if not output_ip and not output_name: if not output_ip and not output_name:
raise error.TestFail("ntpd setting failed of %s guest !!" self.test.fail("ntpd setting failed of %s guest !!" % self.vm_name)
% self.vm_name)
def long_time_test(self): def long_time_test(self):
""" """
...@@ -243,7 +240,7 @@ class NTPTest(object): ...@@ -243,7 +240,7 @@ class NTPTest(object):
logging.info("server time is %s" % server_date) logging.info("server time is %s" % server_date)
logging.info("guest time is %s" % guest_date) logging.info("guest time is %s" % guest_date)
if not abs(int(server_date) - int(guest_date)) < 2: if not abs(int(server_date) - int(guest_date)) < 2:
raise error.TestFail("timing by ntpd on guest failed") self.test.fail("timing by ntpd on guest failed")
def run(test, params, env): def run(test, params, env):
...@@ -258,12 +255,12 @@ def run(test, params, env): ...@@ -258,12 +255,12 @@ def run(test, params, env):
5.After long time, test ntpd service still works on guest. 5.After long time, test ntpd service still works on guest.
""" """
ntp_test = NTPTest(params, env) ntp_test = NTPTest(test, params, env)
ping_s, _ = utils_test.ping(ntp_test.server_ip, count=1, ping_s, _ = utils_test.ping(ntp_test.server_ip, count=1,
timeout=5, session=ntp_test.session) timeout=5, session=ntp_test.session)
if ping_s: if ping_s:
ntp_test.close_session() ntp_test.close_session()
raise error.TestNAError("Please make sure the guest can ping server!") test.cancel("Please make sure the guest can ping server!")
# Start test from here # Start test from here
try: try:
...@@ -271,7 +268,7 @@ def run(test, params, env): ...@@ -271,7 +268,7 @@ def run(test, params, env):
try: try:
ntp_test.server_config() ntp_test.server_config()
except (aexpect.ShellError, remote.LoginTimeoutError), detail: except (aexpect.ShellError, remote.LoginTimeoutError), detail:
raise error.TestFail("server config failed. %s" % detail) test.fail("server config failed. %s" % detail)
logging.info("waiting for ntp server : %s s" % ntp_test.ntpdate_sleep) logging.info("waiting for ntp server : %s s" % ntp_test.ntpdate_sleep)
# Host and Guest will use server's ntpd service to set time. # Host and Guest will use server's ntpd service to set time.
# here wait for some seconds for server ntpd service valid # here wait for some seconds for server ntpd service valid
...@@ -281,24 +278,24 @@ def run(test, params, env): ...@@ -281,24 +278,24 @@ def run(test, params, env):
try: try:
ntp_test.host_config() ntp_test.host_config()
except (aexpect.ShellError, remote.LoginTimeoutError), detail: except (aexpect.ShellError, remote.LoginTimeoutError), detail:
raise error.TestFail("host config failed.%s" % detail) test.fail("host config failed.%s" % detail)
# Guest configuration # Guest configuration
try: try:
ntp_test.guest_config() ntp_test.guest_config()
except (aexpect.ShellError, remote.LoginTimeoutError), detail: except (aexpect.ShellError, remote.LoginTimeoutError), detail:
raise error.TestFail("guest config failed.%s" % detail) test.fail("guest config failed.%s" % detail)
try: try:
# Wait 20min for ntpq test # Wait 20min for ntpq test
ntp_test.ntpq_test() ntp_test.ntpq_test()
except (aexpect.ShellError, remote.LoginTimeoutError), detail: except (aexpect.ShellError, remote.LoginTimeoutError), detail:
raise error.TestFail("ntpq test failed.%s" % detail) test.fail("ntpq test failed.%s" % detail)
try: try:
# Wait 24h for test # Wait 24h for test
ntp_test.long_time_test() ntp_test.long_time_test()
except (aexpect.ShellError, remote.LoginTimeoutError), detail: except (aexpect.ShellError, remote.LoginTimeoutError), detail:
raise error.TestFail("long time test failed.%s" % detail) test.fail("long time test failed.%s" % detail)
finally: finally:
ntp_test.close_session() ntp_test.close_session()
...@@ -6,12 +6,11 @@ import commands ...@@ -6,12 +6,11 @@ import commands
import aexpect import aexpect
from autotest.client.shared import error from avocado.utils import process
from autotest.client.shared import utils
from virttest import utils_misc from virttest import utils_misc
from virttest import utils_test from virttest import utils_test
from virttest import remote from virttest import remote
from virttest import error_context
_receiver_ready = False _receiver_ready = False
...@@ -44,8 +43,8 @@ def run(test, params, env): ...@@ -44,8 +43,8 @@ def run(test, params, env):
vm_receiver = None vm_receiver = None
receiver_addr = params.get("receiver_address") receiver_addr = params.get("receiver_address")
logging.debug(utils.system("numactl --hardware", ignore_status=True)) logging.debug(process.system("numactl --hardware", ignore_status=True))
logging.debug(utils.system("numactl --show", ignore_status=True)) logging.debug(process.system("numactl --show", ignore_status=True))
# pin guest vcpus/memory/vhost threads to last numa node of host by default # pin guest vcpus/memory/vhost threads to last numa node of host by default
if params.get('numa_node'): if params.get('numa_node'):
numa_node = int(params.get('numa_node')) numa_node = int(params.get('numa_node'))
...@@ -60,25 +59,25 @@ def run(test, params, env): ...@@ -60,25 +59,25 @@ def run(test, params, env):
sess = vm_receiver.wait_for_login(timeout=login_timeout) sess = vm_receiver.wait_for_login(timeout=login_timeout)
receiver_addr = vm_receiver.get_address() receiver_addr = vm_receiver.get_address()
if not receiver_addr: if not receiver_addr:
raise error.TestError("Can't get receiver(%s) ip address" % test.error("Can't get receiver(%s) ip address" %
vm_sender.name) vm_sender.name)
if params.get('numa_node'): if params.get('numa_node'):
utils_test.qemu.pin_vm_threads(vm_receiver, node) utils_test.qemu.pin_vm_threads(vm_receiver, node)
finally: finally:
if sess: if sess:
sess.close() sess.close()
@error.context_aware @error_context.context_aware
def install_ntttcp(session): def install_ntttcp(session):
""" Install ntttcp through a remote session """ """ Install ntttcp through a remote session """
logging.info("Installing NTttcp ...") logging.info("Installing NTttcp ...")
try: try:
# Don't install ntttcp if it's already installed # Don't install ntttcp if it's already installed
error.context("NTttcp directory already exists") error_context.context("NTttcp directory already exists")
session.cmd(params.get("check_ntttcp_cmd")) session.cmd(params.get("check_ntttcp_cmd"))
except aexpect.ShellCmdError: except aexpect.ShellCmdError:
ntttcp_install_cmd = params.get("ntttcp_install_cmd") ntttcp_install_cmd = params.get("ntttcp_install_cmd")
error.context("Installing NTttcp on guest") error_context.context("Installing NTttcp on guest")
session.cmd(ntttcp_install_cmd % (platform, platform), timeout=200) session.cmd(ntttcp_install_cmd % (platform, platform), timeout=200)
def receiver(): def receiver():
...@@ -168,13 +167,13 @@ def run(test, params, env): ...@@ -168,13 +167,13 @@ def run(test, params, env):
return lst return lst
try: try:
bg = utils.InterruptedThread(receiver, ()) bg = utils_misc.InterruptedThread(receiver, ())
bg.start() bg.start()
if bg.isAlive(): if bg.isAlive():
sender() sender()
bg.join(suppress_exception=True) bg.join(suppress_exception=True)
else: else:
raise error.TestError("Can't start backgroud receiver thread") test.error("Can't start backgroud receiver thread")
finally: finally:
for i in glob.glob("%s.receiver" % results_path): for i in glob.glob("%s.receiver" % results_path):
f = open("%s.RHS" % results_path, "w") f = open("%s.RHS" % results_path, "w")
......
import logging import logging
from autotest.client.shared import error from avocado.utils import process
from autotest.client import utils
from virttest import utils_test from virttest import utils_test
from virttest import utils_net from virttest import utils_net
from virttest import error_context from virttest import error_context
...@@ -71,8 +69,8 @@ def run(test, params, env): ...@@ -71,8 +69,8 @@ def run(test, params, env):
ext_host = params.get("ext_host", "") ext_host = params.get("ext_host", "")
ext_host_get_cmd = params.get("ext_host_get_cmd", "") ext_host_get_cmd = params.get("ext_host_get_cmd", "")
try: try:
ext_host = utils.system_output(ext_host_get_cmd) ext_host = process.system_output(ext_host_get_cmd)
except error.CmdError: except process.CmdError:
logging.warn("Can't get specified host with cmd '%s'," logging.warn("Can't get specified host with cmd '%s',"
" Fallback to default host '%s'", " Fallback to default host '%s'",
ext_host_get_cmd, ext_host) ext_host_get_cmd, ext_host)
......
...@@ -2,10 +2,10 @@ import logging ...@@ -2,10 +2,10 @@ import logging
import aexpect import aexpect
from autotest.client.shared import error from virttest import error_context
@error.context_aware @error_context.context_aware
def run(test, params, env): def run(test, params, env):
""" """
PXE test: PXE test:
...@@ -18,18 +18,16 @@ def run(test, params, env): ...@@ -18,18 +18,16 @@ def run(test, params, env):
:param params: Dictionary with the test parameters. :param params: Dictionary with the test parameters.
:param env: Dictionary with test environment. :param env: Dictionary with test environment.
""" """
error.context("Try to boot from NIC", logging.info) error_context.context("Try to boot from NIC", logging.info)
vm = env.get_vm(params["main_vm"]) vm = env.get_vm(params["main_vm"])
vm.verify_alive() vm.verify_alive()
timeout = int(params.get("pxe_timeout", 60)) timeout = int(params.get("pxe_timeout", 60))
error.context("Snoop packet in the tap device", logging.info) error_context.context("Snoop packet in the tap device", logging.info)
output = aexpect.run_fg("tcpdump -nli %s" % vm.get_ifname(), output = aexpect.run_fg("tcpdump -nli %s" % vm.get_ifname(),
logging.debug, "(pxe capture) ", timeout)[1] logging.debug, "(pxe capture) ", timeout)[1]
error.context("Analyzing the tcpdump result", logging.info) error_context.context("Analyzing the tcpdump result", logging.info)
if "tftp" not in output: if "tftp" not in output:
raise error.TestFail( test.fail("Couldn't find any TFTP packets after %s seconds" % timeout)
"Couldn't find any TFTP packets after %s seconds" %
timeout)
logging.info("Found TFTP packet") logging.info("Found TFTP packet")
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册