77import aexpect
88from avocado .core import exceptions
99from avocado .utils import process
10+
11+ from virttest import data_dir
1012from virttest import remote
1113from virttest import utils_misc
1214from virttest import utils_net
@@ -448,9 +450,22 @@ def exec_netperf_test(params, env):
448450 netperf_server = params .get ("netperf_server" )
449451 extra_cmd_opts = params .get ("extra_cmd_opts" , "" )
450452 netperf_timeout = params .get ("netperf_timeout" , "60" )
451- test_protocol = params .get ("test_protocol" )
453+ test_protocol = params .get ("test_protocol" , "TCP_STREAM" )
454+ os_type = params .get ("os_type" , "linux" )
455+
456+ # Command configuration parameters
457+ firewall_cmd = params .get ("firewall_cmd" , "systemctl stop firewalld" )
458+ restore_firewall_cmd = params .get ("restore_firewall_cmd" , "systemctl start firewalld" )
459+ kill_netserver_cmd = params .get ("kill_netserver_cmd" , "killall netserver" )
460+ netserver_cmd = params .get ("netserver_cmd" , "netserver" )
461+ netperf_bin = params .get ("netperf_bin" , "netperf" )
462+ netperf_opts = params .get ("netperf_opts" , "-C -c" )
463+ cleanup_netserver_cmd = params .get ("cleanup_netserver_cmd" , "killall netserver" )
464+ netperf_src = os .path .join (data_dir .get_deps_dir ("netperf" ), params .get ("netperf_src" ))
465+ netperf_ver = params .get ("netperf_ver" )
452466 vms = params .get ('vms' ).split ()
453467 vm_objs = {vm_i : env .get_vm (vm_i ) for vm_i in vms }
468+
454469 before_test_cores = process .run ("coredumpctl list" , ignore_status = True , verbose = True ).stdout_text
455470
456471 def _get_access_info (netperf_address ):
@@ -474,20 +489,42 @@ def _get_access_info(netperf_address):
474489 s_func , s_ip , s_session = _get_access_info (netperf_server )
475490
476491 try :
477- if not utils_package .package_install ("netperf" , c_session ):
478- raise exceptions .TestError ("Unable to install netperf in the client host!" )
479- if not utils_package .package_install ("netperf" , s_session ):
480- raise exceptions .TestError ("Unable to install netperf in the server host!" )
481- c_func ("systemctl stop firewalld" )
482- s_func ("systemctl stop firewalld" )
492+ # Install netperf
493+ if os_type == "windows" :
494+ if os .path .exists (netperf_src ) and netperf_server in vms :
495+ vm = vm_objs .get (netperf_server )
496+ remote .copy_files_to (vm .get_address (), "scp" ,
497+ params .get ("username" ), params .get ("password" ) , 22 ,
498+ netperf_src , "C:\\ netperf.exe" , 600 )
499+ LOG .debug ("Copied netperf.exe to Windows guest" )
500+ else :
483501
502+ if os .path .exists (netperf_src ):
503+ if c_session :
504+ c_session .cmd ("cd /tmp && tar -xjf " + netperf_src + " && cd %s && make" % netperf_ver , ignore_all_errors = True )
505+ if s_session :
506+ s_session .cmd ("cd /tmp && tar -xjf " + netperf_src + " && cd %s && make" % netperf_ver , ignore_all_errors = True )
507+ else :
508+ # Fallback to package manager
509+ if not utils_package .package_install ("netperf" , c_session ):
510+ raise exceptions .TestError ("Unable to install netperf in the client host!" )
511+ if not utils_package .package_install ("netperf" , s_session ):
512+ raise exceptions .TestError ("Unable to install netperf in the server host!" )
513+
514+ # Disable firewall
515+ c_func (firewall_cmd , ignore_status = True )
516+ s_func (firewall_cmd , ignore_status = True )
517+
518+ # Start netserver
484519 LOG .debug ("Start netserver..." )
485- if s_ip == netperf_server :
486- s_func ("killall netserver" , ignore_status = True )
487- s_func ("netserver" )
520+ if kill_netserver_cmd :
521+ s_func (kill_netserver_cmd , ignore_status = True )
488522
523+ s_func (netserver_cmd , ignore_status = True )
524+
525+ # Run netperf client
489526 LOG .debug ("Run netperf command..." )
490- test_cmd = f"netperf -H { s_ip } -l { netperf_timeout } -C -c - t { test_protocol } { extra_cmd_opts } "
527+ test_cmd = f"{ netperf_bin } -H { s_ip } -l { netperf_timeout } -t { test_protocol } { netperf_opts } { extra_cmd_opts } "
491528 c_func (test_cmd , timeout = 120 )
492529
493530 for vm in vm_objs .values ():
@@ -505,11 +542,19 @@ def _get_access_info(netperf_address):
505542
506543 finally :
507544 LOG .info ("Test teardown: Cleanup env." )
508- s_func ("killall netserver" )
509- s_func ("systemctl start firewalld" )
510- # TODO: Start firewalld on guest
545+ # Cleanup netserver
546+ s_func (cleanup_netserver_cmd )
547+
548+ # Restore firewall
549+ s_func (restore_firewall_cmd )
511550 process .run ("systemctl start firewalld" , ignore_status = True )
512551
552+ # Cleanup sessions
553+ if c_session :
554+ c_session .close ()
555+ if s_session :
556+ s_session .close ()
557+
513558
514559def prepare_single_vm (params , vm_name , disk_path = '' , iface_list = []):
515560 """
0 commit comments