def netperf_stress(test, params, vm): """ Netperf stress test. """ n_client = utils_netperf.NetperfClient( vm.get_address(), params.get("client_path"), netperf_source=os.path.join(data_dir.get_deps_dir("netperf"), params.get("netperf_client_link")), client=params.get("shell_client"), port=params.get("shell_port"), username=params.get("username"), password=params.get("password"), prompt=params.get("shell_prompt"), linesep=params.get("shell_linesep", "\n").encode().decode( 'unicode_escape'), status_test_command=params.get("status_test_command", ""), compile_option=params.get("compile_option", "")) n_server = utils_netperf.NetperfServer( utils_net.get_host_ip_address(params), params.get("server_path", "/var/tmp"), netperf_source=os.path.join(data_dir.get_deps_dir("netperf"), params.get("netperf_server_link")), password=params.get("hostpassword"), compile_option=params.get("compile_option", "")) try: n_server.start() # Run netperf with message size defined in range. netperf_test_duration = params.get_numeric("netperf_test_duration") test_protocols = params.get("test_protocol") netperf_output_unit = params.get("netperf_output_unit") test_option = params.get("test_option", "") test_option += " -l %s" % netperf_test_duration if params.get("netperf_remote_cpu") == "yes": test_option += " -C" if params.get("netperf_local_cpu") == "yes": test_option += " -c" if netperf_output_unit in "GMKgmk": test_option += " -f %s" % netperf_output_unit t_option = "%s -t %s" % (test_option, test_protocols) n_client.bg_start(utils_net.get_host_ip_address(params), t_option, params.get_numeric("netperf_para_sessions"), params.get("netperf_cmd_prefix", ""), package_sizes=params.get("netperf_sizes")) if utils_misc.wait_for(n_client.is_netperf_running, 10, 0, 1, "Wait netperf test start"): logging.info("Netperf test start successfully.") else: test.error("Can not start netperf client.") utils_misc.wait_for(lambda: not n_client.is_netperf_running(), netperf_test_duration, 0, 5, "Wait netperf test finish %ss" % netperf_test_duration) time.sleep(5) finally: n_server.stop() n_server.package.env_cleanup(True) n_client.package.env_cleanup(True)
def run(test, params, env): """ QEMU flow caches stress test test 1) Make sure nf_conntrack is disabled in host and guest. If nf_conntrack is enabled in host, skip this case. 2) Boot guest with vhost=on/off. 3) Enable multi queues support in guest (optional). 4) After installation of netperf, run netserver in host. 5) Run netperf TCP_CRR protocal test in guest. 6) Transfer file between guest and host. 7) Check the md5 of copied file. This is a sample QEMU test, so people can get used to some of the test APIs. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ msg = "Make sure nf_conntrack is disabled in host and guest." error_context.context(msg, logging.info) if "nf_conntrack" in process.system_output("lsmod"): err = "nf_conntrack load in host, skip this case" test.cancel(err) params["start_vm"] = "yes" error_context.context("Boot up guest", logging.info) env_process.preprocess_vm(test, params, env, params["main_vm"]) vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) if "nf_conntrack" in session.cmd_output("lsmod"): msg = "Unload nf_conntrack module in guest." error_context.context(msg, logging.info) black_str = "#disable nf_conntrack\\nblacklist nf_conntrack\\n" \ "blacklist nf_conntrack_ipv6\\nblacklist xt_conntrack\\n" \ "blacklist nf_conntrack_ftp\\nblacklist xt_state\\n" \ "blacklist iptable_nat\\nblacklist ipt_REDIRECT\\n" \ "blacklist nf_nat\\nblacklist nf_conntrack_ipv4" cmd = "echo -e '%s' >> /etc/modprobe.d/blacklist.conf" % black_str session.cmd(cmd) session = vm.reboot(session, timeout=timeout) if "nf_conntrack" in session.cmd_output("lsmod"): err = "Fail to unload nf_conntrack module in guest." test.error(err) netperf_link = utils_misc.get_path(data_dir.get_deps_dir("netperf"), params["netperf_link"]) md5sum = params.get("pkg_md5sum") win_netperf_link = params.get("win_netperf_link") if win_netperf_link: win_netperf_link = utils_misc.get_path( data_dir.get_deps_dir("netperf"), win_netperf_link) win_netperf_md5sum = params.get("win_netperf_md5sum") server_path = params.get("server_path", "/var/tmp/") client_path = params.get("client_path", "/var/tmp/") win_netperf_path = params.get("win_netperf_path", "c:\\") client_num = params.get("netperf_client_num", 520) netperf_timeout = int(params.get("netperf_timeout", 600)) netperf_client_ip = vm.get_address() host_ip = utils_net.get_host_ip_address(params) netperf_server_ip = params.get("netperf_server_ip", host_ip) username = params.get("username", "root") password = params.get("password", "123456") passwd = params.get("hostpasswd", "123456") client = params.get("shell_client", "ssh") port = params.get("shell_port", "22") prompt = params.get("shell_prompt", r"^root@.*[\#\$]\s*$|#") linesep = params.get("shell_linesep", "\n").encode().decode('unicode_escape') status_test_command = params.get("status_test_command", "echo $?") compile_option_client = params.get("compile_option_client", "") compile_option_server = params.get("compile_option_server", "") if int(params.get("queues", 1)) > 1 and params.get("os_type") == "linux": error_context.context("Enable multi queues support in guest.", logging.info) guest_mac = vm.get_mac_address() ifname = utils_net.get_linux_ifname(session, guest_mac) cmd = "ethtool -L %s combined %s" % (ifname, params.get("queues")) status, out = session.cmd_status_output(cmd) msg = "Fail to enable multi queues support in guest." msg += "Command %s fail output: %s" % (cmd, out) test.error(msg) if params.get("os_type") == "linux": session.cmd("iptables -F", ignore_all_errors=True) g_client_link = netperf_link g_client_path = client_path g_md5sum = md5sum elif params.get("os_type") == "windows": g_client_link = win_netperf_link g_client_path = win_netperf_path g_md5sum = win_netperf_md5sum error_context.context("Setup netperf in guest and host", logging.info) netperf_client = utils_netperf.NetperfClient( netperf_client_ip, g_client_path, g_md5sum, g_client_link, username=username, password=password, prompt=prompt, linesep=linesep, status_test_command=status_test_command, compile_option=compile_option_client) netperf_server = utils_netperf.NetperfServer( netperf_server_ip, server_path, md5sum, netperf_link, client, port, password=passwd, prompt=prompt, linesep=linesep, status_test_command=status_test_command, compile_option=compile_option_server) try: error_context.base_context("Run netperf test between host and guest.") error_context.context("Start netserver in host.", logging.info) netperf_server.start() error_context.context( "Start Netperf in guest for %ss." % netperf_timeout, logging.info) test_option = "-t TCP_CRR -l %s -- -b 10 -D" % netperf_timeout netperf_client.bg_start(netperf_server_ip, test_option, client_num) utils_misc.wait_for(lambda: not netperf_client.is_netperf_running(), timeout=netperf_timeout, first=590, step=2) utils_test.run_file_transfer(test, params, env) finally: netperf_server.stop() netperf_client.package.env_cleanup(True) if session: session.close()
def run(test, params, env): """ Run netperf stress on server and client side. 1) Start multi vm(s) guest. 2) Select multi vm(s) or host to setup netperf server/client. 3) Run netperf stress test. 4) Finish test until timeout env["netperf_run"] is False. :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ login_timeout = float(params.get("login_timeout", 360)) netperf_server = params.get("netperf_server").split() netperf_client = params.get("netperf_client").split() guest_username = params.get("username", "") guest_password = params.get("password", "") host_password = params.get("hostpassword", "redhat") shell_client = params.get("shell_client") shell_port = params.get("shell_port") os_type = params.get("os_type") shell_prompt = params.get("shell_prompt", r"^root@.*[\#\$]\s*$|#") linesep = params.get("shell_linesep", "\n").decode('string_escape') status_test_command = params.get("status_test_command", "echo $?") compile_option_client = params.get("compile_option_client", "") compile_option_server = params.get("compile_option_server", "") host_ip = utils_net.get_host_ip_address(params) vms = params.get("vms") server_infos = [] client_infos = [] for server in netperf_server: s_info = {} if server in vms: server_vm = env.get_vm(server) server_vm.verify_alive() session = server_vm.wait_for_login(timeout=login_timeout) session.cmd("service iptables stop; iptables -F", ignore_all_errors=True) server_ip = server_vm.get_address() s_info["ip"] = server_ip s_info["os_type"] = params.get("os_type_%s" % server, os_type) s_info["username"] = params.get("username_%s" % server, guest_username) s_info["password"] = params.get("password_%s" % server, guest_password) s_info["shell_client"] = params.get("shell_client_%s" % server, shell_client) s_info["shell_port"] = params.get("shell_port_%s" % server, shell_port) s_info["shell_prompt"] = params.get("shell_prompt_%s" % server, shell_prompt) s_info["linesep"] = params.get("linesep_%s" % server, linesep) s_info["status_test_command"] = params.get("status_test_command_%s" % server, status_test_command) else: if server == "localhost": s_info["ip"] = host_ip s_info["password"] = params.get("password_%s" % server, host_password) else: s_info["ip"] = server s_info["password"] = params.get("password_%s" % server, "redhat") s_info["os_type"] = params.get("os_type_%s" % server, "linux") s_info["username"] = params.get("username_%s" % server, "root") s_info["shell_client"] = params.get("shell_client_%s" % server, "ssh") s_info["shell_port"] = params.get("shell_port_%s" % server, "22") s_info["shell_prompt"] = params.get("shell_prompt_%s" % server, r"^\[.*\][\#\$]\s*$") s_info["linesep"] = params.get("linesep_%s" % server, "\n") s_info["status_test_command"] = params.get("status_test_command_%s" % server, "echo $?") server_infos.append(s_info) for client in netperf_client: c_info = {} if client in vms: client_vm = env.get_vm(client) client_vm.verify_alive() session = client_vm.wait_for_login(timeout=login_timeout) session.cmd("service iptables stop; iptables -F", ignore_all_errors=True) client_ip = client_vm.get_address() c_info["ip"] = client_ip c_info["os_type"] = params.get("os_type_%s" % client, os_type) c_info["username"] = params.get("username_%s" % client, guest_username) c_info["password"] = params.get("password_%s" % client, guest_password) c_info["shell_client"] = params.get("shell_client_%s" % client, shell_client) c_info["shell_port"] = params.get("shell_port_%s" % client, shell_port) c_info["shell_prompt"] = params.get("shell_prompt_%s" % client, shell_prompt) c_info["linesep"] = params.get("linesep_%s" % client, linesep) c_info["status_test_command"] = params.get("status_test_command_%s" % client, status_test_command) else: if client == "localhost": c_info["ip"] = host_ip c_info["password"] = params.get("password_%s" % client, host_password) else: c_info["ip"] = client c_info["password"] = params.get("password_%s" % client, "redhat") c_info["os_type"] = params.get("os_type_%s" % client, "linux") c_info["username"] = params.get("username_%s" % client, "root") c_info["shell_client"] = params.get("shell_client_%s" % client, "ssh") c_info["shell_port"] = params.get("shell_port_%s" % client, "23") c_info["shell_prompt"] = params.get("shell_prompt_%s" % client, r"^\[.*\][\#\$]\s*$") c_info["linesep"] = params.get("linesep_%s" % client, "\n") c_info["status_test_command"] = params.get("status_test_command_%s" % client, "echo $?") client_infos.append(c_info) netperf_link = params.get("netperf_link") netperf_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_link) md5sum = params.get("pkg_md5sum") netperf_server_link = params.get("netperf_server_link_win", netperf_link) netperf_server_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_server_link) server_md5sum = params.get("server_md5sum") netperf_client_link = params.get("netperf_client_link_win", netperf_link) netperf_client_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_client_link) client_md5sum = params.get("client_md5sum") server_path_linux = params.get("server_path", "/var/tmp") client_path_linux = params.get("client_path", "/var/tmp") server_path_win = params.get("server_path_win", "c:\\") client_path_win = params.get("client_path_win", "c:\\") netperf_clients = [] netperf_servers = [] for c_info in client_infos: if c_info["os_type"] == "windows": netperf_link_c = netperf_client_link client_path = client_path_win md5sum = client_md5sum else: netperf_link_c = netperf_link client_path = client_path_linux n_client = utils_netperf.NetperfClient(c_info["ip"], client_path, md5sum, netperf_link_c, client=c_info["shell_client"], port=c_info["shell_port"], username=c_info["username"], password=c_info["password"], prompt=c_info["shell_prompt"], linesep=c_info["linesep"], status_test_command=c_info["status_test_command"], compile_option=compile_option_client) netperf_clients.append(n_client) for s_info in server_infos: if s_info["os_type"] == "windows": netperf_link_s = netperf_server_link server_path = server_path_win md5sum = server_md5sum else: netperf_link_s = netperf_link server_path = server_path_linux n_server = utils_netperf.NetperfServer(s_info["ip"], server_path, md5sum, netperf_link_s, client=s_info["shell_client"], port=s_info["shell_port"], username=s_info["username"], password=s_info["password"], prompt=s_info["shell_prompt"], linesep=s_info["linesep"], status_test_command=s_info["status_test_command"], compile_option=compile_option_server) netperf_servers.append(n_server) # Get range of message size. try: for n_server in netperf_servers: n_server.start() # Run netperf with message size defined in range. netperf_test_duration = int(params.get("netperf_test_duration", 60)) netperf_para_sess = params.get("netperf_para_sessions", "1") test_protocols = params.get("test_protocols", "TCP_STREAM") netperf_cmd_prefix = params.get("netperf_cmd_prefix", "") netperf_output_unit = params.get("netperf_output_unit", " ") netperf_package_sizes = params.get("netperf_package_sizes") test_option = params.get("test_option", "") test_option += " -l %s" % netperf_test_duration if params.get("netperf_remote_cpu") == "yes": test_option += " -C" if params.get("netperf_local_cpu") == "yes": test_option += " -c" if netperf_output_unit in "GMKgmk": test_option += " -f %s" % netperf_output_unit start_time = time.time() stop_time = start_time + netperf_test_duration num = 0 s_len = len(server_infos) for protocol in test_protocols.split(): 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 server_ip = server_infos[index]["ip"] n_client.bg_start(server_ip, t_option, netperf_para_sess, netperf_cmd_prefix, package_sizes=netperf_package_sizes) if utils_misc.wait_for(n_client.is_netperf_running, 10, 0, 1, "Wait netperf test start"): logging.info("Netperf test start successfully.") else: 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 # the stress test. env["netperf_run"] = True for n_client in netperf_clients: if n_client.is_netperf_running(): left_time = stop_time - time.time() utils_misc.wait_for(lambda: not n_client.is_netperf_running(), left_time, 0, 5, "Wait netperf test finish %ss" % left_time) time.sleep(5) finally: for n_server in netperf_servers: if n_server: n_server.stop() n_server.package.env_cleanup(True) for n_client in netperf_clients: if n_client: n_client.package.env_cleanup(True) env["netperf_run"] = False if session: session.close()
def setup_netperf_env(): """ Setup netperf envrioments in vms """ def __get_vminfo(): """ Get vms information; """ login_timeout = float(params.get("login_timeout", 360)) clear_iptables_cmd = "service iptables stop; iptables -F" guest_info = [ "status_test_command", "shell_linesep", "shell_prompt", "username", "password", "shell_client", "shell_port", "os_type" ] vms_info = [] for _ in params.get("vms").split(): info = list( map(lambda x: params.object_params(_).get(x), guest_info)) vm = env.get_vm(_) vm.verify_alive() session = vm.wait_for_login(timeout=login_timeout) session.cmd(clear_iptables_cmd, ignore_all_errors=True) vms_info.append((vm, info)) return vms_info netperf_link = params.get("netperf_link") netperf_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_link) md5sum = params.get("pkg_md5sum") netperf_server_link = params.get("netperf_server_link_win", netperf_link) netperf_server_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_server_link) netperf_client_link = params.get("netperf_client_link_win", netperf_link) netperf_client_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_client_link) server_path_linux = params.get("server_path", "/var/tmp") client_path_linux = params.get("client_path", "/var/tmp") server_path_win = params.get("server_path_win", "c:\\") client_path_win = params.get("client_path_win", "c:\\") compile_option_client = params.get("compile_option_client", "") compile_option_server = params.get("compile_option_server", "") netperf_servers, netperf_clients = [], [] for idx, (vm, info) in enumerate(__get_vminfo()): if idx % 2 == 0: if info[-1] == "windows": netperf_link = netperf_server_link server_path = server_path_win else: netperf_link = netperf_link server_path = server_path_linux server = utils_netperf.NetperfServer( vm.get_address(), server_path, md5sum, netperf_link, port=info[-2], client=info[-3], password=info[-4], username=info[-5], prompt=info[-6], linesep=info[-7].encode().decode('unicode_escape'), status_test_command=info[-8], compile_option=compile_option_server) netperf_servers.append((server, vm)) continue else: if info[-1] == "windows": netperf_link = netperf_client_link client_path = client_path_win else: netperf_link = netperf_link client_path = client_path_linux client = utils_netperf.NetperfClient( vm.get_address(), client_path, md5sum, netperf_link, port=info[-2], client=info[-3], password=info[-4], username=info[-5], prompt=info[-6], linesep=info[-7].encode().decode('unicode_escape'), status_test_command=info[-8], compile_option=compile_option_client) netperf_clients.append((client, vm)) continue return netperf_clients, netperf_servers
def run_netperf_stress(test, params, env): """ Run netperf on server and client side, we need run this case on two machines. if dsthost is not set will start netperf server on local host. Netperf stress test will keep running, until stress timeout or env["netperf_run"] is False 1) Start one vm guest os as server. 2) Start a reference machine (dsthost) as client. 3) Run netperf stress test. 4) Finish test until timeout or env["netperf_run"] is False. :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ login_timeout = float(params.get("login_timeout", 360)) dsthost = params.get("dsthost", "localhost") vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) session.cmd("service iptables stop; iptables -F", ignore_all_errors=True) if dsthost in params.get("vms", "vm1 vm2"): server_vm = env.get_vm(dsthost) server_vm.verify_alive() server_vm.wait_for_login(timeout=login_timeout) dsthost_ip = server_vm.get_address() elif re.match(r"((\d){1,3}\.){3}(\d){1,3}", dsthost): dsthost_ip = dsthost else: server_interface = params.get("netdst", "switch") host_nic = utils_net.Interface(server_interface) dsthost_ip = host_nic.get_ip() download_link = params.get("netperf_download_link") md5sum = params.get("pkg_md5sum") server_download_link = params.get("server_download_link", download_link) server_md5sum = params.get("server_md5sum", md5sum) server_path = params.get("server_path", "/var/tmp") client_path = params.get("client_path", "/var/tmp") guest_usrname = params.get("username", "") guest_passwd = params.get("password", "") host_passwd = params.get("hostpasswd") client = params.get("shell_client") port = params.get("shell_port") #main vm run as server when vm_as_server is 'yes'. if params.get("vm_as_server", "yes") == "yes": netserver_ip = vm.get_address() netperf_client_ip = dsthost_ip else: netserver_ip = dsthost_ip netperf_client_ip = vm.get_address() netperf_client = utils_netperf.NetperfClient(netperf_client_ip, client_path, md5sum, download_link, password=host_passwd) netperf_server = utils_netperf.NetperfServer(netserver_ip, server_path, server_md5sum, server_download_link, client, port, username=guest_usrname, password=guest_passwd) # Get range of message size. try: netperf_server.start() # Run netperf with message size defined in range. stress_timeout = float(params.get("netperf_test_timeout", 1200)) netperf_test_duration = float(params.get("netperf_test_duration", 60)) netperf_para_sess = params.get("netperf_para_sessions", "1") test_protocol = params.get("test_protocol", "TCP_STREAM") netperf_cmd_prefix = params.get("netperf_cmd_prefix", "") test_option = "-t %s -l %s" % (test_protocol, netperf_test_duration) start_time = time.time() stop_time = start_time + stress_timeout netperf_client.bg_start(netserver_ip, test_option, netperf_para_sess, netperf_cmd_prefix) if utils_misc.wait_for(netperf_client.is_test_running, 10, 0, 1, "Wait netperf test start"): logging.debug("Netperf test start successfully.") #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 #the stress test. env["netperf_run"] = True else: raise error.TestNAError("Can not start netperf test") while (env["netperf_run"] and time.time() < stop_time): run_left_time = stop_time - time.time() if netperf_client.is_test_running(): if not utils_misc.wait_for( lambda: not netperf_client.is_test_running(), run_left_time, 0, 5, "Wait netperf test finish"): logging.debug("Stress test timeout, finish it") break netperf_client.bg_start(vm.get_address(), test_option, netperf_para_sess) finally: netperf_server.stop() netperf_server.env_cleanup(True) netperf_client.env_cleanup(True) env["netperf_run"] = False if session: session.close()
def run(test, params, env): """ Network stress with multi nics test with netperf. 1) Start multi vm(s) guest. 2) Select multi vm(s) or host to setup netperf server/client. 3) Execute netperf stress on multi nics. 4) Ping test after netperf testing, check whether nics still work. :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ login_timeout = float(params.get("login_timeout", 360)) netperf_server = params.get("netperf_server").split() netperf_client = params.get("netperf_client") guest_username = params.get("username", "") guest_password = params.get("password", "") shell_client = params.get("shell_client") shell_port = params.get("shell_port") os_type = params.get("os_type") shell_prompt = params.get("shell_prompt", r"^root@.*[\#\$]\s*$|#") disable_firewall = params.get("disable_firewall", "") linesep = params.get("shell_linesep", "\n").encode().decode('unicode_escape') status_test_command = params.get("status_test_command", "echo $?") ping_count = int(params.get("ping_count", 10)) compile_option_client = params.get("compile_option_client", "") compile_option_server = params.get("compile_option_server", "") vms = params.get("vms") server_infos = [] client_infos = [] server_ips = [] client_ips = [] os_type = params.get("os_type") if os_type == "windows": host_mem = utils_memory.memtotal() // (1024 * 1024) vm_mem = host_mem / (len(vms.split()) + 1) * 1024 if vm_mem < params.get_numeric("min_mem"): test.cancel("Host total memory is insufficient for this test case," "each VM's memory can not meet guest OS's requirement") params["mem"] = vm_mem params["start_vm"] = "yes" env_process.preprocess(test, params, env) for server in netperf_server: s_info = {} if server in vms: server_vm = env.get_vm(server) server_vm.verify_alive() server_ctl = server_vm.wait_for_serial_login(timeout=login_timeout) error_context.context("Stop fireware on netperf server guest.", logging.info) server_ctl.cmd(disable_firewall, ignore_all_errors=True) server_ip = server_vm.get_address() server_ips.append(server_ip) s_info["ip"] = server_ip s_info["os_type"] = params.get("os_type_%s" % server, os_type) s_info["username"] = params.get("username_%s" % server, guest_username) s_info["password"] = params.get("password_%s" % server, guest_password) s_info["shell_client"] = params.get("shell_client_%s" % server, shell_client) s_info["shell_port"] = params.get("shell_port_%s" % server, shell_port) s_info["shell_prompt"] = params.get("shell_prompt_%s" % server, shell_prompt) s_info["linesep"] = params.get("linesep_%s" % server, linesep) s_info["status_test_command"] = params.get( "status_test_command_%s" % server, status_test_command) else: err = "Only support setup netperf server in guest." test.error(err) server_infos.append(s_info) client = netperf_client.strip() c_info = {} if client in vms: client_vm = env.get_vm(client) client_vm.verify_alive() client_ctl = client_vm.wait_for_serial_login(timeout=login_timeout) if params.get("dhcp_cmd"): status, output = client_ctl.cmd_status_output(params["dhcp_cmd"], timeout=600) if status: logging.warn("Failed to execute dhcp-command, output:\n %s", output) error_context.context("Stop fireware on netperf client guest.", logging.info) client_ctl.cmd(disable_firewall, ignore_all_errors=True) client_ip = client_vm.get_address() client_ips.append(client_ip) params_client_nic = params.object_params(client) nics_count = len(params_client_nic.get("nics", "").split()) if nics_count > 1: for i in range(nics_count)[1:]: client_vm.wait_for_login(nic_index=i, timeout=login_timeout) client_ips.append(client_vm.get_address(index=i)) c_info["ip"] = client_ip c_info["os_type"] = params.get("os_type_%s" % client, os_type) c_info["username"] = params.get("username_%s" % client, guest_username) c_info["password"] = params.get("password_%s" % client, guest_password) c_info["shell_client"] = params.get("shell_client_%s" % client, shell_client) c_info["shell_port"] = params.get("shell_port_%s" % client, shell_port) c_info["shell_prompt"] = params.get("shell_prompt_%s" % client, shell_prompt) c_info["linesep"] = params.get("linesep_%s" % client, linesep) c_info["status_test_command"] = params.get( "status_test_command_%s" % client, status_test_command) else: err = "Only support setup netperf client in guest." test.error(err) client_infos.append(c_info) if params.get("os_type") == "linux": error_context.context("Config static route in netperf server guest.", logging.info) nics_list = utils_net.get_linux_ifname(client_ctl) for ip in server_ips: index = server_ips.index(ip) % len(nics_list) client_ctl.cmd("route add -host %s %s" % (ip, nics_list[index])) netperf_link = params.get("netperf_link") netperf_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_link) md5sum = params.get("pkg_md5sum") netperf_server_link = params.get("netperf_server_link_win", netperf_link) netperf_server_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_server_link) server_md5sum = params.get("server_md5sum") netperf_client_link = params.get("netperf_client_link_win", netperf_link) netperf_client_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_client_link) client_md5sum = params.get("client_md5sum") server_path_linux = params.get("server_path", "/var/tmp") client_path_linux = params.get("client_path", "/var/tmp") server_path_win = params.get("server_path_win", "c:\\") client_path_win = params.get("client_path_win", "c:\\") netperf_clients = [] netperf_servers = [] error_context.context("Setup netperf guest.", logging.info) for c_info in client_infos: if c_info["os_type"] == "windows": netperf_link_c = netperf_client_link client_path = client_path_win md5sum = client_md5sum else: netperf_link_c = netperf_link client_path = client_path_linux n_client = utils_netperf.NetperfClient( c_info["ip"], client_path, md5sum, netperf_link_c, client=c_info["shell_client"], port=c_info["shell_port"], username=c_info["username"], password=c_info["password"], prompt=c_info["shell_prompt"], linesep=c_info["linesep"], status_test_command=c_info["status_test_command"], compile_option=compile_option_client) netperf_clients.append(n_client) error_context.context("Setup netperf server.", logging.info) for s_info in server_infos: if s_info["os_type"] == "windows": netperf_link_s = netperf_server_link server_path = server_path_win md5sum = server_md5sum else: netperf_link_s = netperf_link server_path = server_path_linux n_server = utils_netperf.NetperfServer( s_info["ip"], server_path, md5sum, netperf_link_s, client=s_info["shell_client"], port=s_info["shell_port"], username=s_info["username"], password=s_info["password"], prompt=s_info["shell_prompt"], linesep=s_info["linesep"], status_test_command=s_info["status_test_command"], compile_option=compile_option_server) netperf_servers.append(n_server) try: error_context.context("Start netperf server.", logging.info) for n_server in netperf_servers: n_server.start() test_duration = int(params.get("netperf_test_duration", 60)) test_protocols = params.get("test_protocols", "TCP_STREAM") netperf_sessions = params.get("netperf_sessions", "1") p_sizes = params.get("package_sizes") netperf_cmd_prefix = params.get("netperf_cmd_prefix", "") error_context.context("Start netperf clients.", logging.info) for protocol in test_protocols.split(): error_context.context("Testing %s protocol" % protocol, logging.info) sessions_test = netperf_sessions.split() sizes_test = p_sizes.split() for size in sizes_test: for sess in sessions_test: test_option = params.get("test_option", "") test_option += " -t %s -l %s " % (protocol, test_duration) test_option += " -- -m %s" % size launch_netperf_client(test, server_ips, netperf_clients, test_option, test_duration, sess, netperf_cmd_prefix, params) error_context.context("Ping test after netperf testing.", logging.info) for s_ip in server_ips: status, output = utils_test.ping(s_ip, ping_count, timeout=float(ping_count) * 1.5) if status != 0: test.fail("Ping returns non-zero value %s" % output) package_lost = utils_test.get_loss_ratio(output) if package_lost != 0: test.fail("%s packeage lost when ping server ip %s " % (package_lost, server)) finally: for n_server in netperf_servers: n_server.stop() n_server.cleanup(True) for n_client in netperf_clients: n_client.stop() n_client.cleanup(True) if server_ctl: server_ctl.close() if client_ctl: client_ctl.close()
def test_netperf(): """ Netperf stress test for nic option. """ netperf_client_link = os.path.join(data_dir.get_deps_dir("netperf"), params.get("netperf_client_link")) client_path = params.get("client_path") n_client = utils_netperf.NetperfClient( vm.get_address(), client_path, netperf_source=netperf_client_link, client=params.get("shell_client"), port=params.get("shell_port"), username=params.get("username"), password=params.get("password"), prompt=params.get("shell_prompt"), linesep=params.get("shell_linesep", "\n").encode().decode('unicode_escape'), status_test_command=params.get("status_test_command", ""), compile_option=params.get("compile_option", "")) n_server = utils_netperf.NetperfServer( utils_net.get_host_ip_address(params), params.get("server_path", "/var/tmp"), netperf_source=os.path.join(data_dir.get_deps_dir("netperf"), params.get("netperf_server_link")), password=params.get("hostpassword"), compile_option=params.get("compile_option", "")) try: n_server.start() # Run netperf with message size defined in range. netperf_test_duration = int( params.get("netperf_test_duration", 180)) netperf_para_sess = params.get("netperf_para_sessions", "1") test_protocols = params.get("test_protocols", "TCP_STREAM") netperf_cmd_prefix = params.get("netperf_cmd_prefix", "") netperf_output_unit = params.get("netperf_output_unit") netperf_package_sizes = params.get("netperf_sizes") test_option = params.get("test_option", "") test_option += " -l %s" % netperf_test_duration if params.get("netperf_remote_cpu") == "yes": test_option += " -C" if params.get("netperf_local_cpu") == "yes": test_option += " -c" if netperf_output_unit in "GMKgmk": test_option += " -f %s" % netperf_output_unit start_time = time.time() stop_time = start_time + netperf_test_duration num = 0 for protocol in test_protocols.split(): error_context.context("Testing %s protocol" % protocol, logging.info) t_option = "%s -t %s" % (test_option, protocol) n_client.bg_start(utils_net.get_host_ip_address(params), t_option, netperf_para_sess, netperf_cmd_prefix, package_sizes=netperf_package_sizes) if utils_misc.wait_for(n_client.is_netperf_running, 10, 0, 1, "Wait netperf test start"): logging.info("Netperf test start successfully.") else: 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 # the stress test. env["netperf_run"] = True netperf_test_duration = stop_time - time.time() utils_misc.wait_for( lambda: not n_client.is_netperf_running(), netperf_test_duration, 0, 5, "Wait netperf test finish %ss" % netperf_test_duration) time.sleep(5) finally: n_server.stop() n_server.package.env_cleanup(True) n_client.package.env_cleanup(True)
def run(test, params, env): """ MULTI_QUEUE chang queues number test 1) Boot up VM, and login guest 2) Enable the queues in guest 3) Run netperf_and_ping test 4) Change queues number repeatedly during netperf_and_ping stress testing 5) Reboot VM 6) Repeat above 1-4 steps :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ def change_queues_number(ifname, q_number, queues_status=None): """ change queues number """ if not queues_status: queues_status = get_queues_status(ifname) mq_set_cmd = "ethtool -L %s combined %d" % (ifname, q_number) output = session_serial.cmd_output_safe(mq_set_cmd) cur_queues_status = get_queues_status(ifname) err_msg = "" expect_q_number = q_number if q_number != queues_status[1] and q_number <= queues_status[0]: if (cur_queues_status[1] != q_number or cur_queues_status[0] != queues_status[0]): err_msg = "Param is valid, but change queues failed, " elif cur_queues_status != queues_status: if q_number != queues_status[1]: err_msg = "Param is invalid, " err_msg += "Current queues value is not expected, " expect_q_number = queues_status[1] if len(err_msg) > 0: err_msg += "current queues set is %s, " % cur_queues_status[1] err_msg += "max allow queues set is %s, " % cur_queues_status[0] err_msg += "when run cmd: '%s', " % mq_set_cmd err_msg += "expect queues are %s," % expect_q_number err_msg += "expect max allow queues are %s, " % queues_status[0] err_msg += "output: '%s'" % output test.fail(err_msg) return cur_queues_status def get_queues_status(ifname): """ Get queues status """ mq_get_cmd = "ethtool -l %s" % ifname nic_mq_info = session_serial.cmd_output_safe(mq_get_cmd) queues_reg = re.compile(r"Combined:\s+(\d)", re.I) queues_info = queues_reg.findall(" ".join(nic_mq_info.splitlines())) if len(queues_info) != 2: err_msg = "Oops, get guest queues info failed, " err_msg += "make sure your guest support MQ.\n" err_msg += "Check cmd is: '%s', " % mq_get_cmd err_msg += "Command output is: '%s'." % nic_mq_info test.cancel(err_msg) return [int(x) for x in queues_info] def ping_test(dest_ip, ping_time, ping_lost_ratio): """ ping guest from host,until change queues finished. """ _, output = utils_net.ping(dest=dest_ip, timeout=ping_time) packets_lost = utils_test.get_loss_ratio(output) if packets_lost > ping_lost_ratio: err = " %s%% packages lost during ping. " % packets_lost err += "Ping command log:\n %s" % "\n".join( output.splitlines()[-3:]) test.fail(err) def netperf_test(): """ Netperf stress test for nic option. """ try: n_server.start() # Run netperf with message size defined in range. netperf_test_duration = params.get_numeric("netperf_test_duration") test_protocols = params.get("test_protocols", "TCP_STREAM") netperf_output_unit = params.get("netperf_output_unit") test_option = params.get("test_option", "") test_option += " -l %s" % netperf_test_duration if netperf_output_unit in "GMKgmk": test_option += " -f %s" % netperf_output_unit t_option = "%s -t %s" % (test_option, test_protocols) n_client.bg_start(utils_net.get_host_ip_address(params), t_option, params.get_numeric("netperf_para_sessions"), params.get("netperf_cmd_prefix", ""), package_sizes=params.get("netperf_sizes")) if utils_misc.wait_for(n_client.is_netperf_running, 10, 0, 1, "Wait netperf test start"): logging.info("Netperf test start successfully.") else: test.error("Can not start netperf client.") utils_misc.wait_for( lambda: not n_client.is_netperf_running(), netperf_test_duration, 0, 5, "Wait netperf test finish %ss" % netperf_test_duration) finally: n_server.stop() login_timeout = params.get_numeric("login_timeout", 360) netperf_stress = params.get("run_bgstress") vm = env.get_vm(params["main_vm"]) vm.verify_alive() vm.wait_for_serial_login(timeout=login_timeout) guest_ip = vm.get_address() n_client = utils_netperf.NetperfClient( guest_ip, params.get("client_path"), netperf_source=os.path.join(data_dir.get_deps_dir("netperf"), params.get("netperf_client_link")), client=params.get("shell_client"), username=params.get("username"), password=params.get("password"), compile_option=params.get("compile_option", "")) n_server = utils_netperf.NetperfServer( utils_net.get_host_ip_address(params), params.get("server_path", "/var/tmp"), netperf_source=os.path.join(data_dir.get_deps_dir("netperf"), params.get("netperf_server_link")), password=params.get("hostpassword"), compile_option=params.get("compile_option", "")) wait_time = params.get_numeric("wait_bg_time") ping_lost_ratio = params.get_numeric("background_ping_package_lost_ratio", 5) ping_time = params.get_numeric("background_ping_time") required_reboot = True bg_test = True try: while bg_test: session_serial = vm.wait_for_serial_login(timeout=login_timeout) n_client.session = session_serial error_context.context("Enable multi queues in guest.", logging.info) for nic in vm.virtnet: ifname = utils_net.get_linux_ifname(session_serial, nic.mac) queues = int(nic.queues) change_queues_number(ifname, queues) error_context.context("Run test %s background" % netperf_stress, logging.info) stress_thread = utils_misc.InterruptedThread(netperf_test) stress_thread.start() utils_misc.wait_for(lambda: wait_time, 0, 5, "Wait %s start background" % netperf_stress) # ping test error_context.context("Ping guest from host", logging.info) args = (guest_ip, ping_time, ping_lost_ratio) bg_ping = utils_misc.InterruptedThread(ping_test, args) bg_ping.start() error_context.context("Change queues number repeatedly", logging.info) repeat_counts = params.get_numeric("repeat_counts") for nic in vm.virtnet: queues = int(nic.queues) if queues == 1: logging.info("Nic with single queue, skip and continue") continue ifname = utils_net.get_linux_ifname(session_serial, nic.mac) change_list = params.get("change_list").split(",") for repeat_num in range(repeat_counts): error_context.context( "Change queues number -- %sth" % repeat_num, logging.info) queues_status = get_queues_status(ifname) for q_number in change_list: queues_status = change_queues_number( ifname, int(q_number), queues_status) logging.info("wait for background test finish") try: stress_thread.join() except Exception as err: err_msg = "Run %s test background error!\n " err_msg += "Error Info: '%s'" test.error(err_msg % (netperf_stress, err)) logging.info("Wait for background ping test finish.") try: bg_ping.join() except Exception as err: txt = "Fail to wait background ping test finish. " txt += "Got error message %s" % err test.fail(txt) if required_reboot: logging.info("Rebooting guest ...") vm.reboot() required_reboot = False else: bg_test = False finally: n_server.cleanup(True) n_client.cleanup(True) if session_serial: session_serial.close()
def run(test, params, env): """ KVM migration test: 1) Start a guest. 2) Start netperf server in guest. 3) Start multi netperf clients in host. 4) Migrate the guest in local during netperf clients working. 5) Repeatedly migrate VM and wait until netperf clients stopped. :param test: QEMU test object. :param params: Dictionary with test parameters. :param env: Dictionary with the test environment. """ login_timeout = int(params.get("login_timeout", 360)) mig_timeout = float(params.get("mig_timeout", "3600")) mig_protocol = params.get("migration_protocol", "tcp") mig_cancel_delay = int(params.get("mig_cancel") == "yes") * 2 netperf_timeout = int(params.get("netperf_timeout", "300")) client_num = int(params.get("client_num", "100")) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=login_timeout) guest_address = vm.get_address() host_address = utils_net.get_host_ip_address(params) remote_ip = params.get("remote_host", host_address) netperf_link = utils_misc.get_path(data_dir.get_deps_dir("netperf"), params.get("netperf_link")) md5sum = params.get("pkg_md5sum") netperf_link_win = params.get("netperf_link_win") if netperf_link_win: netperf_link_win = utils_misc.get_path(data_dir.get_deps_dir("netperf"), netperf_link_win) netperf_md5sum_win = params.get("netperf_md5sum_win") netperf_server_link = params.get("netperf_server_link", netperf_link) server_md5sum = params.get("server_md5sum", md5sum) netperf_server_link = utils_misc.get_path(data_dir.get_deps_dir("netperf"), netperf_server_link) server_path = params.get("server_path", "/var/tmp/") client_path = params.get("client_path", "/var/tmp/") server_path_win = params.get("server_path_win") client_path_win = params.get("client_path_win") username = params.get("username", "root") password = params.get("password", "redhat") passwd = params.get("hostpasswd", "redhat") client = params.get("shell_client", "ssh") port = params.get("shell_port", "22") if params.get("os_type") == "linux": session.cmd("iptables -F", ignore_all_errors=True) g_client_link = netperf_link g_server_path = server_path g_client_path = client_path g_client_install = False elif params.get("os_type") == "windows": g_client_link = netperf_link_win g_server_path = server_path_win g_client_path = client_path_win md5sum = netperf_md5sum_win g_client_install = True netperf_client_g = None netperf_client_h = None netperf_server_g = None netperf_server_h = None try: netperf_client_g = utils_netperf.NetperfClient(guest_address, g_client_path, md5sum, g_client_link, client=client, port=port, username=username, password=password, install=g_client_install) netperf_server_h = utils_netperf.NetperfServer(remote_ip, server_path, server_md5sum, netperf_link, password=passwd, install=False) netperf_client_h = utils_netperf.NetperfClient(remote_ip, client_path, md5sum, netperf_link, password=passwd) netperf_server_g = utils_netperf.NetperfServer(guest_address, g_server_path, server_md5sum, netperf_server_link, client=client, port=port, username=username, password=password) error.base_context("Run netperf test between host and guest") error.context("Start netserver in guest.", logging.info) netperf_server_g.start() if netperf_server_h: error.context("Start netserver in host.", logging.info) netperf_server_h.start() error.context("Start Netperf in host", logging.info) test_option = "-l %s" % netperf_timeout netperf_client_h.bg_start(guest_address, test_option, client_num) if netperf_client_g: error.context("Start Netperf in guest", logging.info) netperf_client_g.bg_start(host_address, test_option, client_num) m_count = 0 while netperf_client_h.is_netperf_running(): m_count += 1 error.context("Start migration iterations: %s " % m_count, logging.info) vm.migrate(mig_timeout, mig_protocol, mig_cancel_delay, env=env) finally: if netperf_server_g: if netperf_server_g.is_server_running(): netperf_server_g.stop() netperf_server_g.package.env_cleanup(True) if netperf_server_h: if netperf_server_h.is_server_running(): netperf_server_h.stop() netperf_server_h.package.env_cleanup(True) if netperf_client_h: if netperf_client_h.is_netperf_running(): netperf_client_h.stop() netperf_client_h.package.env_cleanup(True) if netperf_client_g: if netperf_client_g.is_netperf_running(): netperf_client_g.stop() netperf_client_g.package.env_cleanup(True) if session: session.close()
def run(test, params, env): """ QEMU flow caches stress test case, only for linux 1) Make sure nf_conntrack is disabled in host and guest. If nf_conntrack is enabled in host, skip this case. 2) Boot guest with vhost=on/off. 3) Enable multi queues support in guest (optional). 4) After installation of netperf, run netserver in host. 5) Run netperf TCP_CRR protocal test in guest. 6) Transfer file between guest and host. 7) Check the md5 of copied file. This is a sample QEMU test, so people can get used to some of the test APIs. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ def get_if_queues(ifname): """ Query interface queues with 'ethtool -l' :param ifname: interface name """ cmd = "ethtool -l %s" % ifname out = session.cmd_output(cmd) logging.info(out) nf_conntrack_max_set_cmd = params.get("nf_conntrack_max_set") logging.info("nf_conntrack_max_set_cmd is %s", nf_conntrack_max_set_cmd) msg = "Make sure nf_conntrack is disabled in host and guest." error_context.context(msg, logging.info) if str.encode("nf_conntrack") in process.system_output("lsmod"): process.system_output(nf_conntrack_max_set_cmd) params["start_vm"] = "yes" error_context.context("Boot up guest", logging.info) env_process.preprocess_vm(test, params, env, params["main_vm"]) vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) if "nf_conntrack" in session.cmd_output("lsmod"): msg = "Unload nf_conntrack module in guest." error_context.context(msg, logging.info) black_str = "#disable nf_conntrack\\nblacklist nf_conntrack\\n" \ "blacklist nf_conntrack_ipv6\\nblacklist xt_conntrack\\n" \ "blacklist nf_conntrack_ftp\\nblacklist xt_state\\n" \ "blacklist iptable_nat\\nblacklist ipt_REDIRECT\\n" \ "blacklist nf_nat\\nblacklist nf_conntrack_ipv4" cmd = "echo -e '%s' >> /etc/modprobe.d/blacklist.conf" % black_str session.cmd(cmd) session = vm.reboot(session, timeout=timeout) if "nf_conntrack" in session.cmd_output("lsmod"): err = "nf_conntrack module still running in guest, " err += "set nf_conntrack_max instead." error_context.context(err, logging.info) session.cmd(nf_conntrack_max_set_cmd) netperf_link = os.path.join(data_dir.get_deps_dir("netperf"), params.get("netperf_link")) md5sum = params.get("pkg_md5sum") client_num = params.get("netperf_client_num", 520) netperf_timeout = int(params.get("netperf_timeout", 600)) disable_firewall = params.get("disable_firewall", "") if int(params.get("queues", 1)) > 1 and params.get("os_type") == "linux": error_context.context("Enable multi queues support in guest.", logging.info) guest_mac = vm.get_mac_address() ifname = utils_net.get_linux_ifname(session, guest_mac) get_if_queues(ifname) try: cmd = "ethtool -L %s combined %s" % (ifname, params.get("queues")) status, out = session.cmd_status_output(cmd) except Exception: get_if_queues(ifname) msg = "Fail to enable multi queues support in guest." msg += "Command %s fail output: %s" % (cmd, out) test.error(msg) logging.info("Command %s set queues succeed", cmd) error_context.context("Setup netperf in guest", logging.info) if params.get("os_type") == "linux": session.cmd(disable_firewall, ignore_all_errors=True) g_client_link = netperf_link g_client_path = params.get("client_path", "/var/tmp/") netperf_client_ip = vm.get_address() username = params.get("username", "root") password = params.get("password", "123456") client = params.get("shell_client", "ssh") port = params.get("shell_port", "22") prompt = params.get("shell_prompt", r"^root@.*[\#\$]\s*$|#") linesep = params.get("shell_linesep", "\n").encode().decode('unicode_escape') status_test_command = params.get("status_test_command", "echo $?") compile_option_client = params.get("compile_option_client", "") netperf_client = utils_netperf.NetperfClient( netperf_client_ip, g_client_path, md5sum, g_client_link, client, port, username=username, password=password, prompt=prompt, linesep=linesep, status_test_command=status_test_command, compile_option=compile_option_client) error_context.context("Setup netperf in host", logging.info) host_ip = utils_net.get_host_ip_address(params) server_path = params.get("server_path", "/var/tmp/") server_shell_client = params.get("server_shell_client", "ssh") server_shell_port = params.get("server_shell_port", "22") server_passwd = params["hostpasswd"] server_username = params.get("host_username", "root") compile_option_server = params.get("compile_option_server", "") netperf_server = utils_netperf.NetperfServer( host_ip, server_path, md5sum, netperf_link, server_shell_client, server_shell_port, username=server_username, password=server_passwd, prompt=prompt, linesep=linesep, status_test_command=status_test_command, compile_option=compile_option_server) try: error_context.base_context("Run netperf test between host and guest.") error_context.context("Start netserver in host.", logging.info) netperf_server.start() error_context.context( "Start Netperf in guest for %ss." % netperf_timeout, logging.info) test_option = "-t TCP_CRR -l %s -- -b 10 -D" % netperf_timeout netperf_client.bg_start(host_ip, test_option, client_num) start_time = time.time() deviation_time = params.get_numeric("deviation_time") duration = time.time() - start_time max_run_time = netperf_timeout + deviation_time while duration < max_run_time: time.sleep(10) duration = time.time() - start_time status = netperf_client.is_netperf_running() if not status and duration < netperf_timeout - 10: test.fail("netperf terminated unexpectedly") logging.info("Wait netperf test finish %ss", duration) if netperf_client.is_netperf_running(): test.fail("netperf still running, netperf hangs") else: logging.info("netperf runs successfully") finally: netperf_server.stop() netperf_client.cleanup(True) netperf_server.cleanup(True) if session: session.close()
def run(test, params, env): """ KVM migration test: 1) Start a guest. 2) Start netperf server in guest. 3) Start multi netperf clients in host. 4) Migrate the guest in local during netperf clients working. 5) Repeatedly migrate VM and wait until netperf clients stopped. :param test: QEMU test object. :param params: Dictionary with test parameters. :param env: Dictionary with the test environment. """ login_timeout = int(params.get("login_timeout", 360)) mig_timeout = float(params.get("mig_timeout", "3600")) mig_protocol = params.get("migration_protocol", "tcp") mig_cancel_delay = int(params.get("mig_cancel") == "yes") * 2 netperf_timeout = int(params.get("netperf_timeout", "300")) client_num = int(params.get("client_num", "100")) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=login_timeout) guest_address = vm.get_address() host_address = utils_net.get_host_ip_address(params) remote_ip = params.get("remote_host", host_address) netperf_link = os.path.join(data_dir.get_deps_dir("netperf"), params.get("netperf_link")) netperf_server_link = params.get("netperf_server_link_win") if netperf_server_link: netperf_server_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_server_link) netperf_client_link = params.get("netperf_client_link_win", netperf_link) netperf_client_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_client_link) server_path = params.get("server_path", "/var/tmp/") client_path = params.get("client_path", "/var/tmp/") server_path_win = params.get("server_path_win") client_path_win = params.get("client_path_win") if params.get("os_type") == "linux": session.cmd("iptables -F", ignore_all_errors=True) g_client_link = netperf_link g_server_link = netperf_link g_server_path = server_path g_client_path = client_path elif params.get("os_type") == "windows": g_client_link = netperf_client_link g_server_link = netperf_server_link g_server_path = server_path_win g_client_path = client_path_win netperf_client_g = None netperf_client_h = None netperf_server_g = None netperf_server_h = None try: netperf_client_g = utils_netperf.NetperfClient( guest_address, g_client_path, netperf_source=g_client_link, client=params.get("shell_client"), port=params.get("shell_port"), prompt=params.get("shell_prompt", r"^root@.*[\#\$]\s*$|#"), username=params.get("username"), password=params.get("password"), linesep=params.get("shell_linesep", "\n").encode().decode('unicode_escape'), status_test_command=params.get("status_test_command", ""), compile_option=params.get("compile_option_client_g", "")) netperf_server_h = utils_netperf.NetperfServer( remote_ip, server_path, netperf_source=netperf_link, password=params.get("hostpassword"), compile_option=params.get("compile_option", "")) netperf_client_h = utils_netperf.NetperfClient( remote_ip, client_path, netperf_source=netperf_link, password=params.get("hostpassword"), compile_option=params.get("compile_option", "")) netperf_server_g = utils_netperf.NetperfServer( guest_address, g_server_path, netperf_source=g_server_link, username=params.get("username"), password=params.get("password"), client=params.get("shell_client"), port=params.get("shell_port"), prompt=params.get("shell_prompt", r"^root@.*[\#\$]\s*$|#"), linesep=params.get("shell_linesep", "\n").encode().decode('unicode_escape'), status_test_command=params.get("status_test_command", "echo $?"), compile_option=params.get("compile_option_server_g", "")) error_context.base_context("Run netperf test between host and guest") error_context.context("Start netserver in guest.", logging.info) netperf_server_g.start() if netperf_server_h: error_context.context("Start netserver in host.", logging.info) netperf_server_h.start() error_context.context("Start Netperf in host", logging.info) test_option = "-l %s" % netperf_timeout netperf_client_h.bg_start(guest_address, test_option, client_num) if netperf_client_g: error_context.context("Start Netperf in guest", logging.info) netperf_client_g.bg_start(host_address, test_option, client_num) m_count = 0 while netperf_client_h.is_netperf_running(): m_count += 1 error_context.context("Start migration iterations: %s " % m_count, logging.info) vm.migrate(mig_timeout, mig_protocol, mig_cancel_delay, env=env) finally: if netperf_server_g: if netperf_server_g.is_server_running(): netperf_server_g.stop() netperf_server_g.package.env_cleanup(True) if netperf_server_h: if netperf_server_h.is_server_running(): netperf_server_h.stop() netperf_server_h.package.env_cleanup(True) if netperf_client_h: if netperf_client_h.is_netperf_running(): netperf_client_h.stop() netperf_client_h.package.env_cleanup(True) if netperf_client_g: if netperf_client_g.is_netperf_running(): netperf_client_g.stop() netperf_client_g.package.env_cleanup(True) if session: session.close()
def run(test, params, env): """ KVM migration test: 1) Start a guest. 2) Start netperf server in guest. 3) Start multi netperf clients in host. 4) Migrate the guest in local during netperf clients working. 5) Repeatedly migrate VM and wait until netperf clients stopped. :param test: QEMU test object. :param params: Dictionary with test parameters. :param env: Dictionary with the test environment. """ def dlink_preprcess(download_link): """ Preprocess the download link """ if not download_link: raise error.TestNAError("Can not get the netperf download_link") if not utils.is_url(download_link): download_link = utils_misc.get_path(data_dir.get_deps_dir(), download_link) return download_link login_timeout = int(params.get("login_timeout", 360)) mig_timeout = float(params.get("mig_timeout", "3600")) mig_protocol = params.get("migration_protocol", "tcp") mig_cancel_delay = int(params.get("mig_cancel") == "yes") * 2 netperf_timeout = int(params.get("netperf_timeout", "300")) client_num = int(params.get("client_num", "100")) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=login_timeout) guest_address = vm.get_address() download_link = dlink_preprcess(params.get("netperf_download_link")) md5sum = params.get("pkg_md5sum") server_download_link = params.get("server_download_link", download_link) server_md5sum = params.get("server_md5sum", md5sum) server_download_link = dlink_preprcess(server_download_link) server_path = params.get("server_path", "/tmp/server.tar.bz2") client_path = params.get("client_path", "/tmp/client.tar.bz2") username = params.get("username", "root") password = params.get("password", "redhat") passwd = params.get("hostpasswd", "redhat") client = params.get("shell_client", "ssh") port = params.get("shell_port", "22") netperf_client = utils_netperf.NetperfClient("localhost", client_path, md5sum, download_link, password=passwd) netperf_server = utils_netperf.NetperfServer(guest_address, server_path, server_md5sum, server_download_link, client, port, username=username, password=password) try: if params.get("os_type") == "linux": session.cmd("iptables -F", ignore_all_errors=True) error.base_context("Run netperf test between host and guest") error.context("Start netserver in guest.", logging.info) netperf_server.start() error.context("Start Netperf on host", logging.info) test_option = "-l %s" % netperf_timeout netperf_client.bg_start(guest_address, test_option, client_num) m_count = 0 while netperf_client.is_test_running(): m_count += 1 error.context("Start migration iterations: %s " % m_count, logging.info) vm.migrate(mig_timeout, mig_protocol, mig_cancel_delay) finally: netperf_server.stop() netperf_server.env_cleanup(True) netperf_client.env_cleanup(True) if session: session.close()
def run(test, params, env): """ apicv test: 1) Check if apicv is enabled on host, if not, enable it 2) Boot guest and run netperf inside guest 3) Record throughput and shutdown guest 4) Disable apicv on host 5) Boot guest and run netperf inside guest again 6) Compare benchmark scores with step 3) 7) Restore env, set apicv back :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def reload_module(value): """ Reload module """ process.system("rmmod %s" % module) cmd = "modprobe %s %s=%s" % (module, mod_param, value) process.system(cmd) def run_netperf(): """ Run netperf test, return average throughput """ error_context.context("Run netperf test", test.log.info) n_server.start() n_client.session = session throughput = 0 for i in range(repeat_times): output = n_client.start(server_address=host_ip, test_option=params.get("test_option")) throughput += float( re.findall(r"580\s+\d+\.?\d+\s+(\d+\.?\d+)", output)[0]) time.sleep(1) n_server.stop() return throughput / repeat_times module = params["module_name"] mod_param = params["mod_param"] error_context.context("Enable apicv on host", test.log.info) cmd = "cat /sys/module/%s/parameters/%s" % (module, mod_param) ori_apicv = process.getoutput(cmd) if ori_apicv != 'Y': reload_module("Y") params["start_vm"] = "yes" env_process.preprocess_vm(test, params, env, params['main_vm']) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login() host_ip = utils_net.get_host_ip_address(params) n_server = utils_netperf.NetperfServer( address=host_ip, netperf_path=params["server_path"], netperf_source=os.path.join(data_dir.get_deps_dir("netperf"), params.get("netperf_server_link")), username=params.get("host_username", "root"), password=params.get("host_password")) n_client = utils_netperf.NetperfClient( address=vm.get_address(), netperf_path=params["client_path"], netperf_source=os.path.join(data_dir.get_deps_dir("netperf"), params.get("netperf_client_link")), client=params.get("shell_client", "ssh"), port=params.get("shell_port"), username=params.get("username"), password=params.get("password"), prompt=params.get("shell_prompt", r"^root@.*[\#\$]\s*$|#")) repeat_times = params.get_numeric("repeat_times", 10) try: value_on = run_netperf() test.log.info("When enable apicv, average throughput is %s", value_on) vm.destroy() error_context.context("Disable apicv on host", test.log.info) reload_module("N") vm.create(params=params) session = vm.wait_for_login() value_off = run_netperf() test.log.info("When disable apicv, average throughput is %s", value_off) threshold = float(params.get("threshold", 0.9)) if value_on <= value_off * threshold: test.fail("Throughput is smaller when apicv is on than off") finally: n_server.cleanup(True) n_client.cleanup(True) session.close() vm.destroy() reload_module(ori_apicv)
def netperf_test(): """ Netperf stress test between two guest. """ n_client = utils_netperf.NetperfClient( addresses[0], params["client_path"], netperf_source=os.path.join(data_dir.get_deps_dir("netperf"), params.get("netperf_client_link")), client=params.get("shell_client"), port=params.get("shell_port"), prompt=params.get("shell_prompt", r"^root@.*[\#\$]\s*$|#"), username=params.get("username"), password=params.get("password"), linesep=params.get("shell_linesep", "\n").encode().decode('unicode_escape'), status_test_command=params.get("status_test_command", ""), compile_option=params.get("compile_option_client", "")) n_server = utils_netperf.NetperfServer( addresses[1], params["server_path"], netperf_source=os.path.join(data_dir.get_deps_dir("netperf"), params.get("netperf_server_link")), username=params.get("username"), password=params.get("password"), client=params.get("shell_client"), port=params.get("shell_port"), prompt=params.get("shell_prompt", r"^root@.*[\#\$]\s*$|#"), linesep=params.get("shell_linesep", "\n").encode().decode('unicode_escape'), status_test_command=params.get("status_test_command", "echo $?"), compile_option=params.get("compile_option_server", "")) try: n_server.start() # Run netperf with message size defined in range. netperf_test_duration = params.get_numeric("netperf_test_duration") test_protocols = params.get("test_protocols", "TCP_STREAM") netperf_output_unit = params.get("netperf_output_unit") test_option = params.get("test_option", "") test_option += " -l %s" % netperf_test_duration if netperf_output_unit in "GMKgmk": test_option += " -f %s" % netperf_output_unit t_option = "%s -t %s" % (test_option, test_protocols) n_client.bg_start(addresses[1], t_option, params.get_numeric("netperf_para_sessions"), params.get("netperf_cmd_prefix", ""), package_sizes=params.get("netperf_sizes")) if utils_misc.wait_for(n_client.is_netperf_running, 10, 0, 1, "Wait netperf test start"): logging.info("Netperf test start successfully.") else: test.error("Can not start netperf client.") utils_misc.wait_for( lambda: not n_client.is_netperf_running(), netperf_test_duration, 0, 5, "Wait netperf test finish %ss" % netperf_test_duration) finally: n_server.stop() n_server.cleanup(True) n_client.cleanup(True)
def run(test, params, env): """ Run netperf on server and client side, we need run this case on two machines. If dsthost is not set will start netperf server on local host and log a error message.: 1) Start one vm guest os as client or server (windows guest must using as server). 2) Start a reference machine (dsthost) as server/client. 3) Setup netperf on guest and reference machine (dsthost). 4) Start netperf server on the server host. 5) Run netperf client command in guest several time with different message size. 6) Compare UDP performance to make sure it is acceptable. :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ login_timeout = float(params.get("login_timeout", 360)) dsthost = params.get("dsthost", "localhost") vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) main_vm_ip = vm.get_address() session.cmd("iptables -F", ignore_all_errors=True) error.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"), netperf_link) md5sum = params.get("pkg_md5sum") netperf_server_link = params.get("netperf_server_link_win") if netperf_server_link: netperf_server_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_server_link) netperf_client_link = params.get("netperf_client_link_win") if netperf_client_link: netperf_client_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_client_link) server_md5sum = params.get("server_md5sum") client_md5sum = params.get("client_md5sum") os_type = params.get("os_type") server_path = params.get("server_path", "/var/tmp/") client_path = params.get("client_path", "/var/tmp/") server_path_win = params.get("server_path_win", "c:\\") client_path_win = params.get("client_path_win", "c:\\") guest_username = params.get("username", "") guest_password = params.get("password", "") host_password = params.get("hostpassword") client = params.get("shell_client") port = params.get("shell_port") compile_option_client = params.get("compile_option_client", "") compile_option_server = params.get("compile_option_server", "") if dsthost in params.get("vms", "vm1 vm2"): server_vm = env.get_vm(dsthost) server_vm.verify_alive() s_session = server_vm.wait_for_login(timeout=login_timeout) s_session.cmd("iptables -F", ignore_all_errors=True) netserver_ip = server_vm.get_address() s_session.close() s_client = client s_port = port s_username = guest_username s_password = guest_password if os_type == "windows": s_link = netperf_server_link s_path = server_path_win s_md5sum = server_md5sum else: s_link = netperf_link s_path = server_path s_md5sum = md5sum else: if re.match(r"((\d){1,3}\.){3}(\d){1,3}", dsthost): netserver_ip = dsthost else: server_interface = params.get("netdst", "switch") host_nic = utils_net.Interface(server_interface) netserver_ip = host_nic.get_ip() s_client = params.get("shell_client_%s" % dsthost, "ssh") s_port = params.get("shell_port_%s" % dsthost, "22") s_username = params.get("username_%s" % dsthost, "root") s_password = params.get("password_%s" % dsthost, "redhat") s_link = netperf_link s_path = server_path s_md5sum = md5sum if os_type == "windows": c_path = client_path_win c_md5sum = client_md5sum c_link = netperf_client_link else: c_path = client_path c_md5sum = md5sum c_link = netperf_link netperf_client = utils_netperf.NetperfClient( main_vm_ip, c_path, c_md5sum, c_link, client, port, username=guest_username, password=guest_password, compile_option=compile_option_client) netperf_server = utils_netperf.NetperfServer( netserver_ip, s_path, s_md5sum, s_link, s_client, s_port, username=s_username, password=s_password, compile_option=compile_option_server) # Get range of message size. message_size = params.get("message_size_range", "580 590 1").split() start_size = int(message_size[0]) end_size = int(message_size[1]) step = int(message_size[2]) m_size = start_size throughput = [] try: error.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" while (m_size <= end_size): 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) 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\.]+" try: line_tokens = re.findall(re_str, output)[0].split() except IndexError: txt = "Fail to get Throughput for %s." % m_size txt += " netprf client output: %s" % output raise error.TestError(txt) if not line_tokens: raise error.TestError("Output format is not expected") throughput.append(float(line_tokens[5])) msg += output m_size += step finally: netperf_server.stop() 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) 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) 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).") try: if session: session.close() except Exception: pass
def run(test, params, env): """ Network stress with multi nics test with netperf. 1) Start multi vm(s) guest. 2) Select multi vm(s) or host to setup netperf server/client. 3) Execute netperf stress on multi nics. 4) Ping test after netperf testing, check whether nics still work. :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ login_timeout = float(params.get("login_timeout", 360)) netperf_server = params.get("netperf_server").split() netperf_client = params.get("netperf_client") guest_username = params.get("username", "") guest_password = params.get("password", "") host_password = params.get("hostpassword", "redhat") shell_client = params.get("shell_client") shell_port = params.get("shell_port") os_type = params.get("os_type") host_ip = utils_net.get_host_ip_address(params) ping_count = int(params.get("ping_count", 10)) vms = params.get("vms") server_infos = [] client_infos = [] server_ips = [] client_ips = [] for server in netperf_server: s_info = {} if server in vms: server_vm = env.get_vm(server) server_vm.verify_alive() server_ctl = server_vm.wait_for_login(timeout=login_timeout) error.context("Stop fireware on netperf server guest.", logging.info) server_ctl.cmd("service iptables stop; iptables -F", ignore_all_errors=True) server_ip = server_vm.get_address() server_ips.append(server_ip) s_info["ip"] = server_ip s_info["os_type"] = params.get("os_type_%s" % server, os_type) s_info["username"] = params.get("username_%s" % server, guest_username) s_info["password"] = params.get("password_%s" % server, guest_password) s_info["shell_client"] = params.get("shell_client_%s" % server, shell_client) s_info["shell_port"] = params.get("shell_port_%s" % server, shell_port) else: err = "Only support setup netperf server in guest." raise error.TestError(err) server_infos.append(s_info) client = netperf_client.strip() c_info = {} if client in vms: client_vm = env.get_vm(client) client_vm.verify_alive() client_ctl = client_vm.wait_for_login(timeout=login_timeout) error.context("Stop fireware on netperf client guest.", logging.info) client_ctl.cmd("service iptables stop; iptables -F", ignore_all_errors=True) client_ip = client_vm.get_address() client_ips.append(client_ip) client_ctl_mac = server_vm.get_mac_address() params_client_nic = params.object_params(client) nics_count = len(params_client_nic.get("nics", "").split()) if nics_count > 1: for i in range(nics_count)[1:]: client_vm.wait_for_login(nic_index=i, timeout=login_timeout) client_ips.append(client_vm.get_address(index=i)) c_info["ip"] = client_ip c_info["os_type"] = params.get("os_type_%s" % client, os_type) c_info["username"] = params.get("username_%s" % client, guest_username) c_info["password"] = params.get("password_%s" % client, guest_password) c_info["shell_client"] = params.get("shell_client_%s" % client, shell_client) c_info["shell_port"] = params.get("shell_port_%s" % client, shell_port) else: err = "Only support setup netperf client in guest." raise error.TestError(err) client_infos.append(c_info) if params.get("os_type") == "linux": error.context("Config static route in netperf server guest.", logging.info) nics_list = utils_net.get_linux_ifname(client_ctl) for ip in server_ips: index = server_ips.index(ip) % len(nics_list) client_ctl.cmd("route add -host %s %s" % (ip, nics_list[index])) netperf_link = params.get("netperf_link") netperf_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_link) md5sum = params.get("pkg_md5sum") netperf_server_link = params.get("netperf_server_link_win", netperf_link) netperf_server_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_server_link) server_md5sum = params.get("server_md5sum") netperf_client_link = params.get("netperf_client_link_win", netperf_link) netperf_client_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_client_link) client_md5sum = params.get("client_md5sum") server_path_linux = params.get("server_path", "/var/tmp") client_path_linux = params.get("client_path", "/var/tmp") server_path_win = params.get("server_path_win", "c:\\") client_path_win = params.get("client_path_win", "c:\\") netperf_clients = [] netperf_servers = [] error.context("Setup netperf guest.", logging.info) for c_info in client_infos: if c_info["os_type"] == "windows": netperf_link_c = netperf_client_link client_path = client_path_win md5sum = client_md5sum else: netperf_link_c = netperf_link client_path = client_path_linux n_client = utils_netperf.NetperfClient(c_info["ip"], client_path, md5sum, netperf_link_c, client=c_info["shell_client"], port=c_info["shell_port"], username=c_info["username"], password=c_info["password"]) netperf_clients.append(n_client) error.context("Setup netperf server.", logging.info) for s_info in server_infos: if s_info["os_type"] == "windows": netperf_link_s = netperf_server_link server_path = server_path_win md5sum = server_md5sum else: netperf_link_s = netperf_link server_path = server_path_linux n_server = utils_netperf.NetperfServer(s_info["ip"], server_path, md5sum, netperf_link_s, client=s_info["shell_client"], port=s_info["shell_port"], username=s_info["username"], password=s_info["password"]) netperf_servers.append(n_server) try: error.context("Start netperf server.", logging.info) for n_server in netperf_servers: n_server.start() test_duration = int(params.get("netperf_test_duration", 60)) test_protocols = params.get("test_protocols", "TCP_STREAM") netperf_sessions = params.get("netperf_sessions", "1") p_sizes = params.get("package_sizes") netperf_cmd_prefix = params.get("netperf_cmd_prefix", "") netperf_pkg_size = params.get("netperf_pkg_size", "") error.context("Start netperf clients.", logging.info) for protocol in test_protocols.split(): error.context("Testing %s protocol" % protocol, logging.info) sessions_test = netperf_sessions.split() sizes_test = p_sizes.split() for size in sizes_test: for sess in sessions_test: test_option = params.get("test_option", "") test_option += " -t %s -l %s " % (protocol, test_duration) test_option += " -- -m %s" % size launch_netperf_client(server_ips, netperf_clients, test_option, test_duration, sess, netperf_cmd_prefix) error.context("Ping test after netperf testing.", logging.info) for s_ip in server_ips: status, output = utils_test.ping(s_ip, ping_count, timeout=float(ping_count) * 1.5) if status != 0: raise error.TestFail("Ping returns non-zero value %s" % output) package_lost = utils_test.get_loss_ratio(output) if package_lost != 0: raise error.TestFail( "%s packeage lost when ping server ip %s " % (package_lost, server)) finally: for n_server in netperf_servers: if n_server: n_server.stop() n_server.package.env_cleanup(True) for n_client in netperf_clients: if n_client: n_client.package.env_cleanup(True) if server_ctl: server_ctl.close() if client_ctl: client_ctl.close()
def run(test, params, env): """ Run netperf on server and client side, we need run this case on two machines. If dsthost is not set will start netperf server on local host and log a error message.: 1) Start one vm guest os as client or server (windows guest must using as server). 2) Start a reference machine (dsthost) as server/client. 3) Setup netperf on guest and reference machine (dsthost). 4) Start netperf server on the server host. 5) Run netperf client command in guest several time with different message size. 6) Compare UDP performance to make sure it is acceptable. :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def dlink_preprcess(download_link): """ Preprocess the download link """ if not download_link: raise error.TestNAError("Can not get the netperf download_link") if not utils.is_url(download_link): download_link = utils_misc.get_path(data_dir.get_deps_dir(), download_link) return download_link login_timeout = float(params.get("login_timeout", 360)) dsthost = params.get("dsthost", "localhost") vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) session.cmd("iptables -F", ignore_all_errors=True) if dsthost in params.get("vms", "vm1 vm2"): server_vm = env.get_vm(dsthost) server_vm.verify_alive() s_session = server_vm.wait_for_login(timeout=login_timeout) s_session.cmd("iptables -F", ignore_all_errors=True) dsthost_ip = server_vm.get_address() s_session.close() elif re.match(r"((\d){1,3}\.){3}(\d){1,3}", dsthost): dsthost_ip = dsthost else: server_interface = params.get("netdst", "switch") host_nic = utils_net.Interface(server_interface) dsthost_ip = host_nic.get_ip() error.context("Test env prepare", logging.info) download_link = dlink_preprcess(params.get("netperf_download_link")) md5sum = params.get("pkg_md5sum") server_download_link = params.get("server_download_link", download_link) server_download_link = dlink_preprcess(server_download_link) server_md5sum = params.get("server_md5sum", md5sum) server_path = params.get("server_path", "/var/tmp/server.tar.bz2") client_path = params.get("client_path", "/var/tmp/client.tar.bz2") guest_usrname = params.get("username", "") guest_passwd = params.get("password", "") host_passwd = params.get("hostpasswd") client = params.get("shell_client") port = params.get("shell_port") # main vm run as server when vm_as_server is 'yes'. if params.get("vm_as_server") == "yes": netserver_ip = vm.get_address() netperf_client_ip = dsthost_ip else: netserver_ip = dsthost_ip netperf_client_ip = vm.get_address() netperf_client = utils_netperf.NetperfClient(netperf_client_ip, client_path, md5sum, download_link, password=host_passwd) netperf_server = utils_netperf.NetperfServer(netserver_ip, server_path, server_md5sum, server_download_link, client, port, username=guest_usrname, password=guest_passwd) # Get range of message size. message_size = params.get("message_size_range", "580 590 1").split() start_size = int(message_size[0]) end_size = int(message_size[1]) step = int(message_size[2]) m_size = start_size throughput = [] try: error.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" while (m_size <= end_size): 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) output = netperf_client.start(netserver_ip, test_option) if test_protocol == "UDP_STREAM": speed_index = 6 elif test_protocol == "UDP_RR": speed_index = 7 else: error.TestNAError("Protocol %s is not support" % test_protocol) line_tokens = output.splitlines()[speed_index].split() if not line_tokens: raise error.TestError("Output format is not expected") throughput.append(float(line_tokens[5])) msg += output m_size += step finally: netperf_server.stop() 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) 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) 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).") try: if session: session.close() except Exception: pass