def netperf_stress(test, params, vm): """ Netperf stress test. """ n_client = utils_netperf.NetperfClient( vm.get_address(), params.get("client_path"), netperf_source=os.path.join(data_dir.get_deps_dir("netperf"), params.get("netperf_client_link")), client=params.get("shell_client"), port=params.get("shell_port"), username=params.get("username"), password=params.get("password"), prompt=params.get("shell_prompt"), linesep=params.get("shell_linesep", "\n").encode().decode( 'unicode_escape'), status_test_command=params.get("status_test_command", ""), compile_option=params.get("compile_option", "")) n_server = utils_netperf.NetperfServer( utils_net.get_host_ip_address(params), params.get("server_path", "/var/tmp"), netperf_source=os.path.join(data_dir.get_deps_dir("netperf"), params.get("netperf_server_link")), password=params.get("hostpassword"), compile_option=params.get("compile_option", "")) try: n_server.start() # Run netperf with message size defined in range. netperf_test_duration = params.get_numeric("netperf_test_duration") test_protocols = params.get("test_protocol") netperf_output_unit = params.get("netperf_output_unit") test_option = params.get("test_option", "") test_option += " -l %s" % netperf_test_duration if params.get("netperf_remote_cpu") == "yes": test_option += " -C" if params.get("netperf_local_cpu") == "yes": test_option += " -c" if netperf_output_unit in "GMKgmk": test_option += " -f %s" % netperf_output_unit t_option = "%s -t %s" % (test_option, test_protocols) n_client.bg_start(utils_net.get_host_ip_address(params), t_option, params.get_numeric("netperf_para_sessions"), params.get("netperf_cmd_prefix", ""), package_sizes=params.get("netperf_sizes")) if utils_misc.wait_for(n_client.is_netperf_running, 10, 0, 1, "Wait netperf test start"): logging.info("Netperf test start successfully.") else: test.error("Can not start netperf client.") utils_misc.wait_for(lambda: not n_client.is_netperf_running(), netperf_test_duration, 0, 5, "Wait netperf test finish %ss" % netperf_test_duration) time.sleep(5) finally: n_server.stop() n_server.package.env_cleanup(True) n_client.package.env_cleanup(True)
def netperf_test(): """ Netperf stress test for nic option. """ try: n_server.start() # Run netperf with message size defined in range. netperf_test_duration = params.get_numeric("netperf_test_duration") test_protocols = params.get("test_protocols", "TCP_STREAM") netperf_output_unit = params.get("netperf_output_unit") test_option = params.get("test_option", "") test_option += " -l %s" % netperf_test_duration if netperf_output_unit in "GMKgmk": test_option += " -f %s" % netperf_output_unit t_option = "%s -t %s" % (test_option, test_protocols) n_client.bg_start(utils_net.get_host_ip_address(params), t_option, params.get_numeric("netperf_para_sessions"), params.get("netperf_cmd_prefix", ""), package_sizes=params.get("netperf_sizes")) if utils_misc.wait_for(n_client.is_netperf_running, 10, 0, 1, "Wait netperf test start"): logging.info("Netperf test start successfully.") else: test.error("Can not start netperf client.") utils_misc.wait_for( lambda: not n_client.is_netperf_running(), netperf_test_duration, 0, 5, "Wait netperf test finish %ss" % netperf_test_duration) finally: n_server.stop()
def config_control(control_path): """ Edit the control file to adapt the current environment. Replace CLIENTIP with guestip, and replace SERVERIP with hostip. :return: Path of a temp file which contains the result of replacing. """ pattern2repl_dict = {r'CLIENTIP': vm.get_address(), r'SERVERIP': utils_net.get_host_ip_address(params)} control_file = open(control_path) lines = control_file.readlines() control_file.close() for pattern, repl in pattern2repl_dict.items(): for index in range(len(lines)): line = lines[index] lines[index] = re.sub(pattern, repl, line) fd, temp_control_path = tempfile.mkstemp(prefix="control", dir=data_dir.get_tmp_dir()) os.close(fd) temp_control = open(temp_control_path, "w") temp_control.writelines(lines) temp_control.close() return temp_control_path
def test_ping(): """ Ping test for nic option. """ package_sizes = params.objects("ping_sizes") if params["os_type"] == "windows": ifname = utils_net.get_windows_nic_attribute( session=session, key="netenabled", value=True, target="netconnectionID") else: ifname = utils_net.get_linux_ifname(session, vm.get_mac_address()) dest = utils_net.get_host_ip_address(params) for size in package_sizes: error_context.context("Test ping from '%s' to host '%s' on guest '%s'" " with package size %s. " % (ifname, dest, vm.name, size), logging.info) status, output = utils_net.ping(dest=dest, count=10, packetsize=size, session=session, timeout=30) if status: test.fail("%s ping %s unexpected, output %s" % (vm.name, dest, output)) if params["os_type"] == "windows": # windows guest get loss=0 when ping failed sometime, # need further check loss = utils_test.get_loss_ratio(output) if loss or "TTL" in output: pass else: test.fail("Guest ping test hit unexpected loss, " "error_info: %s" % output)
def run(test, params, env): """ When "acpi-index=N" is enabled, NIC name should always be "ethN" 1) Boot up guest with a single nic, add nic option "acpi-index=1" 2) Remove "biosdevname=0" and "net.ifname=0" from kenrel command line 3) Reboot guest 4) Check the nic name, the guest nic name enoN == acpi-index=N :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ login_timeout = int(params.get("login_timeout", 360)) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_serial_login(timeout=login_timeout) ifname = utils_net.get_linux_ifname(session, vm.get_mac_address()) pattern = int(re.findall(r'\d+', ifname)[-1]) nic_name_number = params.get_numeric("nic_name_number") if pattern == nic_name_number: logging.info("nic name match") else: test.fail("nic name doesn't match") host_ip = utils_net.get_host_ip_address(params) status, output = utils_net.ping(host_ip, 10, timeout=30) if status: test.fail("%s ping %s unexpected, output %s" % (vm.name, host_ip, output)) if session: session.close()
def setup_or_cleanup_gluster(is_setup, vol_name, brick_path="", pool_name="", file_path="/etc/glusterfs/glusterd.vol", **kwargs): """ Set up or clean up glusterfs environment on localhost or remote :param is_setup: Boolean value, true for setup, false for cleanup :param vol_name: gluster created volume name :param brick_path: Dir for create glusterfs :param kwargs: Other parameters that need to set for gluster :return: ip_addr or nothing """ try: utils_path.find_command("gluster") except utils_path.CmdNotFoundError: raise exceptions.TestSkipError("Missing command 'gluster'") if not brick_path: tmpdir = data_dir.get_tmp_dir() brick_path = os.path.join(tmpdir, pool_name) # Check gluster server apply or not ip_addr = kwargs.get("gluster_server_ip", "") session = None if ip_addr != "": remote_user = kwargs.get("gluster_server_user") remote_pwd = kwargs.get("gluster_server_pwd") remote_identity_file = kwargs.get("gluster_identity_file") session = remote.remote_login("ssh", ip_addr, "22", remote_user, remote_pwd, "#", identity_file=remote_identity_file) if is_setup: if ip_addr == "": ip_addr = utils_net.get_host_ip_address() add_rpc_insecure(file_path) glusterd_start() logging.debug("finish start gluster") logging.debug("The contents of %s: \n%s", file_path, open(file_path).read()) gluster_vol_create(vol_name, ip_addr, brick_path, True, session) gluster_allow_insecure(vol_name, session) gluster_nfs_disable(vol_name, session) logging.debug("finish vol create in gluster") if session: session.close() return ip_addr else: gluster_vol_stop(vol_name, True, session) gluster_vol_delete(vol_name, session) gluster_brick_delete(brick_path, session) if session: session.close() return ""
def run(test, params, env): """ Test steps: 1) Check the environment and get the params from params. 2) while(loop_time < timeout): ttcp command. 3) clean up. """ # Find the ttcp command. try: path.find_command("ttcp") except path.CmdNotFoundError: test.cancel("Not find ttcp command on host.") # Get VM. vms = env.get_all_vms() for vm in vms: session = vm.wait_for_login() status, _ = session.cmd_status_output("which ttcp") if status: test.cancel("Not find ttcp command on guest.") # Get parameters from params. timeout = int(params.get("LB_ttcp_timeout", "300")) ttcp_server_command = params.get("LB_ttcp_server_command", "ttcp -s -r -v -D -p5015") ttcp_client_command = params.get("LB_ttcp_client_command", "ttcp -s -t -v -D -p5015 -b65536 -l65536 -n1000 -f K") host_session = aexpect.ShellSession("sh") try: current_time = int(time.time()) end_time = current_time + timeout # Start the loop from current_time to end_time. while current_time < end_time: for vm in vms: session = vm.wait_for_login() host_session.sendline(ttcp_server_command) cmd = ("%s %s" % (ttcp_client_command, utils_net.get_host_ip_address(params))) def _ttcp_good(): status, output = session.cmd_status_output(cmd) logging.debug(output) if status: return False return True if not utils_misc.wait_for(_ttcp_good, timeout=60): status, output = session.cmd_status_output(cmd) if status: test.fail("Failed to run ttcp command on guest.\n" "Detail: %s." % output) remote.handle_prompts(host_session, None, None, r"[\#\$]\s*$") current_time = int(time.time()) finally: # Clean up. host_session.close() session.close()
def run(test, params, env): """ Test steps: 1) Check the environment and get the params from params. 2) while(loop_time < timeout): ttcp command. 3) clean up. """ # Find the ttcp command. try: os_dep.command("ttcp") except ValueError: raise error.TestNAError("Not find ttcp command on host.") # Get VM. vms = env.get_all_vms() for vm in vms: session = vm.wait_for_login() status, _ = session.cmd_status_output("which ttcp") if status: raise error.TestNAError("Not find ttcp command on guest.") # Get parameters from params. timeout = int(params.get("LB_ttcp_timeout", "600")) ttcp_server_command = params.get("LB_ttcp_server_command", "ttcp -s -r -v -D -p5015") ttcp_client_command = params.get("LB_ttcp_client_command", "ttcp -s -t -v -D -p5015 -b65536 -l65536 -n1000 -f K") host_session = aexpect.ShellSession("sh") try: current_time = int(time.time()) end_time = current_time + timeout # Start the loop from current_time to end_time. while current_time < end_time: for vm in vms: session = vm.wait_for_login() host_session.sendline(ttcp_server_command) cmd = ("%s %s" % (ttcp_client_command, utils_net.get_host_ip_address(params))) def _ttcp_good(): status, output = session.cmd_status_output(cmd) logging.debug(output) if status: return False return True if not utils_misc.wait_for(_ttcp_good, timeout=5): status, output = session.cmd_status_output(cmd) if status: raise error.TestFail("Failed to run ttcp command on guest.\n" "Detail: %s." % output) remote.handle_prompts(host_session, None, None, r"[\#\$]\s*$") current_time = int(time.time()) finally: # Clean up. host_session.close() session.close()
def _ttcp_good(): status, output = session.cmd_status_output("%s %s" % (ttcp_client_command, utils_net.get_host_ip_address(params))) logging.debug(output) if status: return False return True
def create_gluster_uri(params, stripped=False): """ Create gluster volume uri when using TCP: stripped: gluster_server:/volume not stripped: gluster[+transport]://gluster_server[:port]/volume Create gluster image uri when using unix socket: gluster+unix:///volume/path?socket=/path/to/socket """ vol_name = params.get("gluster_volume_name") # Access gluster server by unix domain socket is_unix_socket = os.path.exists(params.get("gluster_unix_socket", "")) error_context.context("Host name lookup failed") gluster_server = params.get("gluster_server") if not gluster_server or is_unix_socket: gluster_server = socket.gethostname() if not gluster_server or gluster_server == "(none)": gluster_server = utils_net.get_host_ip_address(params) # Start the gluster daemon, if not started # Building gluster uri gluster_uri = None if stripped: gluster_uri = "%s:/%s" % (gluster_server, vol_name) else: volume = "/%s/" % vol_name if is_unix_socket: sock = "?socket=%s" % params["gluster_unix_socket"] img = params.get("image_name").split('/')[-1] fmt = params.get("image_format", "qcow2") image_path = img if params.get_boolean( "image_raw_device") else "%s.%s" % (img, fmt) gluster_uri = "gluster+unix://{v}{p}{s}".format(v=volume, p=image_path, s=sock) else: # Access gluster server by hostname or ip gluster_transport = params.get("gluster_transport") transport = "+%s" % gluster_transport if gluster_transport else "" # QEMU will send 0 which will make gluster to use the default port gluster_port = params.get("gluster_port") port = ":%s" % gluster_port if gluster_port else "" # [IPv6 address] server = "[%s]" % gluster_server if netaddr.valid_ipv6( gluster_server) else gluster_server host = "%s%s" % (server, port) gluster_uri = "gluster{t}://{h}{v}".format(t=transport, h=host, v=volume) return gluster_uri
def setup_certs(params): """ Generating certificates :param params:params """ # Create tmp certificates dir cert_dir = params["cert_dir"] # Remove certificates dir. if os.path.exists(cert_dir): shutil.rmtree(cert_dir) # Setup the certificate authority. hostname = process.run('hostname', ignore_status=False, shell=True, verbose=True).stdout_text.strip() server_ip = utils_net.get_host_ip_address() cn = hostname ca_credential_dict = {} ca_credential_dict['cakey'] = 'ca-key.pem' ca_credential_dict['cacert'] = 'ca-cert.pem' if not os.path.exists(cert_dir): os.makedirs(cert_dir) build_CA(cert_dir, cn, certtool="certtool", credential_dict=ca_credential_dict) # Setup server certificates server_credential_dict = {} server_credential_dict['cakey'] = 'ca-key.pem' server_credential_dict['cacert'] = 'ca-cert.pem' server_credential_dict['serverkey'] = 'server-key.pem' server_credential_dict['servercert'] = 'server-cert.pem' server_credential_dict['ca_cakey_path'] = cert_dir # Build a server key. build_server_key(cert_dir, cn, server_ip, certtool="certtool", credential_dict=server_credential_dict, on_local=True) # Setup client certificates client_credential_dict = {} client_credential_dict['cakey'] = 'ca-key.pem' client_credential_dict['cacert'] = 'ca-cert.pem' client_credential_dict['clientkey'] = 'client-key.pem' client_credential_dict['clientcert'] = 'client-cert.pem' server_credential_dict['ca_cakey_path'] = cert_dir # build a client key. build_client_key(cert_dir, client_cn=cn, certtool="certtool", credential_dict=client_credential_dict)
def form_ping6_args(): """ get source ip address and target ip address ver6 """ src_ipv6 = uefishell_test.send_command(params["command_show6"], params["check_result_show6"], time_interval) target_ipv6 = utils_net.get_host_ip_address(params, "ipv6", True).split("%")[0] return " ".join([src_ipv6[0], target_ipv6])
def run(test, params, env): """ boot guest with the same mac address test. 1) Boot guest with the same mac address 2) Check if the driver is installed and verified 3) Check ip of guest 4) Ping out :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ timeout = int(params.get_numeric("timeout", 360)) error_context.context("Boot guest with 2 virtio-net with the same mac", logging.info) vm = env.get_vm(params["main_vm"]) session = vm.wait_for_login(timeout=timeout) error_context.context("Check if the driver is installed and " "verified", logging.info) driver_name = params.get("driver_name", "netkvm") session = utils_test.qemu.windrv_check_running_verifier( session, vm, test, driver_name, timeout) # wait for getting the 169.254.xx.xx, it gets slower than valid ip. time.sleep(60) error_context.context("Check the ip of guest", logging.info) mac = vm.virtnet[0].mac cmd = 'wmic nicconfig where macaddress="%s" get ipaddress' % mac status, output = session.cmd_status_output(cmd, timeout) if status: test.error("Check ip error, output=%s" % output) lines = [l.strip() for l in output.splitlines() if l.strip()] logging.info(lines) valid_count = 0 for l in lines[1:]: ip = re.findall(r'(\d+.\d+.\d+.\d+)"', l)[0] if not ip.startswith("169.254"): valid_count += 1 if valid_count != 1: test.error("%d valid ip found, should be 1" % valid_count) error_context.context("Ping out from guest", logging.info) host_ip = utils_net.get_host_ip_address(params) status, output = utils_net.ping(host_ip, count=10, timeout=60, session=session) if status: test.fail("Ping %s failed, output=%s" % (host_ip, output))
def run(test, params, env): """ Verify open bios info. Step: 1. Boot guest with qemu cli including "-prom-env 'auto-boot?=false'". 2. SLOF will not boot automatically, it will go to the SLOF user interface directly, and the effect of "-prom-env 'auto-boot?=false'" is same with pressing "s" key during boot. 3. In the SLOF terminal, input "boot" or "reset-all". 4. SLOF will boot up successfully. 5. Ping external host ip inside guest successfully. :param test: Qemu test object. :param params: Dictionary with the test. :param env: Dictionary with test environment. """ def _send_custom_key(): """ Send custom keyword to SLOF's user interface. """ logging.info('Sending \"%s\" to SLOF user interface.', send_key) for key in send_key: key = 'minus' if key == '-' else key vm.send_key(key) vm.send_key('ret') vm = env.get_vm(params["main_vm"]) send_key = params.get('send_key') end_str = params.get('slof_end_str', '0 >') vm.verify_alive() content, next_pos = slof.wait_for_loaded(vm, test, end_str=end_str) logging.info('SLOF stop at \'%s\'.', end_str) error_context.context("Enter to menu by sending \'%s\'." % send_key, logging.info) _send_custom_key() content, _ = slof.wait_for_loaded(vm, test, next_pos, 'Trying to load') error_context.context("Try to log into guest '%s'." % vm.name, logging.info) session = vm.wait_for_login(timeout=float(params["login_timeout"])) logging.info("log into guest '%s' successfully.", vm.name) error_context.context("Try to ping external host.", logging.info) extra_host_ip = utils_net.get_host_ip_address(params) session.cmd('ping %s -c 5' % extra_host_ip) logging.info("Ping host(%s) successfully.", extra_host_ip) session.close() vm.destroy(gracefully=True)
def run(test, params, env): """ Verify open bios info. Step: 1. Boot guest with qemu cli including "-prom-env 'auto-boot?=false'". 2. SLOF will not boot automatically, it will go to the SLOF user interface directly, and the effect of "-prom-env 'auto-boot?=false'" is same with pressing "s" key during boot. 3. In the SLOF terminal, input "boot" or "reset-all". 4. SLOF will boot up successfully. 5. Ping external host ip inside guest successfully. :param test: Qemu test object. :param params: Dictionary with the test. :param env: Dictionary with test environment. """ def _send_custom_key(): """ Send custom keyword to SLOF's user interface. """ logging.info('Sending \"%s\" to SLOF user interface.' % send_key) for key in send_key: key = 'minus' if key == '-' else key vm.send_key(key) vm.send_key('ret') vm = env.get_vm(params["main_vm"]) send_key = params.get('send_key') end_str = params.get('slof_end_str', '0 >') vm.verify_alive() content, next_pos = slof.wait_for_loaded(vm, test, end_str=end_str) logging.info('SLOF stop at \'%s\'.' % end_str) error_context.context( "Enter to menu by sending \'%s\'." % send_key, logging.info) _send_custom_key() content, _ = slof.wait_for_loaded(vm, test, next_pos, 'Trying to load') error_context.context("Try to log into guest '%s'." % vm.name, logging.info) session = vm.wait_for_login(timeout=float(params["login_timeout"])) logging.info("log into guest '%s' successfully." % vm.name) error_context.context("Try to ping external host.", logging.info) extra_host_ip = utils_net.get_host_ip_address(params) session.cmd('ping %s -c 5' % extra_host_ip) logging.info("Ping host(%s) successfully." % extra_host_ip) session.close() vm.destroy(gracefully=True)
def get_host_ip(test): """Get IP for host. Parameters ---------- test : SpiceTest Spice test object. """ try: ip = utils_net.get_host_ip_address(test.cfg) except utils_net.NetError: ips = utils_net.get_all_ips() ip = ips[0] logger.info("Take as a host IP: %s", ip) if test.kvm_g.listening_addr == "ipv6": ip = "[" + utils_misc.convert_ipv4_to_ipv6(ip) + "]" return ip
def run(test, params, env): """ Verify SLOF info with maxmem options. Step: 1. Boot a guest with "maxmem=512G". a. Check no errors from output of SLOF. b. Log in guest successfully. c. Ping external host ip successfully. 2. Shutdown the guest then boot it again with "maxmem=1024G". a. Check no errors from output of SLOF. b. Log in guest successfully. c. Ping external host ip successfully. :param test: Qemu test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ start_pos = 0 for mem in params['maxmem_mem_list'].split(): params['maxmem_mem'] = mem env_process.preprocess_vm(test, params, env, params["main_vm"]) vm = env.get_vm(params["main_vm"]) vm.verify_alive() content, next_pos = slof.wait_for_loaded(vm, test, start_pos) error_context.context("Check the output of SLOF.", logging.info) slof.check_error(test, content) error_context.context("Try to log into guest '%s'." % vm.name, logging.info) timeout = float(params.get("login_timeout", 240)) session = vm.wait_for_login(timeout=timeout) logging.info("log into guest '%s' successfully." % vm.name) error_context.context("Try to ping external host.", logging.info) extra_host_ip = utils_net.get_host_ip_address(params) session.cmd('ping %s -c 5' % extra_host_ip) logging.info("Ping host(%s) successfully." % extra_host_ip) session.close() vm.destroy(gracefully=True) start_pos = next_pos
def gen_rv_file(params, guest_vm, host_subj=None, cacert=None): """ Generates vv file for remote-viewer :param params: all parameters of the test :param guest_vm: object of a guest VM :param host_subj: subject of the host :param cacert: location of certificate of host """ full_screen = params.get("full_screen") proxy = params.get("spice_proxy") rv_file = open('rv_file.vv', 'w') rv_file.write("[virt-viewer]\n" + "type=%s\n" % params.get("display") + "host=%s\n" % utils_net.get_host_ip_address(params) + "port=%s\n" % guest_vm.get_spice_var("spice_port")) ticket = params.get("spice_password", None) ticket_send = params.get("spice_password_send", None) qemu_ticket = params.get("qemu_password", None) if ticket_send: ticket = ticket_send if qemu_ticket: ticket = qemu_ticket if ticket: rv_file.write("password=%s\n" % ticket) if guest_vm.get_spice_var("spice_ssl") == "yes": rv_file.write("tls-port=%s\n" % guest_vm.get_spice_var("spice_tls_port")) rv_file.write("tls-ciphers=DEFAULT\n") if host_subj: rv_file.write("host-subject=%s\n" % host_subj) if cacert: cert = open(cacert) ca = cert.read() ca = ca.replace('\n', r'\n') rv_file.write("ca=%s\n" % ca) if full_screen == "yes": rv_file.write("fullscreen=1\n") if proxy: rv_file.write("proxy=%s\n" % proxy)
def run(test, params, env): """ Test steps: 1) Check the environment and get the params from params. 2) while(loop_time < timeout): ttcp command. 3) clean up. """ # Find the ttcp command. try: os_dep.command("ttcp") except ValueError: raise error.TestNAError("Not find ttcp command on host.") # Get VM. vm = env.get_vm(params.get("main_vm", "virt-tests-vm1")) session = vm.wait_for_login() status, _ = session.cmd_status_output("which ttcp") if status: raise error.TestNAError("Not find ttcp command on guest.") # Get parameters from params. timeout = int(params.get("LB_ttcp_timeout", "600")) ttcp_server_command = params.get("LB_ttcp_server_command", "ttcp -s -r -v -D -p5015 &") ttcp_client_command = params.get("LB_ttcp_client_command", "ttcp -s -t -v -D -p5015 -b65536 -l65536 -n1000 -f K") try: current_time = int(time.time()) end_time = current_time + timeout # Start the loop from current_time to end_time. while current_time < end_time: utils.run(ttcp_server_command) status, output = session.cmd_status_output("%s %s" % (ttcp_client_command, utils_net.get_host_ip_address(params))) if status: raise error.TestFail("Failed to run ttcp command on guest.\n" "Detail: %s." % output) current_time = int(time.time()) finally: # Clean up. logging.debug("No clean up operation for this test.")
def gen_rv_file(params, guest_vm, host_subj = None, cacert = None): """ Generates vv file for remote-viewer :param params: all parameters of the test :param guest_vm: object of a guest VM :param host_subj: subject of the host :param cacert: location of certificate of host """ full_screen = params.get("full_screen") proxy = params.get("spice_proxy") rv_file = open('rv_file.vv', 'w') rv_file.write("[virt-viewer]\n" + "type=%s\n" % params.get("display") + "host=%s\n" % utils_net.get_host_ip_address(params) + "port=%s\n" % guest_vm.get_spice_var("spice_port")) ticket = params.get("spice_password", None) ticket_send = params.get("spice_password_send", None) qemu_ticket = params.get("qemu_password", None) if ticket_send: ticket = ticket_send if qemu_ticket: ticket = qemu_ticket if ticket: rv_file.write("password=%s\n" % ticket) if guest_vm.get_spice_var("spice_ssl") == "yes": rv_file.write("tls-port=%s\n" % guest_vm.get_spice_var("spice_tls_port")) rv_file.write("tls-ciphers=DEFAULT\n") if host_subj: rv_file.write("host-subject=%s\n" % host_subj) if cacert: cert = open(cacert) ca = cert.read() ca = ca.replace('\n', r'\n') rv_file.write("ca=%s\n" % ca) if full_screen == "yes": rv_file.write("fullscreen=1\n") if proxy: rv_file.write("proxy=%s\n" % proxy)
def run(test, params, env): """ Verify SLOF info when LUN ID greater than 255. Step: 1. Boot a guest with scsi system disk which lun=0 2. Check no any errors from output of slof. 3. Could login guest. 4. Could ping external host ip. 5. Shutdown guest. 6. Change the lun id of scsi disk greater than 255(e.g 300). 7. Boot this guest again. 8. Repeat to do step 2 ~ 4. :param test: Qemu test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ params['start_vm'] = 'yes' start_pos = 0 for params['drive_lun_image1'] in params['lun_ids'].split(): env_process.preprocess_vm(test, params, env, params["main_vm"]) vm = env.get_vm(params["main_vm"]) vm.verify_alive() content, next_pos = slof.wait_for_loaded(vm, test, start_pos) error_context.context("Check the output of SLOF.", logging.info) slof.check_error(test, content) error_context.context("Try to log into guest '%s'." % vm.name, logging.info) timeout = float(params.get("login_timeout", 240)) session = vm.wait_for_login(timeout=timeout) logging.info("log into guest '%s' successfully.", vm.name) error_context.context("Try to ping external host.", logging.info) extra_host_ip = utils_net.get_host_ip_address(params) session.cmd('ping %s -c 5' % extra_host_ip) logging.info("Ping host(%s) successfully.", extra_host_ip) session.close() vm.destroy(gracefully=True) start_pos = next_pos
def run(test, params, env): """ Verify SLOF info when LUN ID greater than 255. Step: 1. Boot a guest with scsi system disk which lun=0 2. Check no any errors from output of slof. 3. Could login guest. 4. Could ping external host ip. 5. Shutdown guest. 6. Change the lun id of scsi disk greater than 255(e.g 300). 7. Boot this guest again. 8. Repeat to do step 2 ~ 4. :param test: Qemu test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ params['start_vm'] = 'yes' start_pos = 0 for params['drive_lun_image1'] in params['lun_ids'].split(): env_process.preprocess_vm(test, params, env, params["main_vm"]) vm = env.get_vm(params["main_vm"]) vm.verify_alive() content, next_pos = slof.wait_for_loaded(vm, test, start_pos) error_context.context("Check the output of SLOF.", logging.info) slof.check_error(test, content) error_context.context("Try to log into guest '%s'." % vm.name, logging.info) timeout = float(params.get("login_timeout", 240)) session = vm.wait_for_login(timeout=timeout) logging.info("log into guest '%s' successfully." % vm.name) error_context.context("Try to ping external host.", logging.info) extra_host_ip = utils_net.get_host_ip_address(params) session.cmd('ping %s -c 5' % extra_host_ip) logging.info("Ping host(%s) successfully." % extra_host_ip) session.close() vm.destroy(gracefully=True) start_pos = next_pos
def get_host_ip(test): """Get IP for host. Parameters ---------- test : SpiceTest Spice test object. """ ip_ver = test.kvm_g.listening_addr if not ip_ver: ip_ver = "ipv4" try: ip = utils_net.get_host_ip_address(test.cfg, ip_ver) except utils_net.NetError: ips = utils_net.get_all_ips() ip = ips[0] logger.info("Take as a host IP: %s", ip) if ip_ver == "ipv6": ip = "[" + ip + "]" return ip
def run(test, params, env): """ Verify SLOF info by user interface. Step: Scenario 1: 1.1 Boot a guest with at least two blocks, with "-boot menu=on", Press "F12" in the guest desktop at the early stage of booting process. 1.2 Check the boot menu info whether are match with guest info. 1.3 Select one of valid device to boot up the guest. 1.4 Check whether errors in SLOF. 1.5 Log in guest successfully. 1.6 Ping external host ip successfully. Scenario 2: 2.1. Boot the guest with spapr-vty and press 's' immediately when the guest boot up. 2.2. Check the output of console, whether is stopped enter kernel. 2.3. Type "boot" or "reset-all". 2.4. Check guest whether boot up successfully. 2.5. Log in guest successfully. :param test: Qemu test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ STOP, F12 = range(2) enter_key = {STOP: 's', F12: 'f12'} def _send_custom_key(keystr): """ Send custom keyword to SLOF's user interface. """ logging.info('Sending \"%s\" to SLOF user interface.' % keystr) for key in keystr: key = 'minus' if key == '-' else key vm.send_key(key) vm.send_key('ret') def _send_key(key, custom=True, sleep=0.0): """ Send keywords to SLOF's user interface. """ obj_name = 'select' if re.search(r'^\d+$', key) else key k_params = params.object_params(obj_name.replace('-', '_')) if custom: _send_custom_key(key) else: vm.send_key(key) time.sleep(sleep) content, _ = slof.get_boot_content(vm, 0, k_params['start'], k_params['end']) if content: logging.info('Output of SLOF:\n%s' % ''.join(content)) return ''.join(content) return None def _check_menu_info(menu_info): """ Check the menu info by each items. """ bootable_num = '' for i in range(1, int(params['boot_dev_num']) + 1): option = params['menu_option%d' % i] logging.info( 'Checking the device(%s) if is included in menu list.' % '->'.join(option.split())) dev_type, hba_type, child_bus, addr = option.split() addr = re.sub(r'^0x0?', '', addr) pattern = re.compile( r'(\d+)\)\s+%s(\d+)?\s+:\s+/%s(\S+)?/%s@%s' % (dev_type, hba_type, child_bus, addr), re.M) searched = pattern.search(menu_info) if not searched: test.fail('No such item(%s) in boot menu list.' % '->'.join(option.split())) if i == int(params['bootable_index']): bootable_num = searched.group(1) return bootable_num def _enter_user_interface(mode): """ Enter user interface. """ o = utils_misc.wait_for(lambda: _send_key(enter_key[mode], False), ack_timeout, step=0.0) if not o: test.fail('Failed to enter user interface in %s sec.' % ack_timeout) return o def _f12_user_interface_test(): """ Test f12 user interface. """ menu_list = _enter_user_interface(F12) actual_num = len(re.findall(r'\d+\)', menu_list)) dev_num = params['boot_dev_num'] if actual_num != int(dev_num): test.fail('The number of boot devices is not %s in menu list.' % dev_num) if not utils_misc.wait_for( lambda: _send_key(_check_menu_info(menu_list), False), ack_timeout, step=0.0): test.fail('Failed to load after selecting boot device ' 'in %s sec.' % ack_timeout) def _load_user_interface_test(): """ Test boot/reset-all user interface. """ _enter_user_interface(STOP) if not utils_misc.wait_for( lambda: _send_key(keys, True, 3), ack_timeout, step=0.0): test.fail('Failed to load after \'%s\' in %s sec.' % (keys, ack_timeout)) def _check_serial_log_status(): """ Check the status of serial log. """ file_timeout = 30 if not utils_misc.wait_for( lambda: os.path.isfile(vm.serial_console_log), file_timeout): test.error('No found serial log during %s sec.' % file_timeout) main_tests = { 'f12': _f12_user_interface_test, 'boot': _load_user_interface_test, 'reset-all': _load_user_interface_test } ack_timeout = params['ack_timeout'] keys = params['send_keys'] env_process.process(test, params, env, env_process.preprocess_image, env_process.preprocess_vm) vm = env.get_vm(params["main_vm"]) vm.verify_alive() _check_serial_log_status() main_tests[keys]() error_context.context("Try to log into guest '%s'." % vm.name, logging.info) session = vm.wait_for_login(timeout=float(params['login_timeout'])) logging.info("log into guest '%s' successfully." % vm.name) error_context.context("Try to ping external host.", logging.info) extra_host_ip = utils_net.get_host_ip_address(params) session.cmd('ping %s -c 5' % extra_host_ip) logging.info("Ping host(%s) successfully." % extra_host_ip) vm.destroy(gracefully=True)
def run(test, params, env): """ QEMU flow caches stress test test 1) Make sure nf_conntrack is disabled in host and guest. If nf_conntrack is enabled in host, skip this case. 2) Boot guest with vhost=on/off. 3) Enable multi queues support in guest (optional). 4) After installation of netperf, run netserver in host. 5) Run netperf TCP_CRR protocal test in guest. 6) Transfer file between guest and host. 7) Check the md5 of copied file. This is a sample QEMU test, so people can get used to some of the test APIs. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ msg = "Make sure nf_conntrack is disabled in host and guest." error_context.context(msg, logging.info) if "nf_conntrack" in process.system_output("lsmod"): err = "nf_conntrack load in host, skip this case" test.cancel(err) params["start_vm"] = "yes" error_context.context("Boot up guest", logging.info) env_process.preprocess_vm(test, params, env, params["main_vm"]) vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) if "nf_conntrack" in session.cmd_output("lsmod"): msg = "Unload nf_conntrack module in guest." error_context.context(msg, logging.info) black_str = "#disable nf_conntrack\\nblacklist nf_conntrack\\n" \ "blacklist nf_conntrack_ipv6\\nblacklist xt_conntrack\\n" \ "blacklist nf_conntrack_ftp\\nblacklist xt_state\\n" \ "blacklist iptable_nat\\nblacklist ipt_REDIRECT\\n" \ "blacklist nf_nat\\nblacklist nf_conntrack_ipv4" cmd = "echo -e '%s' >> /etc/modprobe.d/blacklist.conf" % black_str session.cmd(cmd) session = vm.reboot(session, timeout=timeout) if "nf_conntrack" in session.cmd_output("lsmod"): err = "Fail to unload nf_conntrack module in guest." test.error(err) netperf_link = utils_misc.get_path(data_dir.get_deps_dir("netperf"), params["netperf_link"]) md5sum = params.get("pkg_md5sum") win_netperf_link = params.get("win_netperf_link") if win_netperf_link: win_netperf_link = utils_misc.get_path( data_dir.get_deps_dir("netperf"), win_netperf_link) win_netperf_md5sum = params.get("win_netperf_md5sum") server_path = params.get("server_path", "/var/tmp/") client_path = params.get("client_path", "/var/tmp/") win_netperf_path = params.get("win_netperf_path", "c:\\") client_num = params.get("netperf_client_num", 520) netperf_timeout = int(params.get("netperf_timeout", 600)) netperf_client_ip = vm.get_address() host_ip = utils_net.get_host_ip_address(params) netperf_server_ip = params.get("netperf_server_ip", host_ip) username = params.get("username", "root") password = params.get("password", "123456") passwd = params.get("hostpasswd", "123456") client = params.get("shell_client", "ssh") port = params.get("shell_port", "22") prompt = params.get("shell_prompt", r"^root@.*[\#\$]\s*$|#") linesep = params.get("shell_linesep", "\n").encode().decode('unicode_escape') status_test_command = params.get("status_test_command", "echo $?") compile_option_client = params.get("compile_option_client", "") compile_option_server = params.get("compile_option_server", "") if int(params.get("queues", 1)) > 1 and params.get("os_type") == "linux": error_context.context("Enable multi queues support in guest.", logging.info) guest_mac = vm.get_mac_address() ifname = utils_net.get_linux_ifname(session, guest_mac) cmd = "ethtool -L %s combined %s" % (ifname, params.get("queues")) status, out = session.cmd_status_output(cmd) msg = "Fail to enable multi queues support in guest." msg += "Command %s fail output: %s" % (cmd, out) test.error(msg) if params.get("os_type") == "linux": session.cmd("iptables -F", ignore_all_errors=True) g_client_link = netperf_link g_client_path = client_path g_md5sum = md5sum elif params.get("os_type") == "windows": g_client_link = win_netperf_link g_client_path = win_netperf_path g_md5sum = win_netperf_md5sum error_context.context("Setup netperf in guest and host", logging.info) netperf_client = utils_netperf.NetperfClient( netperf_client_ip, g_client_path, g_md5sum, g_client_link, username=username, password=password, prompt=prompt, linesep=linesep, status_test_command=status_test_command, compile_option=compile_option_client) netperf_server = utils_netperf.NetperfServer( netperf_server_ip, server_path, md5sum, netperf_link, client, port, password=passwd, prompt=prompt, linesep=linesep, status_test_command=status_test_command, compile_option=compile_option_server) try: error_context.base_context("Run netperf test between host and guest.") error_context.context("Start netserver in host.", logging.info) netperf_server.start() error_context.context( "Start Netperf in guest for %ss." % netperf_timeout, logging.info) test_option = "-t TCP_CRR -l %s -- -b 10 -D" % netperf_timeout netperf_client.bg_start(netperf_server_ip, test_option, client_num) utils_misc.wait_for(lambda: not netperf_client.is_netperf_running(), timeout=netperf_timeout, first=590, step=2) utils_test.run_file_transfer(test, params, env) finally: netperf_server.stop() netperf_client.package.env_cleanup(True) if session: session.close()
def launch_rv(client_vm, guest_vm, params): """ Launches rv_binary with args based on spice configuration inside client_session on background. remote-viewer will try to connect from vm1 from vm2 @param client_vm - vm object @param guest_vm - vm object @param params """ rv_binary = params.get("rv_binary", "remote-viewer") host_ip = utils_net.get_host_ip_address(params) test_type = params.get("test_type") host_port = None full_screen = params.get("full_screen") display = params.get("display") cmd = rv_binary + " --display=:0.0" ticket = None ticket_send = params.get("spice_password_send") qemu_ticket = params.get("qemu_password") #If qemu_ticket is set, set the password of the VM using the qemu-monitor if qemu_ticket: guest_vm.monitor.cmd("set_password spice %s" % qemu_ticket) logging.info("Sending to qemu monitor: set_password spice %s" % qemu_ticket) client_session = client_vm.wait_for_login( timeout=int(params.get("login_timeout", 360))) if display == "spice": ticket = guest_vm.get_spice_var("spice_password") if guest_vm.get_spice_var("spice_ssl") == "yes": host_tls_port = guest_vm.get_spice_var("spice_tls_port") host_port = guest_vm.get_spice_var("spice_port") cacert = "%s/%s" % (guest_vm.get_spice_var("spice_x509_prefix"), guest_vm.get_spice_var("spice_x509_cacert_file")) #cacert subj is in format for create certificate(with '/' delimiter) #remote-viewer needs ',' delimiter. And also is needed to remove #first character (it's '/') host_subj = guest_vm.get_spice_var("spice_x509_server_subj") host_subj = host_subj.replace('/', ',')[1:] cmd += " spice://%s?tls-port=%s\&port=%s" % (host_ip, host_tls_port, host_port) cmd += " --spice-ca-file=%s" % cacert if params.get("spice_client_host_subject") == "yes": cmd += " --spice-host-subject=\"%s\"" % host_subj #client needs cacert file client_session.cmd("rm -rf %s && mkdir -p %s" % ( guest_vm.get_spice_var("spice_x509_prefix"), guest_vm.get_spice_var("spice_x509_prefix"))) remote.copy_files_to(client_vm.get_address(), 'scp', params.get("username"), params.get("password"), params.get("shell_port"), cacert, cacert) else: host_port = guest_vm.get_spice_var("spice_port") cmd += " spice://%s?port=%s" % (host_ip, host_port) elif display == "vnc": raise NotImplementedError("remote-viewer vnc") else: raise Exception("Unsupported display value") # Check to see if the test is using the full screen option. if full_screen == "yes": logging.info("Remote Viewer Set to use Full Screen") cmd += " --full-screen" cmd = "nohup " + cmd + " &> /dev/null &" # Launch it on background # Launching the actual set of commands try: print_rv_version(client_session, rv_binary) except ShellStatusError, ShellProcessTerminatedError: # Sometimes It fails with Status error, ingore it and continue. # It's not that important to have printed versions in the log. logging.debug("Ignoring a Status Exception that occurs from calling " "print versions of remote-viewer or spice-gtk")
def run(test, params, env): """ QEMU flow caches stress test test 1) Make sure nf_conntrack is disabled in host and guest. If nf_conntrack is enabled in host, skip this case. 2) Boot guest with vhost=on/off. 3) Enable multi queues support in guest (optional). 4) After installation of netperf, run netserver in host. 5) Run netperf TCP_CRR protocal test in guest. 6) Transfer file between guest and host. 7) Check the md5 of copied file. This is a sample QEMU test, so people can get used to some of the test APIs. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ msg = "Make sure nf_conntrack is disabled in host and guest." error_context.context(msg, logging.info) if "nf_conntrack" in process.system_output("lsmod"): err = "nf_conntrack load in host, skip this case" test.cancel(err) params["start_vm"] = "yes" error_context.context("Boot up guest", logging.info) env_process.preprocess_vm(test, params, env, params["main_vm"]) vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) if "nf_conntrack" in session.cmd_output("lsmod"): msg = "Unload nf_conntrack module in guest." error_context.context(msg, logging.info) black_str = "#disable nf_conntrack\\nblacklist nf_conntrack\\n" \ "blacklist nf_conntrack_ipv6\\nblacklist xt_conntrack\\n" \ "blacklist nf_conntrack_ftp\\nblacklist xt_state\\n" \ "blacklist iptable_nat\\nblacklist ipt_REDIRECT\\n" \ "blacklist nf_nat\\nblacklist nf_conntrack_ipv4" cmd = "echo -e '%s' >> /etc/modprobe.d/blacklist.conf" % black_str session.cmd(cmd) session = vm.reboot(session, timeout=timeout) if "nf_conntrack" in session.cmd_output("lsmod"): err = "Fail to unload nf_conntrack module in guest." test.error(err) netperf_link = utils_misc.get_path(data_dir.get_deps_dir("netperf"), params["netperf_link"]) md5sum = params.get("pkg_md5sum") win_netperf_link = params.get("win_netperf_link") if win_netperf_link: win_netperf_link = utils_misc.get_path(data_dir.get_deps_dir("netperf"), win_netperf_link) win_netperf_md5sum = params.get("win_netperf_md5sum") server_path = params.get("server_path", "/var/tmp/") client_path = params.get("client_path", "/var/tmp/") win_netperf_path = params.get("win_netperf_path", "c:\\") client_num = params.get("netperf_client_num", 520) netperf_timeout = int(params.get("netperf_timeout", 600)) netperf_client_ip = vm.get_address() host_ip = utils_net.get_host_ip_address(params) netperf_server_ip = params.get("netperf_server_ip", host_ip) username = params.get("username", "root") password = params.get("password", "123456") passwd = params.get("hostpasswd", "123456") client = params.get("shell_client", "ssh") port = params.get("shell_port", "22") prompt = params.get("shell_prompt", r"^root@.*[\#\$]\s*$|#") linesep = params.get( "shell_linesep", "\n").encode().decode('unicode_escape') status_test_command = params.get("status_test_command", "echo $?") compile_option_client = params.get("compile_option_client", "") compile_option_server = params.get("compile_option_server", "") if int(params.get("queues", 1)) > 1 and params.get("os_type") == "linux": error_context.context("Enable multi queues support in guest.", logging.info) guest_mac = vm.get_mac_address() ifname = utils_net.get_linux_ifname(session, guest_mac) cmd = "ethtool -L %s combined %s" % (ifname, params.get("queues")) status, out = session.cmd_status_output(cmd) msg = "Fail to enable multi queues support in guest." msg += "Command %s fail output: %s" % (cmd, out) test.error(msg) if params.get("os_type") == "linux": session.cmd("iptables -F", ignore_all_errors=True) g_client_link = netperf_link g_client_path = client_path g_md5sum = md5sum elif params.get("os_type") == "windows": g_client_link = win_netperf_link g_client_path = win_netperf_path g_md5sum = win_netperf_md5sum error_context.context("Setup netperf in guest and host", logging.info) netperf_client = utils_netperf.NetperfClient(netperf_client_ip, g_client_path, g_md5sum, g_client_link, username=username, password=password, prompt=prompt, linesep=linesep, status_test_command=status_test_command, compile_option=compile_option_client) netperf_server = utils_netperf.NetperfServer(netperf_server_ip, server_path, md5sum, netperf_link, client, port, password=passwd, prompt=prompt, linesep=linesep, status_test_command=status_test_command, compile_option=compile_option_server) try: error_context.base_context("Run netperf test between host and guest.") error_context.context("Start netserver in host.", logging.info) netperf_server.start() error_context.context("Start Netperf in guest for %ss." % netperf_timeout, logging.info) test_option = "-t TCP_CRR -l %s -- -b 10 -D" % netperf_timeout netperf_client.bg_start(netperf_server_ip, test_option, client_num) utils_misc.wait_for(lambda: not netperf_client.is_netperf_running(), timeout=netperf_timeout, first=590, step=2) utils_test.run_file_transfer(test, params, env) finally: netperf_server.stop() netperf_client.package.env_cleanup(True) if session: session.close()
def test_netperf(): """ Netperf stress test for nic option. """ netperf_client_link = os.path.join(data_dir.get_deps_dir("netperf"), params.get("netperf_client_link")) client_path = params.get("client_path") n_client = utils_netperf.NetperfClient( vm.get_address(), client_path, netperf_source=netperf_client_link, client=params.get("shell_client"), port=params.get("shell_port"), username=params.get("username"), password=params.get("password"), prompt=params.get("shell_prompt"), linesep=params.get("shell_linesep", "\n").encode().decode('unicode_escape'), status_test_command=params.get("status_test_command", ""), compile_option=params.get("compile_option", "")) n_server = utils_netperf.NetperfServer( utils_net.get_host_ip_address(params), params.get("server_path", "/var/tmp"), netperf_source=os.path.join(data_dir.get_deps_dir("netperf"), params.get("netperf_server_link")), password=params.get("hostpassword"), compile_option=params.get("compile_option", "")) try: n_server.start() # Run netperf with message size defined in range. netperf_test_duration = int( params.get("netperf_test_duration", 180)) netperf_para_sess = params.get("netperf_para_sessions", "1") test_protocols = params.get("test_protocols", "TCP_STREAM") netperf_cmd_prefix = params.get("netperf_cmd_prefix", "") netperf_output_unit = params.get("netperf_output_unit") netperf_package_sizes = params.get("netperf_sizes") test_option = params.get("test_option", "") test_option += " -l %s" % netperf_test_duration if params.get("netperf_remote_cpu") == "yes": test_option += " -C" if params.get("netperf_local_cpu") == "yes": test_option += " -c" if netperf_output_unit in "GMKgmk": test_option += " -f %s" % netperf_output_unit start_time = time.time() stop_time = start_time + netperf_test_duration num = 0 for protocol in test_protocols.split(): error_context.context("Testing %s protocol" % protocol, logging.info) t_option = "%s -t %s" % (test_option, protocol) n_client.bg_start(utils_net.get_host_ip_address(params), t_option, netperf_para_sess, netperf_cmd_prefix, package_sizes=netperf_package_sizes) if utils_misc.wait_for(n_client.is_netperf_running, 10, 0, 1, "Wait netperf test start"): logging.info("Netperf test start successfully.") else: test.error("Can not start netperf client.") num += 1 # here when set a run flag, when other case call this case as a # subprocess backgroundly,can set this run flag to False to stop # the stress test. env["netperf_run"] = True netperf_test_duration = stop_time - time.time() utils_misc.wait_for( lambda: not n_client.is_netperf_running(), netperf_test_duration, 0, 5, "Wait netperf test finish %ss" % netperf_test_duration) time.sleep(5) finally: n_server.stop() n_server.package.env_cleanup(True) n_client.package.env_cleanup(True)
def run_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()
br_name = params.get("priv_brname", 'autotest-prbr0') for setup_target in params.get("setup_targets", "").split(): setup_service(setup_target) access_targets = params.get("access_targets", "localhost").split() deny_target = params.get("deny_target", "localhost") all_target = params.get("extra_target", "").split() + vms_tags target_port = params["target_port"] vm = env.get_vm(vms_tags[0]) nic = vm.virtnet[0] if_name = nic.ifname params_nic = params.object_params("nic1") if params["netdst"] == "private": params_nic["netdst"] = params_nic.get("priv_brname", "atbr0") host_ip = utils_net.get_host_ip_address(params_nic) if deny_target in vms_tags: deny_vm = env.get_vm(deny_target) deny_vm_ip = deny_vm.wait_for_get_address(0) elif deny_target == "localhost": deny_vm_ip = host_ip if "NW_DST" in acl_extra_options: acl_extra_options = re.sub("NW_DST", deny_vm_ip, acl_extra_options) acl_extra_options = re.sub("TARGET_PORT", target_port, acl_extra_options) access_sys = {} for target in all_target: if target not in access_targets: if target in vms_tags: os_type = params["os_type"] else:
def run(test, params, env): """ KVM migration test: 1) Start a guest. 2) Start netperf server in guest. 3) Start multi netperf clients in host. 4) Migrate the guest in local during netperf clients working. 5) Repeatedly migrate VM and wait until netperf clients stopped. :param test: QEMU test object. :param params: Dictionary with test parameters. :param env: Dictionary with the test environment. """ login_timeout = int(params.get("login_timeout", 360)) mig_timeout = float(params.get("mig_timeout", "3600")) mig_protocol = params.get("migration_protocol", "tcp") mig_cancel_delay = int(params.get("mig_cancel") == "yes") * 2 netperf_timeout = int(params.get("netperf_timeout", "300")) client_num = int(params.get("client_num", "100")) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=login_timeout) guest_address = vm.get_address() host_address = utils_net.get_host_ip_address(params) remote_ip = params.get("remote_host", host_address) netperf_link = utils_misc.get_path(data_dir.get_deps_dir("netperf"), params.get("netperf_link")) md5sum = params.get("pkg_md5sum") netperf_link_win = params.get("netperf_link_win") if netperf_link_win: netperf_link_win = utils_misc.get_path(data_dir.get_deps_dir("netperf"), netperf_link_win) netperf_md5sum_win = params.get("netperf_md5sum_win") netperf_server_link = params.get("netperf_server_link", netperf_link) server_md5sum = params.get("server_md5sum", md5sum) netperf_server_link = utils_misc.get_path(data_dir.get_deps_dir("netperf"), netperf_server_link) server_path = params.get("server_path", "/var/tmp/") client_path = params.get("client_path", "/var/tmp/") server_path_win = params.get("server_path_win") client_path_win = params.get("client_path_win") username = params.get("username", "root") password = params.get("password", "redhat") passwd = params.get("hostpasswd", "redhat") client = params.get("shell_client", "ssh") port = params.get("shell_port", "22") if params.get("os_type") == "linux": session.cmd("iptables -F", ignore_all_errors=True) g_client_link = netperf_link g_server_path = server_path g_client_path = client_path g_client_install = False elif params.get("os_type") == "windows": g_client_link = netperf_link_win g_server_path = server_path_win g_client_path = client_path_win md5sum = netperf_md5sum_win g_client_install = True netperf_client_g = None netperf_client_h = None netperf_server_g = None netperf_server_h = None try: netperf_client_g = utils_netperf.NetperfClient(guest_address, g_client_path, md5sum, g_client_link, client=client, port=port, username=username, password=password, install=g_client_install) netperf_server_h = utils_netperf.NetperfServer(remote_ip, server_path, server_md5sum, netperf_link, password=passwd, install=False) netperf_client_h = utils_netperf.NetperfClient(remote_ip, client_path, md5sum, netperf_link, password=passwd) netperf_server_g = utils_netperf.NetperfServer(guest_address, g_server_path, server_md5sum, netperf_server_link, client=client, port=port, username=username, password=password) error.base_context("Run netperf test between host and guest") error.context("Start netserver in guest.", logging.info) netperf_server_g.start() if netperf_server_h: error.context("Start netserver in host.", logging.info) netperf_server_h.start() error.context("Start Netperf in host", logging.info) test_option = "-l %s" % netperf_timeout netperf_client_h.bg_start(guest_address, test_option, client_num) if netperf_client_g: error.context("Start Netperf in guest", logging.info) netperf_client_g.bg_start(host_address, test_option, client_num) m_count = 0 while netperf_client_h.is_netperf_running(): m_count += 1 error.context("Start migration iterations: %s " % m_count, logging.info) vm.migrate(mig_timeout, mig_protocol, mig_cancel_delay, env=env) finally: if netperf_server_g: if netperf_server_g.is_server_running(): netperf_server_g.stop() netperf_server_g.package.env_cleanup(True) if netperf_server_h: if netperf_server_h.is_server_running(): netperf_server_h.stop() netperf_server_h.package.env_cleanup(True) if netperf_client_h: if netperf_client_h.is_netperf_running(): netperf_client_h.stop() netperf_client_h.package.env_cleanup(True) if netperf_client_g: if netperf_client_g.is_netperf_running(): netperf_client_g.stop() netperf_client_g.package.env_cleanup(True) if session: session.close()
def form_ping_args(): """ get target ip address ver4 """ return utils_net.get_host_ip_address(params)
def run(test, params, env): """ Test if VM paused when image NFS shutdown, the drive option 'werror' should be stop, the drive option 'cache' should be none. 1) Setup NFS service on host 2) Boot up a VM using another disk on NFS server and write the disk by dd 3) Check if VM status is 'running' 4) Reject NFS connection on host 5) Check if VM status is 'paused' 6) Accept NFS connection on host and continue VM by monitor command 7) Check if VM status is 'running' :param test: kvm test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ def get_nfs_devname(params, session): """ Get the possbile name of nfs storage dev name in guest. :param params: Test params dictionary. :param session: An SSH session object. """ image1_type = params.object_params("image1").get("drive_format") stg_type = params.object_params("stg").get("drive_format") cmd = "" # Seems we can get correct 'stg' devname even if the 'stg' image # has a different type from main image (we call it 'image1' in # config file) with these 'if' sentences. if image1_type == stg_type: cmd = "ls /dev/[hsv]d[a-z]" elif stg_type == "virtio": cmd = "ls /dev/vd[a-z]" else: cmd = "ls /dev/[sh]d[a-z]" cmd += " | tail -n 1" return session.cmd_output(cmd).rstrip() def check_vm_status(vm, status): """ Check if VM has the given status or not. :param vm: VM object. :param status: String with desired status. :return: True if VM status matches our desired status. :return: False if VM status does not match our desired status. """ try: vm.verify_status(status) except (virt_vm.VMStatusError, qemu_monitor.MonitorLockError): return False else: return True error_context.context("Setup NFS Server on local host", logging.info) host_ip = utils_net.get_host_ip_address(params) try: config = NFSCorruptConfig(test, params, host_ip) config.setup() except NFSCorruptError as e: test.error(str(e)) image_name = os.path.join(config.mnt_dir, "nfs_corrupt") params["image_name_stg"] = image_name params["force_create_image_stg"] = "yes" params["create_image_stg"] = "yes" stg_params = params.object_params("stg") error_context.context("Boot vm with image on NFS server", logging.info) env_process.preprocess_image(test, stg_params, image_name) vm = env.get_vm(params["main_vm"]) try: vm.create(params=params) except Exception: config.cleanup() test.error("failed to create VM") session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) nfs_devname = get_nfs_devname(params, session) # Write disk on NFS server error_context.context("Write disk that image on NFS", logging.info) write_disk_cmd = "dd if=/dev/zero of=%s oflag=direct" % nfs_devname logging.info("dd with command: %s", write_disk_cmd) session.sendline(write_disk_cmd) try: # Read some command output, it will timeout session.read_up_to_prompt(timeout=30) except Exception: pass try: error_context.context("Make sure guest is running before test", logging.info) vm.resume() vm.verify_status("running") try: error_context.context("Reject NFS connection on host", logging.info) process.system(config.iptables_rule_gen('A')) error_context.context("Check if VM status is 'paused'", logging.info) if not utils_misc.wait_for( lambda: check_vm_status(vm, "paused"), int(params.get('wait_paused_timeout', 240))): test.error("Guest is not paused after stop NFS") finally: error_context.context("Accept NFS connection on host", logging.info) process.system(config.iptables_rule_gen('D')) error_context.context("Ensure nfs is resumed", logging.info) nfs_resume_timeout = int(params.get('nfs_resume_timeout', 240)) if not utils_misc.wait_for(config.is_mounted_dir_acessible, nfs_resume_timeout): test.error("NFS connection does not resume") error_context.context("Continue guest", logging.info) vm.resume() error_context.context("Check if VM status is 'running'", logging.info) if not utils_misc.wait_for(lambda: check_vm_status(vm, "running"), 20): test.error("Guest does not restore to 'running' status") finally: session.close() vm.destroy(gracefully=True) config.cleanup()
def launch_rv(client_vm, guest_vm, params): """ Launches rv_binary with args based on spice configuration inside client_session on background. remote-viewer will try to connect from vm1 from vm2 :param client_vm - vm object :param guest_vm - vm object :param params """ rv_binary = params.get("rv_binary", "remote-viewer") rv_ld_library_path = params.get("rv_ld_library_path") display = params.get("display") proxy = params.get("spice_proxy", None) host_ip = utils_net.get_host_ip_address(params) host_port = None if guest_vm.get_spice_var("listening_addr") == "ipv6": host_ip = ("[" + utils_misc.convert_ipv4_to_ipv6(host_ip) + "]") host_tls_port = None disable_audio = params.get("disable_audio", "no") full_screen = params.get("full_screen") check_spice_info = params.get("spice_info") ssltype = params.get("ssltype", "") test_type = params.get("test_type") # cmd var keeps final remote-viewer command line # to be executed on client cmd = rv_binary if client_vm.params.get("os_type") != "windows": cmd = cmd + " --display=:0.0" # If qemu_ticket is set, set the password # of the VM using the qemu-monitor ticket = None ticket_send = params.get("spice_password_send") qemu_ticket = params.get("qemu_password") if qemu_ticket: guest_vm.monitor.cmd("set_password spice %s" % qemu_ticket) logging.info("Sending to qemu monitor: set_password spice %s" % qemu_ticket) gencerts = params.get("gencerts") certdb = params.get("certdb") smartcard = params.get("smartcard") host_subj = None cacert_host = None cacert_client = None rv_parameters_from = params.get("rv_parameters_from", "cmd") if rv_parameters_from == 'file': cmd += " " + params.get("rv_file") client_session = client_vm.wait_for_login( timeout=int(params.get("login_timeout", 360))) if display == "spice": ticket = guest_vm.get_spice_var("spice_password") if guest_vm.get_spice_var("spice_ssl") == "yes": #client needs cacert file cacert_host = "%s/%s" % (params.get("spice_x509_prefix"), params.get("spice_x509_cacert_file")) cacert_client = cacert_host if client_vm.params.get("os_type") == "linux": client_session.cmd("rm -rf %s && mkdir -p %s" % ( params.get("spice_x509_prefix"), params.get("spice_x509_prefix"))) if client_vm.params.get("os_type") == "windows": cacert_client = "C:\\%s" % params.get("spice_x509_cacert_file") client_vm.copy_files_to(cacert_host, cacert_client) host_tls_port = guest_vm.get_spice_var("spice_tls_port") host_port = guest_vm.get_spice_var("spice_port") #cacert subj is in format for create certificate(with '/' delimiter) #remote-viewer needs ',' delimiter. And also is needed to remove #first character (it's '/') host_subj = guest_vm.get_spice_var("spice_x509_server_subj") host_subj = host_subj.replace('/', ',')[1:] if ssltype == "invalid_explicit_hs": host_subj = "Invalid Explicit HS" else: host_subj += host_ip # If it's invalid implicit, a remote-viewer connection # will be attempted with the hostname, since ssl certs were # generated with the ip address hostname = socket.gethostname() escape_char = client_vm.params.get("shell_escape_char",'\\') if ssltype == "invalid_implicit_hs" or "explicit" in ssltype: spice_url = " spice://%s?tls-port=%s%s&port=%s" % (hostname, host_tls_port, escape_char, host_port) else: spice_url = " spice://%s?tls-port=%s%s&port=%s" % (host_ip, host_tls_port, escape_char, host_port) if rv_parameters_from == "menu": line = spice_url elif rv_parameters_from == "file": pass else: cmd += spice_url if not rv_parameters_from == "file": cmd += " --spice-ca-file=%s" % cacert_client if ( params.get("spice_client_host_subject") == "yes" and not rv_parameters_from == "file" ): cmd += " --spice-host-subject=\"%s\"" % host_subj else: host_port = guest_vm.get_spice_var("spice_port") if rv_parameters_from == "menu": #line to be sent through monitor once r-v is started #without spice url line = "spice://%s?port=%s" % (host_ip, host_port) elif rv_parameters_from == "file": pass else: cmd += " spice://%s?port=%s" % (host_ip, host_port) elif display == "vnc": raise NotImplementedError("remote-viewer vnc") else: raise Exception("Unsupported display value") #usbredirection support if params.get("usb_redirection_add_device_vm2") == "yes": logging.info("USB redirection set auto redirect on connect for device \ class 0x08") cmd += " --spice-usbredir-redirect-on-connect=\"0x08,-1,-1,-1,1\"" client_root_session = client_vm.wait_for_login( timeout=int(params.get("login_timeout", 360)), username="******", password="******") usb_mount_path = params.get("file_path") #USB was created by qemu (root). This prevents right issue. client_root_session.cmd("chown test:test %s" % usb_mount_path) if not check_usb_policy(client_vm, params): logging.info("No USB policy.") add_usb_policy(client_vm) utils_spice.wait_timeout(3) else: logging.info("USB policy OK") else: logging.info("No USB redirection") # Check to see if the test is using the full screen option. if full_screen == "yes" and not rv_parameters_from == "file" : logging.info("Remote Viewer Set to use Full Screen") cmd += " --full-screen" if disable_audio == "yes": logging.info("Remote Viewer Set to disable audio") cmd += " --spice-disable-audio" # Check to see if the test is using a smartcard. if smartcard == "yes": logging.info("remote viewer Set to use a smartcard") if not rv_parameters_from == file: cmd += " --spice-smartcard" if certdb is not None: logging.debug("Remote Viewer set to use the following certificate" " database: " + certdb) cmd += " --spice-smartcard-db " + certdb if gencerts is not None: logging.debug("Remote Viewer set to use the following certs: " + gencerts) cmd += " --spice-smartcard-certificates " + gencerts if client_vm.params.get("os_type") == "linux": cmd = "nohup " + cmd + " &> ~/rv.log &" # Launch it on background if rv_ld_library_path: cmd = "export LD_LIBRARY_PATH=" + rv_ld_library_path + ";" + cmd if rv_parameters_from == "file": print "Generating file" utils_spice.gen_rv_file(params, guest_vm, host_subj, cacert_host) print "Uploading file to client" client_vm.copy_files_to("rv_file.vv", params.get("rv_file")) # Launching the actual set of commands try: if rv_ld_library_path: print_rv_version(client_session, "LD_LIBRARY_PATH=/usr/local/lib " + rv_binary) else: print_rv_version(client_session, rv_binary) except ShellStatusError, ShellProcessTerminatedError: # Sometimes It fails with Status error, ingore it and continue. # It's not that important to have printed versions in the log. logging.debug("Ignoring a Status Exception that occurs from calling " "print versions of remote-viewer or spice-gtk")
def launch_rv(client_vm, guest_vm, params): """ Launches rv_binary with args based on spice configuration inside client_session on background. remote-viewer will try to connect from vm1 from vm2 :param client_vm - vm object :param guest_vm - vm object :param params """ rv_binary = params.get("rv_binary", "remote-viewer") rv_ld_library_path = params.get("rv_ld_library_path") display = params.get("display") proxy = params.get("spice_proxy", None) if proxy: try: socket.inet_aton(params.get("proxy_ip", None)) except socket.error: raise error.TestNAError("Parameter proxy_ip not changed from default values") host_ip = utils_net.get_host_ip_address(params) host_port = None if guest_vm.get_spice_var("listening_addr") == "ipv6": host_ip = "[" + utils_misc.convert_ipv4_to_ipv6(host_ip) + "]" host_tls_port = None disable_audio = params.get("disable_audio", "no") full_screen = params.get("full_screen") check_spice_info = params.get("spice_info") ssltype = params.get("ssltype") test_type = params.get("test_type") # cmd var keeps final remote-viewer command line # to be executed on client cmd = rv_binary if client_vm.params.get("os_type") != "windows": cmd = cmd + " --display=:0.0" # If qemu_ticket is set, set the password # of the VM using the qemu-monitor ticket = None ticket_send = params.get("spice_password_send") qemu_ticket = params.get("qemu_password") if qemu_ticket: guest_vm.monitor.cmd("set_password spice %s" % qemu_ticket) logging.info("Sending to qemu monitor: set_password spice %s" % qemu_ticket) gencerts = params.get("gencerts") certdb = params.get("certdb") smartcard = params.get("smartcard") host_subj = None cacert = None rv_parameters_from = params.get("rv_parameters_from", "cmd") if rv_parameters_from == "file": cmd += " ~/rv_file.vv" client_session = client_vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) if display == "spice": ticket = guest_vm.get_spice_var("spice_password") if guest_vm.get_spice_var("spice_ssl") == "yes": # client needs cacert file cacert = "%s/%s" % ( guest_vm.get_spice_var("spice_x509_prefix"), guest_vm.get_spice_var("spice_x509_cacert_file"), ) client_session.cmd( "rm -rf %s && mkdir -p %s" % (guest_vm.get_spice_var("spice_x509_prefix"), guest_vm.get_spice_var("spice_x509_prefix")) ) remote.copy_files_to( client_vm.get_address(), "scp", params.get("username"), params.get("password"), params.get("shell_port"), cacert, cacert, ) host_tls_port = guest_vm.get_spice_var("spice_tls_port") host_port = guest_vm.get_spice_var("spice_port") # cacert subj is in format for create certificate(with '/' delimiter) # remote-viewer needs ',' delimiter. And also is needed to remove # first character (it's '/') host_subj = guest_vm.get_spice_var("spice_x509_server_subj") host_subj = host_subj.replace("/", ",")[1:] if ssltype == "invalid_explicit_hs": host_subj = "Invalid Explicit HS" else: host_subj += host_ip # If it's invalid implicit, a remote-viewer connection # will be attempted with the hostname, since ssl certs were # generated with the ip address hostname = socket.gethostname() if ssltype == "invalid_implicit_hs": spice_url = " spice://%s?tls-port=%s\&port=%s" % (hostname, host_tls_port, host_port) else: spice_url = " spice://%s?tls-port=%s\&port=%s" % (host_ip, host_tls_port, host_port) if rv_parameters_from == "menu": line = spice_url elif rv_parameters_from == "file": pass else: cmd += spice_url if not rv_parameters_from == "file": cmd += " --spice-ca-file=%s" % cacert if params.get("spice_client_host_subject") == "yes" and not rv_parameters_from == "file": cmd += ' --spice-host-subject="%s"' % host_subj else: host_port = guest_vm.get_spice_var("spice_port") if rv_parameters_from == "menu": # line to be sent through monitor once r-v is started # without spice url line = "spice://%s?port=%s" % (host_ip, host_port) elif rv_parameters_from == "file": pass else: cmd += " spice://%s?port=%s" % (host_ip, host_port) elif display == "vnc": raise NotImplementedError("remote-viewer vnc") else: raise Exception("Unsupported display value") # Check to see if the test is using the full screen option. if full_screen == "yes" and not rv_parameters_from == "file": logging.info("Remote Viewer Set to use Full Screen") cmd += " --full-screen" if disable_audio == "yes": logging.info("Remote Viewer Set to disable audio") cmd += " --spice-disable-audio" # Check to see if the test is using a smartcard. if smartcard == "yes": logging.info("remote viewer Set to use a smartcard") if not rv_parameters_from == file: cmd += " --spice-smartcard" if certdb is not None: logging.debug("Remote Viewer set to use the following certificate" " database: " + certdb) cmd += " --spice-smartcard-db " + certdb if gencerts is not None: logging.debug("Remote Viewer set to use the following certs: " + gencerts) cmd += " --spice-smartcard-certificates " + gencerts if client_vm.params.get("os_type") == "linux": cmd = "nohup " + cmd + " &> /dev/null &" # Launch it on background if rv_ld_library_path: cmd = "export LD_LIBRARY_PATH=" + rv_ld_library_path + ";" + cmd if rv_parameters_from == "file": print "Generating file" utils_spice.gen_rv_file(params, guest_vm, host_subj, cacert) print "Uploading file to client" client_vm.copy_files_to("rv_file.vv", "~/rv_file.vv") # Launching the actual set of commands try: if rv_ld_library_path: print_rv_version(client_session, "LD_LIBRARY_PATH=/usr/local/lib " + rv_binary) else: print_rv_version(client_session, rv_binary) except (ShellStatusError, ShellProcessTerminatedError): # Sometimes It fails with Status error, ingore it and continue. # It's not that important to have printed versions in the log. logging.debug( "Ignoring a Status Exception that occurs from calling " "print versions of remote-viewer or spice-gtk" ) logging.info("Launching %s on the client (virtual)", cmd) if proxy: if "http" in proxy: split = proxy.split("//")[1].split(":") else: split = proxy.split(":") host_ip = split[0] if len(split) > 1: host_port = split[1] else: host_port = "3128" if rv_parameters_from != "file": client_session.cmd("export SPICE_PROXY=%s" % proxy) if not params.get("rv_verify") == "only": try: client_session.cmd(cmd) except ShellStatusError: logging.debug("Ignoring a status exception, will check connection" "of remote-viewer later") # Send command line through monitor since url was not provided if rv_parameters_from == "menu": utils_spice.wait_timeout(1) str_input(client_vm, line) # client waits for user entry (authentication) if spice_password is set # use qemu monitor password if set, else, if set, try normal password. if qemu_ticket: # Wait for remote-viewer to launch utils_spice.wait_timeout(5) str_input(client_vm, qemu_ticket) elif ticket: if ticket_send: ticket = ticket_send utils_spice.wait_timeout(5) # Wait for remote-viewer to launch str_input(client_vm, ticket) utils_spice.wait_timeout(5) # Wait for conncetion to establish is_rv_connected = True try: utils_spice.verify_established( client_vm, host_ip, host_port, rv_binary, host_tls_port, params.get("spice_secure_channels", None) ) except utils_spice.RVConnectError: if test_type == "negative": logging.info("remote-viewer connection failed as expected") if ssltype in ("invalid_implicit_hs", "invalid_explicit_hs"): # Check the qemu process output to verify what is expected qemulog = guest_vm.process.get_output() if "SSL_accept failed" in qemulog: return else: raise error.TestFail("SSL_accept failed not shown in qemu" + "process as expected.") is_rv_connected = False else: raise error.TestFail("remote-viewer connection failed") if test_type == "negative" and is_rv_connected: raise error.TestFail("remote-viewer connection was established when" + " it was supposed to be unsuccessful") # Get spice info output = guest_vm.monitor.cmd("info spice") logging.debug("INFO SPICE") logging.debug(output) # Check to see if ipv6 address is reported back from qemu monitor if check_spice_info == "ipv6": logging.info("Test to check if ipv6 address is reported" " back from the qemu monitor") # Remove brackets from ipv6 host ip if host_ip[1 : len(host_ip) - 1] in output: logging.info("Reported ipv6 address found in output from" " 'info spice'") else: raise error.TestFail("ipv6 address not found from qemu monitor" " command: 'info spice'") else: logging.info("Not checking the value of 'info spice'" " from the qemu monitor") # prevent from kill remote-viewer after test finish if client_vm.params.get("os_type") == "linux": cmd = "disown -ar" client_session.cmd_output(cmd)
def run(test, params, env): """ Test Step: 1. Boot up guest using the openvswitch bridge 2. Setup related service in test enviroment(http, ftp etc.)(optional) 3. Access the service in guest 4. Setup access control rules in ovs to disable the access 5. Access the service in guest 6. Setup access control rules in ovs to enable the access 7. Access the service in guest 8. Delete the access control rules in ovs 9. Access the service in guest Params: :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def access_service(access_sys, access_targets, disabled, host_ip, ref=False): err_msg = "" err_type = "" for asys in access_sys: for atgt in access_targets: logging.debug("Try to access target %s from %s" % (atgt, asys)) access_params = access_sys[asys] atgt_disabled = access_params['disabled_%s' % atgt] if asys in vms_tags: vm = env.get_vm(asys) session = vm.wait_for_login(timeout=timeout) run_func = session.cmd remote_src = vm ssh_src_ip = vm.get_address() else: run_func = _system_output remote_src = "localhost" ssh_src_ip = host_ip if atgt in vms_tags: vm = env.get_vm(atgt) access_re_sub_string = vm.wait_for_get_address(0) else: access_re_sub_string = host_ip access_cmd = re.sub("ACCESS_TARGET", access_re_sub_string, access_params['access_cmd']) ref_cmd = re.sub("ACCESS_TARGET", access_re_sub_string, access_params['ref_cmd']) if access_cmd in ["ssh", "telnet"]: if atgt in vms_tags: target_vm = env.get_vm(atgt) target_ip = target_vm.get_address() else: target_vm = "localhost" target_ip = host_ip out = "" out_err = "" try: out = remote_login(access_cmd, target_ip, remote_src, params, host_ip) stat = 0 except remote.LoginError as err: stat = 1 out_err = "Failed to login %s " % atgt out_err += "from %s, err: %s" % (asys, err.output) try: out += remote_login(access_cmd, ssh_src_ip, target_vm, params, host_ip) except remote.LoginError as err: stat += 1 out_err += "Failed to login %s " % asys out_err += "from %s, err: %s" % (atgt, err.output) if out_err: out = out_err else: try: out = run_func(access_cmd, timeout=op_timeout) stat = 0 check_string = access_params.get("check_from_output") if check_string and check_string in out: stat = 1 except aexpect.ShellCmdError as err: out = err.output stat = err.status except aexpect.ShellTimeoutError as err: out = err.output stat = 1 session.close() session = vm.wait_for_login(timeout=timeout) run_func = session.cmd except process.CmdError as err: out = err.result.stderr stat = err.result.exit_status if access_params.get("clean_cmd"): try: run_func(access_params['clean_cmd']) except Exception: pass if disabled and atgt_disabled and stat == 0: err_msg += "Still can access %s after" % atgt err_msg += " disable it from ovs. " err_msg += "Command: %s. " % access_cmd err_msg += "Output: %s" % out if disabled and atgt_disabled and stat != 0: logging.debug("Can not access target as expect.") if not disabled and stat != 0: if ref: err_msg += "Can not access %s at the" % atgt err_msg += " beginning. Please check your setup." err_type = "ref" else: err_msg += "Still can not access %s" % atgt err_msg += " after enable the access" err_msg += "Command: %s. " % access_cmd err_msg += "Output: %s" % out if err_msg: session.close() if err_type == "ref": test.cancel(err_msg) test.fail(err_msg) if not ref_cmd: session.close() return try: out = run_func(ref_cmd, timeout=op_timeout) stat = 0 except aexpect.ShellCmdError as err: out = err.output stat = err.status except aexpect.ShellTimeoutError as err: out = err.output stat = 1 except process.CmdError as err: out = err.result.stderr stat = err.result.exit_status if stat != 0: if ref: err_msg += "Refernce command failed at beginning." err_type = "ref" else: err_msg += "Refernce command failed after setup" err_msg += " the rules" err_msg += "Command: %s. " % ref_cmd err_msg += "Output: %s" % out if err_msg: session.close() if err_type == "ref": test.cancel(err_msg) test.fail(err_msg) session.close() def get_acl_cmd(protocol, in_port, action, extra_options): acl_cmd = protocol.strip() acl_cmd += ",in_port=%s" % in_port.strip() if extra_options.strip(): acl_cmd += ",%s" % ",".join(extra_options.strip().split()) if action.strip(): acl_cmd += ",action=%s" % action.strip() return acl_cmd def acl_rules_check(acl_rules, acl_setup_cmd): acl_setup_cmd = re.sub("action=", "actions=", acl_setup_cmd) acl_option = re.split(",", acl_setup_cmd) for line in acl_rules.splitlines(): rule = [_.lower() for _ in re.split("[ ,]", line) if _] item_in_rule = 0 for acl_item in acl_option: if acl_item.lower() in rule: item_in_rule += 1 if item_in_rule == len(acl_option): return True return False def remote_login(client, host, src, params_login, host_ip): src_name = src if src != "localhost": src_name = src.name logging.info("Login %s from %s" % (host, src)) port = params_login["target_port"] username = params_login["username"] password = params_login["password"] prompt = params_login["shell_prompt"] linesep = eval("'%s'" % params_login.get("shell_linesep", r"\n")) quit_cmd = params.get("quit_cmd", "exit") if host == host_ip: # Try to login from guest to host. prompt = r"^\[.*\][\#\$]\s*$" linesep = "\n" username = params_login["host_username"] password = params_login["host_password"] quit_cmd = "exit" if client == "ssh": # We only support ssh for Linux in this test cmd = ("ssh -o UserKnownHostsFile=/dev/null " "-o StrictHostKeyChecking=no " "-o PreferredAuthentications=password -p %s %s@%s" % (port, username, host)) elif client == "telnet": cmd = "telnet -l %s %s %s" % (username, host, port) else: raise remote.LoginBadClientError(client) if src == "localhost": logging.debug("Login with command %s" % cmd) session = aexpect.ShellSession(cmd, linesep=linesep, prompt=prompt) else: if params_login.get("os_type") == "windows": if client == "telnet": cmd = "C:\\telnet.py %s %s " % (host, username) cmd += "%s \"%s\" && " % (password, prompt) cmd += "C:\\wait_for_quit.py" cmd = "%s || ping 127.0.0.1 -n 5 -w 1000 > nul" % cmd else: cmd += " || sleep 5" session = src.wait_for_login() logging.debug("Sending login command: %s" % cmd) session.sendline(cmd) try: out = remote.handle_prompts(session, username, password, prompt, timeout, debug=True) except Exception as err: session.close() raise err try: session.cmd(quit_cmd) session.close() except Exception: pass return out def setup_service(setup_target): setup_timeout = int(params.get("setup_timeout", 360)) if setup_target == "localhost": setup_func = _system_output os_type = "linux" else: setup_vm = env.get_vm(setup_target) setup_session = setup_vm.wait_for_login(timeout=timeout) setup_func = setup_session.cmd os_type = params["os_type"] setup_params = params.object_params(os_type) setup_cmd = setup_params.get("setup_cmd", "service SERVICE restart") prepare_cmd = setup_params.get("prepare_cmd") setup_cmd = re.sub("SERVICE", setup_params.get("service", ""), setup_cmd) error_context.context("Set up %s service in %s" % (setup_params.get("service"), setup_target), logging.info) if prepare_cmd: setup_func(prepare_cmd, timeout=setup_timeout) setup_func(setup_cmd, timeout=setup_timeout) if setup_target != "localhost": setup_session.close() def stop_service(setup_target): setup_timeout = int(params.get("setup_timeout", 360)) if setup_target == "localhost": setup_func = _system_output os_type = "linux" else: setup_vm = env.get_vm(setup_target) setup_session = setup_vm.wait_for_login(timeout=timeout) setup_func = setup_session.cmd os_type = params["os_type"] setup_params = params.object_params(os_type) stop_cmd = setup_params.get("stop_cmd", "service SERVICE stop") cleanup_cmd = setup_params.get("cleanup_cmd") stop_cmd = re.sub("SERVICE", setup_params.get("service", ""), stop_cmd) error_context.context("Stop %s service in %s" % (setup_params.get("service"), setup_target), logging.info) if stop_cmd: setup_func(stop_cmd, timeout=setup_timeout) if cleanup_cmd: setup_func(cleanup_cmd, timeout=setup_timeout) if setup_target != "localhost": setup_session.close() timeout = int(params.get("login_timeout", '360')) op_timeout = int(params.get("op_timeout", "360")) acl_protocol = params['acl_protocol'] acl_extra_options = params.get("acl_extra_options", "") for vm in env.get_all_vms(): session = vm.wait_for_login(timeout=timeout) if params.get("disable_iptables") == "yes": session.cmd("iptables -F") #session.cmd_status_output("service iptables stop") if params.get("copy_scripts"): root_dir = data_dir.get_root_dir() script_dir = os.path.join(root_dir, "shared", "scripts") tmp_dir = params.get("tmp_dir", "C:\\") for script in params.get("copy_scripts").split(): script_path = os.path.join(script_dir, script) vm.copy_files_to(script_path, tmp_dir) if params.get("os_type") == "windows": curl_win_path = params.get("curl_win_path", "C:\\curl\\") session.cmd("dir {0} || mkdir {0}".format(curl_win_path)) for script in params.get("copy_curl").split(): curl_win_link = os.path.join(data_dir.get_deps_dir("curl"), script) vm.copy_files_to(curl_win_link, curl_win_path, timeout=60) session.close() vms_tags = params.objects("vms") br_name = params.get("netdst") if br_name == "private": br_name = params.get("priv_brname", 'autotest-prbr0') for setup_target in params.get("setup_targets", "").split(): setup_service(setup_target) access_targets = params.get("access_targets", "localhost").split() deny_target = params.get("deny_target", "localhost") all_target = params.get("extra_target", "").split() + vms_tags target_port = params["target_port"] vm = env.get_vm(vms_tags[0]) nic = vm.virtnet[0] if_name = nic.ifname params_nic = params.object_params("nic1") if params["netdst"] == "private": params_nic["netdst"] = params_nic.get("priv_brname", "atbr0") host_ip = utils_net.get_host_ip_address(params_nic) if deny_target in vms_tags: deny_vm = env.get_vm(deny_target) deny_vm_ip = deny_vm.wait_for_get_address(0) elif deny_target == "localhost": deny_vm_ip = host_ip if "NW_DST" in acl_extra_options: acl_extra_options = re.sub("NW_DST", deny_vm_ip, acl_extra_options) acl_extra_options = re.sub("TARGET_PORT", target_port, acl_extra_options) access_sys = {} for target in all_target: if target not in access_targets: if target in vms_tags: os_type = params["os_type"] else: os_type = "linux" os_params = params.object_params(os_type) access_param = os_params.object_params(target) check_from_output = access_param.get("check_from_output") access_sys[target] = {} access_sys[target]['access_cmd'] = access_param['access_cmd'] access_sys[target]['ref_cmd'] = access_param.get('ref_cmd', "") access_sys[target]['clean_cmd'] = access_param.get('clean_guest', "") if check_from_output: access_sys[target]['check_from_output'] = check_from_output for tgt in access_targets: tgt_param = access_param.object_params(tgt) acl_disabled = tgt_param.get("acl_disabled") == "yes" access_sys[target]['disabled_%s' % tgt] = acl_disabled error_context.context("Try to access target before setup the rules", logging.info) access_service(access_sys, access_targets, False, host_ip, ref=True) error_context.context("Disable the access in ovs", logging.info) br_infos = utils_net.openflow_manager(br_name, "show").stdout if_port = re.findall(r"(\d+)\(%s\)" % if_name, br_infos) if not if_port: test.cancel("Can not find %s in bridge %s" % (if_name, br_name)) if_port = if_port[0] acl_cmd = get_acl_cmd(acl_protocol, if_port, "drop", acl_extra_options) utils_net.openflow_manager(br_name, "add-flow", acl_cmd) acl_rules = utils_net.openflow_manager(br_name, "dump-flows").stdout if not acl_rules_check(acl_rules, acl_cmd): test.fail("Can not find the rules from ovs-ofctl: %s" % acl_rules) error_context.context("Try to acess target to exam the disable rules", logging.info) access_service(access_sys, access_targets, True, host_ip) error_context.context("Enable the access in ovs", logging.info) acl_cmd = get_acl_cmd(acl_protocol, if_port, "normal", acl_extra_options) utils_net.openflow_manager(br_name, "mod-flows", acl_cmd) acl_rules = utils_net.openflow_manager(br_name, "dump-flows").stdout if not acl_rules_check(acl_rules, acl_cmd): test.fail("Can not find the rules from ovs-ofctl: %s" % acl_rules) error_context.context("Try to acess target to exam the enable rules", logging.info) access_service(access_sys, access_targets, False, host_ip) error_context.context("Delete the access rules in ovs", logging.info) acl_cmd = get_acl_cmd(acl_protocol, if_port, "", acl_extra_options) utils_net.openflow_manager(br_name, "del-flows", acl_cmd) acl_rules = utils_net.openflow_manager(br_name, "dump-flows").stdout if acl_rules_check(acl_rules, acl_cmd): test.fail("Still can find the rules from ovs-ofctl: %s" % acl_rules) error_context.context("Try to acess target to exam after delete the rules", logging.info) access_service(access_sys, access_targets, False, host_ip) for setup_target in params.get("setup_targets", "").split(): stop_service(setup_target)
def run(test, params, env): """ Network stress with multi nics test with netperf. 1) Start multi vm(s) guest. 2) Select multi vm(s) or host to setup netperf server/client. 3) Execute netperf stress on multi nics. 4) Ping test after netperf testing, check whether nics still work. :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ login_timeout = float(params.get("login_timeout", 360)) netperf_server = params.get("netperf_server").split() netperf_client = params.get("netperf_client") guest_username = params.get("username", "") guest_password = params.get("password", "") host_password = params.get("hostpassword", "redhat") shell_client = params.get("shell_client") shell_port = params.get("shell_port") os_type = params.get("os_type") host_ip = utils_net.get_host_ip_address(params) ping_count = int(params.get("ping_count", 10)) vms = params.get("vms") server_infos = [] client_infos = [] server_ips = [] client_ips = [] for server in netperf_server: s_info = {} if server in vms: server_vm = env.get_vm(server) server_vm.verify_alive() server_ctl = server_vm.wait_for_login(timeout=login_timeout) error.context("Stop fireware on netperf server guest.", logging.info) server_ctl.cmd("service iptables stop; iptables -F", ignore_all_errors=True) server_ip = server_vm.get_address() server_ips.append(server_ip) s_info["ip"] = server_ip s_info["os_type"] = params.get("os_type_%s" % server, os_type) s_info["username"] = params.get("username_%s" % server, guest_username) s_info["password"] = params.get("password_%s" % server, guest_password) s_info["shell_client"] = params.get("shell_client_%s" % server, shell_client) s_info["shell_port"] = params.get("shell_port_%s" % server, shell_port) else: err = "Only support setup netperf server in guest." raise error.TestError(err) server_infos.append(s_info) client = netperf_client.strip() c_info = {} if client in vms: client_vm = env.get_vm(client) client_vm.verify_alive() client_ctl = client_vm.wait_for_login(timeout=login_timeout) error.context("Stop fireware on netperf client guest.", logging.info) client_ctl.cmd("service iptables stop; iptables -F", ignore_all_errors=True) client_ip = client_vm.get_address() client_ips.append(client_ip) client_ctl_mac = server_vm.get_mac_address() params_client_nic = params.object_params(client) nics_count = len(params_client_nic.get("nics", "").split()) if nics_count > 1: for i in range(nics_count)[1:]: client_vm.wait_for_login(nic_index=i, timeout=login_timeout) client_ips.append(client_vm.get_address(index=i)) c_info["ip"] = client_ip c_info["os_type"] = params.get("os_type_%s" % client, os_type) c_info["username"] = params.get("username_%s" % client, guest_username) c_info["password"] = params.get("password_%s" % client, guest_password) c_info["shell_client"] = params.get("shell_client_%s" % client, shell_client) c_info["shell_port"] = params.get("shell_port_%s" % client, shell_port) else: err = "Only support setup netperf client in guest." raise error.TestError(err) client_infos.append(c_info) if params.get("os_type") == "linux": error.context("Config static route in netperf server guest.", logging.info) nics_list = utils_net.get_linux_ifname(client_ctl) for ip in server_ips: index = server_ips.index(ip) % len(nics_list) client_ctl.cmd("route add -host %s %s" % (ip, nics_list[index])) netperf_link = params.get("netperf_link") netperf_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_link) md5sum = params.get("pkg_md5sum") netperf_server_link = params.get("netperf_server_link_win", netperf_link) netperf_server_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_server_link) server_md5sum = params.get("server_md5sum") netperf_client_link = params.get("netperf_client_link_win", netperf_link) netperf_client_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_client_link) client_md5sum = params.get("client_md5sum") server_path_linux = params.get("server_path", "/var/tmp") client_path_linux = params.get("client_path", "/var/tmp") server_path_win = params.get("server_path_win", "c:\\") client_path_win = params.get("client_path_win", "c:\\") netperf_clients = [] netperf_servers = [] error.context("Setup netperf guest.", logging.info) for c_info in client_infos: if c_info["os_type"] == "windows": netperf_link_c = netperf_client_link client_path = client_path_win md5sum = client_md5sum else: netperf_link_c = netperf_link client_path = client_path_linux n_client = utils_netperf.NetperfClient(c_info["ip"], client_path, md5sum, netperf_link_c, client=c_info["shell_client"], port=c_info["shell_port"], username=c_info["username"], password=c_info["password"]) netperf_clients.append(n_client) error.context("Setup netperf server.", logging.info) for s_info in server_infos: if s_info["os_type"] == "windows": netperf_link_s = netperf_server_link server_path = server_path_win md5sum = server_md5sum else: netperf_link_s = netperf_link server_path = server_path_linux n_server = utils_netperf.NetperfServer(s_info["ip"], server_path, md5sum, netperf_link_s, client=s_info["shell_client"], port=s_info["shell_port"], username=s_info["username"], password=s_info["password"]) netperf_servers.append(n_server) try: error.context("Start netperf server.", logging.info) for n_server in netperf_servers: n_server.start() test_duration = int(params.get("netperf_test_duration", 60)) test_protocols = params.get("test_protocols", "TCP_STREAM") netperf_sessions = params.get("netperf_sessions", "1") p_sizes = params.get("package_sizes") netperf_cmd_prefix = params.get("netperf_cmd_prefix", "") netperf_pkg_size = params.get("netperf_pkg_size", "") error.context("Start netperf clients.", logging.info) for protocol in test_protocols.split(): error.context("Testing %s protocol" % protocol, logging.info) sessions_test = netperf_sessions.split() sizes_test = p_sizes.split() for size in sizes_test: for sess in sessions_test: test_option = params.get("test_option", "") test_option += " -t %s -l %s " % (protocol, test_duration) test_option += " -- -m %s" % size launch_netperf_client(server_ips, netperf_clients, test_option, test_duration, sess, netperf_cmd_prefix) error.context("Ping test after netperf testing.", logging.info) for s_ip in server_ips: status, output = utils_test.ping(s_ip, ping_count, timeout=float(ping_count) * 1.5) if status != 0: raise error.TestFail("Ping returns non-zero value %s" % output) package_lost = utils_test.get_loss_ratio(output) if package_lost != 0: raise error.TestFail( "%s packeage lost when ping server ip %s " % (package_lost, server)) finally: for n_server in netperf_servers: if n_server: n_server.stop() n_server.package.env_cleanup(True) for n_client in netperf_clients: if n_client: n_client.package.env_cleanup(True) if server_ctl: server_ctl.close() if client_ctl: client_ctl.close()
def _ping_host(): """ Ping host from guest. """ error_context.context("Try to ping external host.", logging.info) extra_host_ip = utils_net.get_host_ip_address(params) session.cmd('ping %s -c 5' % extra_host_ip) logging.info("Ping host(%s) successfully." % extra_host_ip)
def launch_rv(client_vm, guest_vm, params): """ Launches rv_binary with args based on spice configuration inside client_session on background. remote-viewer will try to connect from vm1 from vm2 @param client_vm - vm object @param guest_vm - vm object @param params """ rv_binary = params.get("rv_binary", "remote-viewer") host_ip = utils_net.get_host_ip_address(params) if guest_vm.get_spice_var("listening_addr") == "ipv6": host_ip = "[" + utils_misc.convert_ipv4_to_ipv6(host_ip) + "]" check_spice_info = params.get("spice_info") ssltype = params.get("ssltype") test_type = params.get("test_type") host_port = None full_screen = params.get("full_screen") disable_audio = params.get("disable_audio", "no") display = params.get("display") ticket = None ticket_send = params.get("spice_password_send") qemu_ticket = params.get("qemu_password") gencerts = params.get("gencerts") certdb = params.get("certdb") smartcard = params.get("smartcard") menu = params.get("rv_menu", None) #cmd var keeps final remote-viewer command line to be executed on client cmd = rv_binary + " --display=:0.0" #If qemu_ticket is set, set the password of the VM using the qemu-monitor if qemu_ticket: guest_vm.monitor.cmd("set_password spice %s" % qemu_ticket) logging.info("Sending to qemu monitor: set_password spice %s" % qemu_ticket) client_session = client_vm.wait_for_login( timeout=int(params.get("login_timeout", 360))) if display == "spice": ticket = guest_vm.get_spice_var("spice_password") if guest_vm.get_spice_var("spice_ssl") == "yes": host_tls_port = guest_vm.get_spice_var("spice_tls_port") host_port = guest_vm.get_spice_var("spice_port") cacert = "%s/%s" % (guest_vm.get_spice_var("spice_x509_prefix"), guest_vm.get_spice_var("spice_x509_cacert_file")) #cacert subj is in format for create certificate(with '/' delimiter) #remote-viewer needs ',' delimiter. And also is needed to remove #first character (it's '/') host_subj = guest_vm.get_spice_var("spice_x509_server_subj") host_subj = host_subj.replace('/', ',')[1:] if ssltype == "invalid_explicit_hs": host_subj = "Invalid Explicit HS" else: host_subj += host_ip # If it's invalid implicit, a remote-viewer connection # will be attempted with the hostname, since ssl certs were # generated with the ip address hostname = socket.gethostname() if ssltype == "invalid_implicit_hs": spice_url = " spice://%s?tls-port=%s\&port=%s" % (hostname, host_tls_port, host_port) else: spice_url = " spice://%s?tls-port=%s\&port=%s" % (host_ip, host_tls_port, host_port) if menu == "yes": line = spice_url else: cmd += spice_url cmd += " --spice-ca-file=%s" % cacert if params.get("spice_client_host_subject") == "yes": cmd += " --spice-host-subject=\"%s\"" % host_subj #client needs cacert file client_session.cmd("rm -rf %s && mkdir -p %s" % ( guest_vm.get_spice_var("spice_x509_prefix"), guest_vm.get_spice_var("spice_x509_prefix"))) remote.copy_files_to(client_vm.get_address(), 'scp', params.get("username"), params.get("password"), params.get("shell_port"), cacert, cacert) else: host_port = guest_vm.get_spice_var("spice_port") if menu == "yes": #line to be sent through monitor once r-v is started #without spice url line = "spice://%s?port=%s" % (host_ip, host_port) else: cmd += " spice://%s?port=%s" % (host_ip, host_port) elif display == "vnc": raise NotImplementedError("remote-viewer vnc") else: raise Exception("Unsupported display value") # Check to see if the test is using the full screen option. if full_screen == "yes": logging.info("Remote Viewer Set to use Full Screen") cmd += " --full-screen" if disable_audio == "yes": logging.info("Remote Viewer Set to disable audio") cmd += " --spice-disable-audio" # Check to see if the test is using a smartcard. if smartcard == "yes": logging.info("remote viewer Set to use a smartcard") cmd += " --spice-smartcard" if certdb != None: logging.debug("Remote Viewer set to use the following certificate" " database: " + certdb) cmd += " --spice-smartcard-db " + certdb if gencerts != None: logging.debug("Remote Viewer set to use the following certs: " + gencerts) cmd += " --spice-smartcard-certificates " + gencerts cmd = "nohup " + cmd + " &> /dev/null &" # Launch it on background # Launching the actual set of commands try: print_rv_version(client_session, rv_binary) except ShellStatusError, ShellProcessTerminatedError: # Sometimes It fails with Status error, ingore it and continue. # It's not that important to have printed versions in the log. logging.debug("Ignoring a Status Exception that occurs from calling " "print versions of remote-viewer or spice-gtk")
def launch_rv(client_vm, guest_vm, params): """ Launches rv_binary with args based on spice configuration inside client_session on background. remote-viewer will try to connect from vm1 from vm2 :param client_vm - vm object :param guest_vm - vm object :param params """ rv_binary = params.get("rv_binary", "remote-viewer") host_ip = utils_net.get_host_ip_address(params) if guest_vm.get_spice_var("listening_addr") == "ipv6": host_ip = "[" + utils_misc.convert_ipv4_to_ipv6(host_ip) + "]" check_spice_info = params.get("spice_info") ssltype = params.get("ssltype") test_type = params.get("test_type") host_port = None full_screen = params.get("full_screen") disable_audio = params.get("disable_audio", "no") display = params.get("display") ticket = None ticket_send = params.get("spice_password_send") qemu_ticket = params.get("qemu_password") gencerts = params.get("gencerts") certdb = params.get("certdb") smartcard = params.get("smartcard") menu = params.get("rv_menu", None) # cmd var keeps final remote-viewer command line to be executed on client cmd = rv_binary + " --display=:0.0" # If qemu_ticket is set, set the password of the VM using the qemu-monitor if qemu_ticket: guest_vm.monitor.cmd("set_password spice %s" % qemu_ticket) logging.info("Sending to qemu monitor: set_password spice %s" % qemu_ticket) client_session = client_vm.wait_for_login( timeout=int(params.get("login_timeout", 360))) if display == "spice": ticket = guest_vm.get_spice_var("spice_password") if guest_vm.get_spice_var("spice_ssl") == "yes": host_tls_port = guest_vm.get_spice_var("spice_tls_port") host_port = guest_vm.get_spice_var("spice_port") cacert = "%s/%s" % ( guest_vm.get_spice_var("spice_x509_prefix"), guest_vm.get_spice_var("spice_x509_cacert_file")) # cacert subj is in format for create certificate(with '/' delimiter) # remote-viewer needs ',' delimiter. And also is needed to remove # first character (it's '/') host_subj = guest_vm.get_spice_var("spice_x509_server_subj") host_subj = host_subj.replace('/', ',')[1:] if ssltype == "invalid_explicit_hs": host_subj = "Invalid Explicit HS" else: host_subj += host_ip # If it's invalid implicit, a remote-viewer connection # will be attempted with the hostname, since ssl certs were # generated with the ip address hostname = socket.gethostname() if ssltype == "invalid_implicit_hs": spice_url = " spice://%s?tls-port=%s\&port=%s" % ( hostname, host_tls_port, host_port) else: spice_url = " spice://%s?tls-port=%s\&port=%s" % ( host_ip, host_tls_port, host_port) if menu == "yes": line = spice_url else: cmd += spice_url cmd += " --spice-ca-file=%s" % cacert if params.get("spice_client_host_subject") == "yes": cmd += " --spice-host-subject=\"%s\"" % host_subj # client needs cacert file client_session.cmd("rm -rf %s && mkdir -p %s" % (guest_vm.get_spice_var("spice_x509_prefix"), guest_vm.get_spice_var("spice_x509_prefix"))) remote.copy_files_to(client_vm.get_address(), 'scp', params.get("username"), params.get("password"), params.get("shell_port"), cacert, cacert) else: host_port = guest_vm.get_spice_var("spice_port") if menu == "yes": # line to be sent through monitor once r-v is started # without spice url line = "spice://%s?port=%s" % (host_ip, host_port) else: cmd += " spice://%s?port=%s" % (host_ip, host_port) elif display == "vnc": raise NotImplementedError("remote-viewer vnc") else: raise Exception("Unsupported display value") # Check to see if the test is using the full screen option. if full_screen == "yes": logging.info("Remote Viewer Set to use Full Screen") cmd += " --full-screen" if disable_audio == "yes": logging.info("Remote Viewer Set to disable audio") cmd += " --spice-disable-audio" # Check to see if the test is using a smartcard. if smartcard == "yes": logging.info("remote viewer Set to use a smartcard") cmd += " --spice-smartcard" if certdb is not None: logging.debug("Remote Viewer set to use the following certificate" " database: " + certdb) cmd += " --spice-smartcard-db " + certdb if gencerts is not None: logging.debug("Remote Viewer set to use the following certs: " + gencerts) cmd += " --spice-smartcard-certificates " + gencerts cmd = "nohup " + cmd + " &> /dev/null &" # Launch it on background # Launching the actual set of commands try: print_rv_version(client_session, rv_binary) except ShellStatusError, ShellProcessTerminatedError: # Sometimes It fails with Status error, ingore it and continue. # It's not that important to have printed versions in the log. logging.debug("Ignoring a Status Exception that occurs from calling " "print versions of remote-viewer or spice-gtk")
def run(test, params, env): """ Change certain netkvm driver parameter value and check the setting result. 1) start vm 2) check and install wireshark and winpcap 3) enable netkvm driver TxLSO 4) start file transfer and use wireshark to log traffic, some packets length should over 1514 5) disable TxLSO and set MTU to 1000 6) start file transfer and log file transfer traffic again, no packet length should over 1014 param test: the test object param params: the test params param env: test environment """ def _is_process_finished(session, process_name): """ Check whether the target process is finished running param session: a guest session to send command param process_name: the target process name return: True if process does not exists, False if still exists """ check_proc_cmd = check_proc_temp % process_name status, output = session.cmd_status_output(check_proc_cmd) if status: return False return process_name not in output def _start_wireshark_session(): """ Start a wireshark session and log network traffic to a file """ error_context.context("Start wireshark session", logging.info) session_serial = vm.wait_for_serial_login(timeout=timeout) guest_ip = vm.get_address() try: run_wireshark_cmd = run_wireshark_temp % (host_ip, guest_ip) status, output = session_serial.cmd_status_output( run_wireshark_cmd, timeout=timeout) if status: test.error("Failed to start wireshark session, " "status=%s, output=%s" % (status, output)) is_started = utils_misc.wait_for( lambda: not _is_process_finished(session_serial, "tshark.exe"), 20, 5, 1) if not is_started: test.error("Timeout when wait for wireshark start") finally: session_serial.close() def _stop_wireshark_session(): """ Stop the running wireshark session """ error_context.context("Stop wireshark", logging.info) status, output = session.cmd_status_output(stop_wireshark_cmd, timeout=timeout) if status: test.error("Failed to stop wireshark: status=%s, output=%s" % (status, output)) def _parse_log_file(packet_filter): """ Parse the log file generated by the previous wireshark session. param packet_filter: the filter to apply when dump packets return: the output of the parse result """ error_context.context("Parse wireshark log file", logging.info) parse_log_cmd = parse_log_temp % packet_filter status, output = session.cmd_status_output(parse_log_cmd, timeout=timeout) if status: test.error("Failed to parse session log file," " status=%s, output=%s" % (status, output)) return output def _get_traffic_log(packet_filter): """ Use wireshark to log the file transfer network traffic, and return the packets dump output. param packet_filter: the filter to apply when dump packets return: the output of the parse result """ _start_wireshark_session() error_context.context("Start file transfer", logging.info) utils_test.run_file_transfer(test, params, env) time.sleep(30) _stop_wireshark_session() return _parse_log_file(packet_filter) def _set_driver_param(index): """ set the netkvm driver param's value. param index: the index of the list of target params """ param_name = param_names[index] param_value = param_values[index] utils_net.set_netkvm_param_value(vm, param_name, param_value) def _get_driver_version(session): """ Get current installed virtio driver version return: a int value of version, e.g. 191 """ query_version_cmd = params["query_version_cmd"] output = session.cmd_output(query_version_cmd) version_str = output.strip().split('=')[1] version = version_str.split('.')[-1][0:3] return int(version) timeout = params.get("timeout", 360) driver_verifier = params["driver_verifier"] wireshark_name = params.get("wireshark_name") run_wireshark_temp = params.get("run_wireshark_temp") stop_wireshark_cmd = params.get("stop_wireshark_cmd") check_proc_temp = params.get("check_proc_temp") parse_log_temp = params.get("parse_log_temp") param_names = params.get("param_names").split() param_values = params.get("param_values").split() vm = env.get_vm(params["main_vm"]) vm.verify_alive() host_ip = utils_net.get_host_ip_address(params) session = vm.wait_for_login(timeout=timeout) # make sure to enter desktop vm.send_key('meta_l-d') time.sleep(30) error_context.context("Check if the driver is installed and " "verified", logging.info) session = utils_test.qemu.windrv_check_running_verifier( session, vm, test, driver_verifier, timeout) if _get_driver_version(session) > 189: param_names.append("*JumboPacket") else: param_names.append("MTU") error_context.context("Install winpcap", logging.info) install_winpcap_cmd = params.get("install_winpcap_cmd") install_winpcap_cmd = utils_misc.set_winutils_letter( session, install_winpcap_cmd) status, output = session.cmd_status_output(install_winpcap_cmd, timeout=timeout) if status: test.error("Failed to install pcap, status=%s, output=%s" % (status, output)) logging.info("Wait for pcap installation to complete") autoit_name = params.get("autoit_name") utils_misc.wait_for(lambda: _is_process_finished(session, autoit_name), timeout, 20, 3) error_context.context("Check if wireshark is installed", logging.info) check_installed_cmd = params.get("check_installed_cmd") check_result = session.cmd_output(check_installed_cmd) if "tshark" not in check_result: error_context.context("Install wireshark", logging.info) install_wireshark_cmd = params.get("install_wireshark_cmd") install_wireshark_cmd = utils_misc.set_winutils_letter( session, install_wireshark_cmd) status, output = session.cmd_status_output(install_wireshark_cmd, timeout=timeout) if status: test.error("Failed to install wireshark, status=%s, output=%s" % (status, output)) logging.info("Wait for wireshark installation to complete") utils_misc.wait_for( lambda: _is_process_finished(session, wireshark_name), timeout, 20, 3) else: logging.info("Wireshark is already installed") session.close() virtio_win.prepare_netkvmco(vm) error_context.context("Enable scatter gather", logging.info) _set_driver_param(0) session = vm.wait_for_login(timeout=timeout) error_context.context("Log network traffic with scatter gather enabled", logging.info) output = _get_traffic_log("frame.len>1514") logging.info("Check length > 1514 packets") if "Len" not in output: test.fail("No packet length >= 1514, output=%s" % output) session.close() error_context.context("Disable scatter gather", logging.info) _set_driver_param(1) _set_driver_param(2) session = vm.wait_for_login(timeout=timeout) error_context.context("Log network traffic with scatter gather disabled", logging.info) logging.info("Check length > 1014 packets") output = _get_traffic_log("frame.len>1014") if "Len" in output: test.fail("Some packet length > 1014, output=%s" % output)
def run_rv_gui(test, params, env): """ Tests GUI automation of remote-viewer @param test: QEMU test object. @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ #Get required paramters host_ip = utils_net.get_host_ip_address(params) screenshot_dir = params.get("screenshot_dir") #screenshot_name = params.get("screenshot_name") screenshot_exp_name = params.get("screenshot_expected_name") expected_rv_corners_fs = "Corners: +0+0 -0+0 -0-0 +0-0" screenshot_exp_file = "" host_port = None guest_res = "" guest_res2 = "" rv_res = "" rv_res2 = "" rv_binary = params.get("rv_binary", "remote-viewer") changex = params.get("changex") changey = params.get("changey") accept_pct = params.get("accept_pct") tests = params.get("rv_gui_test_list").split() rv_version = params.get("rv_version") rv_version_el7 = params.get("rv_version_el7") ticket = params.get("spice_password", None) errors = 0 guest_vm = env.get_vm(params["guest_vm"]) guest_vm.verify_alive() guest_session = guest_vm.wait_for_login( timeout=int(params.get("login_timeout", 360))) guest_root_session = guest_vm.wait_for_login( timeout=int(params.get("login_timeout", 360)), username="******", password="******") #update host_port host_port = guest_vm.get_spice_var("spice_port") client_vm = env.get_vm(params["client_vm"]) client_vm.verify_alive() client_session = client_vm.wait_for_login( timeout=int(params.get("login_timeout", 360))) output = client_session.cmd('cat /etc/redhat-release') isRHEL7 = "release 7." in output client_session.cmd("export DISPLAY=:0") guest_session.cmd("export DISPLAY=:0") #if isRHEL7: # pass # client_session.cmd('mkdir /home/test/.dbus/session-bus/ # client_session.cmd('. /home/test/.dbus/session-bus/`cat ' + \ # '/etc/machine-id`-0') #else: client_session.cmd('. /home/test/.dbus/session-bus/`cat ' + \ '/var/lib/dbus/machine-id`-0') client_session.cmd('export DBUS_SESSION_BUS_ADDRESS ' + \ 'DBUS_SESSION_BUS_PID DBUS_SESSION_BUS_WINDOWID') client_session.cmd("cd %s" % params.get("test_script_tgt")) rv_res_orig = getrvgeometry(client_session, host_port, host_ip) logging.info("Executing gui tests: " + str(tests)) #Make sure Accessibility is enabled before running the GUI tests if isRHEL7: logging.info("Enabling accessibility") client_session.cmd("export DISPLAY=:0.0") client_session.cmd("gsettings set org.gnome.desktop.interface" " toolkit-accessibility true") #Go through all tests to be run for i in tests: logging.info("Test: " + i) #Verification that needs to be done prior to running the gui test. if "zoom" in i or "autoresize" in i: #Get preliminary information needed for the zoom tests guest_res = getres(guest_session) rv_res = getrvgeometry(client_session, host_port, host_ip) # if i in ("screenshot"): if "screenshot" in i: screenshot_exp_file = os.path.join(screenshot_dir, \ screenshot_exp_name) try: client_session.cmd('[ -e ' + screenshot_exp_file +' ]') client_session.cmd('rm ' + screenshot_exp_file) logging.info("Deleted: " + screenshot_exp_file) except ShellCmdError: logging.info(screenshot_exp_name + " doesn't exist, continue") cmd = "./unittests/%s_rv.py" % i #Verification of the printscreen test prior to the test being run if "printscreen" in i: output = client_session.cmd('cat /etc/redhat-release') if "release 7." in output: output = guest_session.cmd('rm -vf /home/test/Pictures/Screen*') logging.info("Screenshots removed: " + output) #Adding parameters to the test if (i == "connect"): cmd += " 'spice://%s:%s'" % (host_ip, host_port) if ticket: cmd += " %s > /dev/null 2>&1" % ticket #Run the test client_session_dt = client_vm.wait_for_login( timeout=int(params.get("login_timeout", 360))) client_session_dt.cmd("export DISPLAY=:0.0") client_session_dt.cmd('. /home/test/.dbus/session-bus/`cat ' + \ '/var/lib/dbus/machine-id`-0') client_session_dt.cmd('export DBUS_SESSION_BUS_ADDRESS ' + \ 'DBUS_SESSION_BUS_PID DBUS_SESSION_BUS_WINDOWID') print "Running test: " + cmd try: logging.info(client_session_dt.cmd(cmd)) except: logging.error("Status: FAIL") errors += 1 else: logging.info("Status: PASS") client_session_dt.close() #Wait before doing any verification utils_spice.wait_timeout(5) #Verification Needed after the gui test was run if "zoom" in i: guest_res2 = getres(guest_session) rv_res2 = getrvgeometry(client_session, host_port, host_ip) #Check to see that the resolution doesn't change logstr = "Checking that the guest's resolution doesn't change" checkresequal(guest_res, guest_res2, logstr) if "zoomin" in i: #verify the rv window has increased errorstr = "Checking the rv window's size has increased" logging.info(errorstr) checkgeometryincrease(rv_res, rv_res2, errorstr) if "zoomout" in i: #verify the rv window has decreased errorstr = "Checking the rv window's size has decreased" logging.info(errorstr) checkgeometryincrease(rv_res2, rv_res, errorstr) if "zoomnorm" in i: errorstr = "Checking the rv window's size is the same as " + \ "it was originally when rv was started." checkresequal(rv_res2, rv_res_orig, errorstr) if "quit" in i or "close" in i: #Verify for quit tests that remote viewer is not running on client try: rvpid = str(client_session.cmd("pgrep remote-viewer")) raise error.TestFail("Remote-viewer is still running: " + rvpid) except ShellCmdError: logging.info("Remote-viewer process is no longer running.") if "screenshot" in i: #Verify the screenshot was created and clean up try: client_session.cmd('[ -e ' + screenshot_exp_file + ' ]') client_session.cmd('rm ' + screenshot_exp_file) print screenshot_exp_name + " was created as expected" except ShellCmdError: raise error.TestFail("Screenshot " + screenshot_exp_file + \ " was not created") if i == "fullscreen" or i == "fullscreen_shortcut": #Verify that client's res = guests's res guest_res = getres(guest_session) client_res = getres(client_session) rv_geometry = getrvgeometry(client_session, host_port, host_ip) rv_corners = getrvcorners(client_session, host_port, host_ip) if(client_res == guest_res): logging.info("PASS: Guest resolution is the same as the client") #Verification #2, client's res = rv's geometry if(client_res == rv_geometry): logging.info("PASS client's res = geometry of rv window") else: raise error.TestFail("Client resolution: " + client_res + \ " differs from the rv's geometry: " + rv_geometry) else: raise error.TestFail("Guest resolution: " + guest_res + \ "differs from the client: " + client_res) #Verification #3, verify the rv window is at the top corner if(rv_corners in expected_rv_corners_fs): logging.info("PASS: rv window is at the top corner: " + \ rv_corners) else: raise error.TestFail("rv window is not at the top corner " + \ "as expected, it is at: " + rv_corners) #Verify rv window < client's res if i == "leave_fullscreen" or i == "leave_fullscreen_shortcut": rv_corners = getrvcorners(client_session, host_port, host_ip) if(rv_corners not in expected_rv_corners_fs): logging.info("PASS: rv window is not at top corner: " + \ rv_corners) else: raise error.TestFail("rv window, leaving full screen failed.") if "printscreen" in i: output = client_session.cmd('cat /etc/redhat-release') if "release 7." in output: output = guest_session.cmd('ls -al /home/test/Pictures | grep Screen*') logging.info("Screenshot Taken Found: " + output) else: output = guest_root_session.cmd("ps aux | grep gnome-screenshot") index = 1 found = 0 plist = output.splitlines() for line in plist: print str(index) + " " + line index += 1 list2 = line.split() #get gnome-screenshot info gss_pid = str(list2[1]) gss_process_name = str(list2[10]) #Verify gnome-screenshot is running and kill it if gss_process_name == "gnome-screenshot": found = 1 guest_root_session.cmd("kill " + gss_pid) break else: continue if not (found): raise error.TestFail("gnome-screenshot is not running.") #Verify the shutdown dialog is present if "ctrl_alt_del" in i: #looking for a blank named dialog will not work for RHEL 7 #Will need to find a better solution to verify #the shutdown dialog has come up if isRHEL7: #wait 80 seconds for the VM to completely shutdown utils_spice.wait_timeout(90) try: guest_vm.verify_alive() raise error.TestFail("Guest VM is still alive, shutdown failed.") except VMDeadError: logging.info("Guest VM is verified to be shutdown") else: guest_session.cmd("xwininfo -name ''") #If autoresize_on is run, change window geometry if i == "autoresize_on" or i == "autoresize_off": logging.info("Attempting to change the window size of rv to:" + \ str(changex) + "x" + str(changey)) #wmctrl_cmd = "wmctrl -r 'spice://%s?port=%s (1) - Remote Viewer'" \ # % (host_ip, host_port) wmctrl_cmd = "wmctrl -r %s" % window_title wmctrl_cmd += " -e 0,0,0," + str(changex) + "," + str(changey) output = client_session.cmd(wmctrl_cmd) logging.info("Original res: " + guest_res) logging.info("Original geometry: " + rv_res) #Wait for the rv window to change and guest to adjust resolution utils_spice.wait_timeout(2) guest_res2 = getres(guest_session) rv_res2 = getrvgeometry(client_session, host_port, host_ip) logging.info("After test res: " + guest_res2) logging.info("After test geometry: " + rv_res2) #Get the required information width2 = int(guest_res2.split('x')[0]) rvwidth2 = int(rv_res2.split('x')[0]) #The second split of - is a workaround because the xwinfo sometimes #prints out dashes after the resolution for some reason. height2 = int(guest_res2.split('x')[1].split('-')[0]) rvheight2 = int(rv_res2.split('x')[1].split('-')[0]) #the width and height that was specified is changed w/alotted limit percentchange(accept_pct, changey, rvheight2, "Height parameter:") percentchange(accept_pct, changex, rvwidth2, "Width parameter:") if i == "autoresize_on": #resolution is changed, attempted to match the window logging.info("Checking resolution is changed, attempted" + \ " to match the window, when autoresize is on") percentchange(accept_pct, rvheight2, height2, "Height param:") percentchange(accept_pct, rvwidth2, width2, "Width param:") if i == "autoresize_off": #resolutions did not change logging.info("Checking the resolution does not change" + \ ", when autoresize is off") logstr = "Checking that the guest's resolution doesn't change" checkresequal(guest_res, guest_res2, logstr) #Verify a connection is established if i == "connect": try: utils_spice.verify_established(client_vm, host_ip, \ host_port, rv_binary) except utils_spice.RVConnectError: raise error.TestFail("remote-viewer connection failed") if errors: raise error.TestFail("%d GUI tests failed, see log for more details" \ % errors)
def _ping_host(): """ Ping host from guest. """ error_context.context("Try to ping external host.", logging.info) extra_host_ip = utils_net.get_host_ip_address(params) session.cmd('ping %s -c 5' % extra_host_ip) logging.info("Ping host(%s) successfully.", extra_host_ip)
def run(test, params, env): """ Test hotplug of NIC devices 1) Boot up guest with one or multi nics 2) Add multi host network devices through monitor cmd and check if they are added 3) Add multi nic devices through monitor cmd and check if they are added 4) Check if new interface gets ip address 5) Disable primary link of guest 6) Ping guest new ip from host 7) Delete nic device and netdev if user config "do_random_unhotplug" 8) Ping guest's new ip address after guest pause/resume 9) Re-enable primary link of guest and hotunplug the plug nics BEWARE OF THE NETWORK BRIDGE DEVICE USED FOR THIS TEST ("nettype=bridge" and "netdst=<bridgename>" param). The virt-test default bridge virbr0, leveraging libvirt, works fine for the purpose of this test. When using other bridges, the timeouts which usually happen when the bridge topology changes (that is, devices get added and removed) may cause random failures. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ 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) primary_nic = [nic for nic in vm.virtnet] run_dhclient = params.get("run_dhclient", "no") guest_is_linux = "linux" == params.get("os_type", "") host_ip_addr = utils_net.get_host_ip_address(params) if guest_is_linux: # Modprobe the module if specified in config file module = params.get("modprobe_module") if module: session.cmd_output_safe("modprobe %s" % module) nic_hotplug_count = int(params.get("nic_hotplug_count", 1)) nic_hotplugged = [] try: for nic_index in xrange(1, nic_hotplug_count + 1): nic_name = "hotplug_nic%s" % nic_index nic_params = params.object_params(nic_name) nic_model = nic_params["pci_model"] nic_params["nic_model"] = nic_model nic_params["nic_name"] = nic_name error.context("Disable other link(s) of guest", logging.info) disable_nic_list = primary_nic + nic_hotplugged for nic in disable_nic_list: vm.set_link(nic.device_id, up=False) error.context("Hotplug %sth '%s' nic named '%s'" % (nic_index, nic_model, nic_name)) hotplug_nic = vm.hotplug_nic(**nic_params) # Only run dhclient if explicitly set and guest is not windows. # Most modern Linux guests run NetworkManager, # and thus do not need this. s_session = vm.wait_for_serial_login(timeout=login_timeout) if guest_is_linux: if run_dhclient == "yes": s_session.cmd_output_safe("killall -9 dhclient") ifname = utils_net.get_linux_ifname(s_session, hotplug_nic["mac"]) s_session.cmd_output_safe("ifconfig %s up" % ifname) s_session.cmd_output_safe("dhclient %s &" % ifname) arp_clean = "arp -n|awk '/^[1-9]/{print \"arp -d \" $1}'|sh" s_session.cmd_output_safe(arp_clean) error.context("Check if new interface gets ip address", logging.info) try: hotnic_ip = vm.wait_for_get_address(nic_name) except virt_vm.VMIPAddressMissingError, err: if params.get("additional_operation"): p_cfg = "/etc/sysconfig/network-scripts/ifcfg-%s" % ifname cfg_con = "DEVICE=%s\nBOOTPROTO=dhcp\nONBOOT=yes" % ifname cmd = "echo '%s' > %s" % (cfg_con, p_cfg) s_session.cmd_output_safe(cmd) s_session.cmd_output_safe("killall -9 dhclient") s_session.cmd_output_safe("dhclient %s " % ifname) hotnic_ip = vm.wait_for_get_address(nic_name) else: err_msg = "Could not get or verify nic ip address" err_msg += "error info: '%s' " % err raise error.TestFail(err_msg) logging.info("Got the ip address of new nic: %s", hotnic_ip) error.context("Ping guest's new ip from host", logging.info) if params.get("additional_operation"): s_session.cmd_output_safe("route add %s dev %s" % (host_ip_addr, ifname)) status, output = utils_test.ping(hotnic_ip, 10, timeout=30) if status: err_msg = "New nic failed ping test, error info: '%s'" raise error.TestFail(err_msg % output) error.context("Ping guest's new ip after pasue/resume", logging.info) vm.monitor.cmd("stop") vm.monitor.cmd("cont") status, output = utils_test.ping(hotnic_ip, 10, timeout=30) if status: err_msg = "New nic failed ping test after stop/cont, " err_msg += "error info: '%s'" % output raise error.TestFail(err_msg) if params.get("additional_operation"): s_session.cmd_output_safe("route del %s dev %s" % (host_ip_addr, ifname)) # random hotunplug nic nic_hotplugged.append(hotplug_nic) if random.randint(0, 1) and params.get("do_random_unhotplug"): error.context("Detaching the previously attached nic from vm", logging.info) unplug_nic_index = random.randint(0, len(nic_hotplugged) - 1) vm.hotunplug_nic(nic_hotplugged[unplug_nic_index].nic_name) nic_hotplugged.pop(unplug_nic_index) finally: for nic in nic_hotplugged: vm.hotunplug_nic(nic.nic_name) error.context("Re-enabling the primary link(s)", logging.info) for nic in primary_nic: vm.set_link(nic.device_id, up=True)
def run(test, params, env): """ Run netperf stress on server and client side. 1) Start multi vm(s) guest. 2) Select multi vm(s) or host to setup netperf server/client. 3) Run netperf stress test. 4) Finish test until timeout env["netperf_run"] is False. :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ login_timeout = float(params.get("login_timeout", 360)) netperf_server = params.get("netperf_server").split() netperf_client = params.get("netperf_client").split() guest_username = params.get("username", "") guest_password = params.get("password", "") host_password = params.get("hostpassword", "redhat") shell_client = params.get("shell_client") shell_port = params.get("shell_port") os_type = params.get("os_type") shell_prompt = params.get("shell_prompt", r"^root@.*[\#\$]\s*$|#") linesep = params.get("shell_linesep", "\n").decode('string_escape') status_test_command = params.get("status_test_command", "echo $?") compile_option_client = params.get("compile_option_client", "") compile_option_server = params.get("compile_option_server", "") host_ip = utils_net.get_host_ip_address(params) vms = params.get("vms") server_infos = [] client_infos = [] for server in netperf_server: s_info = {} if server in vms: server_vm = env.get_vm(server) server_vm.verify_alive() session = server_vm.wait_for_login(timeout=login_timeout) session.cmd("service iptables stop; iptables -F", ignore_all_errors=True) server_ip = server_vm.get_address() s_info["ip"] = server_ip s_info["os_type"] = params.get("os_type_%s" % server, os_type) s_info["username"] = params.get("username_%s" % server, guest_username) s_info["password"] = params.get("password_%s" % server, guest_password) s_info["shell_client"] = params.get("shell_client_%s" % server, shell_client) s_info["shell_port"] = params.get("shell_port_%s" % server, shell_port) s_info["shell_prompt"] = params.get("shell_prompt_%s" % server, shell_prompt) s_info["linesep"] = params.get("linesep_%s" % server, linesep) s_info["status_test_command"] = params.get("status_test_command_%s" % server, status_test_command) else: if server == "localhost": s_info["ip"] = host_ip s_info["password"] = params.get("password_%s" % server, host_password) else: s_info["ip"] = server s_info["password"] = params.get("password_%s" % server, "redhat") s_info["os_type"] = params.get("os_type_%s" % server, "linux") s_info["username"] = params.get("username_%s" % server, "root") s_info["shell_client"] = params.get("shell_client_%s" % server, "ssh") s_info["shell_port"] = params.get("shell_port_%s" % server, "22") s_info["shell_prompt"] = params.get("shell_prompt_%s" % server, r"^\[.*\][\#\$]\s*$") s_info["linesep"] = params.get("linesep_%s" % server, "\n") s_info["status_test_command"] = params.get("status_test_command_%s" % server, "echo $?") server_infos.append(s_info) for client in netperf_client: c_info = {} if client in vms: client_vm = env.get_vm(client) client_vm.verify_alive() session = client_vm.wait_for_login(timeout=login_timeout) session.cmd("service iptables stop; iptables -F", ignore_all_errors=True) client_ip = client_vm.get_address() c_info["ip"] = client_ip c_info["os_type"] = params.get("os_type_%s" % client, os_type) c_info["username"] = params.get("username_%s" % client, guest_username) c_info["password"] = params.get("password_%s" % client, guest_password) c_info["shell_client"] = params.get("shell_client_%s" % client, shell_client) c_info["shell_port"] = params.get("shell_port_%s" % client, shell_port) c_info["shell_prompt"] = params.get("shell_prompt_%s" % client, shell_prompt) c_info["linesep"] = params.get("linesep_%s" % client, linesep) c_info["status_test_command"] = params.get("status_test_command_%s" % client, status_test_command) else: if client == "localhost": c_info["ip"] = host_ip c_info["password"] = params.get("password_%s" % client, host_password) else: c_info["ip"] = client c_info["password"] = params.get("password_%s" % client, "redhat") c_info["os_type"] = params.get("os_type_%s" % client, "linux") c_info["username"] = params.get("username_%s" % client, "root") c_info["shell_client"] = params.get("shell_client_%s" % client, "ssh") c_info["shell_port"] = params.get("shell_port_%s" % client, "23") c_info["shell_prompt"] = params.get("shell_prompt_%s" % client, r"^\[.*\][\#\$]\s*$") c_info["linesep"] = params.get("linesep_%s" % client, "\n") c_info["status_test_command"] = params.get("status_test_command_%s" % client, "echo $?") client_infos.append(c_info) netperf_link = params.get("netperf_link") netperf_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_link) md5sum = params.get("pkg_md5sum") netperf_server_link = params.get("netperf_server_link_win", netperf_link) netperf_server_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_server_link) server_md5sum = params.get("server_md5sum") netperf_client_link = params.get("netperf_client_link_win", netperf_link) netperf_client_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_client_link) client_md5sum = params.get("client_md5sum") server_path_linux = params.get("server_path", "/var/tmp") client_path_linux = params.get("client_path", "/var/tmp") server_path_win = params.get("server_path_win", "c:\\") client_path_win = params.get("client_path_win", "c:\\") netperf_clients = [] netperf_servers = [] for c_info in client_infos: if c_info["os_type"] == "windows": netperf_link_c = netperf_client_link client_path = client_path_win md5sum = client_md5sum else: netperf_link_c = netperf_link client_path = client_path_linux n_client = utils_netperf.NetperfClient(c_info["ip"], client_path, md5sum, netperf_link_c, client=c_info["shell_client"], port=c_info["shell_port"], username=c_info["username"], password=c_info["password"], prompt=c_info["shell_prompt"], linesep=c_info["linesep"], status_test_command=c_info["status_test_command"], compile_option=compile_option_client) netperf_clients.append(n_client) for s_info in server_infos: if s_info["os_type"] == "windows": netperf_link_s = netperf_server_link server_path = server_path_win md5sum = server_md5sum else: netperf_link_s = netperf_link server_path = server_path_linux n_server = utils_netperf.NetperfServer(s_info["ip"], server_path, md5sum, netperf_link_s, client=s_info["shell_client"], port=s_info["shell_port"], username=s_info["username"], password=s_info["password"], prompt=s_info["shell_prompt"], linesep=s_info["linesep"], status_test_command=s_info["status_test_command"], compile_option=compile_option_server) netperf_servers.append(n_server) # Get range of message size. try: for n_server in netperf_servers: n_server.start() # Run netperf with message size defined in range. netperf_test_duration = int(params.get("netperf_test_duration", 60)) netperf_para_sess = params.get("netperf_para_sessions", "1") test_protocols = params.get("test_protocols", "TCP_STREAM") netperf_cmd_prefix = params.get("netperf_cmd_prefix", "") netperf_output_unit = params.get("netperf_output_unit", " ") netperf_package_sizes = params.get("netperf_package_sizes") test_option = params.get("test_option", "") test_option += " -l %s" % netperf_test_duration if params.get("netperf_remote_cpu") == "yes": test_option += " -C" if params.get("netperf_local_cpu") == "yes": test_option += " -c" if netperf_output_unit in "GMKgmk": test_option += " -f %s" % netperf_output_unit start_time = time.time() stop_time = start_time + netperf_test_duration num = 0 s_len = len(server_infos) for protocol in test_protocols.split(): error_context.context("Testing %s protocol" % protocol, logging.info) t_option = "%s -t %s" % (test_option, protocol) for n_client in netperf_clients: index = num % s_len server_ip = server_infos[index]["ip"] n_client.bg_start(server_ip, t_option, netperf_para_sess, netperf_cmd_prefix, package_sizes=netperf_package_sizes) if utils_misc.wait_for(n_client.is_netperf_running, 10, 0, 1, "Wait netperf test start"): logging.info("Netperf test start successfully.") else: test.error("Can not start netperf client.") num += 1 # here when set a run flag, when other case call this case as a # subprocess backgroundly, can set this run flag to False to stop # the stress test. env["netperf_run"] = True for n_client in netperf_clients: if n_client.is_netperf_running(): left_time = stop_time - time.time() utils_misc.wait_for(lambda: not n_client.is_netperf_running(), left_time, 0, 5, "Wait netperf test finish %ss" % left_time) time.sleep(5) finally: for n_server in netperf_servers: if n_server: n_server.stop() n_server.package.env_cleanup(True) for n_client in netperf_clients: if n_client: n_client.package.env_cleanup(True) env["netperf_run"] = False if session: session.close()
def setup_or_cleanup_gluster(is_setup, vol_name, brick_path="", pool_name="", file_path="/etc/glusterfs/glusterd.vol", **kwargs): # pylint: disable=E1121 """ Set up or clean up glusterfs environment on localhost or remote. These actions can be skipped by configuration on remote in case where a static gluster instance is used, s. base.cfg. In this case, only the host ip is returned. :param is_setup: Boolean value, true for setup, false for cleanup :param vol_name: gluster created volume name :param brick_path: Dir for create glusterfs :param kwargs: Other parameters that need to set for gluster :return: ip_addr or nothing """ if kwargs.get("gluster_managed_by_test", "yes") != "yes": if not is_setup: return "" gluster_server_ip = kwargs.get("gluster_server_ip") if not gluster_server_ip: return utils_net.get_host_ip_address() return gluster_server_ip try: utils_path.find_command("gluster") except utils_path.CmdNotFoundError: raise exceptions.TestSkipError("Missing command 'gluster'") if not brick_path: tmpdir = data_dir.get_tmp_dir() brick_path = os.path.join(tmpdir, pool_name) # Check gluster server apply or not ip_addr = kwargs.get("gluster_server_ip", "") session = None if ip_addr != "": remote_user = kwargs.get("gluster_server_user") remote_pwd = kwargs.get("gluster_server_pwd") remote_identity_file = kwargs.get("gluster_identity_file") session = remote.remote_login("ssh", ip_addr, "22", remote_user, remote_pwd, "#", identity_file=remote_identity_file) if is_setup: if ip_addr == "": ip_addr = utils_net.get_host_ip_address() add_rpc_insecure(file_path) glusterd_start() LOG.debug("finish start gluster") LOG.debug("The contents of %s: \n%s", file_path, open(file_path).read()) gluster_vol_create(vol_name, ip_addr, brick_path, True, session) gluster_allow_insecure(vol_name, session) gluster_nfs_disable(vol_name, session) LOG.debug("finish vol create in gluster") if session: session.close() return ip_addr else: gluster_vol_stop(vol_name, True, session) gluster_vol_delete(vol_name, session) gluster_brick_delete(brick_path, session) if session: session.close() return ""
def run(test, params, env): """ Run netperf stress on server and client side. 1) Start multi vm(s) guest. 2) Select multi vm(s) or host to setup netperf server/client. 3) Run netperf stress test. 4) Finish test until timeout env["netperf_run"] is False. :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ login_timeout = float(params.get("login_timeout", 360)) netperf_server = params.get("netperf_server").split() netperf_client = params.get("netperf_client").split() guest_username = params.get("username", "") guest_password = params.get("password", "") host_password = params.get("hostpassword", "redhat") shell_client = params.get("shell_client") shell_port = params.get("shell_port") os_type = params.get("os_type") compile_option_client = params.get("compile_option_client", "") compile_option_server = params.get("compile_option_server", "") host_ip = utils_net.get_host_ip_address(params) vms = params.get("vms") server_infos = [] client_infos = [] for server in netperf_server: s_info = {} if server in vms: server_vm = env.get_vm(server) server_vm.verify_alive() session = server_vm.wait_for_login(timeout=login_timeout) session.cmd("service iptables stop; iptables -F", ignore_all_errors=True) server_ip = server_vm.get_address() s_info["ip"] = server_ip s_info["os_type"] = params.get("os_type_%s" % server, os_type) s_info["username"] = params.get("username_%s" % server, guest_username) s_info["password"] = params.get("password_%s" % server, guest_password) s_info["shell_client"] = params.get("shell_client_%s" % server, shell_client) s_info["shell_port"] = params.get("shell_port_%s" % server, shell_port) else: if server == "localhost": s_info["ip"] = host_ip s_info["password"] = params.get("password_%s" % server, host_password) else: s_info["ip"] = server s_info["password"] = params.get("password_%s" % server, "redhat") s_info["os_type"] = params.get("os_type_%s" % server, "linux") s_info["username"] = params.get("username_%s" % server, "root") s_info["shell_client"] = params.get("shell_client_%s" % server, "ssh") s_info["shell_port"] = params.get("shell_port_%s" % server, "22") server_infos.append(s_info) for client in netperf_client: c_info = {} if client in vms: client_vm = env.get_vm(client) client_vm.verify_alive() session = client_vm.wait_for_login(timeout=login_timeout) session.cmd("service iptables stop; iptables -F", ignore_all_errors=True) client_ip = client_vm.get_address() c_info["ip"] = client_ip c_info["os_type"] = params.get("os_type_%s" % client, os_type) c_info["username"] = params.get("username_%s" % client, guest_username) c_info["password"] = params.get("password_%s" % client, guest_password) c_info["shell_client"] = params.get("shell_client_%s" % client, shell_client) c_info["shell_port"] = params.get("shell_port_%s" % client, shell_port) else: if client == "localhost": c_info["ip"] = host_ip c_info["password"] = params.get("password_%s" % client, host_password) else: c_info["ip"] = client c_info["password"] = params.get("password_%s" % client, "redhat") c_info["os_type"] = params.get("os_type_%s" % client, "linux") c_info["username"] = params.get("username_%s" % client, "root") c_info["shell_client"] = params.get("shell_client_%s" % client, "ssh") c_info["shell_port"] = params.get("shell_port_%s" % client, "23") client_infos.append(c_info) netperf_link = params.get("netperf_link") netperf_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_link) md5sum = params.get("pkg_md5sum") netperf_server_link = params.get("netperf_server_link_win", netperf_link) netperf_server_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_server_link) server_md5sum = params.get("server_md5sum") netperf_client_link = params.get("netperf_client_link_win", netperf_link) netperf_client_link = os.path.join(data_dir.get_deps_dir("netperf"), netperf_client_link) client_md5sum = params.get("client_md5sum") server_path_linux = params.get("server_path", "/var/tmp") client_path_linux = params.get("client_path", "/var/tmp") server_path_win = params.get("server_path_win", "c:\\") client_path_win = params.get("client_path_win", "c:\\") netperf_clients = [] netperf_servers = [] for c_info in client_infos: if c_info["os_type"] == "windows": netperf_link_c = netperf_client_link client_path = client_path_win md5sum = client_md5sum else: netperf_link_c = netperf_link client_path = client_path_linux n_client = utils_netperf.NetperfClient(c_info["ip"], client_path, md5sum, netperf_link_c, client=c_info["shell_client"], port=c_info["shell_port"], username=c_info["username"], password=c_info["password"], compile_option=compile_option_client) netperf_clients.append(n_client) for s_info in server_infos: if s_info["os_type"] == "windows": netperf_link_s = netperf_server_link server_path = server_path_win md5sum = server_md5sum else: netperf_link_s = netperf_link server_path = server_path_linux n_server = utils_netperf.NetperfServer(s_info["ip"], server_path, md5sum, netperf_link_s, client=s_info["shell_client"], port=s_info["shell_port"], username=s_info["username"], password=s_info["password"], compile_option=compile_option_server) netperf_servers.append(n_server) # Get range of message size. try: for n_server in netperf_servers: n_server.start() # Run netperf with message size defined in range. netperf_test_duration = int(params.get("netperf_test_duration", 60)) netperf_para_sess = params.get("netperf_para_sessions", "1") test_protocols = params.get("test_protocols", "TCP_STREAM") netperf_cmd_prefix = params.get("netperf_cmd_prefix", "") netperf_output_unit = params.get("netperf_output_unit", " ") netperf_package_sizes = params.get("netperf_package_sizes") test_option = params.get("test_option", "") test_option += " -l %s" % netperf_test_duration if params.get("netperf_remote_cpu") == "yes": test_option += " -C" if params.get("netperf_local_cpu") == "yes": test_option += " -c" if netperf_output_unit in "GMKgmk": test_option += " -f %s" % netperf_output_unit start_time = time.time() stop_time = start_time + netperf_test_duration num = 0 s_len = len(server_infos) for protocol in test_protocols.split(): error.context("Testing %s protocol" % protocol, logging.info) t_option = "%s -t %s" % (test_option, protocol) for n_client in netperf_clients: index = num % s_len server_ip = server_infos[index]["ip"] n_client.bg_start(server_ip, t_option, netperf_para_sess, netperf_cmd_prefix, package_sizes=netperf_package_sizes) if utils_misc.wait_for(n_client.is_netperf_running, 10, 0, 1, "Wait netperf test start"): logging.info("Netperf test start successfully.") else: raise error.TestError("Can not start netperf client.") num += 1 # here when set a run flag, when other case call this case as a # subprocess backgroundly, can set this run flag to False to stop # the stress test. env["netperf_run"] = True for n_client in netperf_clients: if n_client.is_netperf_running(): left_time = stop_time - time.time() utils_misc.wait_for(lambda: not n_client.is_netperf_running(), left_time, 0, 5, "Wait netperf test finish %ss" % left_time) finally: for n_server in netperf_servers: if n_server: n_server.stop() n_server.package.env_cleanup(True) for n_client in netperf_clients: if n_client: n_client.package.env_cleanup(True) env["netperf_run"] = False if session: session.close()
def run(test, params, env): """ Test hotplug of NIC devices 1) Boot up guest with one or multi nics 2) Add multi host network devices through monitor cmd and check if they are added 3) Add multi nic devices through monitor cmd and check if they are added 4) Check if new interface gets ip address 5) Disable primary link of guest 6) Ping guest new ip from host 7) Delete nic device and netdev if user config "do_random_unhotplug" 8) Ping guest's new ip address after guest pause/resume 9) Re-enable primary link of guest and hotunplug the plug nics BEWARE OF THE NETWORK BRIDGE DEVICE USED FOR THIS TEST ("nettype=bridge" and "netdst=<bridgename>" param). The virt-test default bridge virbr0, leveraging libvirt, works fine for the purpose of this test. When using other bridges, the timeouts which usually happen when the bridge topology changes (that is, devices get added and removed) may cause random failures. :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ def renew_ip_address(session, mac, is_linux_guest=True): if not is_linux_guest: utils_net.restart_windows_guest_network_by_key(session, "macaddress", mac) return None ifname = utils_net.get_linux_ifname(session, mac) p_cfg = "/etc/sysconfig/network-scripts/ifcfg-%s" % ifname cfg_con = "DEVICE=%s\nBOOTPROTO=dhcp\nONBOOT=yes" % ifname make_conf = "test -f %s || echo '%s' > %s" % (p_cfg, cfg_con, p_cfg) arp_clean = "arp -n|awk '/^[1-9]/{print \"arp -d \" $1}'|sh" session.cmd_output_safe(make_conf) session.cmd_output_safe("ifconfig %s up" % ifname) session.cmd_output_safe("dhclient -r", timeout=240) session.cmd_output_safe("dhclient %s" % ifname, timeout=240) session.cmd_output_safe(arp_clean) return None def get_hotplug_nic_ip(vm, nic, session, is_linux_guest=True): def __get_address(): try: index = [ _idx for _idx, _nic in enumerate( vm.virtnet) if _nic == nic][0] return vm.wait_for_get_address(index, timeout=90) except IndexError: raise error.TestError( "Nic '%s' not exists in VM '%s'" % (nic["nic_name"], vm.name)) except (virt_vm.VMIPAddressMissingError, virt_vm.VMAddressVerificationError): renew_ip_address(session, nic["mac"], is_linux_guest) return nic_ip = utils_misc.wait_for(__get_address, timeout=360) if nic_ip: return nic_ip cached_ip = vm.address_cache.get(nic["mac"]) arps = utils.system_output("arp -aen") logging.debug("Can't get IP address:") logging.debug("\tCached IP: %s" % cached_ip) logging.debug("\tARP table: %s" % arps) return None def ping_hotplug_nic(ip, mac, session, is_linux_guest): status, output = utils_test.ping(ip, 10, timeout=30) if status != 0: if not is_linux_guest: return status, output ifname = utils_net.get_linux_ifname(session, mac) add_route_cmd = "route add %s dev %s" % (ip, ifname) del_route_cmd = "route del %s dev %s" % (ip, ifname) logging.warn("Failed to ping %s from host.") logging.info("Add route and try again") session.cmd_output_safe(add_route_cmd) status, output = utils_test.ping(hotnic_ip, 10, timeout=30) logging.info("Del the route.") status, output = session.cmd_output_safe(del_route_cmd) return status, output login_timeout = int(params.get("login_timeout", 360)) vm = env.get_vm(params["main_vm"]) vm.verify_alive() primary_nic = [nic for nic in vm.virtnet] guest_is_linux = ("linux" == params.get("os_type", "")) host_ip_addr = utils_net.get_host_ip_address(params) if guest_is_linux: # Modprobe the module if specified in config file module = params.get("modprobe_module") if module: s_session = vm.wait_for_serial_login(timeout=login_timeout) s_session.cmd_output_safe("modprobe %s" % module) s_session.close() nic_hotplug_count = int(params.get("nic_hotplug_count", 1)) nic_hotplugged = [] try: for nic_index in xrange(1, nic_hotplug_count + 1): # need to reconnect serial port after # guest reboot for windows guest s_session = vm.wait_for_serial_login(timeout=login_timeout) nic_name = "hotplug_nic%s" % nic_index nic_params = params.object_params(nic_name) nic_model = nic_params["pci_model"] nic_params["nic_model"] = nic_model nic_params["nic_name"] = nic_name error.context("Disable other link(s) of guest", logging.info) disable_nic_list = primary_nic + nic_hotplugged for nic in disable_nic_list: if guest_is_linux: ifname = utils_net.get_linux_ifname(s_session, nic["mac"]) s_session.cmd_output_safe("ifconfig %s 0.0.0.0" % ifname) else: s_session.cmd_output_safe("ipconfig /release all") vm.set_link(nic.device_id, up=False) error.context("Hotplug %sth '%s' nic named '%s'" % (nic_index, nic_model, nic_name)) hotplug_nic = vm.hotplug_nic(**nic_params) error.context("Check if new interface gets ip address", logging.info) hotnic_ip = get_hotplug_nic_ip( vm, hotplug_nic, s_session, guest_is_linux) if not hotnic_ip: raise error.TestFail("Hotplug nic can get ip address") logging.info("Got the ip address of new nic: %s", hotnic_ip) error.context("Ping guest's new ip from host", logging.info) status, output = ping_hotplug_nic(host_ip_addr, hotplug_nic["mac"], s_session, guest_is_linux) if status: err_msg = "New nic failed ping test, error info: '%s'" raise error.TestFail(err_msg % output) error.context("Reboot vm after hotplug nic", logging.info) # reboot vm via serial port since some guest can't auto up # hotplug nic and next step will check is hotplug nic works. s_session = vm.reboot(session=s_session, serial=True) vm.verify_alive() hotnic_ip = get_hotplug_nic_ip( vm, hotplug_nic, s_session, guest_is_linux) if not hotnic_ip: raise error.TestFail( "Hotplug nic can't get ip after reboot vm") error.context("Ping guest's new ip from host", logging.info) status, output = ping_hotplug_nic(host_ip_addr, hotplug_nic["mac"], s_session, guest_is_linux) if status: err_msg = "New nic failed ping test, error info: '%s'" raise error.TestFail(err_msg % output) error.context("Pause vm", logging.info) vm.monitor.cmd("stop") vm.verify_status("paused") error.context("Resume vm", logging.info) vm.monitor.cmd("cont") vm.verify_status("running") error.context("Ping guest's new ip after resume", logging.info) status, output = ping_hotplug_nic(host_ip_addr, hotplug_nic["mac"], s_session, guest_is_linux) if status: err_msg = "New nic failed ping test after stop/cont, " err_msg += "error info: '%s'" % output raise error.TestFail(err_msg) # random hotunplug nic nic_hotplugged.append(hotplug_nic) if random.randint(0, 1) and params.get("do_random_unhotplug"): error.context("Detaching the previously attached nic from vm", logging.info) unplug_nic_index = random.randint(0, len(nic_hotplugged) - 1) vm.hotunplug_nic(nic_hotplugged[unplug_nic_index].nic_name) nic_hotplugged.pop(unplug_nic_index) s_session = vm.reboot(session=s_session, serial=True) vm.verify_alive() s_session.close() finally: for nic in nic_hotplugged: vm.hotunplug_nic(nic.nic_name) error.context("Re-enabling the primary link(s)", logging.info) for nic in primary_nic: vm.set_link(nic.device_id, up=True) error.context("Reboot vm to verify it alive after hotunplug nic(s)", logging.info) serial = len(vm.virtnet) > 0 and False or True session = vm.reboot(serial=serial) vm.verify_alive() session.close()
def run(test, params, env): """ Verify SLOF info with hugepage. Step: 1. Assign definite size hugepage and mount it in host. 2. Boot a guest by following ways: a. hugepage as backing file b. hugepage not as backing file then Check if any error info in output of SLOF. 3. Get the size of memory inside guest. 4. Hot plug pc-dimm by QMP. 5. Get the size of memory after hot plug pc-dimm inside guest, then check the different value of memory. 6. Reboot guest. 7. Guest could login successfully. 8. Guest could ping external host ip. :param test: Qemu test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ def _wait_for_login(cur_pos=0): """Wait for login guest.""" content, next_pos = slof.wait_for_loaded(vm, test, cur_pos) error_context.context("Check the output of SLOF.", logging.info) slof.check_error(test, content) error_context.context("Try to log into guest '%s'." % vm.name, logging.info) timeout = float(params.get("login_timeout", 240)) session = vm.wait_for_login(timeout=timeout) logging.info("log into guest '%s' successfully." % vm.name) return session, next_pos _setup_hugepage(params) params['start_vm'] = 'yes' env_process.preprocess_vm(test, params, env, params["main_vm"]) vm = env.get_vm(params["main_vm"]) vm.verify_alive() session, next_pos = _wait_for_login() error_context.context('Get guest free memory size before hotplug pc-dimm.', logging.info) orig_mem = int(session.cmd_output(cmd=params['free_mem_cmd'])) logging.debug('Guest free memory size is %d bytes' % orig_mem) error_context.context('Hotplug pc-dimm for guest.', logging.info) htp_mem = MemoryHotplugTest(test, params, env) htp_mem.hotplug_memory(vm, params['plug_mem_name']) plug_timeout = float(params.get('plug_timeout', 5)) if not utils_misc.wait_for( lambda: _check_mem_increase(session, params, orig_mem), plug_timeout): test.fail("Guest memory size is not increased %s in %s sec." % (params['size_plug'], params.get('plug_timeout', 5))) error_context.context('Reboot guest', logging.info) session.close() vm.reboot() session, _ = _wait_for_login(next_pos) error_context.context("Try to ping external host.", logging.info) extra_host_ip = utils_net.get_host_ip_address(params) session.cmd('ping %s -c 5' % extra_host_ip) logging.info("Ping host(%s) successfully." % extra_host_ip) session.close() vm.destroy(gracefully=True)
def run(test, params, env): """ Do network stress test when under memory stress 1) Boot a guest with vhost=on 2) swapoff in guest 3) flood ping from guest to host 4) do stress test :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ def flood_ping(session, host_ip, os_type="linux"): """ Do flood ping from guest to host :param session: session to send flood ping :param host_ip: the IP of the host """ flood_minutes = int(params["flood_minutes"]) logging.info("Flood ping for %s minutes" % flood_minutes) # TODO: windows guest doesn't have proper flood ping like linux, # will consider how to implement it for windows later if os_type == "linux": utils_net.ping(host_ip, flood=True, session=session, timeout=flood_minutes * 60) def load_stress(): """ Load background IO/CPU/Memory stress in guest """ error_context.context("launch stress app in guest", logging.info) args = (test, params, env, params["stress_test"]) bg_test = utils_test.BackgroundTest( utils_test.run_virt_sub_test, args) bg_test.start() if not utils_misc.wait_for(bg_test.is_alive, first=10, step=3, timeout=100): test.fail("background test start failed") def unload_stress(session): """ Stop stress app :param session: guest session """ error_context.context("stop stress app in guest", logging.info) cmd = params.get("stop_cmd") session.sendline(cmd) timeout = float(params.get("login_timeout", 240)) vm = env.get_vm(params["main_vm"]) host_ip = utils_net.get_host_ip_address(params) session = vm.wait_for_login(timeout=timeout) os_type = params["os_type"] if os_type == "linux": session.cmd("swapoff -a", timeout=300) error_context.context("Run memory heavy stress in guest", logging.info) if os_type == "linux": test_mem = params.get("memory", 256) stress_args = "--cpu 4 --io 4 --vm 2 --vm-bytes %sM" % int(test_mem) stress_test = utils_test.VMStress(vm, "stress", params, stress_args=stress_args) stress_test.load_stress_tool() else: load_stress() flood_ping(session, host_ip, os_type) if os_type == "linux": stress_test.unload_stress() stress_test.clean() else: unload_stress(session) error_context.context("Ping test after flood ping," " Check if the network is still alive", logging.info) count = params["count"] timeout = float(count) * 1.5 status, output = utils_net.ping(host_ip, count, session=session, timeout=timeout) if status != 0: test.fail("Ping failed, status: %s," " output: %s" % (status, output)) session.close()
def run_rv_vmshutdown(test, params, env): """ Tests clean exit after shutting down the VM. Covers two cases: (1)Shutdown from the command line of the guest. (2)Shutdown from the qemu monitor. Verify after the shutdown: (1)Verifying the guest is down (2)Verify the spice connection to the guest is no longer established (3)Verify the remote-viewer process is not running :param test: QEMU test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ # Get the required variables rv_binary = params.get("rv_binary", "remote-viewer") host_ip = utils_net.get_host_ip_address(params) shutdownfrom = params.get("shutdownfrom") cmd_cli_shutdown = params.get("cmd_cli_shutdown") cmd_qemu_shutdown = params.get("cmd_qemu_shutdown") host_port = None guest_vm = env.get_vm(params["guest_vm"]) guest_vm.verify_alive() guest_session = guest_vm.wait_for_login( timeout=int(params.get("login_timeout", 360)), username="******", password="******") client_vm = env.get_vm(params["client_vm"]) client_vm.verify_alive() client_session = client_vm.wait_for_login( timeout=int(params.get("login_timeout", 360)), username="******", password="******") if guest_vm.get_spice_var("spice_ssl") == "yes": host_port = guest_vm.get_spice_var("spice_tls_port") else: host_port = guest_vm.get_spice_var("spice_port") # Determine if the test is to shutdown from cli or qemu monitor if shutdownfrom == "cmd": logging.info("Shutting down guest from command line:" " %s\n" % cmd_cli_shutdown) output = guest_session.cmd(cmd_cli_shutdown) logging.debug("Guest is being shutdown: %s" % output) elif shutdownfrom == "qemu_monitor": logging.info("Shutting down guest from qemu monitor\n") output = guest_vm.monitor.cmd(cmd_qemu_shutdown) logging.debug("Output of %s: %s" % (cmd_qemu_shutdown, output)) else: raise error.TestFail("shutdownfrom var not set, valid values are" " cmd or qemu_monitor") # wait for the guest vm to be shutoff logging.info("Waiting for the guest VM to be shutoff") utils_misc.wait_for(guest_vm.is_dead, 90, 30, 1, "waiting...") logging.info("Guest VM is now shutoff") # Verify there was a clean exit by #(1)Verifying the guest is down #(2)Verify the spice connection to the guest is no longer established #(3)Verify the remote-viewer process is not running try: guest_vm.verify_alive() raise error.TestFail("Guest VM is still alive, shutdown failed.") except VMDeadError: logging.info("Guest VM is verified to be shutdown") try: utils_spice.verify_established( client_vm, host_ip, host_port, rv_binary) raise error.TestFail("Remote-Viewer connection to guest" "is still established.") except utils_spice.RVConnectError: logging.info("There is no remote-viewer connection as expected") else: raise error.TestFail("Unexpected error while trying to see if there" " was no spice connection to the guest") # Verify the remote-viewer process is not running logging.info("Checking to see if remote-viewer process is still running on" " client after VM has been shutdown") try: pidoutput = str(client_session.cmd("pgrep remote-viewer")) raise error.TestFail("Remote-viewer is still running on the client.") except ShellCmdError: logging.info("Remote-viewer process is not running as expected.")
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): """ Test Step 1. boot up two virtual machine 2. For linux guest,Transfer data: host <--> guest1 <--> guest2 <-->host via ipv6 For windows guest,Transfer data: host <--> guest1&guest2 via ipv6 3. after data transfer, check data have no change Params: :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ timeout = int(params.get("login_timeout", '360')) client = params.get("file_transfer_client") port = params.get("file_transfer_port") password = params.get("password") username = params.get("username") tmp_dir = params["tmp_dir"] filesize = int(params.get("filesize", '4096')) dd_cmd = params["dd_cmd"] file_trans_timeout = int(params.get("file_trans_timeout", '1200')) file_md5_check_timeout = int(params.get("file_md5_check_timeout", '600')) def get_file_md5sum(file_name, session, timeout): """ Get file md5sum from guest. """ logging.info("Get md5sum of the file:'%s'" % file_name) try: o = session.cmd_output("md5sum %s" % file_name, timeout=timeout) file_md5sum = re.findall(r"\w+", o)[0] except IndexError: test.error("Could not get file md5sum in guest") return file_md5sum sessions = {} addresses = {} inet_name = {} vms = [] error_context.context("Boot vms for test", logging.info) for vm_name in params.get("vms", "vm1 vm2").split(): vms.append(env.get_vm(vm_name)) # config ipv6 address host and guest. host_ifname = params.get("netdst") host_address = utils_net.get_host_ip_address(params, ip_ver="ipv6", linklocal=True) error_context.context("Get ipv6 address of host: %s" % host_address, logging.info) for vm in vms: vm.verify_alive() sessions[vm] = vm.wait_for_login(timeout=timeout) if params.get("os_type") == "linux": inet_name[vm] = utils_net.get_linux_ifname(sessions[vm], vm.get_mac_address()) addresses[vm] = utils_net.get_guest_ip_addr(sessions[vm], vm.get_mac_address(), params.get("os_type"), ip_version="ipv6", linklocal=True) error_context.context( "Get ipv6 address of %s: %s" % (vm.name, addresses[vm]), logging.info) # prepare test data guest_path = (tmp_dir + "src-%s" % utils_misc.generate_random_string(8)) dest_path = (tmp_dir + "dst-%s" % utils_misc.generate_random_string(8)) host_path = os.path.join(test.tmpdir, "tmp-%s" % utils_misc.generate_random_string(8)) logging.info("Test setup: Creating %dMB file on host", filesize) process.run(dd_cmd % (host_path, filesize), shell=True) try: src_md5 = (crypto.hash_file(host_path, algorithm="md5")) error_context.context("md5 value of data from src: %s" % src_md5, logging.info) # transfer data for vm in vms: error_context.context("Transfer data from host to %s" % vm.name, logging.info) remote.copy_files_to(addresses[vm], client, username, password, port, host_path, guest_path, timeout=file_trans_timeout, interface=host_ifname) dst_md5 = get_file_md5sum(guest_path, sessions[vm], timeout=file_md5_check_timeout) error_context.context( "md5 value of data in %s: %s" % (vm.name, dst_md5), logging.info) if dst_md5 != src_md5: test.fail("File changed after transfer host -> %s" % vm.name) if params.get("os_type") == "linux": for vm_src in addresses: for vm_dst in addresses: if vm_src != vm_dst: error_context.context( "Transferring data from %s to %s" % (vm_src.name, vm_dst.name), logging.info) remote.scp_between_remotes(addresses[vm_src], addresses[vm_dst], port, password, password, username, username, guest_path, dest_path, timeout=file_trans_timeout, src_inter=host_ifname, dst_inter=inet_name[vm_src]) dst_md5 = get_file_md5sum( dest_path, sessions[vm_dst], timeout=file_md5_check_timeout) error_context.context( "md5 value of data in %s: %s" % (vm.name, dst_md5), logging.info) if dst_md5 != src_md5: test.fail("File changed transfer %s -> %s" % (vm_src.name, vm_dst.name)) for vm in vms: error_context.context("Transfer data from %s to host" % vm.name, logging.info) remote.copy_files_from(addresses[vm], client, username, password, port, guest_path, host_path, timeout=file_trans_timeout, interface=host_ifname) error_context.context("Check whether the file changed after trans", logging.info) dst_md5 = (crypto.hash_file(host_path, algorithm="md5")) error_context.context( "md5 value of data after copying to host: %s" % dst_md5, logging.info) if dst_md5 != src_md5: test.fail("File changed after transfer (md5sum mismatch)") process.system_output("rm -rf %s" % host_path, timeout=timeout) finally: process.system("rm -rf %s" % host_path, timeout=timeout, ignore_status=True) for vm in vms: if params.get("os_type") == "linux": sessions[vm].cmd("rm -rf %s %s || true" % (guest_path, dest_path), timeout=timeout, ignore_all_errors=True) else: sessions[vm].cmd("del /f %s" % guest_path, timeout=timeout, ignore_all_errors=True) sessions[vm].close()
def launch_rv(test, client_vm, guest_vm, params): """ Launches rv_binary with args based on spice configuration inside client_session on background. remote-viewer will try to connect from vm1 from vm2 :param client_vm - vm object :param guest_vm - vm object :param params """ rv_binary = params.get("rv_binary", "remote-viewer") rv_ld_library_path = params.get("rv_ld_library_path") display = params.get("display") proxy = params.get("spice_proxy", None) if proxy: try: socket.inet_aton(params.get("proxy_ip", None)) except socket.error: test.cancel('Parameter proxy_ip not changed from default values') host_ip = utils_net.get_host_ip_address(params) host_port = None if guest_vm.get_spice_var("listening_addr") == "ipv6": host_ip = ("[" + utils_misc.convert_ipv4_to_ipv6(host_ip) + "]") host_tls_port = None disable_audio = params.get("disable_audio", "no") full_screen = params.get("full_screen") check_spice_info = params.get("spice_info") ssltype = params.get("ssltype") test_type = params.get("test_type") # cmd var keeps final remote-viewer command line # to be executed on client cmd = rv_binary if client_vm.params.get("os_type") != "windows": cmd = cmd + " --display=:0.0" # If qemu_ticket is set, set the password # of the VM using the qemu-monitor ticket = None ticket_send = params.get("spice_password_send") qemu_ticket = params.get("qemu_password") if qemu_ticket: guest_vm.monitor.cmd("set_password spice %s" % qemu_ticket) logging.info("Sending to qemu monitor: set_password spice %s", qemu_ticket) gencerts = params.get("gencerts") certdb = params.get("certdb") smartcard = params.get("smartcard") host_subj = None cacert = None rv_parameters_from = params.get("rv_parameters_from", "cmd") if rv_parameters_from == 'file': cmd += " ~/rv_file.vv" client_session = client_vm.wait_for_login( timeout=int(params.get("login_timeout", 360))) if display == "spice": ticket = guest_vm.get_spice_var("spice_password") if guest_vm.get_spice_var("spice_ssl") == "yes": # client needs cacert file cacert = "%s/%s" % ( guest_vm.get_spice_var("spice_x509_prefix"), guest_vm.get_spice_var("spice_x509_cacert_file")) client_session.cmd("rm -rf %s && mkdir -p %s" % (guest_vm.get_spice_var("spice_x509_prefix"), guest_vm.get_spice_var("spice_x509_prefix"))) remote.copy_files_to(client_vm.get_address(), 'scp', params.get("username"), params.get("password"), params.get("shell_port"), cacert, cacert) host_tls_port = guest_vm.get_spice_var("spice_tls_port") host_port = guest_vm.get_spice_var("spice_port") # cacert subj is in format for create certificate(with '/' delimiter) # remote-viewer needs ',' delimiter. And also is needed to remove # first character (it's '/') host_subj = guest_vm.get_spice_var("spice_x509_server_subj") host_subj = host_subj.replace('/', ',')[1:] if ssltype == "invalid_explicit_hs": host_subj = "Invalid Explicit HS" else: host_subj += host_ip # If it's invalid implicit, a remote-viewer connection # will be attempted with the hostname, since ssl certs were # generated with the ip address hostname = socket.gethostname() if ssltype == "invalid_implicit_hs": spice_url = r" spice://%s?tls-port=%s\&port=%s" % ( hostname, host_tls_port, host_port) else: spice_url = r" spice://%s?tls-port=%s\&port=%s" % ( host_ip, host_tls_port, host_port) if rv_parameters_from == "menu": line = spice_url elif rv_parameters_from == "file": pass else: cmd += spice_url if not rv_parameters_from == "file": cmd += " --spice-ca-file=%s" % cacert if (params.get("spice_client_host_subject") == "yes" and not rv_parameters_from == "file"): cmd += " --spice-host-subject=\"%s\"" % host_subj else: host_port = guest_vm.get_spice_var("spice_port") if rv_parameters_from == "menu": # line to be sent through monitor once r-v is started # without spice url line = "spice://%s?port=%s" % (host_ip, host_port) elif rv_parameters_from == "file": pass else: cmd += " spice://%s?port=%s" % (host_ip, host_port) elif display == "vnc": raise NotImplementedError("remote-viewer vnc") else: raise Exception("Unsupported display value") # Check to see if the test is using the full screen option. if full_screen == "yes" and not rv_parameters_from == "file": logging.info("Remote Viewer Set to use Full Screen") cmd += " --full-screen" if disable_audio == "yes": logging.info("Remote Viewer Set to disable audio") cmd += " --spice-disable-audio" # Check to see if the test is using a smartcard. if smartcard == "yes": logging.info("remote viewer Set to use a smartcard") if not rv_parameters_from == "file": cmd += " --spice-smartcard" if certdb is not None: logging.debug( "Remote Viewer set to use the following certificate" " database: %s", certdb) cmd += " --spice-smartcard-db " + certdb if gencerts is not None: logging.debug("Remote Viewer set to use the following certs: %s", gencerts) cmd += " --spice-smartcard-certificates " + gencerts if client_vm.params.get("os_type") == "linux": cmd = "nohup " + cmd + " &> /dev/null &" # Launch it on background if rv_ld_library_path: cmd = "export LD_LIBRARY_PATH=" + rv_ld_library_path + ";" + cmd if rv_parameters_from == "file": logging.info("Generating file") utils_spice.gen_rv_file(params, guest_vm, host_subj, cacert) logging.info("Uploading file to client") client_vm.copy_files_to("rv_file.vv", "~/rv_file.vv") # Launching the actual set of commands try: if rv_ld_library_path: print_rv_version(client_session, "LD_LIBRARY_PATH=/usr/local/lib " + rv_binary) else: print_rv_version(client_session, rv_binary) except (ShellStatusError, ShellProcessTerminatedError): # Sometimes It fails with Status error, ingore it and continue. # It's not that important to have printed versions in the log. logging.debug("Ignoring a Status Exception that occurs from calling " "print versions of remote-viewer or spice-gtk") logging.info("Launching %s on the client (virtual)", cmd) if proxy: if "http" in proxy: split = proxy.split('//')[1].split(':') else: split = proxy.split(':') host_ip = split[0] if len(split) > 1: host_port = split[1] else: host_port = "3128" if rv_parameters_from != "file": client_session.cmd("export SPICE_PROXY=%s" % proxy) if not params.get("rv_verify") == "only": try: client_session.cmd(cmd) except ShellStatusError: logging.debug("Ignoring a status exception, will check connection" "of remote-viewer later") # Send command line through monitor since url was not provided if rv_parameters_from == "menu": utils_spice.wait_timeout(1) str_input(client_vm, line) # client waits for user entry (authentication) if spice_password is set # use qemu monitor password if set, else, if set, try normal password. if qemu_ticket: # Wait for remote-viewer to launch utils_spice.wait_timeout(5) str_input(client_vm, qemu_ticket) elif ticket: if ticket_send: ticket = ticket_send utils_spice.wait_timeout(5) # Wait for remote-viewer to launch str_input(client_vm, ticket) utils_spice.wait_timeout(15) # Wait for conncetion to establish is_rv_connected = True try: utils_spice.verify_established( client_vm, host_ip, host_port, rv_binary, host_tls_port, params.get("spice_secure_channels", None)) except utils_spice.RVConnectError: if test_type == "negative": logging.info("remote-viewer connection failed as expected") if ssltype in ("invalid_implicit_hs", "invalid_explicit_hs"): # Check the qemu process output to verify what is expected qemulog = guest_vm.process.get_output() if "SSL_accept failed" in qemulog: return else: test.fail("SSL_accept failed not shown in qemu" "process as expected.") is_rv_connected = False else: test.fail("remote-viewer connection failed") if test_type == "negative" and is_rv_connected: test.fail("remote-viewer connection was established when" " it was supposed to be unsuccessful") # Get spice info output = guest_vm.monitor.cmd("info spice") logging.debug("INFO SPICE") logging.debug(output) # Check to see if ipv6 address is reported back from qemu monitor if (check_spice_info == "ipv6"): logging.info("Test to check if ipv6 address is reported" " back from the qemu monitor") # Remove brackets from ipv6 host ip if (host_ip[1:len(host_ip) - 1] in output): logging.info("Reported ipv6 address found in output from" " 'info spice'") else: test.fail("ipv6 address not found from qemu monitor" " command: 'info spice'") else: logging.info("Not checking the value of 'info spice'" " from the qemu monitor") # prevent from kill remote-viewer after test finish if client_vm.params.get("os_type") == "linux": cmd = "disown -ar" client_session.cmd_output(cmd)
def run(test, params, env): """ Verify SLOF info by user interface. Step: Scenario 1: 1.1 Boot a guest with at least two blocks, with "-boot menu=on", Press "F12" in the guest desktop at the early stage of booting process. 1.2 Check the boot menu info whether are match with guest info. 1.3 Select one of valid device to boot up the guest. 1.4 Check whether errors in SLOF. 1.5 Log in guest successfully. 1.6 Ping external host ip successfully. Scenario 2: 2.1. Boot the guest with spapr-vty and press 's' immediately when the guest boot up. 2.2. Check the output of console, whether is stopped enter kernel. 2.3. Type "boot" or "reset-all". 2.4. Check guest whether boot up successfully. 2.5. Log in guest successfully. :param test: Qemu test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ STOP, F12 = range(2) enter_key = {STOP: 's', F12: 'f12'} def _send_custom_key(keystr): """ Send custom keyword to SLOF's user interface. """ logging.info('Sending \"%s\" to SLOF user interface.' % keystr) for key in keystr: key = 'minus' if key == '-' else key vm.send_key(key) vm.send_key('ret') def _send_key(key, custom=True, sleep=0.0): """ Send keywords to SLOF's user interface. """ obj_name = 'select' if re.search(r'^\d+$', key) else key k_params = params.object_params(obj_name.replace('-', '_')) if custom: _send_custom_key(key) else: vm.send_key(key) time.sleep(sleep) content, _ = slof.get_boot_content(vm, 0, k_params['start'], k_params['end']) if content: logging.info('Output of SLOF:\n%s' % ''.join(content)) return ''.join(content) return None def _check_menu_info(menu_info): """ Check the menu info by each items. """ bootable_num = '' for i in range(1, int(params['boot_dev_num']) + 1): option = params['menu_option%d' % i] logging.info('Checking the device(%s) if is included in menu list.' % '->'.join(option.split())) dev_type, hba_type, child_bus, addr = option.split() addr = re.sub(r'^0x0?', '', addr) pattern = re.compile(r'(\d+)\)\s+%s(\d+)?\s+:\s+/%s(\S+)?/%s@%s' % (dev_type, hba_type, child_bus, addr), re.M) searched = pattern.search(menu_info) if not searched: test.fail('No such item(%s) in boot menu list.' % '->'.join(option.split())) if i == int(params['bootable_index']): bootable_num = searched.group(1) return bootable_num def _enter_user_interface(mode): """ Enter user interface. """ o = utils_misc.wait_for( lambda: _send_key(enter_key[mode], False), ack_timeout, step=0.0) if not o: test.fail('Failed to enter user interface in %s sec.' % ack_timeout) return o def _f12_user_interface_test(): """ Test f12 user interface. """ menu_list = _enter_user_interface(F12) actual_num = len(re.findall(r'\d+\)', menu_list)) dev_num = params['boot_dev_num'] if actual_num != int(dev_num): test.fail( 'The number of boot devices is not %s in menu list.' % dev_num) if not utils_misc.wait_for( lambda: _send_key( _check_menu_info(menu_list), False), ack_timeout, step=0.0): test.fail('Failed to load after selecting boot device ' 'in %s sec.' % ack_timeout) def _load_user_interface_test(): """ Test boot/reset-all user interface. """ _enter_user_interface(STOP) if not utils_misc.wait_for( lambda: _send_key(keys, True, 3), ack_timeout, step=0.0): test.fail( 'Failed to load after \'%s\' in %s sec.' % (keys, ack_timeout)) def _check_serial_log_status(): """ Check the status of serial log. """ file_timeout = 30 if not utils_misc.wait_for( lambda: os.path.isfile(vm.serial_console_log), file_timeout): test.error('No found serial log during %s sec.' % file_timeout) main_tests = {'f12': _f12_user_interface_test, 'boot': _load_user_interface_test, 'reset-all': _load_user_interface_test} ack_timeout = params['ack_timeout'] keys = params['send_keys'] env_process.process( test, params, env, env_process.preprocess_image, env_process.preprocess_vm) vm = env.get_vm(params["main_vm"]) vm.verify_alive() _check_serial_log_status() main_tests[keys]() error_context.context("Try to log into guest '%s'." % vm.name, logging.info) session = vm.wait_for_login(timeout=float(params['login_timeout'])) logging.info("log into guest '%s' successfully." % vm.name) error_context.context("Try to ping external host.", logging.info) extra_host_ip = utils_net.get_host_ip_address(params) session.cmd('ping %s -c 5' % extra_host_ip) logging.info("Ping host(%s) successfully." % extra_host_ip) vm.destroy(gracefully=True)
def run(test, params, env): """ Verify SLOF info with multi-devices. Step: 1. Boot a guest by following ways: a. attach two pci-bridges b. multiple virtio-net-pci devices attached multiple pci-bridges by one to one. 2. Check if any error info from output of SLOF. 3. Guest could login sucessfully. 4. Guest could ping external host ip. 5. For virtio-net-pci scenario, check the number of NIC if equal to qemu command. :param test: Qemu test object. :param params: Dictionary with the test parameters. :param env: Dictionary with test environment. """ if params['device_type'] == 'pci-bridge': for id in range(1, int(params['pci_bridge_num'])): params['pci_controllers'] += ' pci_bridge%d' % id params['type_pci_bridge%d' % id] = 'pci-bridge' elif params['device_type'] == 'virtio-net-pci': pci_num = int(params['pci_bridge_num']) nic_id = 0 for pci_id in range(pci_num): params['pci_controllers'] += ' pci_bridge%d' % pci_id params['type_pci_bridge%d' % pci_id] = 'pci-bridge' nic_num_per_pci = int(params['nic_num_per_pci_bridge']) for i in range(nic_num_per_pci): params["nics"] = ' '.join([params["nics"], 'nic%d' % nic_id]) params["nic_pci_bus_nic%d" % nic_id] = 'pci_bridge%d' % pci_id nic_id += 1 params['start_vm'] = 'yes' env_process.preprocess_vm(test, params, env, params["main_vm"]) vm = env.get_vm(params["main_vm"]) vm.verify_alive() content, _ = slof.wait_for_loaded(vm, test) error_context.context("Check the output of SLOF.", logging.info) slof.check_error(test, content) error_context.context("Try to log into guest '%s'." % vm.name, logging.info) timeout = float(params.get("login_timeout", 240)) session = vm.wait_for_login(timeout=timeout) logging.info("log into guest '%s' successfully." % vm.name) error_context.context("Try to ping external host.", logging.info) extra_host_ip = utils_net.get_host_ip_address(params) session.cmd('ping %s -c 5' % extra_host_ip) logging.info("Ping host(%s) successfully." % extra_host_ip) if params['device_type'] == 'virtio-net-pci': nic_num = int(str(session.cmd_output(params['nic_check_cmd']))) error_context.context('Found %d ehternet controllers inside guest.' % nic_num, logging.info) if (pci_num * nic_num_per_pci) != nic_num: test.fail( "The number of ethernet controllers is not equal to %s " "inside guest." % (pci_num * nic_num_per_pci)) logging.info( 'The number of ehternet controllers inside guest is equal to ' 'qemu command line(%d * %d).' % (pci_num, nic_num_per_pci)) session.close() vm.destroy(gracefully=True)