def get_all_assets(): asset_data_list = [] download_dir = data_dir.get_download_dir() for asset in glob.glob(os.path.join(download_dir, "*.ini")): asset_name = os.path.basename(asset).split(".")[0] asset_data_list.append(bootstrap.get_asset_info(asset_name)) return asset_data_list
def get_asset_info(asset, ini_dir=None, section=None): """" Parse $asset.ini file and returns a dictionary suitable for asset.download_file() :param asset: Asset name. A file ending in .ini. :param ini_dir: Directory where to search .ini file. :param section: Name of the [] section in .ini file. If None, then use asset name. """ asset_info = {} ini_dir = ini_dir or data_dir.get_download_dir() asset_path = os.path.join(ini_dir, '%s.ini' % asset) assert os.path.exists(asset_path), "Missing asset file %s" % asset_path asset_cfg = ConfigLoader(asset_path) section = section or asset asset_info['url'] = asset_cfg.get(section, 'url') asset_info['sha1_url'] = asset_cfg.get(section, 'sha1_url') asset_info['title'] = asset_cfg.get(section, 'title') destination = asset_cfg.get(section, 'destination') if not os.path.isabs(destination): destination = os.path.join(data_dir.get_data_dir(), destination) asset_info['destination'] = destination asset_info['asset_exists'] = os.path.isfile(destination) # Optional fields d_uncompressed = asset_cfg.get(section, 'destination_uncompressed') if d_uncompressed is not None and not os.path.isabs(d_uncompressed): d_uncompressed = os.path.join(data_dir.get_data_dir(), d_uncompressed) asset_info['destination_uncompressed'] = d_uncompressed asset_info['uncompress_cmd'] = asset_cfg.get(section, 'uncompress_cmd') return asset_info
def get_all_assets(): asset_data_list = [] download_dir = data_dir.get_download_dir() for asset in glob.glob(os.path.join(download_dir, '*.ini')): asset_name = os.path.basename(asset)[:-4] asset_data_list.append(get_asset_info(asset_name)) return asset_data_list
def install_stress_app(self): error.context("install stress app in guest") session = self.get_session() installed = session.cmd_status(self.params.get("app_check_cmd")) == 0 if installed: logging.debug("Stress has been installed.") return try: pkg = utils.unmap_url_cache(data_dir.get_download_dir(), self.link, self.md5sum) except Exception, detail: raise StressError(str(detail))
def install_stress_app(self): error.context("install stress app in guest") session = self.get_session() _, output = session.cmd_status_output(self.app_check_cmd) installed = re.search("Usage:", output) if installed: logging.debug("Stress has been installed.") return try: pkg = utils.unmap_url_cache(data_dir.get_download_dir(), self.link, self.md5sum) except Exception, detail: raise StressError(str(detail))
def env_setup(session, ip, user, port, password): error.context("Setup env for %s" % ip) ssh_cmd(session, "iptables -F; true") ssh_cmd(session, "service iptables stop; true") ssh_cmd(session, "echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore") download_link = params.get("netperf_download_link") download_dir = data_dir.get_download_dir() md5sum = params.get("pkg_md5sum") pkg = utils.unmap_url_cache(download_dir, download_link, md5sum) remote.scp_to_remote(ip, shell_port, username, password, pkg, "/tmp") ssh_cmd(session, params.get("setup_cmd")) agent_path = os.path.join(test.virtdir, "scripts/netperf_agent.py") remote.scp_to_remote(ip, shell_port, username, password, agent_path, "/tmp")
def env_setup(session, ip_addr, username, shell_port, password): """ Test env setup """ error.context("Setup env for %s" % ip_addr) ssh_cmd(session, "service iptables stop; true") netperf_links = params["netperf_links"].split() remote_dir = params.get("remote_dir", "/var/tmp") for netperf_link in netperf_links: if utils.is_url(netperf_link): download_dir = data_dir.get_download_dir() md5sum = params.get("pkg_md5sum") netperf_dir = utils.unmap_url_cache(download_dir, netperf_link, md5sum) elif netperf_link: netperf_dir = os.path.join(data_dir.get_root_dir(), "shared/%s" % netperf_link) remote.scp_to_remote(ip_addr, shell_port, username, password, netperf_dir, remote_dir) ssh_cmd(session, params.get("setup_cmd"))
def __init__(self, params): self.params = params self.link = self.params.get("download_link") self.md5sum = self.params.get("md5sum") self.tmp_dir = data_dir.get_download_dir() self.install_cmd = self.params.get("install_cmd") % self.tmp_dir self.config_cmd = self.params.get("config_cmd") self.vm_bytes = self.params.get("stress_vm_bytes", "128M") # One vm's memory size vm_memory = int(self.params.get("vm_memory", 1048576)) # Memory needs to be reserved for vms. self.vm_reserved = len(self.params.get("vms").split()) * vm_memory # Set consumed memory for host stress tool self.count_vm_bytes() self.start_cmd = self.params.get("start_cmd") if re.search("--vm-bytes", self.start_cmd): self.start_cmd = self.start_cmd % self.vm_bytes self.stop_cmd = self.params.get("stop_cmd") self.check_cmd = self.params.get("check_cmd") self.app_check_cmd = self.params.get("app_check_cmd")
def netload_kill_problem(session_serial): setup_cmd = params.get("setup_cmd") clean_cmd = params.get("clean_cmd") firewall_flush = params.get("firewall_flush", "service iptables stop") error.context("Stop firewall in guest and host.", logging.info) try: utils.run(firewall_flush) except Exception: logging.warning("Could not stop firewall in host") try: session_serial.cmd(firewall_flush) except Exception: logging.warning("Could not stop firewall in guest") netperf_links = params["netperf_links"].split() remote_dir = params.get("remote_dir", "/var/tmp") # netperf_links support multi links. In case we need apply patchs to # netperf or need copy other files. for netperf_link in netperf_links: if utils.is_url(netperf_link): download_dir = data_dir.get_download_dir() netperf_link = utils.unmap_url_cache(download_dir, netperf_link) netperf_dir = download_dir elif netperf_link: netperf_link = utils_misc.get_path(data_dir.get_deps_dir(), netperf_link) vm.copy_files_to(netperf_link, remote_dir) utils.force_copy(netperf_link, remote_dir) guest_ip = vm.get_address(0) server_ip = utils_net.get_correspond_ip(guest_ip) error.context("Setup and run netperf server in host and guest", logging.info) session_serial.cmd(setup_cmd % remote_dir, timeout=200) utils.run(setup_cmd % remote_dir, timeout=200) try: session_serial.cmd(clean_cmd) except Exception: pass session_serial.cmd(params.get("netserver_cmd") % remote_dir) utils.run(clean_cmd, ignore_status=True) utils.run(params.get("netserver_cmd") % remote_dir) p_size = params.get("packet_size", "1500") host_netperf_cmd = params.get("netperf_cmd") % ( remote_dir, "TCP_STREAM", guest_ip, p_size) guest_netperf_cmd = params.get("netperf_cmd") % ( remote_dir, "TCP_STREAM", server_ip, p_size) try: error.context("Start heavy network load host <=> guest.", logging.info) session_serial.sendline(guest_netperf_cmd) utils.BgJob(host_netperf_cmd) # Wait for create big network usage. time.sleep(10) msg = "During netperf running, Check that we can kill VM with signal 0" error.context(msg, logging.info) kill_and_check(vm) finally: error.context("Clean up netperf server in host and guest.", logging.info) utils.run(clean_cmd, ignore_status=True) try: session_serial.cmd(clean_cmd) except Exception: pass
def run_netperf_udp(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. 2) Start a reference machine (dsthost) as server. 3) Setup netperf on guest and reference machine (dsthost). 4) Run netserver on server using control.server. 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 get_remote_host_session(): dsthostssh = remote.remote_login("ssh", dsthost, 22, "root", passwd, "#", timeout=30) if dsthostssh: dsthostssh.set_status_test_command("echo $?") return dsthostssh else: return None def scp_to_remote(local_path="", remote_path=""): remote.scp_to_remote(dsthost, 22, "root", passwd, local_path, remote_path) vm.copy_files_to(local_path, remote_path) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) dsthost = params.get("dsthost") if not dsthost: dsthost = utils_net.get_ip_address_by_interface(params.get("netdst")) logging.error("dsthost is not set, use localhost ip %s" % dsthost) else: logging.info("Dest host is %s" % dsthost) passwd = params.get("hostpasswd") test_timeout = float(params.get("test_timeout", "1200")) error.context("Create session connection to remote machine") dsthostssh = utils_misc.wait_for(get_remote_host_session, 120, 0, 2) if not dsthostssh: raise error.TestError("Could not login into remote host %s " % dsthost) # Get range of message size. message_size_range = params.get("message_size_range") message_size = message_size_range.split() start_size = int(message_size[0]) end_size = int(message_size[1]) step = int(message_size[2]) m_size = start_size error.context("Copy netperf to dsthost and guest vm.") download_link = params.get("netperf_download_link") download_dir = data_dir.get_download_dir() md5sum = params.get("pkg_md5sum") host_netperf_dir = utils.unmap_url_cache(download_dir, download_link, md5sum) remote_dir = params.get("tmp_dir", "/tmp") scp_to_remote(host_netperf_dir, remote_dir) # Setup netpref. error.context("Set up netperf on reference machine.", logging.info) cmd = params.get("setup_cmd") (status, output) = dsthostssh.cmd_status_output(cmd % remote_dir, timeout=test_timeout) if status != 0: raise error.TestError("Fail to setup netperf on reference machine.") error.context("Setup netperf on guest os.", logging.info) (status, output) = session.cmd_status_output(cmd % remote_dir, timeout=test_timeout) if status != 0: raise error.TestError("Fail to setup netperf on guest os.") # Start netperf server in dsthost. cmd = "killall netserver" dsthostssh.cmd_status_output(cmd) cmd = params.get("netserver_cmd") txt = "Run netserver on server (dsthost) using control.server." error.context(txt, logging.info) (status, output) = dsthostssh.cmd_status_output(cmd) if status != 0: txt = "Fail to start netperf server on remote machine." txt += " Command output: %s" % output raise error.TestError(txt) throughput = [] # Run netperf with message size defined in range. msg = "Detail result for netperf udp test with different message size.\n" while (m_size <= end_size): test_protocol = params.get("test_protocol", "UDP_STREAM") cmd = params.get("netperf_cmd") % (dsthost, test_protocol, m_size) txt = "Run netperf client command in guest: %s" % cmd error.context(txt, logging.info) (status, output) = session.cmd_status_output(cmd) if status != 0: txt = "Fail to execute netperf client side command in guest." txt += " Command output: %s" % output raise error.TestError(txt) 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 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: remote_files = "%s/netperf*" % remote_dir dsthostssh.cmd("killall -9 netserver", ignore_all_errors=True) dsthostssh.cmd("rm -rf %s" % remote_files, ignore_all_errors=True) session.cmd("rm -rf %s" % remote_files, ignore_all_errors=True) utils.system("rm -rf %s" % host_netperf_dir, ignore_status=True) session.close() dsthostssh.close() except Exception: pass
def run_multi_queues_test(test, params, env): """ Enable MULTI_QUEUE feature in guest 1) Boot up VM(s) 2) Login guests one by one 3) Enable MQ for all virtio nics by ethtool -L 4) Run netperf on guest 5) check vhost threads on host, if vhost is enable 6) check cpu affinity if smp == queues @param test: QEMU test object. @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ def run_netperf(vm_session, n_instance, host_ip, client_path, test_time, ext_args, taskset_cpu=[]): cmd = "" if taskset_cpu: cmd += "taskset -c %s " % " ".join(taskset_cpu) cmd += "/home/netperf_agent.py %d " % n_instance cmd += "%s -D 1 -H %s -l %s %s" % (client_path, host_ip, int(test_time) * 1.5, ext_args) cmd += " > /home/netperf_log &" session.cmd(cmd, timeout=120) def netperf_env_setup(session, host_path): tmp_dir = params.get("tmp_dir") agent_path = os.path.join(test.virtdir, "scripts/netperf_agent.py") guest_root_path = params.get("tmp_dir", "/home") vm.copy_files_to(agent_path, guest_root_path) vm.copy_files_to(host_path, guest_root_path, timeout=transfer_timeout) error.context("Setup env in linux guest") session.cmd("service iptables stop; true") session.cmd("iptables -F; true") session.cmd(setup_cmd % tmp_dir) def get_virtio_queues_irq(session): """ Return multi queues input irq list """ guest_irq_info = session.cmd_output("cat /proc/interrupts") return re.findall(r"(\d+):.*virtio\d+-input.\d", guest_irq_info) def get_cpu_affinity_hint(session, irq_number): """ Return the cpu affinity_hint of irq_number """ cmd_get_cpu_affinity = r"cat /proc/irq/%s/affinity_hint" % irq_number return session.cmd_output(cmd_get_cpu_affinity).strip() def get_cpu_index(cpu_id): """ Transfer cpu_id to cpu index """ cpu_used_index = [] for cpu_index in range(int(vm.cpuinfo.smp)): if int(cpu_id) & (0b1 << cpu_index) != 0: cpu_used_index.append(cpu_index) return cpu_used_index def set_cpu_affinity(session): """ Set cpu affinity """ cmd_set_cpu_affinity = r"echo $(cat /proc/irq/%s/affinity_hint)" cmd_set_cpu_affinity += " > /proc/irq/%s/smp_affinity" irq_list = get_virtio_queues_irq(session) for irq in irq_list: session.cmd(cmd_set_cpu_affinity % (irq, irq)) def get_cpu_irq_statistics(session, irq_number, cpu_id=None): """ Get guest interrupts statistics """ cmd = r"cat /proc/interrupts | sed -n '/^\s\+%s:/p'" % irq_number irq_statics = session.cmd_output(cmd) irq_statics_list = map(int, irq_statics.split()[1:-2]) if irq_statics_list: if cpu_id and cpu_id < len(irq_statics_list): return irq_statics_list[cpu_id] if not cpu_id: return irq_statics_list return [] login_timeout = int(params.get("login_timeout", 360)) transfer_timeout = int(params.get("transfer_timeout", 360)) queues = int(params.get("queues", 1)) setup_cmd = params.get("setup_cmd") vms = params.get("vms").split() if queues == 1: logging.info("No need to enable MQ feature for single queue") return for vm in vms: vm = env.get_vm(vm) vm.verify_alive() session = vm.wait_for_login(timeout=login_timeout) for i, nic in enumerate(vm.virtnet): if "virtio" in nic['nic_model']: ifname = utils_net.get_linux_ifname(session, vm.get_mac_address(0)) session.cmd_output("ethtool -L %s combined %d" % (ifname, queues)) o = session.cmd_output("ethtool -l %s" % ifname) if len(re.findall(r"Combined:\s+%d\s" % queues, o)) != 2: raise error.TestError("Fail to enable MQ feature of (%s)" % nic.nic_name) logging.info("MQ feature of (%s) is enabled" % nic.nic_name) # Run netperf under ground error.context("Set netperf test env on host", logging.info) download_dir = data_dir.get_download_dir() download_link = params.get("netperf_download_link") md5sum = params.get("pkg_md5sum") pkg = utils.unmap_url_cache(download_dir, download_link, md5sum) utils.system(setup_cmd % download_dir) os_type = params.get("os_type") if os_type == "linux": netperf_env_setup(session, pkg) else: raise error.context("Run netperf server on the host") netserver_path = "%s/netperf-2.6.0/src/netserver" % download_dir utils.system("pidof netserver || %s" % netserver_path) host_ip = utils_net.get_host_ip_address(params) n_instance = int(params.get("instance", queues)) client_path = "%s/netperf-2.6.0/src/netperf" % "/home" error.context("Run %s netperf on the guest" % int(queues)) ext_args = params.get("ext_args", "") test_time = params.get("test_time", 60) taskset_cpu = params.get("netperf_taskset_cpu", []) check_cpu_affinity = params.get("check_cpu_affinity", 'yes') if check_cpu_affinity == 'yes' and (vm.cpuinfo.smp == queues): utils.system("systemctl stop irqbalance.service") set_cpu_affinity(session) netperf_thread = utils.InterruptedThread(run_netperf, (session, n_instance, host_ip, client_path, test_time, ext_args, taskset_cpu)) netperf_thread.start() def all_clients_works(): try: content = session.cmd("grep -c MIGRATE /home/netperf_log") if int(n_instance) == int(content): return True except: content = 0 return False if utils_misc.wait_for(all_clients_works, 120, 5, 5, "Wait until all netperf clients start to work"): logging.debug("All netperf clients start to work.") else: raise error.TestNAError("Error, not all netperf clients at work") if params.get("vhost") == 'vhost=on': error.context("Check vhost threads on host", logging.info) vhost_thread_pattern = params.get("vhost_thread_pattern", r"\w+\s+(\d+)\s.*\[vhost-%s\]") vhost_threads = vm.get_vhost_threads(vhost_thread_pattern) time.sleep(10) top_cmd = r"top -n 1 -p %s -b" % ",".join(map(str, vhost_threads)) top_info = utils.system_output(top_cmd) logging.info("%s", top_info) vhost_re = re.compile(r"S(\s+0.0+){2}.*vhost-\d+[\d|+]") sleep_vhost_thread = len(vhost_re.findall(top_info, re.I)) running_threads = len(vhost_threads) - int(sleep_vhost_thread) n_instance = min(n_instance, int(queues), int(vm.cpuinfo.smp)) if (running_threads != n_instance): err_msg = "Run %s netperf session, but %s queues works" raise error.TestError(err_msg % (n_instance, running_threads)) # check cpu affinity error.context("Check cpu affinity", logging.info) if check_cpu_affinity == 'yes' and (vm.cpuinfo.smp == queues): vectors = params.get("vectors", None) expect_vectors = 2 * int(queues) + 1 if (not vectors) and (params.get("enable_msix_vectors") == "yes"): vectors = expect_vectors if vectors and (vectors >= expect_vectors) and taskset_cpu: cpu_irq_affinity = {} for irq in get_virtio_queues_irq(session): cpu_id = get_cpu_affinity_hint(session, irq) cpu_index = get_cpu_index(cpu_id) if cpu_index: for cpu in cpu_index: cpu_irq_affinity["%s" % cpu] = irq else: raise error.TestError("Can not get the cpu") irq_number = cpu_irq_affinity[taskset_cpu] irq_ori = get_cpu_irq_statistics(session, irq_number) logging.info("Cpu irq info: %s" % irq_ori) time.sleep(10) irq_cur = get_cpu_irq_statistics(session, irq_number) logging.info("After 10s, cpu irq info: %s" % irq_cur) irq_change_list = map(lambda x: x[0] - x[1], zip(irq_cur, irq_ori)) cpu_affinity = irq_change_list.index(max(irq_change_list)) if cpu_affinity != int(taskset_cpu): err_msg = "Error, taskset on cpu %s, but queues use cpu %s" raise error.TestError(err_msg % (taskset_cpu, cpu_affinity)) netperf_thread.join() session.cmd("rm -rf /home/netperf*") session.close()
def run_netperf_udp(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. 2) Start a reference machine (dsthost) as server. 3) Setup netperf on guest and reference machine (dsthost). 4) Run netserver on server using control.server. 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 get_remote_host_session(): dsthostssh = remote.remote_login("ssh", dsthost, 22, "root", passwd, "#", timeout=30) if dsthostssh: dsthostssh.set_status_test_command("echo $?") return dsthostssh else: return None def scp_to_remote(local_path="", remote_path=""): remote.scp_to_remote(dsthost, 22, "root", passwd, local_path, remote_path) vm.copy_files_to(local_path, remote_path) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) dsthost = params.get("dsthost") if not dsthost: dsthost = utils_net.get_ip_address_by_interface(params.get("netdst")) logging.error("dsthost is not set, use localhost ip %s" % dsthost) else: logging.info("Dest host is %s" % dsthost) passwd = params.get("hostpasswd") test_timeout = float(params.get("test_timeout", "1200")) error.context("Create session connection to remote machine") dsthostssh = utils_misc.wait_for(get_remote_host_session, 120, 0, 2) if not dsthostssh: raise error.TestError("Could not login into remote host %s " % dsthost) # Get range of message size. message_size_range = params.get("message_size_range") message_size = message_size_range.split() start_size = int(message_size[0]) end_size = int(message_size[1]) step = int(message_size[2]) m_size = start_size error.context("Copy netperf to dsthost and guest vm.") netperf_links = params["netperf_links"].split() remote_dir = params.get("remote_dir", "/var/tmp") for netperf_link in netperf_links: if utils.is_url(netperf_link): download_dir = data_dir.get_download_dir() md5sum = params.get("pkg_md5sum") netperf_dir = utils.unmap_url_cache(download_dir, netperf_link, md5sum) elif netperf_link: netperf_dir = os.path.join(test.virtdir, netperf_link) scp_to_remote(netperf_dir, remote_dir) # Setup netpref. error.context("Set up netperf on reference machine.", logging.info) cmd = params.get("setup_cmd") (status, output) = dsthostssh.cmd_status_output(cmd % remote_dir, timeout=test_timeout) if status != 0: raise error.TestError("Fail to setup netperf on reference machine.") error.context("Setup netperf on guest os.", logging.info) (status, output) = session.cmd_status_output(cmd % remote_dir, timeout=test_timeout) if status != 0: raise error.TestError("Fail to setup netperf on guest os.") # Start netperf server in dsthost. cmd = "killall netserver" dsthostssh.cmd_status_output(cmd) cmd = params.get("netserver_cmd") txt = "Run netserver on server (dsthost) using control.server." error.context(txt, logging.info) (status, output) = dsthostssh.cmd_status_output(cmd) if status != 0: txt = "Fail to start netperf server on remote machine." txt += " Command output: %s" % output raise error.TestError(txt) throughput = [] # Run netperf with message size defined in range. msg = "Detail result for netperf udp test with different message size.\n" while(m_size <= end_size): test_protocol = params.get("test_protocol", "UDP_STREAM") cmd = params.get("netperf_cmd") % (dsthost, test_protocol, m_size) txt = "Run netperf client command in guest: %s" % cmd error.context(txt, logging.info) (status, output) = session.cmd_status_output(cmd) if status != 0: txt = "Fail to execute netperf client side command in guest." txt += " Command output: %s" % output raise error.TestError(txt) 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 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: remote_files = "%s/netperf*" % remote_dir dsthostssh.cmd("killall -9 netserver", ignore_all_errors=True) dsthostssh.cmd("rm -rf %s" % remote_files, ignore_all_errors=True) session.cmd("rm -rf %s" % remote_files, ignore_all_errors=True) session.close() dsthostssh.close() except Exception: pass
def netload_kill_problem(session_serial): setup_cmd = params.get("setup_cmd") clean_cmd = params.get("clean_cmd") firewall_flush = params.get("firewall_flush", "service iptables stop") error.context("Stop firewall in guest and host.", logging.info) try: utils.run(firewall_flush) except Exception: logging.warning("Could not stop firewall in host") try: session_serial.cmd(firewall_flush) except Exception: logging.warning("Could not stop firewall in guest") netperf_links = params["netperf_links"].split() remote_dir = params.get("remote_dir", "/var/tmp") # netperf_links support multi links. In case we need apply patchs to # netperf or need copy other files. for netperf_link in netperf_links: if utils.is_url(netperf_link): download_dir = data_dir.get_download_dir() netperf_link = utils.unmap_url_cache(download_dir, netperf_link) netperf_dir = download_dir elif netperf_link: netperf_link = utils_misc.get_path(data_dir.get_deps_dir(), netperf_link) vm.copy_files_to(netperf_link, remote_dir) utils.force_copy(netperf_link, remote_dir) guest_ip = vm.get_address(0) server_ip = utils_net.get_correspond_ip(guest_ip) error.context("Setup and run netperf server in host and guest", logging.info) session_serial.cmd(setup_cmd % remote_dir, timeout=200) utils.run(setup_cmd % remote_dir, timeout=200) try: session_serial.cmd(clean_cmd) except Exception: pass session_serial.cmd(params.get("netserver_cmd") % remote_dir) utils.run(clean_cmd, ignore_status=True) utils.run(params.get("netserver_cmd") % remote_dir) p_size = params.get("packet_size", "1500") host_netperf_cmd = params.get("netperf_cmd") % (remote_dir, "TCP_STREAM", guest_ip, p_size) guest_netperf_cmd = params.get("netperf_cmd") % (remote_dir, "TCP_STREAM", server_ip, p_size) try: error.context("Start heavy network load host <=> guest.", logging.info) session_serial.sendline(guest_netperf_cmd) utils.BgJob(host_netperf_cmd) # Wait for create big network usage. time.sleep(10) msg = "During netperf running, Check that we can kill VM with signal 0" error.context(msg, logging.info) kill_and_check(vm) finally: error.context("Clean up netperf server in host and guest.", logging.info) utils.run(clean_cmd, ignore_status=True) try: session_serial.cmd(clean_cmd) except Exception: pass