提交 d3c7d4d4 编写于 作者: J Jason Wang 提交者: Lucas Meneghel Rodrigues

tests.autotest_control: Add function for running autotest in background

Add two helper functions run_autotest_background()
  & wait_autotest_background().
  Some testcases(ioquit,net_perf2,suspendresume) need run_autotest_background()
  to add workload. Both functions are wrapper of run_autotest thus place them
  in run_autotest.py. If we want to use them, we should import test.autotest
  first.
Signed-off-by: NJason Wang <jasowang@redhat.com>
Signed-off-by: NAmos Kong <akong@redhat.com>

We have update virt/tests/autotest.py to guest_autotest.py
So run_autotest() have to rename to run_guest_autotest()
Signed-off-by: NFeng Yang <fyang@redhat.com>

interface update
Signed-off-by: NFeng Yang <fyang@redhat.com>
Signed-off-by: NYiqiao Pu <ypu@redhat.com>
上级 87dd7823
import os
import os, logging, sys
from autotest.client.shared import error
from virttest import utils_test
......@@ -6,7 +7,7 @@ def run_autotest_control(test, params, env):
"""
Run an autotest test inside a guest.
@param test: kvm test object.
@param test: QEMU test object.
@param params: Dictionary with test parameters.
@param env: Dictionary with the test environment.
"""
......@@ -23,3 +24,66 @@ def run_autotest_control(test, params, env):
utils_test.run_autotest(vm, session, control_path, timeout, outputdir,
params)
def run_autotest_control_background(test, params, env,
test_control_file="control"):
"""
Wrapper of run_autotest_control() and make it run in the background through
fork() and let it run in the child process.
1) Flush the stdio.
2) Build test params which is recevied from arguments and used by
run_autotest_control()
3) Fork the process and let the run_autotest_control() run in the child
4) Catch the exception raise by run_autotest_control() and exit the child with
non-zero return code.
5) If no exception catched, reutrn 0
@param test: QEMU test object
@param params: Dictionary with the test parameters
@param env: Dictionary with test environment.
@param test_control_file: The control file of autotest running in the guest
"""
def flush():
sys.stdout.flush()
sys.stderr.flush()
logging.info("Running autotest background ...")
flush()
pid = os.fork()
if pid:
# Parent process
return pid
flag_fname = "/tmp/autotest-flag-file-pid-" + str(os.getpid())
open(flag_fname, 'w').close()
try:
params['test_control_file'] = test_control_file
# Launch autotest
run_autotest_control(test, params, env)
os.remove(flag_fname)
except error.TestFail, message_fail:
logging.info("[Autotest Background FAIL] %s" % message_fail)
os.remove(flag_fname)
os._exit(1)
except error.TestError, message_error:
logging.info("[Autotest Background ERROR] %s" % message_error)
os.remove(flag_fname)
os._exit(2)
logging.info("[Auototest Background GOOD]")
os._exit(0)
def wait_autotest_background(pid):
"""
Wait for background autotest finish.
@param pid: Pid of the child process executing background autotest
"""
logging.info("Waiting for background autotest to finish ...")
(pid, s) = os.waitpid(pid,0)
status = os.WEXITSTATUS(s)
if status != 0:
return False
return True
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册