Ejemplo n.º 1
0
def run_fullscreen_setup(test, params, env):
    """
    Simple test for Remote Desktop connection
    Tests expectes that Remote Desktop client (spice/vnc) will be executed
    from within a second guest so we won't be limited to Linux only clients

    The plan is to support remote-viewer at first place

    @param test: QEMU test object.
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """
    # Get necessary params
    test_timeout = float(params.get("test_timeout", 600))

    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)))

    logging.debug("Exporting guest display")
    guest_session.cmd("export DISPLAY=:0.0")
    utils_spice.launch_startx(guest_vm)

    # Get the min, current, and max resolution on the guest
    output = guest_session.cmd("xrandr | grep Screen")
    outputlist = output.split()

    minimum = "640x480"

    current_index = outputlist.index("current")
    current = outputlist[current_index + 1]
    current += outputlist[current_index + 2]
    # Remove trailing comma
    current += outputlist[current_index + 3].replace(",", "")

    maximum = "2560x1600"

    logging.info("Minimum: " + minimum + " Current: " + current +
                 " Maximum: " + maximum)
    if (current != minimum):
        resolution = minimum
    else:
        resolution = maximum

    # Changing the guest resolution
    guest_session.cmd("xrandr -s " + resolution)
    logging.info("The resolution on the guest has been changed from " +
                 current + " to: " + resolution)

    # Start vdagent daemon
    utils_spice.start_vdagent(guest_session, test_timeout)

    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)))

    client_session.close()
    guest_session.close()
Ejemplo n.º 2
0
def run_fullscreen_setup(test, params, env):
    """
    Simple test for Remote Desktop connection
    Tests expectes that Remote Desktop client (spice/vnc) will be executed
    from within a second guest so we won't be limited to Linux only clients

    The plan is to support remote-viewer at first place

    @param test: QEMU test object.
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """
    # Get necessary params
    test_timeout = float(params.get("test_timeout", 600))

    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)))

    logging.debug("Exporting guest display")
    guest_session.cmd("export DISPLAY=:0.0")
    utils_spice.launch_startx(guest_vm)

    # Get the min, current, and max resolution on the guest
    output = guest_session.cmd("xrandr | grep Screen")
    outputlist = output.split()

    minimum = "640x480"

    current_index = outputlist.index("current")
    current = outputlist[current_index + 1]
    current += outputlist[current_index + 2]
    # Remove trailing comma
    current += outputlist[current_index + 3].replace(",", "")

    maximum = "2560x1600"

    logging.info("Minimum: " + minimum + " Current: " + current +
                 " Maximum: " + maximum)
    if(current != minimum):
        resolution = minimum
    else:
        resolution = maximum

    # Changing the guest resolution
    guest_session.cmd("xrandr -s " + resolution)
    logging.info("The resolution on the guest has been changed from " +
                 current + " to: " + resolution)

    # Start vdagent daemon
    utils_spice.start_vdagent(guest_session, test_timeout)

    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)))

    client_session.close()
    guest_session.close()
Ejemplo n.º 3
0
def run_rv_copyandpaste(test, params, env):
    """
    Testing copying and pasting between a client and guest
    Supported configurations:
    config_test: defines the test to run (Copying image, text, large textual
    data, positive or negative, and disabled copy paste set to be true or false
    text_to_test: In config defines the text to copy, and if it is numeric it
    will copy that amount of textual data, which is generated by cb.py.

    @param test: QEMU test object.
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """
    # Collect test parameters
    test_type = params.get("config_test")
    script = params.get("guest_script")
    dst_path = params.get("dst_dir", "guest_script")
    image_type = params.get("image_type")
    dst_image_path = params.get("dst_dir", "image_tocopy_name")
    dst_image_path_bmp = params.get("dst_dir", "image_tocopy_name_bmp")
    cp_disabled_test = params.get("disable_copy_paste")
    image_name = params.get("image_tocopy_name")
    image_name_bmp = params.get("image_tocopy_name_bmp")
    testing_text = params.get("text_to_test")
    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)))

    guest_vm = env.get_vm(params["guest_vm"])
    guest_session = guest_vm.wait_for_login(timeout=int(params.get("login_timeout", 360)))
    logging.info("Get PID of remote-viewer")
    client_session.cmd("pgrep remote-viewer")

    guest_vm.verify_alive()
    # The following is to copy files to the client and guest and do the test
    # copy the script to both the client and guest
    scriptdir = os.path.join("scripts", script)
    script_path = utils_misc.get_path(test.virtdir, scriptdir)

    # The following is to copy the test image to either the client or guest
    # if the test deals with images.
    imagedir = os.path.join("deps", image_name)
    imagedir_bmp = os.path.join("deps", image_name_bmp)
    image_path = utils_misc.get_path(test.virtdir, imagedir)
    image_path_bmp = utils_misc.get_path(test.virtdir, imagedir_bmp)

    logging.info(
        "Transferring the clipboard script to client & guest," "destination directory: %s, source script location: %s",
        dst_path,
        script_path,
    )

    client_vm.copy_files_to(script_path, dst_path, timeout=60)
    guest_vm.copy_files_to(script_path, dst_path, timeout=60)

    if "image" in test_type:
        if "client_to_guest" in test_type:
            if "png" in image_type:
                logging.info(
                    "Transferring the image to client" "destination directory: %s, source image: %s",
                    dst_image_path,
                    image_path,
                )
                client_vm.copy_files_to(image_path, dst_image_path, timeout=60)
            else:
                logging.info(
                    "Transferring a bmp image to client" "destination directory: %s, source image: %s",
                    dst_image_path_bmp,
                    image_path_bmp,
                )
                client_vm.copy_files_to(image_path_bmp, dst_image_path_bmp, timeout=60)
        elif "guest_to_client" in test_type:
            if "png" in image_type:
                logging.info(
                    "Transferring the image to client" "destination directory: %s, source image: %s",
                    dst_image_path,
                    image_path,
                )
                guest_vm.copy_files_to(image_path, dst_image_path, timeout=60)
            else:
                logging.info(
                    "Transferring a bmp image to client" "destination directory: %s, source image: %s",
                    dst_image_path_bmp,
                    image_path_bmp,
                )
                guest_vm.copy_files_to(image_path_bmp, dst_image_path_bmp, timeout=60)
        else:
            raise error.TestFail("Incorrect Test_Setup")

    client_session.cmd("export DISPLAY=:0.0")

    utils_spice.launch_startx(guest_vm)

    guest_session.cmd("export DISPLAY=:0.0")
    # Verify that gnome is now running on the guest
    guest_session.cmd("ps aux | grep -v grep | grep gnome-session")

    # Make sure the clipboards are clear before starting the test
    clear_cb(guest_session, params)
    clear_cb(client_session, params)
    wait_timeout(5)

    # Figure out which test needs to be run
    if cp_disabled_test == "yes":
        # These are negative tests, clipboards are not synced because the VM
        # is set to disable copy and paste.
        if "client_to_guest" in test_type:
            if "image" in test_type:
                logging.info(
                    "Negative Test Case: Copy/Paste Disabled, Copying"
                    "Image from the Client to Guest Should Not Work\n"
                )
                copyandpasteimg_cpdisabled_neg(client_session, guest_session, guest_session, params)
            else:
                logging.info(
                    "Negative Test Case: Copy/Paste Disabled, Copying" " from the Client to Guest Should Not Work\n"
                )
                copy_and_paste_cpdisabled_neg(client_session, guest_session, guest_session, params)
        if "guest_to_client" in test_type:
            if "image" in test_type:
                logging.info(
                    "Negative Test Case: Copy/Paste Disabled, Copying"
                    "Image from the Guest to Client Should Not Work\n"
                )
                copyandpasteimg_cpdisabled_neg(guest_session, client_session, guest_session, params)
            else:
                logging.info(
                    "Negative Test Case: Copy/Paste Disabled, Copying" " from the Guest to Client Should Not Work\n"
                )
                copy_and_paste_cpdisabled_neg(guest_session, client_session, guest_session, params)

    elif "positive" in test_type:
        # These are positive tests, where the clipboards are synced because
        # copy and paste is not disabled and the spice-vdagent is running
        if "client_to_guest" in test_type:
            if "image" in test_type:
                if "restart" in test_type:
                    logging.info("Restart Vdagent, Cp Img Client to Guest")
                    restart_cppaste_image(client_session, guest_session, guest_session, params)
                else:
                    logging.info("Copying an Image from the Client to Guest")
                    copy_and_paste_image_pos(client_session, guest_session, guest_session, params)
            elif testing_text.isdigit():
                if "restart" in test_type:
                    logging.info(
                        "Restart Vdagent, Copying a String of size " + testing_text + " from the Client to Guest"
                    )
                    restart_cppaste_lrgtext(client_session, guest_session, guest_session, params)
                else:
                    logging.info("Copying a String of size " + testing_text + " from the Client to Guest")
                    copy_and_paste_largetext(client_session, guest_session, guest_session, params)
            else:
                if "restart" in test_type:
                    logging.info("Restart Vdagent, Copying from Client to Guest\n")
                    restart_cppaste(client_session, guest_session, guest_session, params)
                else:
                    logging.info("Copying from the Client to Guest\n")
                    copy_and_paste_pos(client_session, guest_session, guest_session, params)
        if "guest_to_client" in test_type:
            if "image" in test_type:
                if "restart" in test_type:
                    logging.info("Restart Vdagent, Copy Img Guest to Client")
                    restart_cppaste_image(guest_session, client_session, guest_session, params)
                else:
                    logging.info("Copying an Image from the Guest to Client")
                    copy_and_paste_image_pos(guest_session, client_session, guest_session, params)
            elif testing_text.isdigit():
                if "restart" in test_type:
                    logging.info(
                        "Restart Vdagent, Copying a String of size " + testing_text + " from the Guest to Client"
                    )
                    restart_cppaste_lrgtext(guest_session, client_session, guest_session, params)
                else:
                    logging.info("Copying a String of size " + testing_text + " from the Guest to Client")
                    copy_and_paste_largetext(guest_session, client_session, guest_session, params)
            else:
                if "restart" in test_type:
                    logging.info("Restart Vdagent, Copying: Client to Guest\n")
                    restart_cppaste(guest_session, client_session, guest_session, params)
                else:
                    logging.info("Copying from the Guest to Client\n")
                    copy_and_paste_pos(guest_session, client_session, guest_session, params)
    elif "negative" in test_type:
        # These are negative tests, where the clipboards are not synced because
        # the spice-vdagent service will not be running on the guest.
        if "client_to_guest" in test_type:
            if "image" in test_type:
                logging.info("Negative Test Case: Copying an Image from the " "Client to Guest")
                copy_and_paste_image_neg(client_session, guest_session, guest_session, params)
            else:
                logging.info("Negative Test Case: Copying from the Client to" "Guest Should Not Work\n")
                copy_and_paste_neg(client_session, guest_session, guest_session, params)
        if "guest_to_client" in test_type:
            if "image" in test_type:
                logging.info("Negative Test Case: Copying an Image from the " "Guest to Client")
                copy_and_paste_image_neg(guest_session, client_session, guest_session, params)
            else:
                logging.info("Negative Test Case: Copying from the Guest to" " Client Should Not Work\n")
                copy_and_paste_neg(guest_session, client_session, guest_session, params)
    else:
        # The test is not supported, verify what is a supported test.
        raise error.TestFail("Couldn't Find the Correct Test To Run")
Ejemplo n.º 4
0
def run_rv_logging(test, params, env):
    """
    Tests the logging of remote-viewer

    @param test: QEMU test object.
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """

    # Get the necessary parameters to run the tests
    log_test = params.get("logtest")
    qxl_logfile = params.get("qxl_log")
    spicevdagent_logfile = params.get("spice_log")
    interpreter = params.get("interpreter")
    script = params.get("guest_script")
    script_params = params.get("script_params", "")
    dst_path = params.get("dst_dir", "guest_script")
    script_call = os.path.join(dst_path, script)
    testing_text = params.get("text_to_test")

    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)))

    scriptdir = os.path.join("scripts", script)
    script_path = utils_misc.get_path(test.virtdir, scriptdir)

    # Copying the clipboard script to the guest to test spice vdagent
    logging.info("Transferring the clipboard script to the guest,"
                 "destination directory: %s, source script location: %s",
                 dst_path, script_path)
    guest_vm.copy_files_to(script_path, dst_path, timeout=60)

    # Some logging tests need the full desktop environment
    guest_session.cmd("export DISPLAY=:0.0")

    utils_spice.launch_startx(guest_vm)

    # Logging test for the qxl driver
    if(log_test == 'qxl'):
        logging.info("Running the logging test for the qxl driver")
        guest_session.cmd("grep -i qxl " + qxl_logfile)
    # Logging test for spice-vdagent
    elif(log_test == 'spice-vdagent'):
        logging.info("Running the logging test for spice-vdagent daemon")
        utils_spice.start_vdagent(guest_session, test_timeout=15)

        # Testing the log after stopping spice-vdagentd
        utils_spice.stop_vdagent(guest_session, test_timeout=15)
        output = guest_session.cmd("tail -n 3 " + spicevdagent_logfile +
                                   " | grep 'vdagentd quiting'")

        # Testing the log after starting spice-vdagentd
        utils_spice.start_vdagent(guest_session, test_timeout=15)
        output = guest_session.cmd("tail -n 2 " + spicevdagent_logfile +
                                   " | grep 'opening vdagent virtio channel'")

        # Testing the log after restart spice-vdagentd
        utils_spice.restart_vdagent(guest_session, test_timeout=10)
        output = guest_session.cmd("tail -n 2 " + spicevdagent_logfile +
                                   " | grep 'opening vdagent virtio channel'")

        cmd = "echo \"SPICE_VDAGENTD_EXTRA_ARGS=-dd\"> /etc/sysconfig/spice-vdagentd"
        guest_session.cmd(cmd)
        utils_spice.restart_vdagent(guest_session, test_timeout=10)

        # Finally test copying text within the guest
        cmd = "%s %s %s %s" % (interpreter, script_call,
                               script_params, testing_text)

        logging.info("This command here: " + cmd)

        try:
            logging.debug("------------ Script output ------------")
            output = guest_session.cmd(cmd)

            if "The text has been placed into the clipboard." in output:
                logging.info("Copying of text was successful")
            else:
                raise error.TestFail("Copying to the clipboard failed ELSE",
                                     output)
        except:
            raise error.TestFail("Copying to the clipboard failed try" +
                                 " block failed")

        logging.debug("------------ End of script output of the Copying"
                      " Session ------------")

        output = guest_session.cmd("tail -n 3 " + spicevdagent_logfile +
                                   " | grep 'clipboard grab'")

    else:
        # Couldn't find the right test to run
        guest_session.close()
        raise error.TestFail("Couldn't find the right test to run,"
                             + " check cfg files.")
    guest_session.close()
Ejemplo n.º 5
0
def run_rv_input(test, params, env):
    """
    Test for testing keyboard inputs through spice.
    Test depends on rv_connect test.

    @param test: QEMU test object.
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """

    guest_vm = env.get_vm(params["guest_vm"])
    guest_vm.verify_alive()

    client_vm = env.get_vm(params["client_vm"])
    client_vm.verify_alive()

    guest_session = guest_vm.wait_for_login(
              timeout=int(params.get("login_timeout", 360)))
    try:
        guest_session.cmd("! test -e /etc/redhat-release")
    except ShellCmdError:
        deploy_epel_repo(guest_session, params)

    utils_spice.launch_startx(guest_vm)

    guest_session.cmd("export DISPLAY=:0.0")
    utils_spice.wait_timeout(3)
    # Verify that gnome is now running on the guest
    guest_session.cmd("ps aux | grep -v grep | grep gnome-session")

    install_wxpython(guest_session, params)

    deploy_test_form(test, guest_vm, params)

    #Get test type and perform proper test
    test_type = params.get("config_test")
    test_mapping = {'type_and_func_keys': test_type_and_func_keys,
                    'leds_and_esc_keys': test_leds_and_esc_keys,
                    'nonus_layout': test_nonus_layout,
                    'leds_migration': test_leds_migration}
    test_parameters = {'type_and_func_keys': (client_vm, guest_session, params),
                'leds_and_esc_keys': (client_vm, guest_session, params),
                'nonus_layout': (client_vm, guest_session, params),
                'leds_migration': (client_vm, guest_vm, guest_session, params)}

    try:
        func = test_mapping[test_type]
        args = test_parameters[test_type]
    except:
        raise error.TestFail("Unknown type of test")

    func(*args)

    #Get file with caught keycodes from guest
    result_path = get_test_results(guest_vm)
    #Analyze results and raise fail exp. If sent scancodes
    #do not match with expected keycodes
    result = analyze_results(result_path, test_type)
    if result is not None:
        raise error.TestFail("Testing of sending keys failed:"
                            "  Expected keycode = %s" % result)

    guest_session.close()
Ejemplo n.º 6
0
def run_rv_logging(test, params, env):
    """
    Tests the logging of remote-viewer

    @param test: QEMU test object.
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """

    # Get the necessary parameters to run the tests
    log_test = params.get("logtest")
    qxl_logfile = params.get("qxl_log")
    spicevdagent_logfile = params.get("spice_log")
    interpreter = params.get("interpreter")
    script = params.get("guest_script")
    script_params = params.get("script_params", "")
    dst_path = params.get("dst_dir", "guest_script")
    script_call = os.path.join(dst_path, script)
    testing_text = params.get("text_to_test")

    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)))

    scriptdir = os.path.join("scripts", script)
    script_path = utils_misc.get_path(test.virtdir, scriptdir)

    # Copying the clipboard script to the guest to test spice vdagent
    logging.info(
        "Transferring the clipboard script to the guest,"
        "destination directory: %s, source script location: %s", dst_path,
        script_path)
    guest_vm.copy_files_to(script_path, dst_path, timeout=60)

    # Some logging tests need the full desktop environment
    guest_session.cmd("export DISPLAY=:0.0")

    utils_spice.launch_startx(guest_vm)

    # Logging test for the qxl driver
    if (log_test == 'qxl'):
        logging.info("Running the logging test for the qxl driver")
        guest_session.cmd("grep -i qxl " + qxl_logfile)
    # Logging test for spice-vdagent
    elif (log_test == 'spice-vdagent'):
        logging.info("Running the logging test for spice-vdagent daemon")
        utils_spice.start_vdagent(guest_session, test_timeout=15)

        # Testing the log after stopping spice-vdagentd
        utils_spice.stop_vdagent(guest_session, test_timeout=15)
        output = guest_session.cmd("tail -n 3 " + spicevdagent_logfile +
                                   " | grep 'vdagentd quiting'")

        # Testing the log after starting spice-vdagentd
        utils_spice.start_vdagent(guest_session, test_timeout=15)
        output = guest_session.cmd("tail -n 2 " + spicevdagent_logfile +
                                   " | grep 'opening vdagent virtio channel'")

        # Testing the log after restart spice-vdagentd
        utils_spice.restart_vdagent(guest_session, test_timeout=10)
        output = guest_session.cmd("tail -n 2 " + spicevdagent_logfile +
                                   " | grep 'opening vdagent virtio channel'")

        cmd = "echo \"SPICE_VDAGENTD_EXTRA_ARGS=-dd\"> /etc/sysconfig/spice-vdagentd"
        guest_session.cmd(cmd)
        utils_spice.restart_vdagent(guest_session, test_timeout=10)

        # Finally test copying text within the guest
        cmd = "%s %s %s %s" % (interpreter, script_call, script_params,
                               testing_text)

        logging.info("This command here: " + cmd)

        try:
            logging.debug("------------ Script output ------------")
            output = guest_session.cmd(cmd)

            if "The text has been placed into the clipboard." in output:
                logging.info("Copying of text was successful")
            else:
                raise error.TestFail("Copying to the clipboard failed ELSE",
                                     output)
        except:
            raise error.TestFail("Copying to the clipboard failed try" +
                                 " block failed")

        logging.debug("------------ End of script output of the Copying"
                      " Session ------------")

        output = guest_session.cmd("tail -n 3 " + spicevdagent_logfile +
                                   " | grep 'clipboard grab'")

    else:
        # Couldn't find the right test to run
        guest_session.close()
        raise error.TestFail("Couldn't find the right test to run," +
                             " check cfg files.")
    guest_session.close()
Ejemplo n.º 7
0
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)
    host_port = None
    full_screen = params.get("full_screen")
    display = params.get("display")
    cmd = rv_binary + " --display=:0.0"
    ticket = None

    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_port = guest_vm.get_spice_var("spice_tls_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" % (host_ip, 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
    utils_spice.launch_startx(client_vm)

    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"
        )
Ejemplo n.º 8
0
def run_rv_input(test, params, env):
    """
    Test for testing keyboard inputs through spice.
    Test depends on rv_connect test.

    @param test: QEMU test object.
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """

    guest_vm = env.get_vm(params["guest_vm"])
    guest_vm.verify_alive()

    client_vm = env.get_vm(params["client_vm"])
    client_vm.verify_alive()

    guest_session = guest_vm.wait_for_login(
        timeout=int(params.get("login_timeout", 360)))
    try:
        guest_session.cmd("! test -e /etc/redhat-release")
    except ShellCmdError:
        deploy_epel_repo(guest_session, params)

    utils_spice.launch_startx(guest_vm)

    guest_session.cmd("export DISPLAY=:0.0")
    utils_spice.wait_timeout(3)
    # Verify that gnome is now running on the guest
    guest_session.cmd("ps aux | grep -v grep | grep gnome-session")

    install_wxpython(guest_session, params)

    deploy_test_form(test, guest_vm, params)

    #Get test type and perform proper test
    test_type = params.get("config_test")
    test_mapping = {
        'type_and_func_keys': test_type_and_func_keys,
        'leds_and_esc_keys': test_leds_and_esc_keys,
        'nonus_layout': test_nonus_layout,
        'leds_migration': test_leds_migration
    }
    test_parameters = {
        'type_and_func_keys': (client_vm, guest_session, params),
        'leds_and_esc_keys': (client_vm, guest_session, params),
        'nonus_layout': (client_vm, guest_session, params),
        'leds_migration': (client_vm, guest_vm, guest_session, params)
    }

    try:
        func = test_mapping[test_type]
        args = test_parameters[test_type]
    except:
        raise error.TestFail("Unknown type of test")

    func(*args)

    #Get file with caught keycodes from guest
    result_path = get_test_results(guest_vm)
    #Analyze results and raise fail exp. If sent scancodes
    #do not match with expected keycodes
    result = analyze_results(result_path, test_type)
    if result is not None:
        raise error.TestFail("Testing of sending keys failed:"
                             "  Expected keycode = %s" % result)

    guest_session.close()
Ejemplo n.º 9
0
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)
    host_port = None
    full_screen = params.get("full_screen")
    display = params.get("display")
    cmd = rv_binary + " --display=:0.0"
    ticket = None

    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_port = guest_vm.get_spice_var("spice_tls_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" % (host_ip, 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
    utils_spice.launch_startx(client_vm)

    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")