提交 bd2d442f 编写于 作者: F Feng Yang 提交者: Lucas Meneghel Rodrigues

qemu.tests: Bug fix and update in migration_with_netperf.py

This patch re-format this test script.
Use utils_misc.wait_for instead of hard code sleep 20.
Add cleanup code.
Use error.context.
Remove unused import
Signed-off-by: NFeng Yang <fyang@redhat.com>
上级 99c1aa7a
import logging, time, os, commands
import logging, os
from autotest.client.shared import utils, error
from autotest.client import utils as client_utils
from virttest import utils_misc
@error.context_aware
def run_migration_with_netperf(test, params, env):
......@@ -17,23 +17,24 @@ def run_migration_with_netperf(test, params, env):
@param env: Dictionary with the test environment.
"""
def start_netperf_server():
logging.info("Start netserver in guest.")
netserver_cmd = params.get("netserver_cmd") % "/tmp"
(s, o) = session.cmd_status_output(netserver_cmd,
timeout=netperf_timeout)
if s:
raise error.TestFail("Fail to start netserver:\n %s" % o)
netserver_cmd = params.get("netserver_cmd")
(status, output) = session.cmd_status_output(netserver_cmd,
timeout=netperf_timeout)
if status:
raise error.TestFail("Fail to start netserver:\n %s" % output)
def start_netperf_client(i=0):
logging.info("Netperf_%s" % i)
cmd = "cd %s && %s" % (netperf_path, netperf_cmd)
try:
netperf_output = commands.getoutput(cmd)
netperf_output = utils.system_output(netperf_cmd)
open("Netperf_%s" % i, "w").write(netperf_output)
except OSError:
pass
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
login_timeout = int(params.get("login_timeout", 360))
......@@ -42,49 +43,54 @@ def run_migration_with_netperf(test, params, env):
cmd_timeout = int(params.get("cmd_timeout", "360"))
mig_protocol = params.get("migration_protocol", "tcp")
mig_cancel_delay = int(params.get("mig_cancel") == "yes") * 2
netperf_path = params.get("netperf_path")
if not netperf_path.startswith("/"):
netperf_path = os.path.join(test.bindir, netperf_path)
cleanup_cmd = params.get("cleanup_cmd")
netperf_timeout = int(params.get("netperf_timeout", "300"))
client_num = int(params.get("client_num", "100"))
bg_list = []
m_count = 0
try:
session.cmd("service iptables stop")
logging.info("Setup netperf server in guest.")
vm.copy_files_to(netperf_path, "/tmp")
setup_cmd = params.get("setup_cmd")
cmd = "cd /tmp/netperf2 && %s" % setup_cmd
session.cmd(cmd, timeout=cmd_timeout)
logging.info("Setup netperf client in host.")
error.context("Setup netperf server in guest.", logging.info)
netperf_dir = os.path.join(os.environ['AUTODIR'], "tests/netperf2")
for i in params.get("netperf_files").split():
vm.copy_files_to("%s/%s" % (netperf_dir, i), "/tmp")
utils.get_file("%s/%s" % (netperf_dir, i), "/tmp/%s" %i)
setup_cmd = params.get("setup_cmd")
session.cmd(setup_cmd, timeout=cmd_timeout)
error.context("Setup netperf client in host.", logging.info)
utils.system(setup_cmd)
netperf_cmd = params.get("netperf_cmd") % (vm.get_address(),
netperf_timeout)
cmd = "cd %s && %s" % (netperf_path, setup_cmd)
utils.system(cmd)
bg = utils.InterruptedThread(start_netperf_server)
bg.start()
netperf_timeout)
error.context("Start netserver in guest.", logging.info)
bg_list.append(utils.InterruptedThread(start_netperf_server))
if bg_list[0]:
bg_list[0].start()
# Wait netserver start in guest.
time.sleep(20)
for i in range(client_num):
ses = vm.wait_for_login(timeout=login_timeout)
n_cmd = params.get("netserver_check_cmd", "ps -a | grep netserver")
utils_misc.wait_for(lambda: not ses.cmd_status(n_cmd), 30, 2, 2)
if ses:
ses.close()
for i in xrange(1, client_num + 1):
bg_list.append(utils.InterruptedThread(start_netperf_client, (i,)))
bg_list[i].start()
while True:
m_count += 1
logging.info("Start migration iterations: %s " % m_count)
error.context("Start migration iterations: %s " % m_count,
logging.info)
vm.migrate(mig_timeout, mig_protocol, mig_cancel_delay)
if not bg_list[0].isAlive():
if not bg_list[-1].isAlive():
logging.info("Background Netperf finished.")
break
finally:
try:
for b in bg_list:
if b:
b.join(timeout=10, suppress_exception=True)
finally:
session.cmd("killall netserver", timeout=cmd_timeout)
bg.join(timeout=10, suppress_exception=True)
session.close()
session.cmd("killall -9 netserver ; echo 1", timeout=cmd_timeout)
if cleanup_cmd:
utils.system(cleanup_cmd)
session.cmd(cleanup_cmd)
if session:
session.close()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册