1 import logging
, os
, signal
2 from autotest_lib
.client
.common_lib
import error
3 from autotest_lib
.client
.bin
import utils
4 from autotest_lib
.client
.virt
import aexpect
, virt_utils
6 def run_netperf(test
, params
, env
):
8 Network stress test with netperf.
10 1) Boot up a VM with multiple nics.
11 2) Launch netserver on guest.
12 3) Execute multiple netperf clients on host in parallel
13 with different protocols.
14 4) Output the test result.
16 @param test: KVM test object.
17 @param params: Dictionary with the test parameters.
18 @param env: Dictionary with test environment.
20 vm
= env
.get_vm(params
["main_vm"])
22 login_timeout
= int(params
.get("login_timeout", 360))
23 session
= vm
.wait_for_login(timeout
=login_timeout
)
25 session_serial
= vm
.wait_for_serial_login(timeout
=login_timeout
)
27 netperf_dir
= os
.path
.join(os
.environ
['AUTODIR'], "tests/netperf2")
28 setup_cmd
= params
.get("setup_cmd")
30 firewall_flush
= "iptables -F"
31 session_serial
.cmd_output(firewall_flush
)
33 utils
.run("iptables -F")
37 for i
in params
.get("netperf_files").split():
38 vm
.copy_files_to(os
.path
.join(netperf_dir
, i
), "/tmp")
41 session_serial
.cmd(firewall_flush
)
42 except aexpect
.ShellError
:
43 logging
.warning("Could not flush firewall rules on guest")
45 session_serial
.cmd(setup_cmd
% "/tmp", timeout
=200)
46 session_serial
.cmd(params
.get("netserver_cmd") % "/tmp")
48 tcpdump
= env
.get("tcpdump")
51 # Stop the background tcpdump process
53 pid
= int(utils
.system_output("pidof tcpdump"))
54 logging
.debug("Stopping the background tcpdump")
55 os
.kill(pid
, signal
.SIGSTOP
)
60 guest_ip
= vm
.get_address(i
)
61 logging
.info("Netperf_%s: netserver %s" % (i
, guest_ip
))
62 result_file
= os
.path
.join(test
.resultsdir
, "output_%s_%s"
63 % (test
.iteration
, i
))
65 result
= open(result_file
, "w")
66 result
.write("Netperf test results\n")
68 for p
in params
.get("protocols").split():
69 packet_size
= params
.get("packet_size", "1500")
70 for size
in packet_size
.split():
71 cmd
= params
.get("netperf_cmd") % (netperf_dir
, p
,
73 logging
.info("Netperf_%s: protocol %s" % (i
, p
))
75 netperf_output
= utils
.system_output(cmd
,
77 result
.write("%s\n" % netperf_output
)
79 logging
.error("Test of protocol %s failed", p
)
84 raise error
.TestFail("Some netperf tests failed: %s" %
88 logging
.info("Setup and run netperf clients on host")
89 utils
.run(setup_cmd
% netperf_dir
)
92 nic_num
= len(params
.get("nics").split())
93 for i
in range(nic_num
):
94 bg
.append(virt_utils
.Thread(netperf
, (i
,)))
107 session_serial
.cmd_output("killall netserver")
109 logging
.debug("Resuming the background tcpdump")
110 logging
.info("pid is %s" % pid
)
111 os
.kill(pid
, signal
.SIGCONT
)