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

Merge pull request #1293 from luckyh/replace-autotest-qemu-p8

[qemu] Replace autotest modules - n
......@@ -2,15 +2,14 @@ import os
import logging
import time
from autotest.client.shared import error
from virttest import error_context
from virttest import utils_net
from virttest import utils_netperf
from virttest import utils_misc
from virttest import data_dir
@error.context_aware
@error_context.context_aware
def run(test, params, env):
"""
Run netperf stress on server and client side.
......@@ -227,7 +226,8 @@ def run(test, params, env):
num = 0
s_len = len(server_infos)
for protocol in test_protocols.split():
error.context("Testing %s protocol" % protocol, logging.info)
error_context.context("Testing %s protocol" % protocol,
logging.info)
t_option = "%s -t %s" % (test_option, protocol)
for n_client in netperf_clients:
index = num % s_len
......@@ -239,7 +239,7 @@ def run(test, params, env):
"Wait netperf test start"):
logging.info("Netperf test start successfully.")
else:
raise error.TestError("Can not start netperf client.")
test.error("Can not start netperf client.")
num += 1
# here when set a run flag, when other case call this case as a
# subprocess backgroundly, can set this run flag to False to stop
......
......@@ -2,14 +2,13 @@ import logging
import os
import re
from autotest.client.shared import error
from virttest import error_context
from virttest import utils_net
from virttest import utils_netperf
from virttest import data_dir
@error.context_aware
@error_context.context_aware
def run(test, params, env):
"""
Run netperf on server and client side, we need run this case on two
......@@ -39,7 +38,7 @@ def run(test, params, env):
main_vm_ip = vm.get_address()
session.cmd("iptables -F", ignore_all_errors=True)
error.context("Test env prepare", logging.info)
error_context.context("Test env prepare", logging.info)
netperf_link = params.get("netperf_link")
if netperf_link:
netperf_link = os.path.join(data_dir.get_deps_dir("netperf"),
......@@ -147,7 +146,7 @@ def run(test, params, env):
throughput = []
try:
error.context("Start netperf_server", logging.info)
error_context.context("Start netperf_server", logging.info)
netperf_server.start()
# Run netperf with message size defined in range.
msg = "Detail result of netperf test with different packet size.\n"
......@@ -155,7 +154,7 @@ def run(test, params, env):
test_protocol = params.get("test_protocol", "UDP_STREAM")
test_option = "-t %s -- -m %s" % (test_protocol, m_size)
txt = "Run netperf client with protocol: '%s', packet size: '%s'"
error.context(txt % (test_protocol, m_size), logging.info)
error_context.context(txt % (test_protocol, m_size), logging.info)
output = netperf_client.start(netserver_ip, test_option)
re_str = "[0-9\.]+\s+[0-9\.]+\s+[0-9\.]+\s+[0-9\.]+\s+[0-9\.]+"
re_str += "\s+[0-9\.]+"
......@@ -164,9 +163,9 @@ def run(test, params, env):
except IndexError:
txt = "Fail to get Throughput for %s." % m_size
txt += " netprf client output: %s" % output
raise error.TestError(txt)
test.error(txt)
if not line_tokens:
raise error.TestError("Output format is not expected")
test.error("Output format is not expected")
throughput.append(float(line_tokens[5]))
msg += output
m_size += step
......@@ -175,17 +174,17 @@ def run(test, params, env):
file(os.path.join(test.debugdir, "udp_results"), "w").write(msg)
failratio = float(params.get("failratio", 0.3))
error.context("Compare UDP performance.", logging.info)
error_context.context("Compare UDP performance.", logging.info)
for i in range(len(throughput) - 1):
if abs(throughput[i] - throughput[i + 1]) > throughput[i] * failratio:
txt = "The gap between adjacent throughput is greater than"
txt += "%f." % failratio
txt += "Please refer to log file for details:\n %s" % msg
raise error.TestFail(txt)
test.fail(txt)
logging.info("The UDP performance as measured via netperf is ok.")
logging.info("Throughput of netperf command: %s" % throughput)
logging.debug("Output of netperf command:\n %s" % msg)
error.context("Kill netperf server on server (dsthost).")
error_context.context("Kill netperf server on server (dsthost).")
try:
if session:
......
......@@ -2,15 +2,15 @@ import logging
import re
import os
from autotest.client.shared import error
from autotest.client import utils
from avocado.utils import process
from virttest import error_context
from virttest import utils_misc
STEP_1, STEP_2, STEP_3, STEP_4, STEP_5, STEP_6 = range(6)
@error.context_aware
@error_context.context_aware
def run(test, params, env):
"""
KVM nfs performance test:
......@@ -41,7 +41,7 @@ def run(test, params, env):
" error message:\n%s", func.__name__, e)
def _clean_up(step_cnt):
error.context("Clean up", logging.info)
error_context.context("Clean up", logging.info)
if step_cnt >= STEP_5:
# remove test file.
cmd = "rm -f %s" % " ".join(test_file_list)
......@@ -65,7 +65,7 @@ def run(test, params, env):
# Clean up caches
session.cmd("echo 3 >/proc/sys/vm/drop_caches")
error.context("test %s size block write performance in guest"
error_context.context("test %s size block write performance in guest"
" using dd commands" % blk_size, logging.info)
dd_cmd = "dd"
dd_cmd += " if=/dev/zero"
......@@ -85,7 +85,7 @@ def run(test, params, env):
# Clean up caches
session.cmd("echo 3 >/proc/sys/vm/drop_caches")
error.context("test %s size block read performance in guest"
error_context.context("test %s size block read performance in guest"
" using dd commands" % blk_size, logging.info)
dd_cmd = "dd"
dd_cmd += " if=%s" % test_file
......@@ -102,10 +102,10 @@ def run(test, params, env):
return out
if not hasattr(test, "write_perf_keyval"):
raise error.TestNAError("There is no 'write_perf_keyval' method in"
test.cancel("There is no 'write_perf_keyval' method in"
" test object, skip this test")
error.context("boot guest over virtio driver", logging.info)
error_context.context("boot guest over virtio driver", logging.info)
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
timeout = int(params.get("login_timeout", 360))
......@@ -117,13 +117,14 @@ def run(test, params, env):
kvm_userspace_ver_cmd = params.get("kvm_userspace_ver_cmd", "")
if kvm_userspace_ver_cmd:
try:
cmd_result = utils.run(kvm_userspace_ver_cmd)
cmd_result = process.run(kvm_userspace_ver_cmd)
qemu_version = cmd_result.stdout.strip()
except error.CmdError:
except process.CmdError:
qemu_version = "Unknown"
else:
qemu_path = utils_misc.get_qemu_binary(params)
version_line = utils.system_output("%s -help | head -n 1" % qemu_path)
version_line = process.system_output("%s -help | head -n 1"
% qemu_path)
matches = re.findall("version .*?,", version_line, re.I)
if matches:
qemu_version = " ".join(matches[0].split()[1:]).strip(",")
......@@ -140,7 +141,8 @@ def run(test, params, env):
raise
# After STEP 2
error.context("mount nfs server in guest with tcp protocol", logging.info)
error_context.context("mount nfs server in guest with tcp protocol",
logging.info)
nfs_server = params.get("nfs_server")
nfs_path = params.get("nfs_path")
mnt_option = params.get("mnt_option")
......@@ -153,7 +155,7 @@ def run(test, params, env):
if (not nfs_server) or (not nfs_path) or (not mnt_point):
_clean_up(STEP_2)
raise error.TestError("Missing configuration for nfs partition."
test.error("Missing configuration for nfs partition."
" Check your config files")
try:
......@@ -201,7 +203,7 @@ def run(test, params, env):
tmp_list = re.findall(speed_pattern, out)
if not tmp_list:
_clean_up(STEP_5)
raise error.TestError("Could not get correct write result."
test.error("Could not get correct write result."
" dd cmd output:\n%s" % out)
_, _, speed = tmp_list[0]
speed = utils_misc.normalize_data_size(speed)
......@@ -213,7 +215,7 @@ def run(test, params, env):
tmp_list = re.findall(speed_pattern, out)
if not tmp_list:
_clean_up(STEP_6)
raise error.TestError("Could not get correct read result."
test.error("Could not get correct read result."
" dd cmd output:\n%s" % out)
_, _, speed = tmp_list[0]
speed = utils_misc.normalize_data_size(speed)
......
......@@ -4,11 +4,9 @@ import random
import aexpect
from autotest.client.shared import error
from autotest.client.shared import utils
from virttest import utils_test
from virttest import utils_net
from virttest import utils_misc
def run(test, params, env):
......@@ -65,15 +63,15 @@ def run(test, params, env):
utils_test.run_file_transfer(test, params, env)
logging.info("Failover test with file transfer")
transfer_thread = utils.InterruptedThread(utils_test.run_file_transfer,
(test, params, env))
transfer_thread = utils_misc.InterruptedThread(
utils_test.run_file_transfer, (test, params, env))
transfer_thread.start()
try:
while transfer_thread.isAlive():
for vlan, nic in enumerate(vm.virtnet):
device_id = nic.device_id
if not device_id:
raise error.TestError("Could not find peer device for"
test.error("Could not find peer device for"
" nic device %s" % nic)
vm.set_link(device_id, up=False)
time.sleep(random.randint(1, 30))
......@@ -86,8 +84,8 @@ def run(test, params, env):
transfer_thread.join()
logging.info("Failover test 2 with file transfer")
transfer_thread = utils.InterruptedThread(utils_test.run_file_transfer,
(test, params, env))
transfer_thread = utils_misc.InterruptedThread(
utils_test.run_file_transfer, (test, params, env))
transfer_thread.start()
try:
nic_num = len(vm.virtnet)
......@@ -97,7 +95,7 @@ def run(test, params, env):
for num in xrange(nic_num):
device_id = vm.virtnet[num].device_id
if not device_id:
raise error.TestError("Could not find peer device for"
test.error("Could not find peer device for"
" nic device %s" % nic)
if num == up_index:
vm.set_link(device_id, up=True)
......
......@@ -2,16 +2,16 @@ import time
import logging
import re
from autotest.client.shared import error
from autotest.client.shared import utils
from avocado.utils import process
from virttest import error_context
from virttest import utils_test
from virttest import utils_misc
from virttest import env_process
from virttest import utils_net
@error.context_aware
@error_context.context_aware
def run(test, params, env):
"""
Qemu host nic bonding test:
......@@ -40,19 +40,20 @@ def run(test, params, env):
params['netdst'] = bond_br_name
host_bridges = utils_net.Bridge()
error.context("Load bonding module with mode 802.3ad", logging.info)
if not utils.system("lsmod|grep bonding", ignore_status=True):
utils.system("modprobe -r bonding")
error_context.context("Load bonding module with mode 802.3ad",
logging.info)
if not process.system("lsmod|grep bonding", ignore_status=True):
process.system("modprobe -r bonding")
utils.system(
process.system(
"modprobe bonding mode=%s miimon=%s" %
(bonding_mode, bonding_miimon))
error.context("Bring up %s" % bond_iface, logging.info)
error_context.context("Bring up %s" % bond_iface, logging.info)
host_ifaces = utils_net.get_host_iface()
if bond_iface not in host_ifaces:
raise error.TestError("Can not find bond0 in host")
test.error("Can not find bond0 in host")
bond_iface = utils_net.Interface(bond_iface)
bond_iface.up()
......@@ -69,48 +70,49 @@ def run(test, params, env):
if (len(host_ph_ifaces_un) < 2 or
len(host_ph_ifaces_un) < host_iface_bonding):
raise error.TestNAError("Host need %s nics"
" at least." % host_iface_bonding)
test.cancel("Host need %s nics at least." % host_iface_bonding)
error.context("Add nics to %s" % bond_iface.name, logging.info)
error_context.context("Add nics to %s" % bond_iface.name, logging.info)
host_ifaces_bonding = host_ph_ifaces_un[:host_iface_bonding]
ifenslave_cmd = "ifenslave %s" % bond_iface.name
op_ifaces = []
for host_iface_bonding in host_ifaces_bonding:
op_ifaces.append(utils_net.Interface(host_iface_bonding))
ifenslave_cmd += " %s" % host_iface_bonding
utils.system(ifenslave_cmd)
process.system(ifenslave_cmd)
error.context("Add a new bridge and add %s to it." % bond_iface.name,
logging.info)
error_context.context("Add a new bridge and add %s to it."
% bond_iface.name, logging.info)
if bond_br_name not in host_bridges.list_br():
host_bridges.add_bridge(bond_br_name)
host_bridges.add_port(bond_br_name, bond_iface.name)
error.context("Get ip address for bridge", logging.info)
utils.system("dhclient -r; dhclient %s" % bond_br_name)
error_context.context("Get ip address for bridge", logging.info)
process.system("dhclient -r; dhclient %s" % bond_br_name)
error.context("Boot up guest with bridge %s" % bond_br_name, logging.info)
error_context.context("Boot up guest with bridge %s" % bond_br_name,
logging.info)
params["start_vm"] = "yes"
vm_name = params.get("main_vm")
env_process.preprocess_vm(test, params, env, vm_name)
vm = env.get_vm(vm_name)
session = vm.wait_for_login(timeout=timeout)
error.context("Checking guest netowrk via ping.", logging.info)
error_context.context("Checking guest netowrk via ping.", logging.info)
ping_cmd = params.get("ping_cmd")
ping_cmd = re.sub("REMOTE_HOST", remote_host, ping_cmd)
session.cmd(ping_cmd, timeout=ping_timeout)
error.context("Start file transfer", logging.info)
f_transfer = utils.InterruptedThread(utils_test.run_virt_sub_test,
error_context.context("Start file transfer", logging.info)
f_transfer = utils_misc.InterruptedThread(
utils_test.run_virt_sub_test,
args=(test, params, env,),
kwargs={"sub_type": "file_transfer"})
f_transfer.start()
utils_misc.wait_for(lambda: utils.system_output("pidof scp",
ignore_status=True), 30)
utils_misc.wait_for(
lambda: process.system_output("pidof scp", ignore_status=True), 30)
error.context("Disable and enable physical "
error_context.context("Disable and enable physical "
"interfaces in %s" % bond_br_name, logging.info)
while True:
for op_iface in op_ifaces:
......
import logging
import random
from autotest.client.shared import utils
from avocado.utils import process
from virttest import utils_test
from virttest import utils_net
......@@ -74,7 +74,7 @@ def run(test, params, env):
if nic_ip:
return nic_ip
cached_ip = vm.address_cache.get(nic["mac"])
arps = utils.system_output("arp -aen")
arps = process.system_output("arp -aen")
logging.debug("Can't get IP address:")
logging.debug("\tCached IP: %s", cached_ip)
logging.debug("\tARP table: %s", arps)
......
......@@ -3,14 +3,13 @@ import re
import random
import logging
from autotest.client.shared import error
from autotest.client.shared import utils
from virttest import error_context
from virttest import utils_test
from virttest import utils_net
from virttest import utils_misc
@error.context_aware
@error_context.context_aware
def run(test, params, env):
"""
Test failover by team driver
......@@ -35,13 +34,13 @@ def run(test, params, env):
ports = re.findall(r"%s" % params["ptn_teamnl"], output_teamnl)
for port in ifnames:
if port not in ports:
raise error.TestFail("Add %s to %s failed." % (port, team_if))
test.fail("Add %s to %s failed." % (port, team_if))
session_serial.cmd_output_safe(params["killdhclient_cmd"])
output = session_serial.cmd_output_safe(params["getip_cmd"],
timeout=300)
team_ip = re.search(r"%s" % params["ptn_ipv4"], output).group()
if not team_ip:
raise error.TestFail("Failed to get ip address of %s" % team_if)
test.fail("Failed to get ip address of %s" % team_if)
return ports, team_ip
def failover(ifnames, timeout):
......@@ -66,15 +65,14 @@ def run(test, params, env):
def check_ping(status, output):
""" ratio <5% is acceptance."""
if status != 0:
raise error.TestFail("Ping failed, staus:%s, output:%s"
% (status, output))
test.fail("Ping failed, staus:%s, output:%s" % (status, output))
# if status != 0 the ping process seams hit issue.
ratio = utils_test.get_loss_ratio(output)
if ratio == -1:
raise error.TestFail('''The ratio is %s, and status is %s,
output is %s''' % (ratio, status, output))
test.fail("The ratio is %s, and status is %s, "
"output is %s" % (ratio, status, output))
elif ratio > int(params["failed_ratio"]):
raise error.TestFail("The loss raito is %s, test failed" % ratio)
test.fail("The loss raito is %s, test failed" % ratio)
logging.info("ping pass with loss raito:%s, that less than %s" %
(ratio, params["failed_ratio"]))
......@@ -94,14 +92,15 @@ def run(test, params, env):
team_if = params.get("team_if")
# initial
error.context("Step1: Configure the team environment", logging.info)
error_context.context("Step1: Configure the team environment",
logging.info)
# steps of building the teaming environment starts
modprobe_cmd = "modprobe team"
session_serial.cmd_output_safe(modprobe_cmd)
session_serial.cmd_output_safe(params["createteam_cmd"])
# this cmd is to create the team0 and correspoding userspace daemon
if not team_if_exist():
raise error.TestFail("Interface %s is not created." % team_if)
test.fail("Interface %s is not created." % team_if)
# check if team0 is created successfully
ports, team_ip = team_port_add(ifnames, team_if)
logging.debug("The list of the ports that added to %s : %s"
......@@ -115,45 +114,48 @@ def run(test, params, env):
# steps of building finished
try:
error.context("Login in guest via ssh", logging.info)
error_context.context("Login in guest via ssh", logging.info)
# steps of testing this case starts
session = vm.wait_for_login(timeout=timeout)
dest = utils_net.get_ip_address_by_interface(params["netdst"])
count = params.get("count")
timeout = float(count) * 2
error.context("Step2: Check if guest can ping out:", logging.info)
error_context.context("Step2: Check if guest can ping out:",
logging.info)
status, output = utils_test.ping(dest=dest, count=10,
interface=team_if,
timeout=30,
session=session)
check_ping(status, output)
# small ping check if the team0 works w/o failover
error.context("Step3: Start failover testing until ping finished",
logging.info)
failover_thread = utils.InterruptedThread(failover, (ifnames, timeout))
error_context.context("Step3: Start failover testing until "
"ping finished", logging.info)
failover_thread = utils_misc.InterruptedThread(failover,
(ifnames, timeout))
failover_thread.start()
# start failover loop until ping finished
error.context("Step4: Start ping host for %s counts"
error_context.context("Step4: Start ping host for %s counts"
% count, logging.info)
if failover_thread.is_alive():
status, output = utils_test.ping(dest=dest, count=count,
interface=team_if,
timeout=float(count) * 1.5,
session=session)
error.context("Step5: Check if ping succeeded", logging.info)
error_context.context("Step5: Check if ping succeeded",
logging.info)
check_ping(status, output)
else:
raise error.TestWarn("The failover thread is not alive")
test.error("The failover thread is not alive")
time.sleep(3)
try:
timeout = timeout * 1.5
failover_thread.join(timeout)
except Exception:
raise error.TestWarn("Failed to join the failover thread")
test.error("Failed to join the failover thread")
# finish the main steps and check the result
session_serial.cmd_output_safe(params["killteam_cmd"])
if team_if_exist():
raise error.TestFail("Remove %s failed" % team_if)
test.fail("Remove %s failed" % team_if)
logging.info("%s removed" % team_if)
# remove the team0 and the daemon, check if succeed
finally:
......
import time
import logging
from autotest.client.shared import error
from virttest import error_context
@error.context_aware
@error_context.context_aware
def run(test, params, env):
"""
Generate a dump on NMI, then analyse the dump file:
......@@ -21,7 +22,7 @@ def run(test, params, env):
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
error.context("Boot a windows guest", logging.info)
error_context.context("Boot a windows guest", logging.info)
timeout = float(params.get("login_timeout", 360))
session = vm.wait_for_login(timeout=timeout)
manual_reboot_cmd = params.get("manual_reboot_cmd")
......@@ -34,7 +35,7 @@ def run(test, params, env):
session.sendline(del_dump_cmd)
if params.get("config_cmds"):
error.context("Configure guest for dump", logging.info)
error_context.context("Configure guest for dump", logging.info)
# Wait guest fully boot up, or configure command may fail in windows
time.sleep(30)
reg_cmds = params.get("config_cmds").split(",")
......@@ -42,18 +43,18 @@ def run(test, params, env):
for reg_cmd in reg_cmds:
cmd = params.get(reg_cmd.strip())
msg += " The command is %s " % cmd
error.context(msg)
error_context.context(msg)
s, o = session.cmd_status_output(cmd, 360)
if s:
raise error.TestFail("Fail command: %s. Output: %s" % (cmd, o))
test.fail("Fail command: %s. Output: %s" % (cmd, o))
if params.get("reboot_after_config") == "yes":
error.context("Reboot guest", logging.info)
error_context.context("Reboot guest", logging.info)
session = vm.reboot(timeout=timeout * 2)
try:
if nmi_cmd:
error.context("Send inject-nmi or nmi from host to guest",
error_context.context("Send inject-nmi or nmi from host to guest",
logging.info)
vm.monitor.send_args_cmd(nmi_cmd)
# Wait guest create dump file.
......@@ -62,28 +63,29 @@ def run(test, params, env):
logging.info("Waiting guest for creating dump file"
" (%ssec)" % bsod_time)
time.sleep(bsod_time)
error.context("Send a system_reset monitor command", logging.info)
error_context.context("Send a system_reset monitor command",
logging.info)
vm.monitor.send_args_cmd(manual_reboot_cmd)
session = vm.wait_for_login(timeout=timeout)
if check_dump_cmd:
error.context("Verify whether the dump files are generated",
logging.info)
error_context.context("Verify whether the dump files are "
"generated", logging.info)
s, o = session.cmd_status_output(check_dump_cmd, 360)
logging.debug("Output for check_dump_cmd command: %s" % o)
if s:
err_msg = "Could not find dump files in guest. Output: '%s'" % o
raise error.TestFail(err_msg)
test.fail(err_msg)
if analyze_cmd:
error.context("Analyze dump file in guest", logging.info)
error_context.context("Analyze dump file in guest", logging.info)
try:
vm.copy_files_from(params["dump_path"], ".", timeout=100)
except Exception:
pass
s, o = session.cmd_status_output(analyze_cmd, timeout=1200)
if s:
raise error.TestFail("Analysis Failed. Command: '%s'.\n\n"
test.fail("Analysis Failed. Command: '%s'.\n\n"
" Output: %s" % (analyze_cmd, o))
finally:
if session is not None and del_dump_cmd:
......
import time
import logging
from autotest.client.shared import error
from virttest import error_context
@error.context_aware
@error_context.context_aware
def run(test, params, env):
"""
Test the function of nmi injection and verify the response of guest
......@@ -27,16 +28,16 @@ def run(test, params, env):
"--args='nmi_watchdog=%d'" %
(kernel_version, nmi_watchdog_type))
error.context("Add 'nmi_watchdog=%d' to guest kernel cmdline and reboot"
% nmi_watchdog_type)
error_context.context("Add 'nmi_watchdog=%d' to guest kernel "
"cmdline and reboot" % nmi_watchdog_type)
session.cmd(update_kernel_cmd)
time.sleep(int(params.get("sleep_before_reset", 10)))
session = vm.reboot(session, method='shell', timeout=timeout)
try:
error.context("Getting guest's number of vcpus")
error_context.context("Getting guest's number of vcpus")
guest_cpu_num = session.cmd(params["cpu_chk_cmd"])
error.context("Getting guest's NMI counter")
error_context.context("Getting guest's NMI counter")
output = session.cmd(get_nmi_cmd)
logging.debug(output.strip())
nmi_counter1 = output.split()[1:]
......@@ -45,17 +46,17 @@ def run(test, params, env):
"increases")
time.sleep(60)
error.context("Getting guest's NMI counter 2nd time")
error_context.context("Getting guest's NMI counter 2nd time")
output = session.cmd(get_nmi_cmd)
logging.debug(output.strip())
nmi_counter2 = output.split()[1:]
error.context("")
error_context.context("")
for i in range(int(guest_cpu_num)):
logging.info("vcpu: %s, nmi_counter1: %s, nmi_counter2: %s" %
(i, nmi_counter1[i], nmi_counter2[i]))
if int(nmi_counter2[i]) <= int(nmi_counter1[i]):
raise error.TestFail("Guest's NMI counter did not increase "
test.fail("Guest's NMI counter did not increase "
"after 60 seconds")
finally:
session.close()
import logging
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):
"""
NOTE: hotplug_vcpu is added since RHEL.6.3,
......@@ -23,29 +22,30 @@ def run(test, params, env):
hotplug_cmd = "cpu_set %s online"
error.context("boot the vm, with '-smp X,maxcpus=Y' option,"
error_context.context("boot the vm, with '-smp X,maxcpus=Y' option,"
"thus allow hotplug vcpu", logging.info)
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
error.context("check if CPUs in guest matches qemu cmd "
error_context.context("check if CPUs in guest matches qemu cmd "
"before hot-plug", logging.info)
smp_by_cmd = int(params.get("smp"))
if not utils_misc.check_if_vm_vcpu_match(smp_by_cmd, vm):
raise error.TestError("CPU quantity mismatch cmd before hotplug !")
test.error("CPU quantity mismatch cmd before hotplug !")
# Start vCPU hotplug
error.context("hotplugging non-existed vCPU...", logging.info)
error_context.context("hotplugging non-existed vCPU...", logging.info)
vcpus_need_hotplug = params.get("nonexist_vcpu", "-1 161").split(" ")
for vcpu in vcpus_need_hotplug:
try:
error.context("hot-pluging vCPU %s" % vcpu, logging.info)
error_context.context("hot-pluging vCPU %s" % vcpu, logging.info)
output = vm.monitor.send_args_cmd(hotplug_cmd % vcpu)
finally:
error.context("output from monitor is: %s" % output, logging.info)
error_context.context("output from monitor is: %s" % output,
logging.info)
# Windows is a little bit lazy that needs more secs to recognize.
error.context("hotplugging finished, let's wait a few sec and"
error_context.context("hotplugging finished, let's wait a few sec and"
" check cpus quantity in guest.", logging.info)
if not utils_misc.wait_for(lambda: utils_misc.check_if_vm_vcpu_match(
smp_by_cmd, vm),
60, first=10, step=5.0, text="retry later"):
raise error.TestFail("CPU quantity mismatch cmd after hotplug !")
test.fail("CPU quantity mismatch cmd after hotplug !")
import logging
import resource
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 error_context
from virttest import utils_misc
from virttest import utils_test
from virttest.staging import utils_memory
@error.context_aware
@error_context.context_aware
def run(test, params, env):
"""
Qemu numa consistency test:
......@@ -33,13 +33,12 @@ def run(test, params, env):
in numa_node_info.nodes[_].cpus][0])
return node_used_host
error.context("Get host numa topological structure", logging.info)
error_context.context("Get host numa topological structure", logging.info)
timeout = float(params.get("login_timeout", 240))
host_numa_node = utils_misc.NumaInfo()
node_list = host_numa_node.online_nodes
if len(node_list) < 2:
raise error.TestNAError("This host only has one NUMA node, "
"skipping test...")
test.cancel("This host only has one NUMA node, skipping test...")
node_list.sort()
params['smp'] = len(node_list)
params['vcpu_cores'] = 1
......@@ -69,20 +68,22 @@ def run(test, params, env):
qemu_pid = vm.get_pid()
drop = 0
for cpuid in range(len(vcpu_threads)):
error.context("Get vcpu %s used numa node." % cpuid, logging.info)
error_context.context("Get vcpu %s used numa node." % cpuid,
logging.info)
memory_status, _ = utils_test.qemu.get_numa_status(host_numa_node,
qemu_pid)
node_used_host = get_vcpu_used_node(host_numa_node,
vcpu_threads[cpuid])
node_used_host_index = node_list.index(node_used_host)
memory_used_before = memory_status[node_used_host_index]
error.context("Allocate memory in guest", logging.info)
error_context.context("Allocate memory in guest", logging.info)
session.cmd(mount_cmd)
binded_dd_cmd = "taskset %s" % str(2 ** int(cpuid))
binded_dd_cmd += " dd if=/dev/urandom of=/tmp/%s" % cpuid
binded_dd_cmd += " bs=1M count=%s" % dd_size
session.cmd(binded_dd_cmd)
error.context("Check qemu process memory use status", logging.info)
error_context.context("Check qemu process memory use status",
logging.info)
node_after = get_vcpu_used_node(host_numa_node, vcpu_threads[cpuid])
if node_after != node_used_host:
logging.warn("Node used by vcpu thread changed. So drop the"
......@@ -98,15 +99,14 @@ def run(test, params, env):
if 1 - float(memory_allocated) / float(dd_size) > 0.05:
numa_hardware_cmd = params.get("numa_hardware_cmd")
if numa_hardware_cmd:
numa_info = utils.system_output(numa_hardware_cmd,
numa_info = process.system_output(numa_hardware_cmd,
ignore_status=True)
msg = "Expect malloc %sM memory in node %s," % (dd_size,
node_used_host)
msg += "but only malloc %sM \n" % memory_allocated
msg += "Please check more details of the numa node: %s" % numa_info
raise error.TestFail(msg)
test.fail(msg)
session.close()
if drop == len(vcpu_threads):
raise error.TestError("All test rounds are dropped."
" Please test it again.")
test.error("All test rounds are dropped. Please test it again.")
import logging
from autotest.client.shared import error
logger = logging.getLogger(__name__)
dbg = logger.debug
......@@ -37,7 +36,7 @@ def run(test, params, env):
if numa_nodes:
numa_nodes = int(params.get("numa_nodes"))
if len(numa) != numa_nodes:
raise error.TestFail(
test.fail(
"Wrong number of numa nodes: %d. Expected: %d" %
(len(numa), numa_nodes))
......@@ -46,7 +45,7 @@ def run(test, params, env):
if size is not None:
size = int(size)
if size != numa[nodenr][0]:
raise error.TestFail(
test.fail(
"Wrong size of numa node %d: %d. Expected: %d" %
(nodenr, numa[nodenr][0], size))
......@@ -54,6 +53,6 @@ def run(test, params, env):
if cpus is not None:
cpus = set([int(v) for v in cpus.split()])
if cpus != numa[nodenr][1]:
raise error.TestFail(
test.fail(
"Wrong CPU set on numa node %d: %s. Expected: %s" %
(nodenr, numa[nodenr][1], cpus))
......@@ -2,9 +2,9 @@ import os
import re
import logging
from autotest.client.shared import error
from autotest.client import utils
from avocado.utils import process
from virttest import error_context
from virttest import utils_misc
from virttest import funcatexit
from virttest import utils_test
......@@ -41,19 +41,21 @@ def get_tmpfs_write_speed():
Get the tmpfs write speed of the host
return: The write speed of tmpfs, the unit is kb/s.
"""
utils.run("mkdir -p /tmp/test_speed && mount -t tmpfs none /tmp/test_speed")
output = utils.run("dd if=/dev/urandom of=/tmp/test_speed/test bs=1k count=1024")
process.run("mkdir -p /tmp/test_speed && "
"mount -t tmpfs none /tmp/test_speed")
output = process.run("dd if=/dev/urandom of=/tmp/test_speed/test "
"bs=1k count=1024")
try:
speed = re.search("\s([\w\s\.]+)/s", output.stderr, re.I).group(1)
return float(utils_misc.normalize_data_size(speed, 'K', 1024))
except Exception:
return 3072
finally:
utils.run("umount /tmp/test_speed")
process.run("umount /tmp/test_speed")
os.removedirs("/tmp/test_speed")
@error.context_aware
@error_context.context_aware
def run(test, params, env):
"""
Qemu numa stress test:
......@@ -70,8 +72,7 @@ def run(test, params, env):
"""
host_numa_node = utils_misc.NumaInfo()
if len(host_numa_node.online_nodes) < 2:
raise error.TestNAError("Host only has one NUMA node, "
"skipping test...")
test.cancel("Host only has one NUMA node, skipping test...")
timeout = float(params.get("login_timeout", 240))
test_count = int(params.get("test_count", 4))
......@@ -100,7 +101,7 @@ def run(test, params, env):
utils_memory.drop_caches()
if utils_memory.freememtotal() < tmpfs_size:
raise error.TestNAError("Host does not have enough free memory to run the test, "
test.cancel("Host does not have enough free memory to run the test, "
"skipping test...")
if not os.path.isdir(tmpfs_path):
......@@ -114,33 +115,33 @@ def run(test, params, env):
os.remove(memory_file)
utils_memory.drop_caches()
if utils_memory.freememtotal() < tmpfs_size:
raise error.TestError("Don't have enough memory to execute this "
test.error("Don't have enough memory to execute this "
"test after %s round" % test_round)
error.context("Executing stress test round: %s" % test_round,
error_context.context("Executing stress test round: %s" % test_round,
logging.info)
numa_node_malloc = most_used_node
numa_dd_cmd = "numactl -m %s %s" % (numa_node_malloc, dd_cmd)
error.context("Try to allocate memory in node %s" % numa_node_malloc,
logging.info)
error_context.context("Try to allocate memory in node %s"
% numa_node_malloc, logging.info)
try:
utils_misc.mount("none", tmpfs_path, "tmpfs", perm=mount_fs_size)
funcatexit.register(env, params.get("type"), utils_misc.umount,
"none", tmpfs_path, "tmpfs")
utils.system(numa_dd_cmd, timeout=dd_timeout)
process.system(numa_dd_cmd, timeout=dd_timeout)
except Exception, error_msg:
if "No space" in str(error_msg):
pass
else:
raise error.TestFail("Can not allocate memory in node %s."
test.fail("Can not allocate memory in node %s."
" Error message:%s" % (numa_node_malloc,
str(error_msg)))
error.context("Run memory heavy stress in guest", logging.info)
error_context.context("Run memory heavy stress in guest", logging.info)
autotest_control.run(test, params, env)
error.context("Get the qemu process memory use status", logging.info)
error_context.context("Get the qemu process memory use status",
logging.info)
node_after, memory_after = max_mem_map_node(host_numa_node, qemu_pid)
if node_after == most_used_node and memory_after >= memory_used:
raise error.TestFail("Memory still stick in "
"node %s" % numa_node_malloc)
test.fail("Memory still stick in node %s" % numa_node_malloc)
else:
most_used_node = node_after
memory_used = memory_after
......
import os
import logging
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):
"""
try to exploit the guest to test whether nx(cpu) bit takes effect.
......@@ -29,17 +28,17 @@ def run(test, params, env):
exploit_file = os.path.join(data_dir.get_deps_dir(), 'nx', 'x64_sc_rdo.c')
dst_dir = '/tmp'
error.context("Copy the Exploit file to guest.", logging.info)
error_context.context("Copy the Exploit file to guest.", logging.info)
vm.copy_files_to(exploit_file, dst_dir)
error.context("Build exploit program in guest.", logging.info)
error_context.context("Build exploit program in guest.", logging.info)
build_exploit = "gcc -o /tmp/nx_exploit /tmp/x64_sc_rdo.c"
if session.cmd_status(build_exploit):
raise error.TestError("Failed to build the exploit program")
test.error("Failed to build the exploit program")
exploit_cmd = "/tmp/nx_exploit"
error.context("Run exploit program in guest.", logging.info)
error_context.context("Run exploit program in guest.", logging.info)
# if nx is enabled (by default), the program failed.
# segmentation error. return value of shell is not zero.
exec_res = session.cmd_status(exploit_cmd)
......@@ -47,25 +46,25 @@ def run(test, params, env):
if nx_on == 'yes':
if exec_res:
logging.info('NX works good.')
error.context("Using execstack to remove the protection.",
error_context.context("Using execstack to remove the protection.",
logging.info)
enable_exec = 'execstack -s %s' % exploit_cmd
if session.cmd_status(enable_exec):
if session.cmd_status("execstack --help"):
msg = "Please make sure guest have execstack command."
raise error.TestError(msg)
raise error.TestError('Failed to enable the execstack')
test.error(msg)
test.error('Failed to enable the execstack')
if session.cmd_status(exploit_cmd):
raise error.TestFail('NX is still protecting. Error.')
test.fail('NX is still protecting. Error.')
else:
logging.info('NX is disabled as desired. good')
else:
raise error.TestFail('Fatal Error: NX does not protect anything!')
test.fail('Fatal Error: NX does not protect anything!')
else:
if exec_res:
msg = "qemu fail to disable 'nx' flag or the exploit is corrupted."
raise error.TestError(msg)
test.error(msg)
else:
logging.info('NX is disabled, and this Test Case passed.')
if session:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册