def ping(session, nic, dst_ip, strick_check, flood_minutes): d_packet_size = [1, 4, 48, 512, 1440, 1500, 1505, 4054, 4055, 4096, 4192, 8878, 9000, 32767, 65507] packet_size = params.get("packet_size", "").split() or d_packet_size for size in packet_size: error.context("Ping with packet size %s" % size, logging.info) status, output = utils_test.ping(dst_ip, 10, interface=nic, packetsize=size, timeout=30, session=session) if strict_check: ratio = utils_test.get_loss_ratio(output) if ratio != 0: raise error.TestFail("Loss ratio is %s for packet size" " %s" % (ratio, size)) else: if status != 0: raise error.TestFail("Ping returns non-zero value %s" % output) error.context("Flood ping test", logging.info) utils_test.ping( dst_ip, None, interface=nic, flood=True, output_func=None, timeout=flood_minutes * 60, session=session ) error.context("Final ping test", logging.info) counts = params.get("ping_counts", 100) status, output = utils_test.ping(dst_ip, counts, interface=nic, timeout=float(counts) * 1.5, session=session) if strick_check == "yes": ratio = utils_test.get_loss_ratio(output) if ratio != 0: raise error.TestFail("Packet loss ratio is %s after flood" % ratio) else: if status != 0: raise error.TestFail("Ping returns non-zero value %s" % output)
def set_link_test(linkid): """ Issue set_link commands and test its function @param linkid: id of netdev or devices to be tested """ ip = vm.get_address(0) error.context("Disable guest link by set_link", logging.info) vm.set_link(linkid, up=False) error.context("Ping guest from host", logging.info) s, o = utils_test.ping(ip, count=10, timeout=20) if utils_test.get_loss_ratio(o) != 100: raise error.TestFail("Still can ping the %s after down %s" % (ip, linkid)) error.context("Re-enable guest link by set_link", logging.info) vm.set_link(linkid, up=True) # Waiting for guest network up again. session = vm.wait_for_login(timeout=timeout) session.close() error.context("Ping guest from host", logging.info) s, o = utils_test.ping(ip, count=10, timeout=20) # we use 100% here as the notification of link status changed may be # delayed in guest driver if utils_test.get_loss_ratio(o) == 100: raise error.TestFail("Packet loss during ping %s after up %s" % (ip, linkid))
def ping(test, os_type, match_error, dest, count, session, same_vlan): """ In 'session' ping 'dest'. If the two guests are in the same vlan, loss ratio should be 0%. Otherwise, loss ratio should be 100%. :param test: QEMU test object :param dest: dest ip address :param count: ping count :param session: in which guest to do ping test :param same_vlan: whether the two guests are in the same vlan """ if os_type == "linux": status, output = utils_test.ping(dest, count, timeout=int(count) * 1.50, session=session) loss_ratio = utils_test.get_loss_ratio(output) ping_result_check(test, loss_ratio, same_vlan) logging.debug("%s" % output) elif os_type == "windows": # TODO, not supported by now status, output = utils_test.ping(dest, count, timeout=60, session=session) if match_error in str(output): ratio = 100 else: loss_ratio = utils_test.get_loss_ratio(output) ping_result_check(test, loss_ratio, same_vlan)
def guest_netwok_connecting_check(guest_ip, link_up, change_queues=False): """ Check whether guest network is connective by ping """ if link_up: vm.wait_for_login() guest_ip = vm.get_address() if change_queues: env["run_change_queues"] = False bg_thread = utils.InterruptedThread(change_queues_number_repeatly, (guest_ifname,)) bg_thread.start() utils_misc.wait_for(lambda: env["run_change_queues"], 30, 0, 2, "wait queues change start") _, output = utils_test.ping(guest_ip, count=10, timeout=20) if not link_up and utils_test.get_loss_ratio(output) != 100: err_msg = "guest network still connecting after down the link" raise error.TestFail(err_msg) elif link_up and utils_test.get_loss_ratio(output) == 100: err_msg = "All packets lost during ping guest ip after link up" raise error.TestFail(err_msg) else: logging.info("Guest network connecting is exactly as expected") if change_queues: env["run_change_queues"] = False bg_thread.join()
def guest_netwok_connecting_check(guest_ip, link_up, change_queues=False): """ Check whether guest network is connective by ping """ if change_queues: env["run_change_queues"] = False bg_thread = utils_misc.InterruptedThread( change_queues_number_repeatly, (guest_ifname,)) bg_thread.start() utils_misc.wait_for(lambda: env["run_change_queues"], 30, 0, 2, "wait queues change start") time.sleep(0.5) output = utils_test.ping(guest_ip, 10, interface=host_interface, timeout=20, session=None)[1] if not link_up and utils_test.get_loss_ratio(output) < 80: err_msg = "guest network still connecting after down the link" test.fail(err_msg) elif link_up and utils_test.get_loss_ratio(output) > 20: err_msg = "All packets lost during ping guest ip after link up" test.fail(err_msg) if change_queues: env["run_change_queues"] = False bg_thread.join()
def run(test, params, env): """ Boot guest with iommu_platform, then do ping test 1) Boot a VM with iommu_platform=on 2) add intel_iommu=on in guest kernel line 3) reboot guest 4) do ping test :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ if utils_misc.get_cpu_vendor(verbose=False) != 'GenuineIntel': test.cancel("This case only support Intel platform") login_timeout = int(params.get("login_timeout", 360)) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=login_timeout) ping_count = int(params.get("ping_count", 10)) guest_ip = vm.get_address() try: status, output = utils_test.ping(guest_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 guest ip %s " % (package_lost, guest_ip)) finally: session.close()
def guest_netwok_connecting_check(guest_ip, link_up): """ Check whether guest network is connective by ping """ if link_up: vm.wait_for_login() guest_ip = vm.get_address() s, o = utils_test.ping(guest_ip, count=10, timeout=20) if not link_up and utils_test.get_loss_ratio(o) != 100: err_msg = "guest network still connecting after down the link" raise error.TestFail(err_msg) elif link_up and utils_test.get_loss_ratio(o) == 100: err_msg = "All packets lost during ping guest ip after link up" raise error.TestFail(err_msg) else: logging.info("Guest network connecting is exactly as expected")
def large_frame_ping(count=100): logging.info("Large frame ping") _, output = utils_test.ping(guest_ip, count, packetsize=max_icmp_pkt_size, timeout=float(count) * 2) ratio = utils_test.get_loss_ratio(output) if ratio != 0: test.fail("Loss ratio of large frame ping is %s" % ratio)
def ping_test(dest_ip, ping_time, lost_raito, session=None): status, output = utils_test.ping(dest=dest_ip, timeout=ping_time, session=session) packets_lost = utils_test.get_loss_ratio(output) if packets_lost > lost_raito: err = " %s%% packages lost during ping. " % packets_lost err += "Ping command log:\n %s" % "\n".join(output.splitlines()[-3:]) raise error.TestFail(err)
def large_frame_ping(count=100): logging.info("Large frame ping") _, o = utils_test.ping(ip, count, interface=ifname, packetsize=max_icmp_pkt_size, timeout=float(count) * 2) ratio = utils_test.get_loss_ratio(o) if ratio != 0: raise error.TestFail("Loss ratio of large frame ping is %s" % ratio)
def verify_mtu(): logging.info("Verify the path MTU") s, o = utils_test.ping(ip, 10, interface=ifname, packetsize=max_icmp_pkt_size, hint="do", timeout=15) if s != 0: logging.error(o) raise error.TestFail("Path MTU is not as expected") if utils_test.get_loss_ratio(o) != 0: logging.error(o) raise error.TestFail("Packet loss ratio during MTU " "verification is not zero")
def launch_client(sessions, servers, server_ctl, clients, l, nf_args, port, params): """ Launch netperf clients """ # Start netserver error.context("Start Netserver on guest", logging.info) remote_dir = params.get("remote_dir", "/var/tmp") client_path = os.path.join(remote_dir, "netperf-2.6.0/src/netperf") server_path = os.path.join(remote_dir, "netperf-2.6.0/src/netserver") if params.get("os_type") == "windows": winutils_vol = utils_misc.get_winutils_vol(server_ctl) client_path = "%s:\\netperf" % winutils_vol netserv_start_cmd = params.get("netserv_start_cmd") % winutils_vol logging.info("Netserver start cmd is '%s'" % netserv_start_cmd) if "NETSERVER.EXE" not in server_ctl.cmd_output("tasklist"): server_ctl.cmd_output(netserv_start_cmd) o_tasklist = server_ctl.cmd_output("tasklist") if "NETSERVER.EXE" not in o_tasklist.upper(): msg = "Can not start netserver in Windows guest" raise error.TestError(msg) else: logging.info("Netserver start cmd is '%s'" % server_path) ssh_cmd(server_ctl, "pidof netserver || %s" % server_path) logging.info("Netserver start successfully") # start netperf error.context("Start netperf client threads", logging.info) client_threads = [] for client in clients: test_timeout = len(clients) * l server = servers[clients.index(client) % len(servers)] netperf_cmd = "%s -H %s -l %s %s" % (client_path, server, int(l), nf_args) client_threads.append([ssh_cmd, (client, netperf_cmd, test_timeout)]) result_info = utils_misc.parallel(client_threads) counts = 5 for server in servers: if not re.findall("TEST.*to %s" % server, str(result_info)): raise error.TestError("Nerperf stress on nic %s failed" % server) logging.info("Network stress on %s successfully" % server) status, output = utils_test.ping(server, counts, timeout=float(counts) * 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))
def set_link_test(linkid): """ Issue set_link commands and test its function @param linkid: id of netdev or devices to be tested """ ip = vm.get_address(0) vm.set_link(linkid, up=False) _, o = utils_test.ping(ip, count=10, timeout=20) if utils_test.get_loss_ratio(o) != 100: raise error.TestFail("Still can ping the %s after down %s" % (ip, linkid)) vm.set_link(linkid, up=True) _, o = utils_test.ping(ip, count=10, timeout=20) # we use 100% here as the notification of link status changed may be # delayed in guest driver if utils_test.get_loss_ratio(o) == 100: raise error.TestFail("Packet loss during ping %s after up %s" % (ip, linkid))
def verify_mtu(): logging.info("Verify the path MTU") status, output = utils_test.ping(guest_ip, 10, packetsize=max_icmp_pkt_size, hint="do", timeout=15) if status != 0: logging.error(output) test.fail("Path MTU is not as expected") if utils_test.get_loss_ratio(output) != 0: logging.error(output) test.fail("Packet loss ratio during MTU " "verification is not zero")
def size_increase_ping(step=random.randrange(90, 110)): logging.info("Size increase ping") for size in range(0, max_icmp_pkt_size + 1, step): logging.info("Ping %s with size %s", ip, size) s, o = utils_test.ping(ip, 1, interface=ifname, packetsize=size, hint="do", timeout=1) if s != 0: s, o = utils_test.ping( ip, 10, interface=ifname, packetsize=size, adaptive=True, hint="do", timeout=20 ) if utils_test.get_loss_ratio(o) > int(params.get("fail_ratio", 50)): raise error.TestFail("Ping loss ratio is greater " "than 50% for size %s" % size)
def size_increase_ping(step=random.randrange(90, 110)): logging.info("Size increase ping") for size in range(0, max_icmp_pkt_size + 1, step): logging.info("Ping %s with size %s", guest_ip, size) status, output = utils_test.ping(guest_ip, 1, packetsize=size, hint="do", timeout=1) if status != 0: status, output = utils_test.ping( guest_ip, 10, packetsize=size, adaptive=True, hint="do", timeout=20 ) fail_ratio = int(params.get("fail_ratio", 50)) if utils_test.get_loss_ratio(output) > fail_ratio: raise error.TestFail("Ping loss ratio is greater " "than 50% for size %s" % size)
def check_ping(status, output): """ ratio <5% is acceptance.""" if status != 0: test.fail("Ping failed, staus:%s, output:%s" % (status, output)) # if status != 0 the ping process seams hit issue. ratio = utils_test.get_loss_ratio(output) if ratio == -1: test.fail("The ratio is %s, and status is %s, " "output is %s" % (ratio, status, output)) elif ratio > int(params["failed_ratio"]): test.fail("The loss raito is %s, test failed" % ratio) logging.info("ping pass with loss raito:%s, that less than %s" % (ratio, params["failed_ratio"]))
def _ping_with_params(test, params, dest, interface=None, packet_size=None, interval=None, count=0, session=None, flood=False): if flood: cmd = "ping " + dest + " -f -q" if interface: cmd += " -S %s" % interface flood_minutes = float(params.get("flood_minutes", 10)) status, output = utils_net.raw_ping(cmd, flood_minutes * 60, session, logging.debug) else: timeout = float(count) * 1.5 status, output = utils_net.ping(dest, count, interval, interface, packet_size, session=session, timeout=timeout) if status != 0: test.fail("Ping failed, status: %s," " output: %s" % (status, output)) if params.get("strict_check", "no") == "yes": ratio = utils_test.get_loss_ratio(output) if ratio != 0: test.fail("Loss ratio is %s" % ratio)
def ping_test(session, dst, drop_flow=False): """ Ping test, check icmp """ ping_status, ping_output = utils_test.ping(dest=dst, count=10, timeout=20, session=session) # when drop_flow is true, ping should failed(return not zero) # drop_flow is false, ping should success packets_lost = 100 if ping_status and not drop_flow: raise error.TestError("Ping should success when not drop_icmp") elif not ping_status: packets_lost = utils_test.get_loss_ratio(ping_output) if drop_flow and packets_lost != 100: raise error.TestError("When drop_icmp, ping shouldn't works") if not drop_flow and packets_lost == 100: raise error.TestError("When not drop_icmp, ping should works") info_msg = "Correct, icmp flow %s dropped, ping '%s', " info_msg += "packets lost rate is: '%s'" logging.info( info_msg % ((drop_flow and "was" or "was not"), (ping_status and "failed" or "success"), packets_lost) )
def run(test, params, env): """ Run Pktgen test between host/guest 1) Boot the main vm, or just grab it if it's already booted. 2) Configure pktgen server(only linux) 3) Run pktgen test, finish when timeout or env["pktgen_run"] != True :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)) error.context("Init the VM, and try to login", logging.info) external_host = params.get("external_host") if not external_host: get_host_cmd = "ip route | awk '/default/ {print $3}'" external_host = utils.system_output(get_host_cmd) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=login_timeout) error.context("Pktgen server environment prepare", logging.info) # pktgen server only support linux, since pktgen is a linux kernel module pktgen_server = params.get("pktgen_server", "localhost") params_server = params.object_params("pktgen_server") s_shell_client = params_server.get("shell_client", "ssh") s_shell_port = params_server.get("shell_port", "22") s_username = params_server.get("username", "root") s_passwd = params_server.get("password", "123456") s_shell_prompt = params_server.get("shell_prompt") server_session = "" # pktgen server is autotest virtual guest(only linux) if pktgen_server in params.get("vms", "vm1 vm2"): vm_pktgen = env.get_vm(pktgen_server) vm_pktgen.verify_alive() server_session = vm_pktgen.wait_for_login(timeout=login_timeout) runner = server_session.cmd_output_safe pktgen_ip = vm_pktgen.get_address() pktgen_mac = vm_pktgen.get_mac_address() server_interface = utils_net.get_linux_ifname(server_session, pktgen_mac) # pktgen server is a external host assigned elif re.match(r"((\d){1,3}\.){3}(\d){1,3}", pktgen_server): pktgen_ip = pktgen_server server_session = remote.wait_for_login(s_shell_client, pktgen_ip, s_shell_port, s_username, s_passwd, s_shell_prompt) runner = server_session.cmd_output_safe server_interface = params.get("server_interface") if not server_interface: raise error.TestNAError("Must config server interface before test") else: # using host as a pktgen server server_interface = params.get("netdst", "switch") host_nic = utils_net.Interface(server_interface) pktgen_ip = host_nic.get_ip() pktgen_mac = host_nic.get_mac() runner = utils.system # copy pktgen_test scipt to the test server. local_path = os.path.join(data_dir.get_root_dir(), "shared/scripts/pktgen.sh") remote_path = "/tmp/pktgen.sh" remote.scp_to_remote(pktgen_ip, s_shell_port, s_username, s_passwd, local_path, remote_path) error.context("Run pktgen test", logging.info) run_threads = params.get("pktgen_threads", 1) pktgen_stress_timeout = float(params.get("pktgen_test_timeout", 600)) exec_cmd = "%s %s %s %s %s" % (remote_path, vm.get_address(), vm.get_mac_address(), server_interface, run_threads) try: env["pktgen_run"] = True try: # Set a run flag in env, when other case call this case as a sub # backgroud process, can set run flag to False to stop this case. start_time = time.time() stop_time = start_time + pktgen_stress_timeout while (env["pktgen_run"] and time.time() < stop_time): runner(exec_cmd, timeout=pktgen_stress_timeout) # using ping to kill the pktgen stress except aexpect.ShellTimeoutError: session.cmd("ping %s" % pktgen_ip, ignore_all_errors=True) finally: env["pktgen_run"] = False error.context("Verify Host and guest kernel no error and call trace", logging.info) vm.verify_kernel_crash() utils_misc.verify_host_dmesg() error.context("Ping external host after pktgen test", logging.info) session_ping = vm.wait_for_login(timeout=login_timeout) status, output = utils_test.ping(dest=external_host, session=session_ping, timeout=240, count=20) loss_ratio = utils_test.get_loss_ratio(output) if (loss_ratio > int(params.get("packet_lost_ratio", 5)) or loss_ratio == -1): logging.debug("Ping %s output: %s" % (external_host, output)) raise error.TestFail("Guest network connction unusable," + "packet lost ratio is '%d%%'" % loss_ratio) if server_session: server_session.close() if session: session.close() if session_ping: session_ping.close()
def run(test, params, env): """ Expose host MTU to guest test 1) Boot up guest with param 'host_mtu=4000' in nic part 2) Disable NetworkManager in guest 3) set mtu of guest tap (eg: tap0) and physical nic (eg: eno1) to 4000 in host 4) check the mtu in guest 5) ping from guest to external host with packet size 3972 :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ def get_ovs_ports(ovs): """ Get ovs ports :param ovs: ovs bridge name """ cmd = "ovs-vsctl list-ports %s" % ovs return process.system_output(cmd, shell=True).decode() def is_ovs_backend(netdst): """ Check whether the host is OVS backend :param netdst: netdst get from command line """ return netdst in process.system_output("ovs-vsctl list-br", ignore_status=True, shell=True).decode() def cleanup_ovs_ports(netdst, ports): """ Clean up created ovs ports in this case :param netdst: netdst get from command line :param ports: existing ports need to be remain before this test """ if is_ovs_backend(netdst) is True: ports = set(get_ovs_ports(netdst).splitlines()) - \ set(ports.splitlines()) for p in ports: process.system("ovs-vsctl del-port %s %s" % (netdst, p)) netdst = params.get("netdst", "switch") if netdst in utils_net.Bridge().list_br(): host_hw_interface = utils_net.Bridge().list_iface()[0] elif is_ovs_backend(netdst) is True: host_hw_interface = get_ovs_ports(netdst) tmp_ports = re.findall(r"t[0-9]-[a-zA-Z0-9]{6}", host_hw_interface) if tmp_ports: for p in tmp_ports: process.system_output("ovs-vsctl del-port %s %s" % (netdst, p)) host_hw_interface = get_ovs_ports(netdst) else: test.cancel("The host is using Macvtap backend, which is not" " supported by now!") params["start_vm"] = "yes" env_process.preprocess_vm(test, params, env, params["main_vm"]) vm = env.get_vm(params["main_vm"]) vm.verify_alive() vm_iface = vm.get_ifname() # TODO, will support windows later process.system_output(params["set_mtu_cmd"] % host_hw_interface) process.system_output(params["set_mtu_cmd"] % vm_iface) os_type = params.get("os_type", "linux") login_timeout = float(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=login_timeout) host_ip = utils_net.get_ip_address_by_interface(params["netdst"]) if os_type == "linux": # TODO, will support windows later session.cmd_output_safe(params["nm_stop_cmd"]) guest_ifname = utils_net.get_linux_ifname(session, vm.get_mac_address()) output = session.cmd_output_safe( params["check_guest_mtu_cmd"] % guest_ifname) error_context.context(output, logging.info) match_string = "mtu %s" % params["mtu_value"] if match_string in output: logging.info("Host mtu %s exposed to guest as expected!" % params["mtu_value"]) logging.info("Ping from guest to host with packet size 3972") status, output = utils_test.ping(host_ip, 10, packetsize=3972, timeout=30, session=session) ratio = utils_test.get_loss_ratio(output) if ratio != 0: test.fail("Loss ratio is %s", ratio) else: test.fail("host mtu %s not exposed to guest" % params["mtu_value"]) cleanup_ovs_ports(netdst, host_hw_interface) 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", "^root@.*[\#\$]\s*$|#") linesep = params.get("shell_linesep", "\n").decode('string_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 = [] 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) 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." 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) 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("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) 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." 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"], 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("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("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("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): """ Test 802.1Q vlan of NIC. For Linux guest: 1) Create two VMs. 2) load 8021q module in guest. 3) Setup vlans by ip in guest and using hard-coded ip address. 4) Enable arp_ignore for all ipv4 device in guest. 5) Repeat steps 2 - 4 in every guest. 6) Test by ping between same and different vlans of two VMs. 7) Test by flood ping between same vlan of two VMs. 8) Test by TCP data transfer between same vlan of two VMs. 9) Remove the named vlan-device. 10) Test maximal plumb/unplumb vlans. For Windows guest: 1) Create two VMs. 2) Set vlan tag in every guest and guest will get subnet ip(169.254) automatically. 3) Test by ping between same vlan of two VMs. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ def add_vlan(test, session, v_id, iface="eth0", cmd_type="ip"): """ Creates a vlan-device on iface by cmd that assigned by cmd_type now only support 'ip' and 'vconfig' """ vlan_if = '%s.%s' % (iface, v_id) txt = "Create vlan interface '%s' on %s" % (vlan_if, iface) error_context.context(txt, logging.info) if cmd_type == "vconfig": cmd = "vconfig add %s %s" % (iface, v_id) elif cmd_type == "ip": v_name = "%s.%s" % (iface, v_id) cmd = "ip link add link %s %s type vlan id %s " % (iface, v_name, v_id) else: err_msg = "Unexpected vlan operation command: %s, " % cmd_type err_msg += "only support 'ip' and 'vconfig' now" test.error(err_msg) session.cmd(cmd) def set_ip_vlan(session, v_id, vlan_ip, iface="eth0"): """ Set ip address of vlan interface """ iface = "%s.%s" % (iface, v_id) txt = "Assign IP '%s' to vlan interface '%s'" % (vlan_ip, iface) error_context.context(txt, logging.info) session.cmd("ifconfig %s %s" % (iface, vlan_ip)) def set_arp_ignore(session): """ Enable arp_ignore for all ipv4 device in guest """ error_context.context("Enable arp_ignore for all ipv4 device in guest", logging.info) ignore_cmd = "echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore" session.cmd(ignore_cmd) def rem_vlan(test, session, v_id, iface="eth0", cmd_type="ip"): """ Removes the named vlan interface(iface+v_id) """ v_iface = '%s.%s' % (iface, v_id) if cmd_type == "vconfig": rem_vlan_cmd = "vconfig rem %s" % v_iface elif cmd_type == "ip": rem_vlan_cmd = "ip link delete %s" % v_iface else: err_msg = "Unexpected vlan operation command: %s, " % cmd_type err_msg += "only support 'ip' and 'vconfig' now" test.error(err_msg) error_context.context("Remove vlan interface '%s'." % v_iface, logging.info) return session.cmd_status(rem_vlan_cmd) def nc_transfer(test, src, dst): """ Transfer file by netcat """ nc_port = utils_misc.find_free_port(1025, 5334, vm_ip[dst]) listen_cmd = params.get("listen_cmd") send_cmd = params.get("send_cmd") # listen in dst listen_cmd = listen_cmd % (nc_port, "receive") sessions[dst].sendline(listen_cmd) time.sleep(2) # send file from src to dst send_cmd = send_cmd % (vlan_ip[dst], str(nc_port), "file") sessions[src].cmd(send_cmd, timeout=60) try: sessions[dst].read_up_to_prompt(timeout=60) except aexpect.ExpectError: # kill server session_ctl[dst].cmd_output_safe("killall -9 nc") test.fail("Fail to receive file" " from vm%s to vm%s" % (src + 1, dst + 1)) # check MD5 message digest of receive file in dst output = sessions[dst].cmd_output("md5sum receive").strip() digest_receive = re.findall(r'(\w+)', output)[0] if digest_receive == digest_origin[src]: logging.info("File succeed received in vm %s", vlan_ip[dst]) else: logging.info("Digest_origin is %s", digest_origin[src]) logging.info("Digest_receive is %s", digest_receive) test.fail("File transferred differ from origin") sessions[dst].cmd("rm -f receive") def flood_ping(src, dst): """ Flood ping test # we must use a dedicated session because the aexpect # does not have the other method to interrupt the process in # the guest rather than close the session. """ txt = "Flood ping from %s interface %s to %s" % (vms[src].name, ifname[src], vlan_ip[dst]) error_context.context(txt, logging.info) session_flood = vms[src].wait_for_login(timeout=60) utils_test.ping(vlan_ip[dst], flood=True, interface=ifname[src], session=session_flood, timeout=10) session_flood.close() vms = [] sessions = [] session_ctl = [] ifname = [] vm_ip = [] digest_origin = [] vlan_ip = ['', ''] ip_unit = ['1', '2'] subnet = params.get("subnet", "192.168") vlan_num = int(params.get("vlan_num", 5)) maximal = int(params.get("maximal", 4094)) file_size = params.get("file_size", 4096) cmd_type = params.get("cmd_type", "ip") login_timeout = int(params.get("login_timeout", 360)) vms.append(env.get_vm(params["main_vm"])) vms.append(env.get_vm("vm2")) for vm_ in vms: vm_.verify_alive() for vm_index, vm in enumerate(vms): if params["os_type"] == "windows": session = vm.wait_for_serial_login(timeout=login_timeout) set_vlan_cmd = params.get("set_vlan_cmd") nicid = utils_net.get_windows_nic_attribute(session=session, key="netenabled", value=True, target="netconnectionID") set_vlan_cmd = set_vlan_cmd % nicid session.cmd(set_vlan_cmd, timeout=240) time.sleep(10) ifname.append(nicid) dev_mac = vm.virtnet[0].mac vm_ip.append(utils_net.get_guest_ip_addr(session, dev_mac, os_type="windows", linklocal=True)) logging.debug("IP address is %s in %s" % (vm_ip, vm.name)) session_ctl.append(session) continue error_context.base_context("Prepare test env on %s" % vm.name) session = vm.wait_for_login(timeout=login_timeout) if not session: err_msg = "Could not log into guest %s" % vm.name test.error(err_msg) sessions.append(session) logging.info("Logged in %s successful" % vm.name) session_ctl.append(vm.wait_for_login(timeout=login_timeout)) ifname.append(utils_net.get_linux_ifname(session, vm.get_mac_address())) # get guest ip vm_ip.append(vm.get_address()) logging.debug("IP address is %s in %s" % (vm_ip, vm.name)) # produce sized file in vm dd_cmd = "dd if=/dev/urandom of=file bs=1M count=%s" session.cmd(dd_cmd % file_size) # record MD5 message digest of file md5sum_output = session.cmd("md5sum file", timeout=60) digest_origin.append(re.findall(r'(\w+)', md5sum_output)[0]) # stop firewall in vm stop_firewall_cmd = "systemctl stop firewalld||service firewalld stop" session.cmd_output_safe(stop_firewall_cmd) error_context.context("Load 8021q module in guest %s" % vm.name, logging.info) session.cmd_output_safe("modprobe 8021q") error_context.context("Setup vlan environment in guest %s" % vm.name, logging.info) for vlan_i in range(1, vlan_num + 1): add_vlan(test, session, vlan_i, ifname[vm_index], cmd_type) v_ip = "%s.%s.%s" % (subnet, vlan_i, ip_unit[vm_index]) set_ip_vlan(session, vlan_i, v_ip, ifname[vm_index]) set_arp_ignore(session) if params["os_type"] == "windows": for vm_index, vm in enumerate(vms): status, output = utils_test.ping(dest=vm_ip[(vm_index + 1) % 2], count=10, session=session_ctl[vm_index], timeout=30) loss = utils_test.get_loss_ratio(output) if not loss and ("TTL=" in output): pass # window get loss=0 when ping fail sometimes, need further check else: test.fail("Guests ping test hit unexpected loss, error info: %s" % output) for sess in session_ctl: if sess: sess.close() return try: for vlan in range(1, vlan_num + 1): error_context.base_context("Test for vlan %s" % vlan, logging.info) error_context.context("Ping test between vlans", logging.info) interface = ifname[0] + '.' + str(vlan) for vm_index, vm in enumerate(vms): for vlan2 in range(1, vlan_num + 1): interface = ifname[vm_index] + '.' + str(vlan) dest = ".".join((subnet, str(vlan2), ip_unit[(vm_index + 1) % 2])) status, output = utils_test.ping(dest, count=2, interface=interface, session=sessions[vm_index], timeout=30) if ((vlan == vlan2) ^ (status == 0)): err_msg = "%s ping %s unexpected, " % (interface, dest) err_msg += "error info: %s" % output test.fail(err_msg) error_context.context("Flood ping between vlans", logging.info) vlan_ip[0] = ".".join((subnet, str(vlan), ip_unit[0])) vlan_ip[1] = ".".join((subnet, str(vlan), ip_unit[1])) flood_ping(0, 1) flood_ping(1, 0) error_context.context("Transferring data between vlans by nc", logging.info) nc_transfer(test, 0, 1) nc_transfer(test, 1, 0) finally: # If client can not connect the nc server, need kill the server. for session in session_ctl: session.cmd_output_safe("killall -9 nc") error_context.base_context("Remove vlan") for vm_index, vm in enumerate(vms): for vlan in range(1, vlan_num + 1): status = rem_vlan(test, sessions[vm_index], vlan, ifname[vm_index], cmd_type) if status: logging.error("Remove vlan %s failed" % vlan) # Plumb/unplumb maximal number of vlan interfaces if params.get("do_maximal_test", "no") == "yes": bound = maximal + 1 try: error_context.base_context("Vlan scalability test") error_context.context("Testing the plumb of vlan interface", logging.info) for vlan_index in range(1, bound): add_vlan(test, sessions[0], vlan_index, ifname[0], cmd_type) vlan_added = vlan_index if vlan_added != maximal: test.fail("Maximal interface plumb test failed") finally: for vlan_index in range(1, vlan_added + 1): if rem_vlan(test, sessions[0], vlan_index, ifname[0], cmd_type): logging.error("Remove vlan %s failed" % vlan_index) error_context.base_context("Vlan negative test") error_context.context("Create vlan with ID %s in guest" % bound, logging.info) try: add_vlan(test, sessions[0], bound, ifname[0], cmd_type) test.fail("Maximal ID allow to vlan is %s" % maximal) except aexpect.ShellCmdError as detail: pattern = params["msg_pattern"] if not re.search(pattern, detail.output, re.M | re.I): raise sessions.extend(session_ctl) for sess in sessions: if sess: sess.close()
def run(test, params, env): """ Test Steps: 1. boot up guest with sndbuf=1048576 or other value. 2. Transfer file between host and guest. 3. Run netperf between host and guest. 4. During netperf testing, from an external host ping the host whitch booting the guest. Params: :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ dst_ses = None try: error.context("Transfer file between host and guest", logging.info) utils_test.run_file_transfer(test, params, env) dsthost = params.get("dsthost") login_timeout = int(params.get("login_timeout", 360)) if dsthost: params_host = params.object_params("dsthost") dst_ses = remote.wait_for_login(params_host.get("shell_client"), dsthost, params_host.get("shell_port"), params_host.get("username"), params_host.get("password"), params_host.get("shell_prompt"), timeout=login_timeout) else: vm = env.get_vm(params["main_vm"]) vm.verify_alive() dst_ses = vm.wait_for_login(timeout=login_timeout) dsthost = vm.get_address() bg_stress_test = params.get("background_stress_test", 'netperf_stress') error.context("Run subtest %s between host and guest." % bg_stress_test, logging.info) s_thread = "" wait_time = float(params.get("wait_bg_time", 60)) bg_stress_run_flag = params.get("bg_stress_run_flag") env[bg_stress_run_flag] = False stress_thread = utils.InterruptedThread( utils_test.run_virt_sub_test, (test, params, env), {"sub_type": bg_stress_test}) stress_thread.start() if not utils_misc.wait_for(lambda: env.get(bg_stress_run_flag), wait_time, 0, 1, "Wait %s test start" % bg_stress_test): err = "Fail to start netperf test between guest and host" raise error.TestError(err) ping_timeout = int(params.get("ping_timeout", 60)) host_ip = utils_net.get_host_ip_address(params) txt = "Ping %s from %s during netperf testing" % (host_ip, dsthost) error.context(txt, logging.info) status, output = utils_test.ping(host_ip, session=dst_ses, timeout=ping_timeout) if status != 0: raise error.TestFail("Ping returns non-zero value %s" % output) package_lost = utils_test.get_loss_ratio(output) package_lost_ratio = float(params.get("package_lost_ratio", 5)) txt = "%s%% packeage lost when ping %s from %s." % (package_lost, host_ip, dsthost) if package_lost > package_lost_ratio: raise error.TestFail(txt) logging.info(txt) finally: try: stress_thread.join(60) except Exception: pass if dst_ses: dst_ses.close()
def run(test, params, env): """ Expose host MTU to guest test 1) Boot up guest with param 'host_mtu=4000' in nic part 2) Disable NetworkManager in guest 3) set mtu of guest tap (eg: tap0) and physical nic (eg: eno1) to 4000 in host 4) check the mtu in guest 5) ping from guest to external host with packet size 3972 :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ def cleanup_ovs_ports(netdst, ports): """ Clean up created ovs ports in this case :param netdst: netdst get from command line :param ports: existing ports need to be remain before this test """ host_bridge = utils_net.find_bridge_manager(netdst) if utils_net.ovs_br_exists(netdst) is True: ports = set(host_bridge.list_ports(netdst)) - set(ports) for p in ports: utils_net.find_bridge_manager(netdst).del_port(netdst, p) netdst = params.get("netdst", "switch") host_bridge = utils_net.find_bridge_manager(netdst) if netdst in utils_net.Bridge().list_br(): host_hw_interface = utils_net.Bridge().list_iface(netdst)[0] else: host_hw_interface = host_bridge.list_ports(netdst) tmp_ports = re.findall(r"t[0-9]{1,}-[a-zA-Z0-9]{6}", ' '.join(host_hw_interface)) if tmp_ports: for p in tmp_ports: host_bridge.del_port(netdst, p) host_hw_interface = host_bridge.list_ports(netdst) params["start_vm"] = "yes" env_process.preprocess_vm(test, params, env, params["main_vm"]) vm = env.get_vm(params["main_vm"]) vm.verify_alive() vm_iface = vm.get_ifname() # Get host interface original mtu value before setting if netdst in utils_net.Bridge().list_br(): host_hw_iface = utils_net.Interface(host_hw_interface) elif utils_net.ovs_br_exists(netdst) is True: host_hw_iface = utils_net.Interface(' '.join(host_hw_interface)) host_mtu_origin = host_hw_iface.get_mtu() utils_net.Interface(vm_iface).set_mtu(int(params["mtu_value"])) host_hw_iface.set_mtu(int(params["mtu_value"])) os_type = params.get("os_type", "linux") login_timeout = float(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=login_timeout) host_ip = utils_net.get_ip_address_by_interface(params["netdst"]) if os_type == "linux": session.cmd_output_safe(params["nm_stop_cmd"]) guest_ifname = utils_net.get_linux_ifname(session, vm.get_mac_address()) output = session.cmd_output_safe( params["check_linux_mtu_cmd"] % guest_ifname) error_context.context(output, logging.info) match_string = "mtu %s" % params["mtu_value"] if match_string not in output: test.fail("host mtu %s not exposed to guest" % params["mtu_value"]) elif os_type == "windows": connection_id = utils_net.get_windows_nic_attribute( session, "macaddress", vm.get_mac_address(), "netconnectionid") output = session.cmd_output_safe( params["check_win_mtu_cmd"] % connection_id) error_context.context(output, logging.info) lines = output.strip().splitlines() lines_len = len(lines) line_table = lines[0].split(' ') line_value = lines[2].split(' ') while '' in line_table: line_table.remove('') while '' in line_value: line_value.remove('') index = 0 for name in line_table: if re.findall("MTU", name): break index += 1 mtu_value = line_value[index] logging.info("MTU is %s", mtu_value) if not int(mtu_value) == int(params["mtu_value"]): test.fail("Host mtu %s is not exposed to " "guest!" % params["mtu_value"]) logging.info("Ping from guest to host with packet size 3972") status, output = utils_test.ping(host_ip, 10, packetsize=3972, timeout=30, session=session) ratio = utils_test.get_loss_ratio(output) if ratio != 0: test.fail("Loss ratio is %s", ratio) # Restore host mtu after finish testing utils_net.Interface(vm_iface).set_mtu(host_mtu_origin) host_hw_iface.set_mtu(host_mtu_origin) if netdst not in utils_net.Bridge().list_br(): cleanup_ovs_ports(netdst, host_hw_interface) session.close()
def run_ping(test, params, env): """ Ping the guest with different size of packets. Packet Loss Test: 1) Ping the guest with different size/interval of packets. Stress Test: 1) Flood ping the guest. 2) Check if the network is still usable. @param test: KVM test object. @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) counts = params.get("ping_counts", 100) flood_minutes = float(params.get("flood_minutes", 10)) nics = vm.virtnet strict_check = params.get("strict_check", "no") == "yes" packet_size = [0, 1, 4, 48, 512, 1440, 1500, 1505, 4054, 4055, 4096, 4192, 8878, 9000, 32767, 65507] try: for i, nic in enumerate(nics): ip = vm.get_address(i) if not ip: logging.error("Could not get the ip of nic index %d: %s", i, nic) continue for size in packet_size: logging.info("Ping with packet size %s", size) status, output = utils_test.ping(ip, 10, packetsize=size, timeout=20) if strict_check: ratio = utils_test.get_loss_ratio(output) if ratio != 0: raise error.TestFail("Loss ratio is %s for packet size" " %s" % (ratio, size)) else: if status != 0: raise error.TestFail("Ping failed, status: %s," " output: %s" % (status, output)) logging.info("Flood ping test") utils_test.ping(ip, None, flood=True, output_func=None, timeout=flood_minutes * 60) logging.info("Final ping test") status, output = utils_test.ping(ip, counts, timeout=float(counts) * 1.5) if strict_check: ratio = utils_test.get_loss_ratio(output) if ratio != 0: raise error.TestFail("Ping failed, status: %s," " output: %s" % (status, output)) else: if status != 0: raise error.TestFail("Ping returns non-zero value %s" % output) finally: session.close()
def _get_loss_ratio(output): if params.get("strict_check", "no") == "yes": ratio = utils_test.get_loss_ratio(output) if ratio != 0: raise error.TestFail("Loss ratio is %s" % ratio)
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", "service iptables stop;" " iptables -F") 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 = [] 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.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_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) 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: 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): """ create/delete macvtap in host 1) Verify no other macvtap share the physical network device. 2) Create a macvtap device in host. 3) Check configuraton of macvtap device. 4) Ping out from host with the interface that create macvtap. 5) Delete the macvtap device create in step 2. 6) Ping out from host with the interface that create macvtap. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ ifname = params.get("macvtap_base_interface") macvtap_mode = params.get("macvtap_mode", "passthru") dest_host = params.get("dest_host") set_mac = params.get("set_mac", "yes") == "yes" macvtaps = [] if not ifname: ifname = params.get("netdst") ifname = utils_net.get_macvtap_base_iface(ifname) error.context("Verify no other macvtap share the physical network device.", logging.info) macvtap_devices = get_macvtap_device_on_ifname(ifname) for device in macvtap_devices: utils.system_output("ip link delete %s" % device) for mode in macvtap_mode.split(): macvtap_name = "%s_01" % mode txt = "Create %s mode macvtap device %s on %s." % (mode, macvtap_name, ifname) error.context(txt, logging.info) cmd = " ip link add link %s name %s type macvtap mode %s" % (ifname, macvtap_name, mode) utils.system(cmd, timeout=240) if set_mac: txt = "Determine and configure mac address of %s, " % macvtap_name txt += "Then link up it." error.context(txt, logging.info) mac = utils_net.generate_mac_address_simple() cmd = " ip link set %s address %s up" % (macvtap_name, mac) utils.system(cmd, timeout=240) error.context("Check configuraton of macvtap device", logging.info) check_cmd = " ip -d link show %s" % macvtap_name try: tap_info = utils.system_output(check_cmd, timeout=240) except error.CmdError: err = "Fail to create %s mode macvtap on %s" % (mode, ifname) raise error.TestFail(err) if set_mac: if mac not in tap_info: err = "Fail to set mac for %s" % macvtap_name raise error.TestFail(err) macvtaps.append(macvtap_name) if not dest_host: dest_host_get_cmd = "ip route | awk '/default/ { print $3 }'" dest_host_get_cmd = params.get("dest_host_get_cmd", dest_host_get_cmd) dest_host = utils.system_output(dest_host_get_cmd).split()[-1] txt = "Ping dest host %s from " % dest_host txt += "localhost with the interface %s" % ifname error.context(txt, logging.info) status, output = utils_test.ping(dest_host, 10, interface=ifname, timeout=20) ratio = utils_test.get_loss_ratio(output) if "passthru" in macvtap_mode: ifnames = utils_net.get_host_iface() ifnames.remove(ifname) logging.info("ifnames = %s", ifnames) ips = [] for name in ifnames: try: _ip = utils_net.get_ip_address_by_interface(name) if _ip != "127.0.0.1": ips.append(_ip) except Exception: pass logging.info("ips = %s", ips) if not ips: if ratio != 100: err = "%s did not lost network connection after " % ifname err += " creating %s mode macvtap on it." % macvtap_mode raise error.TestFail(err) else: err = "%s is not the only network device in host" % ifname logging.debug(err) else: if ratio != 0: err = "Package lost during ping %s from %s " % (dest_host, ifname) err += "after creating %s mode macvtap on it." % macvtap_mode raise error.TestFail(err) for name in macvtaps: txt = "Delete macvtap device %s on %s." % (name, ifname) error.context(txt, logging.info) del_cmd = "ip link delete %s" % name utils.system(del_cmd) devices = get_macvtap_device_on_ifname(ifname) if name in devices: err = "Fail to delete macvtap %s on %s" % (name, ifname) raise error.TestFail(err) logging.info("dest_host = %s", dest_host) txt = "Ping dest host %s from " % dest_host txt += "localhost with the interface %s" % ifname error.context(txt, logging.info) status, output = utils_test.ping(dest_host, 10, interface=ifname, timeout=20) if status != 0: raise error.TestFail("Ping failed, status: %s," " output: %s" % (status, output)) ratio = utils_test.get_loss_ratio(output) if ratio != 0: err = "Package lost during ping %s from %s " % (dest_host, ifname) raise error.TestFail(err)
def run(test, params, env): """ Test basic QinQ - 10 * 4096 with bridge backend 1) Create a private bridge 2) Boot a VM over private bridge 3) Create interfaces in guest with qinq.sh 4) Set IP on guest L1 interface and bring this interface on 5) Create 802.1ad interface on host with the private bridge 6) Start tcpdump on host 7) Do ping test 8) Check tcpdump result with vlan tag and ethertype 9) Set IP on guest L2 interface and bring this interface on 10) Create 802.1q interface on host with the 802.1ad interface 11) Start tcpdump on host 12) Do ping test 13) Check tcpdump result with vlan tag and ethertype 14) SCP file transfer between host and guest :param test: KVM test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def copy_qinq_file(vm, guest_qinq_dir): """ Copy qinq file from host to guest :param vm: guest vm :param guest_qinq_dir: qing script dir in guest """ error_context.context("Copy qinq script to guest", logging.info) host_qinq_dir = os.path.join(data_dir.get_deps_dir(), params.get("copy_qinq_script")) vm.copy_files_to(host_qinq_dir, guest_qinq_dir) def check_tcpdump_result(session, iface_name, ethertype, ethertype2=None, vlan_tag=None, vlan_tag2=None, enable_logging=False): """ Check tcpdump result. :param session: guest session :param iface_name: the tcpdump file of the interface :param ethertype: ethertype value need to be matched :param ethertype2: ethertype value 2 needed to be matched if not None :param vlan_tag: vlan tag value needed to be matched if not None :param vlan_tag2: vlan tag value 2 needed to be matched if not None :param enable_logging: whether to dump tcpdump results during test """ get_tcpdump_log_cmd = params["get_tcpdump_log_cmd"] % iface_name tcpdump_content = session.cmd_output(get_tcpdump_log_cmd, timeout=300).strip() lines = tcpdump_content.splitlines() sum = 0 for i in range(len(lines)): if enable_logging: logging.info("line %s: %s", i, lines[i]) if not ethertype2: if "ICMP echo re" in lines[i] and \ ethertype in lines[i-1]: sum += 1 if vlan_tag and vlan_tag not in lines[i - 1]: if "too much work for irq" in lines[i - 1]: continue else: test.fail( "in %s tcpdump log, there should be vlan " "tag %s" % (iface_name, vlan_tag)) elif not vlan_tag: if "vlan" in lines[i - 1]: test.fail("in %s tcpdump log, there should not be " "vlan tag" % iface_name) else: if "ICMP echo re" in lines[i] and \ ethertype in lines[i-1] and \ ethertype2 in lines[i-1]: sum += 1 if vlan_tag not in lines[i-1] or \ vlan_tag2 not in lines[i-1]: if "too much work for irq" in lines[i - 1]: continue else: test.fail( "in %s tcpdump log, there should be vlan " "tag %s" % (iface_name, vlan_tag)) if sum == 0: test.fail("in %s tcpdump log, ethertype is not %s" % (iface_name, ethertype)) def compare_host_guest_md5sum(name): """ Compare md5 value of file on host and guest :param name: file name """ txt = "Comparing md5sum of the file %s on guest and host" % name error_context.context(txt, logging.info) host_result = crypto.hash_file(name, algorithm="md5") try: output = session.cmd_output("md5sum %s" % name).split()[0] guest_result = re.findall(r"\w+", output)[0] except IndexError: logging.error("Could not get file md5sum in guest") return False logging.debug("md5sum: guest(%s), host(%s)", guest_result, host_result) return guest_result == host_result if params["netdst"] not in utils_net.Bridge().list_br(): test.cancel("Only support Linux bridge") login_timeout = int(params.get("login_timeout", "600")) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=login_timeout) guest_qinq_dir = params["guest_qinq_dir"] copy_qinq_file(vm, guest_qinq_dir) session.close() vm.destroy(gracefully=True) brname = params.get("private_bridge", "tmpbr") host_bridges = utils_net.Bridge() if brname in host_bridges.list_br(): utils_net.Interface(brname).down() host_bridges.del_bridge(brname) logging.debug("Create private bridge %s", brname) host_bridges.add_bridge(brname) host_bridge_iface = utils_net.Interface(brname) logging.debug("Bring up %s", brname) netmask = params["net_mask"] host_bridge_iface.up() host_bridge_iface.set_ip("192.168.1.1") host_bridge_iface.set_netmask(int(netmask)) login_timeout = int(params.get("login_timeout", "600")) params['netdst'] = brname params["start_vm"] = "yes" params["image_snapshot"] = "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_serial_login(timeout=login_timeout) stop_NM_cmd = params.get("stop_NM_cmd") session.cmd(stop_NM_cmd, ignore_all_errors=True) mac = vm.get_mac_address() nic_name = utils_net.get_linux_ifname(session, mac) # Set first_nic IP in guest ip = params["ip_vm"] session.cmd_output("ip addr add %s/%s dev %s" % (ip, netmask, nic_name)) # Create vlans via script qinq.sh output = session.cmd_output("sh %sqinq.sh %s" % (guest_qinq_dir, nic_name), timeout=300) logging.info("%s", output) # Set interface v1v10 IP in guest L1tag_iface = params["L1tag_iface"] L1tag_iface_ip = params["L1tag_iface_ip"] session.cmd_output("ifconfig %s %s netmask %s" % (L1tag_iface, L1tag_iface_ip, netmask)) output = session.cmd_output("ifconfig %s" % L1tag_iface, timeout=120) logging.info(output) # Start tcpdump on L1tag interface and first_nic in guest error_context.context("Start tcpdump in %s" % params["main_vm"], logging.info) L1tag_tcpdump_log = params.get("tcpdump_log") % L1tag_iface L1tag_tcpdump_cmd = params.get("tcpdump_cmd") % (L1tag_iface, L1tag_tcpdump_log) first_nic_tcpdump_log = params.get("tcpdump_log") % nic_name first_nic_tcpdump_cmd = params.get("tcpdump_cmd") % (nic_name, first_nic_tcpdump_log) session.sendline(L1tag_tcpdump_cmd) time.sleep(2) session.sendline(first_nic_tcpdump_cmd) time.sleep(5) # Create 802.1ad vlan via bridge in host error_context.context("Create 802.1ad vlan via bridge %s" % brname, logging.info) advlan_ifname = params["advlan_name"] add_advlan_cmd = params["add_advlan_cmd"] process.system_output(add_advlan_cmd) advlan_iface = utils_net.Interface(advlan_ifname) advlan_iface.set_mac(params["advlan_mac"]) advlan_iface.set_ip(params["advlan_ip"]) advlan_iface.set_netmask(int(netmask)) advlan_iface.up() output = process.getoutput("ifconfig %s" % advlan_ifname) logging.info(output) # Ping guest from host via 802.1ad vlan interface error_context.context( "Start ping test from host to %s via %s" % (L1tag_iface_ip, advlan_ifname), logging.info) ping_count = int(params.get("ping_count")) status, output = utils_net.ping(L1tag_iface_ip, ping_count, interface=advlan_ifname, 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 guest ip %s " % (package_lost, L1tag_iface_ip)) # Stop tcpdump and check result session.cmd_output_safe("pkill tcpdump") check_tcpdump_result(session, L1tag_iface, "ethertype IPv4 (0x0800)") check_tcpdump_result(session, nic_name, "ethertype 802.1Q-QinQ (0x88a8)", vlan_tag="vlan 10,") # Set IP on L2 tag on the guest interface with vid 20 L2tag_iface = params["L2tag_iface"] L2tag_iface_ip = params["L2tag_iface_ip"] session.cmd_output("ip addr add %s/%s dev %s" % (L2tag_iface_ip, netmask, L2tag_iface)) output = session.cmd_output("ifconfig %s" % L2tag_iface, timeout=120) logging.info(output) # Start tcpdump on L1tag interface, L2tag interface and first_nic in guest error_context.context("Start tcpdump in %s" % params["main_vm"], logging.info) L2tag_tcpdump_log = params.get("tcpdump_log") % L2tag_iface L2tag_tcpdump_cmd = params.get("tcpdump_cmd") % (L2tag_iface, L2tag_tcpdump_log) session.sendline(L1tag_tcpdump_cmd) time.sleep(2) session.sendline(L2tag_tcpdump_cmd) time.sleep(2) session.sendline(first_nic_tcpdump_cmd) time.sleep(5) # Create 802.1q vlan via 802.1ad vlan in host error_context.context( "Create 802.1q vlan via 802.1ad vlan %s" % advlan_ifname, logging.info) qvlan_ifname = params["qvlan_name"] add_qvlan_cmd = params["add_qvlan_cmd"] process.system_output(add_qvlan_cmd) qvlan_iface = utils_net.Interface(qvlan_ifname) qvlan_iface.set_ip(params["qvlan_ip"]) qvlan_iface.set_netmask(int(netmask)) qvlan_iface.up() output = process.getoutput("ifconfig %s" % qvlan_ifname) logging.info(output) # Ping guest from host via 802.1q vlan interface error_context.context( "Start ping test from host to %s via %s" % (L2tag_iface_ip, qvlan_ifname), logging.info) status, output = utils_net.ping(L2tag_iface_ip, ping_count, interface=qvlan_ifname, 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 >= 5: test.fail("%s packeage lost when ping guest ip %s " % (package_lost, L2tag_iface_ip)) # Stop tcpdump and check result session.cmd_output_safe("pkill tcpdump") check_tcpdump_result(session, L1tag_iface, "ethertype 802.1Q (0x8100)", vlan_tag="vlan 20,") check_tcpdump_result(session, L2tag_iface, "ethertype IPv4 (0x0800)") check_tcpdump_result(session, nic_name, ethertype="ethertype 802.1Q-QinQ (0x88a8)", ethertype2="ethertype 802.1Q", vlan_tag="vlan 10,", vlan_tag2="vlan 20,") # scp file to guest with L2 vlan tag file_size = int(params.get("file_size", "4096")) host_path = params.get("host_path", "/tmp/transferred_file") guest_path = params.get("guest_path", "/tmp/transferred_file") transfer_timeout = int(params.get("transfer_timeout", 1000)) cmd = "dd if=/dev/zero of=%s bs=1M count=%d" % (host_path, file_size) error_context.context("Creating %dMB file on host" % file_size, logging.info) process.run(cmd) error_context.context( "Transferring file host -> guest, " "timeout: %ss" % transfer_timeout, logging.info) shell_port = int(params.get("shell_port", 22)) password = params["password"] username = params["username"] remote.scp_to_remote(L2tag_iface_ip, shell_port, username, password, host_path, guest_path) if not compare_host_guest_md5sum(host_path): test.fail("md5sum mismatch on guest and host") session.close() vm.destroy(gracefully=True) host_bridge_iface.down() host_bridges.del_bridge(brname)
def run(test, params, env): """ Run Pktgen test between host/guest 1) Boot the main vm, or just grab it if it's already booted. 2) Configure pktgen server(only linux) 3) Run pktgen test, finish when timeout or env["pktgen_run"] != True :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)) error.context("Init the VM, and try to login", logging.info) external_host = params.get("external_host") if not external_host: get_host_cmd = "ip route | awk '/default/ {print $3}'" external_host = utils.system_output(get_host_cmd) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=login_timeout) error.context("Pktgen server environment prepare", logging.info) # pktgen server only support linux, since pktgen is a linux kernel module pktgen_server = params.get("pktgen_server", "localhost") params_server = params.object_params("pktgen_server") s_shell_client = params_server.get("shell_client", "ssh") s_shell_port = params_server.get("shell_port", "22") s_username = params_server.get("username", "root") s_passwd = params_server.get("password", "123456") s_shell_prompt = params_server.get("shell_prompt") server_session = "" # pktgen server is autotest virtual guest(only linux) if pktgen_server in params.get("vms", "vm1 vm2"): vm_pktgen = env.get_vm(pktgen_server) vm_pktgen.verify_alive() server_session = vm_pktgen.wait_for_login(timeout=login_timeout) runner = server_session.cmd_output_safe pktgen_ip = vm_pktgen.get_address() pktgen_mac = vm_pktgen.get_mac_address() server_interface = utils_net.get_linux_ifname(server_session, pktgen_mac) # pktgen server is a external host assigned elif re.match(r"((\d){1,3}\.){3}(\d){1,3}", pktgen_server): pktgen_ip = pktgen_server server_session = remote.wait_for_login( s_shell_client, pktgen_ip, s_shell_port, s_username, s_passwd, s_shell_prompt ) runner = server_session.cmd_output_safe server_interface = params.get("server_interface") if not server_interface: raise error.TestNAError("Must config server interface before test") else: # using host as a pktgen server server_interface = params.get("netdst", "switch") host_nic = utils_net.Interface(server_interface) pktgen_ip = host_nic.get_ip() pktgen_mac = host_nic.get_mac() runner = utils.system # copy pktgen_test scipt to the test server. local_path = os.path.join(data_dir.get_root_dir(), "shared/scripts/pktgen.sh") remote_path = "/tmp/pktgen.sh" remote.scp_to_remote(pktgen_ip, s_shell_port, s_username, s_passwd, local_path, remote_path) error.context("Run pktgen test", logging.info) run_threads = params.get("pktgen_threads", 1) pktgen_stress_timeout = float(params.get("pktgen_test_timeout", 600)) exec_cmd = "%s %s %s %s %s" % (remote_path, vm.get_address(), vm.get_mac_address(), server_interface, run_threads) try: env["pktgen_run"] = True try: # Set a run flag in env, when other case call this case as a sub # backgroud process, can set run flag to False to stop this case. start_time = time.time() stop_time = start_time + pktgen_stress_timeout while env["pktgen_run"] and time.time() < stop_time: runner(exec_cmd, timeout=pktgen_stress_timeout) # using ping to kill the pktgen stress except aexpect.ShellTimeoutError: session.cmd("ping %s" % pktgen_ip, ignore_all_errors=True) finally: env["pktgen_run"] = False error.context("Verify Host and guest kernel no error and call trace", logging.info) vm.verify_kernel_crash() utils_misc.verify_host_dmesg() error.context("Ping external host after pktgen test", logging.info) status, output = utils_test.ping(dest=external_host, session=session, timeout=240, count=20) loss_ratio = utils_test.get_loss_ratio(output) if loss_ratio > int(params.get("packet_lost_ratio", 5)) or loss_ratio == -1: logging.debug("Ping %s output: %s" % (external_host, output)) raise error.TestFail("Guest network connction unusable," + "packet lost ratio is '%d%%'" % loss_ratio) if server_session: server_session.close() if session: session.close()
def run(test, params, env): """ MULTI_QUEUE enabled by default check test 1) Boot up a VM, and login to the guest 2) Check the queues according to the value set in qemu cmd line for smp and queues 3) do ping test :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ def get_queues_status(session, ifname, timeout=240): """ Get queues status :param session: guest session :param ifname: interface name :param timeout: timeout of session.cmd_output :return: queues status list """ mq_get_cmd = "ethtool -l %s" % ifname nic_mq_info = session.cmd_output(mq_get_cmd, timeout=timeout, safe=True) 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 chk_mq_enabled(vm, queues): """ Check whether MQ value set in qemu cmd line fits the value in guest :param vm: guest vm :param queues: queues value in qemu cmd line """ login_timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=login_timeout) mac = vm.get_mac_address(0) ifname = utils_net.get_linux_ifname(session, mac) queues_status_list = get_queues_status(session, ifname) session.close() if not queues_status_list[0] == queues or \ not queues_status_list[1] == min(queues, int(vm.cpuinfo.smp)): txt = "Pre-set maximums Combined should equals to queues in qemu" txt += " cmd line.\n" txt += "Current hardware settings Combined should be the min of " txt += "queues and smp.\n" txt += "Pre-set maximum Combined is: %s, " % queues_status_list[0] txt += " queues in qemu cmd line is: %s.\n" % queues txt += "Current hardware settings Combined " txt += "is: %s, " % queues_status_list[1] txt += " smp in qemu cmd line is: %s." % int(vm.cpuinfo.smp) test.fail(txt) error_context.context("Init the guest and try to login", logging.info) queues_list = params["queues_list"].split() for queues in queues_list: params["queues"] = int(queues) params["start_vm"] = "yes" env_process.preprocess_vm(test, params, env, params["main_vm"]) vm = env.get_vm(params["main_vm"]) vm.verify_alive() chk_mq_enabled(vm, int(queues)) guest_ip = vm.get_address() status, output = utils_net.ping(guest_ip, 10, session=None, timeout=20) if utils_test.get_loss_ratio(output) > 0: test.fail("Packet lost while doing ping test") vm.destroy(gracefully=True)
def run(test, params, env): """ Vhost zero copy test 1) Enable/Disable vhost_net zero copy in host 1) Boot the main vm. 3) Run the ping test, check guest nic works. 4) check vm is alive have no crash :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ def zerocp_enable_status(): """ Check whether host have enabled zero copy, if enabled return True, else return False. """ def_para_path = "/sys/module/vhost_net/parameters/experimental_zcopytx" para_path = params.get("zcp_set_path", def_para_path) cmd_status = utils.system("grep 1 %s" % para_path, ignore_status=True) if cmd_status: return False else: return True def enable_zerocopytx_in_host(enable=True): """ Enable or disable vhost_net zero copy in host """ cmd = "modprobe -rf vhost_net; " if enable: cmd += "modprobe vhost-net experimental_zcopytx=1" else: cmd += "modprobe vhost-net experimental_zcopytx=0" if utils.system(cmd) or enable != zerocp_enable_status(): raise error.TestNAError("Set vhost_net zcopytx failed") error.context("Set host vhost_net experimental_zcopytx", logging.info) if params.get("enable_zerocp", 'yes') == 'yes': enable_zerocopytx_in_host() else: enable_zerocopytx_in_host(False) error.context("Boot vm with 'vhost=on'", logging.info) params["vhost"] = "vhost=on" params["start_vm"] = 'yes' login_timeout = int(params.get("login_timeout", 360)) env_process.preprocess_vm(test, params, env, params.get("main_vm")) vm = env.get_vm(params["main_vm"]) vm.verify_alive() vm.wait_for_login(timeout=login_timeout) guest_ip = vm.get_address() error.context("Check guest nic is works by ping", logging.info) status, output = utils_test.ping(guest_ip, count=10, timeout=20) if status: err_msg = "Run ping %s failed, after set zero copy" % guest_ip raise error.TestError(err_msg) elif utils_test.get_loss_ratio(output) == 100: err_msg = "All packets lost during ping guest %s." % guest_ip raise error.TestFail(err_msg) # in vm.verify_alive will check whether have userspace or kernel crash error.context("Check guest is alive and have no crash", logging.info) vm.verify_alive()
def run(test, params, env): """ Test Steps: 1. boot up guest with sndbuf=1048576 or other value. 2. Transfer file between host and guest. 3. Run netperf between host and guest. 4. During netperf testing, from an external host ping the host whitch booting the guest. Params: :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ dst_ses = None try: error_context.context("Transfer file between host and guest", logging.info) utils_test.run_file_transfer(test, params, env) dsthost = params.get("dsthost") login_timeout = int(params.get("login_timeout", 360)) if dsthost: params_host = params.object_params("dsthost") dst_ses = remote.wait_for_login(params_host.get("shell_client"), dsthost, params_host.get("shell_port"), params_host.get("username"), params_host.get("password"), params_host.get("shell_prompt"), timeout=login_timeout) else: vm = env.get_vm(params["main_vm"]) vm.verify_alive() dst_ses = vm.wait_for_login(timeout=login_timeout) dsthost = vm.get_address() bg_stress_test = params.get("background_stress_test", 'netperf_stress') error_context.context( ("Run subtest %s between host and guest." % bg_stress_test), logging.info) wait_time = float(params.get("wait_bg_time", 60)) bg_stress_run_flag = params.get("bg_stress_run_flag") env[bg_stress_run_flag] = False stress_thread = utils_misc.InterruptedThread( utils_test.run_virt_sub_test, (test, params, env), {"sub_type": bg_stress_test}) stress_thread.start() if not utils_misc.wait_for(lambda: env.get(bg_stress_run_flag), wait_time, 0, 1, "Wait %s test start" % bg_stress_test): err = "Fail to start netperf test between guest and host" test.error(err) ping_timeout = int(params.get("ping_timeout", 60)) host_ip = utils_net.get_host_ip_address(params) txt = "Ping %s from %s during netperf testing" % (host_ip, dsthost) error_context.context(txt, logging.info) status, output = utils_test.ping(host_ip, session=dst_ses, timeout=ping_timeout) if status != 0: test.fail("Ping returns non-zero value %s" % output) package_lost = utils_test.get_loss_ratio(output) package_lost_ratio = float(params.get("package_lost_ratio", 5)) txt = "%s%% packeage lost when ping %s from %s." % (package_lost, host_ip, dsthost) if package_lost > package_lost_ratio: test.fail(txt) logging.info(txt) finally: try: stress_thread.join(60) except Exception: pass if dst_ses: dst_ses.close()