Ejemplo n.º 1
0
def test_leds_and_esc_keys(client_vm, guest_session, params):
    """
    Test LEDS and Escaped keys.
    Function sends various keys through qemu monitor to client VM.

    @param client_vm - vm object
    @param guest_session - ssh session to guest VM
    @param params
    """

    # Run wxPython form catching KeyEvents on guest
    run_test_form(guest_session, params)
    utils_spice.wait_timeout(3)

    # Prepare lists with the keys to be sent to client machine
    leds = ["a", "caps_lock", "a", "caps_lock", "num_lock", "kp_1", "num_lock", "kp_1"]
    shortcuts = ["a", "shift-a", "shift_r-a", "ctrl-a", "ctrl-c", "ctrl-v", "alt-x"]
    escaped = ["insert", "delete", "home", "end", "pgup", "pgdn", "up", "down", "right", "left"]

    test_keys = leds + shortcuts + escaped

    # Send keys to client machine
    logging.info("Sending leds and escaped keys to client machine")
    for key in test_keys:
        client_vm.send_key(key)
        utils_spice.wait_timeout(0.3)
Ejemplo n.º 2
0
def test_leds_and_esc_keys(client_vm, guest_session, params):
    """
    Test LEDS and Escaped keys.
    Function sends various keys through qemu monitor to client VM.

    @param client_vm - vm object
    @param guest_session - ssh session to guest VM
    @param params
    """

    #Run wxPython form catching KeyEvents on guest
    run_test_form(guest_session, params)
    utils_spice.wait_timeout(3)

    #Prepare lists with the keys to be sent to client machine
    leds = ['a', 'caps_lock', 'a', 'caps_lock', 'num_lock', 'kp_1', 'num_lock',
           'kp_1']
    shortcuts = ['a', 'shift-a', 'shift_r-a', 'ctrl-a', 'ctrl-c', 'ctrl-v',
                'alt-x']
    escaped = ['insert', 'delete', 'home', 'end', 'pgup', 'pgdn', 'up',
              'down', 'right', 'left']

    test_keys = leds + shortcuts + escaped

    #Send keys to client machine
    logging.info("Sending leds and escaped keys to client machine")
    for key in test_keys:
        client_vm.send_key(key)
        utils_spice.wait_timeout(0.3)
Ejemplo n.º 3
0
def test_leds_migration(client_vm, guest_vm, guest_session, params):
    """
    Check LEDS after migration.
    Function sets LEDS (caps, num) to ON and send scancodes of "a" and "1 (num)"
    and expected to get keycodes of "A" and "1" after migration.

    @param client_vm - vm object
    @param guest_vm - vm object
    @param guest_session - ssh session to guest VM
    @param params
    """

    #Run wxPython form catching KeyEvents on guest
    run_test_form(guest_session, params)
    utils_spice.wait_timeout(3)

    #Tested keys before migration
    test_keys = ['a', 'kp_1', 'caps_lock', 'num_lock', 'a', 'kp_1']
    logging.info("Sending leds keys to client machine before migration")
    for key in test_keys:
        client_vm.send_key(key)
        utils_spice.wait_timeout(0.3)

    guest_vm.migrate()
    utils_spice.wait_timeout(5)

    #Tested keys after migration
    test_keys = ['a', 'kp_1']
    logging.info("Sending leds keys to client machine after migration")
    for key in test_keys:
        client_vm.send_key(key)
        utils_spice.wait_timeout(0.3)
    utils_spice.wait_timeout(30)
Ejemplo n.º 4
0
def run_rv_connect(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.
    """

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

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

    utils_spice.wait_timeout(15)

    launch_rv(client_vm, guest_vm, params)

    client_session.close()
    guest_session.close()
Ejemplo n.º 5
0
def run_smartcard_setup(test, params, env):
    """
    Simple setup test to create certs on the client to be passed to VM's
    smartcard.

    @param test: QEMU test object.
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """
    # Get necessary params
    cert_list = params.get("gencerts").split(",")
    cert_db = params.get("certdb")
    self_sign = params.get("self_sign")
    cert_trustargs = params.get("trustargs")

    logging.debug("Cert List:")
    for cert in cert_list:
        logging.debug(cert)
        logging.debug(cert_trustargs)
        logging.debug("CN=" + cert)
        logging.debug(cert_db)


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

    #generate a random string, used to create a random key for the certs
    randomstring = utils_misc.generate_random_string(2048)
    cmd = "echo '" + randomstring + "' > /tmp/randomtext.txt"
    output = client_session.cmd(cmd)
    #output2 = client_session.cmd("cat /tmp/randomtext.txt")
    utils_spice.wait_timeout(5)

    #for each cert listed by the test, create it on the client
    for cert in cert_list:
        cmd = "certutil "
        if self_sign:
            cmd += " -x "
        cmd += "-t '" + cert_trustargs + "' -S -s " + "'CN=" + cert
        cmd += "' -n '" + cert + "' -d " + cert_db
        cmd += " -z " + "/tmp/randomtext.txt"
        logging.debug(cmd)
        output = client_session.cmd(cmd)
        logging.debug("Cert Created: " + output)

    cmd = "certutil -L -d " + cert_db
    output = client_session.cmd(cmd)
    logging.info("Listing all certs on the client: " + output)

    #Verify that all the certs have been generated on the client
    for cert in cert_list:
        if not(cert in output):
            raise error.TestFail("Certificate %s not found" % cert)

    client_session.close()
Ejemplo n.º 6
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)))

    utils_spice.wait_timeout(10)

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

    # 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.º 7
0
def run(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.
    """

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

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

    if (client_vm.params.get("os_type") == "windows" and
            client_vm.params.get("rv_installer", None)):
        utils_spice.install_rv_win(client_vm, params.get("rv_installer"))
        return

    if params.get("clear_interface", "yes") == "yes":
        for vm in params.get("vms").split():
            try:
                session = env.get_vm(vm).wait_for_login(timeout=360)
                output = session.cmd('cat /etc/redhat-release')
                logging.info(output)
            except ShellCmdError:
                raise error.TestNAError("Test is only currently supported on "
                                        "RHEL and Fedora operating systems")
            if "release 6." in output:
                waittime = 15
            else:
                waittime = 60
            utils_spice.clear_interface(env.get_vm(vm),
                                        int(params.get("login_timeout", "360")))

        utils_spice.wait_timeout(waittime)

    launch_rv(client_vm, guest_vm, params)

    client_session.close()
    guest_session.close()
Ejemplo n.º 8
0
def test_leds_migration(client_vm, guest_vm, guest_session, params):
    """
    Check LEDS after migration.
    Function sets LEDS (caps, num) to ON and send scancodes of "a" and "1 (num)"
    and expected to get keycodes of "A" and "1" after migration.

    :param client_vm - vm object
    :param guest_vm - vm object
    :param guest_session - ssh session to guest VM
    :param params
    """

    # Turn numlock on RHEL6 on before the test begins:
    grep_ver_cmd = "grep -o 'release [[:digit:]]' /etc/redhat-release"
    rhel_ver = guest_session.cmd(grep_ver_cmd).strip()

    logging.info("RHEL version: #{0}#".format(rhel_ver))

    if rhel_ver == "release 6":
        client_vm.send_key('num_lock')

    #Run PyGTK form catching KeyEvents on guest
    run_test_form(guest_session, params)
    utils_spice.wait_timeout(3)

    # Tested keys before migration
    test_keys = ['a', 'kp_1', 'caps_lock', 'num_lock', 'a', 'kp_1']
    logging.info("Sending leds keys to client machine before migration")
    for key in test_keys:
        client_vm.send_key(key)
        utils_spice.wait_timeout(0.3)

    guest_vm.migrate()
    utils_spice.wait_timeout(8)

    #Tested keys after migration
    test_keys = ['a', 'kp_1', 'caps_lock', 'num_lock']
    logging.info("Sending leds keys to client machine after migration")
    for key in test_keys:
        client_vm.send_key(key)
        utils_spice.wait_timeout(0.3)
    utils_spice.wait_timeout(30)
Ejemplo n.º 9
0
def test_type_and_func_keys(client_vm, guest_session, params):
    """
    Test typewriter and functional keys.
    Function sends various keys through qemu monitor to client VM.

    @param client_vm - vm object
    @param guest_session - ssh session to guest VM
    @param params
    """

    run_test_form(guest_session, params)
    utils_spice.wait_timeout(3)

    # Send typewriter and functional keys to client machine based on scancodes
    logging.info("Sending typewriter and functional keys to client machine")
    for i in range(1, 69):
        # Avoid Ctrl, RSH, LSH, PtScr, Alt, CpsLk
        if not (i in [29, 42, 54, 55, 56, 58]):
            client_vm.send_key(str(hex(i)))
            utils_spice.wait_timeout(0.3)
Ejemplo n.º 10
0
def test_type_and_func_keys(client_vm, guest_session, params):
    """
    Test typewriter and functional keys.
    Function sends various keys through qemu monitor to client VM.

    :param client_vm - vm object
    :param guest_session - ssh session to guest VM
    :param params
    """

    run_test_form(guest_session, params)
    utils_spice.wait_timeout(3)

    # Send typewriter and functional keys to client machine based on scancodes
    logging.info("Sending typewriter and functional keys to client machine")
    for i in range(1, 69):
        # Avoid Ctrl, RSH, LSH, PtScr, Alt, CpsLk
        if not (i in [29, 42, 54, 55, 56, 58]):
            client_vm.send_key(str(hex(i)))
            utils_spice.wait_timeout(0.3)
Ejemplo n.º 11
0
def test_nonus_layout(client_vm, guest_session, params):
    """
    Test some keys of non-us keyboard layouts (de, cz).
    Function sends various keys through qemu monitor to client VM.

    @param client_vm - vm object
    @param guest_session - ssh session to guest VM
    @param params
    """

    # Run wxPython form catching KeyEvents on guest
    run_test_form(guest_session, params)
    utils_spice.wait_timeout(3)

    # Czech layout - test some special keys
    cmd = "setxkbmap cz"
    guest_session.cmd(cmd)
    test_keys = ["7", "8", "9", "0", "alt_r-x", "alt_r-c", "alt_r-v"]
    logging.info("Sending czech keys to client machine")
    for key in test_keys:
        client_vm.send_key(key)
        utils_spice.wait_timeout(0.3)

    # German layout - test some special keys
    cmd = "setxkbmap de"
    guest_session.cmd(cmd)
    test_keys = ["minus", "0x1a", "alt_r-q", "alt_r-m"]
    logging.info("Sending german keys to client machine")
    for key in test_keys:
        client_vm.send_key(key)
        utils_spice.wait_timeout(0.3)

    cmd = "setxkbmap us"
    guest_session.cmd(cmd)
Ejemplo n.º 12
0
def test_nonus_layout(client_vm, guest_session, params):
    """
    Test some keys of non-us keyboard layouts (de, cz).
    Function sends various keys through qemu monitor to client VM.

    :param client_vm - vm object
    :param guest_session - ssh session to guest VM
    :param params
    """

    #Run PyGTK form catching KeyEvents on guest
    run_test_form(guest_session, params)
    utils_spice.wait_timeout(3)

    # Czech layout - test some special keys
    cmd = "setxkbmap cz"
    guest_session.cmd(cmd)
    test_keys = ['7', '8', '9', '0', 'alt_r-x', 'alt_r-c', 'alt_r-v']
    logging.info("Sending czech keys to client machine")
    for key in test_keys:
        client_vm.send_key(key)
        utils_spice.wait_timeout(0.3)

    # German layout - test some special keys
    cmd = "setxkbmap de"
    guest_session.cmd(cmd)
    test_keys = ['minus', '0x1a', 'alt_r-q', 'alt_r-m']
    logging.info("Sending german keys to client machine")
    for key in test_keys:
        client_vm.send_key(key)
        utils_spice.wait_timeout(0.3)

    cmd = "setxkbmap us"
    guest_session.cmd(cmd)
Ejemplo n.º 13
0
def test_nonus_layout(client_vm, guest_session, params):
    """
    Test some keys of non-us keyboard layouts (de, cz).
    Function sends various keys through qemu monitor to client VM.

    :param client_vm - vm object
    :param guest_session - ssh session to guest VM
    :param params
    """

    #Run PyGTK form catching KeyEvents on guest
    run_test_form(guest_session, params)
    utils_spice.wait_timeout(3)

    # Czech layout - test some special keys
    cmd = "setxkbmap cz"
    guest_session.cmd(cmd)
    test_keys = ['7', '8', '9', '0', 'alt_r-x', 'alt_r-c', 'alt_r-v']
    logging.info("Sending czech keys to client machine")
    for key in test_keys:
        client_vm.send_key(key)
        utils_spice.wait_timeout(0.3)

    # German layout - test some special keys
    cmd = "setxkbmap de"
    guest_session.cmd(cmd)
    test_keys = ['minus', '0x1a', 'alt_r-q', 'alt_r-m']
    logging.info("Sending german keys to client machine")
    for key in test_keys:
        client_vm.send_key(key)
        utils_spice.wait_timeout(0.3)

    cmd = "setxkbmap us"
    guest_session.cmd(cmd)
Ejemplo n.º 14
0
def run_rv_connect(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.
    """

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

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

    if (client_vm.params.get("os_type") == "windows" and
       client_vm.params.get("rv_installer", None)):
        utils_spice.install_rv_win(client_vm, params.get("rv_installer"))
        return

    if params.get("clear_interface", "yes") == "yes":
        for vm in params.get("vms").split():
            utils_spice.clear_interface(env.get_vm(vm),
                                        int(params.get("login_timeout", "360")))
        utils_spice.wait_timeout(15)

    launch_rv(client_vm, guest_vm, params)

    client_session.close()
    guest_session.close()
Ejemplo n.º 15
0
def run(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.
    """

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

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

    if (client_vm.params.get("os_type") == "windows"
            and client_vm.params.get("rv_installer", None)):
        utils_spice.install_rv_win(client_vm, params.get("rv_installer"))
        return

    if params.get("clear_interface", "yes") == "yes":
        for vm in params.get("vms").split():
            utils_spice.clear_interface(
                env.get_vm(vm), int(params.get("login_timeout", "360")))
        utils_spice.wait_timeout(15)

    launch_rv(client_vm, guest_vm, params)

    client_session.close()
    guest_session.close()
Ejemplo n.º 16
0
        # 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)
    try:
        client_session.cmd(cmd)
    except ShellStatusError:
        logging.debug("Ignoring a status exception, will check connection of"
                      "remote-viewer later")

    # client waits for user entry (authentication) if spice_password is set
    # use qemu monitor password if set, else check if the normal password is set
    if qemu_ticket:
        # Wait for remote-viewer to launch
        utils_spice.wait_timeout(5)
        send_ticket(client_vm, qemu_ticket)
    elif ticket:
        if ticket_send:
            ticket = ticket_send

        utils_spice.wait_timeout(5)  # Wait for remote-viewer to launch
        send_ticket(client_vm, ticket)
    utils_spice.wait_timeout(5)  # Wait for conncetion to establish
    try:
        utils_spice.verify_established(client_vm, host_ip, host_port, rv_binary)
    except utils_spice.RVConnectError:
        if test_type == "negative":
            logging.info("remote-viewer connection failed as expected")
        else:
            raise error.TestFail("remote-viewer connection failed")
Ejemplo n.º 17
0
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)
Ejemplo n.º 18
0
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)
Ejemplo n.º 19
0
def run(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))

    utils_spice.wait_timeout(20)

    for vm in params.get("vms").split():
        utils_spice.clear_interface(env.get_vm(vm),
                                    int(params.get("login_timeout", "360")))

    utils_spice.wait_timeout(20)

    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(username="******",
                                                 password="******")

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

    # 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_root_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.º 20
0
    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)
    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 r-v was started without spice url
    if menu == "yes":
        utils_spice.wait_timeout(1)
        str_input(client_vm, line)
        client_vm.send_key("tab")
        client_vm.send_key("tab")
        client_vm.send_key("tab")
        client_vm.send_key("kp_enter")

    # client waits for user entry (authentication) if spice_password is set
    # use qemu monitor password if set, else check if the normal password is
    # set
    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:
Ejemplo n.º 21
0
def run(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))

    utils_spice.wait_timeout(20)

    for vm in params.get("vms").split():
        utils_spice.clear_interface(env.get_vm(vm),
                                    int(params.get("login_timeout", "360")))

    utils_spice.wait_timeout(20)

    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(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)))
    client_root_session = client_vm.wait_for_login(username="******",
                                                   password="******")

    logging.debug("Exporting client display")
    client_session.cmd("export DISPLAY=:0.0")

    # Get the min, current, and max resolution on the guest
    output = client_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):
        newClientResolution = minimum
    else:
        newClientResolution = maximum

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

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

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

    current_index = outputlist.index("current")
    currentGuestRes = outputlist[current_index + 1]
    currentGuestRes += outputlist[current_index + 2]
    currentGuestRes += outputlist[current_index + 3].replace(",", "")
    logging.info("Current Resolution of Guest: " + currentGuestRes)

    if (newClientResolution == currentGuestRes):
        raise error.TestFail("Client resolution is same as guest resolution!")

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

    client_session.close()
    guest_session.close()
Ejemplo n.º 22
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_misc.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
    try:
        client_session.cmd("startx &", timeout=15)
    except (ShellCmdError, ShellStatusError):
        logging.debug("Ignoring an Exception that Occurs from calling startx")

    utils_spice.wait_timeout(15)

    try:
        print_rv_version(client_session, rv_binary)
    except ShellStatusError:
        # 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)
    client_session.cmd(cmd)

    # client waits for user entry (authentication) if spice_password is set
    if ticket:
        utils_spice.wait_timeout(5)  # Wait for remote-viewer to launch
        send_ticket(client_vm, ticket)

    utils_spice.wait_timeout(5)  # Wait for conncetion to establish
    verify_established(client_session, host_ip, host_port, rv_binary)

    #prevent from kill remote-viewer after test finish
    cmd = "disown -ar"
    client_session.cmd(cmd)
Ejemplo n.º 23
0
def setup_vm_windows(test, params, env, vm):
    setup_type = vm.params.get("setup_type", None)
    logging.info("Setup type: %s" % setup_type)

    if vm.params.get("display", None) == "vnc":
        logging.info("Display of VM is VNC; assuming it is client")
        utils_spice.install_rv_win(vm, params.get("rv_installer"), env)
        utils_spice.install_usbclerk_win(vm, params.get("usb_installer"), env)
        return

    if setup_type == "guest_tools":
        logging.info("Installing Windows guest tools")
        session = vm.wait_for_login(
                             timeout = int(params.get("login_timeout", 360)))
        winqxl = params.get("winqxl")
        winvdagent = params.get("winvdagent")
        vioserial = params.get("vioserial")
        pnputil = params.get("pnputil")
        winp7 = params.get("winp7zip")
        guest_script_req = params.get("guest_script_req")
        md5sumwin = params.get("md5sumwin")
        md5sumwin_dir = os.path.join("scripts", md5sumwin)
        guest_sr_dir = os.path.join("scripts", guest_script_req)
        guest_sr_path = utils_misc.get_path(test.virtdir, guest_sr_dir)
        md5sumwin_path = utils_misc.get_path(test.virtdir, md5sumwin_dir)
        winp7_path = os.path.join(test.virtdir, 'deps', winp7)
        winqxlzip = os.path.join(test.virtdir, 'deps', winqxl)
        winvdagentzip = os.path.join(test.virtdir, 'deps', winvdagent)
        vioserialzip = os.path.join(test.virtdir, 'deps', vioserial)
        #copy p7zip to windows and install it silently
        logging.info("Installing 7zip")
        vm.copy_files_to(winp7_path, "C:\\")
        session.cmd_status("start /wait msiexec /i C:\\7z920-x64.msi /qn") 

        #copy over the winqxl, winvdagent, virtio serial 
        vm.copy_files_to(winqxlzip, "C:\\")
        vm.copy_files_to(winvdagentzip, "C:\\")
        vm.copy_files_to(vioserialzip, "C:\\")
        vm.copy_files_to(guest_sr_path, "C:\\")
        vm.copy_files_to(md5sumwin_path, "C:\\")
        
        #extract winvdagent zip and start service if vdservice is not installed
        try:
            output = session.cmd('sc queryex type= service state= all' +
                                 ' | FIND "vdservice"')
        except aexpect.ShellCmdError:
            session.cmd_status('"C:\\Program Files\\7-Zip\\7z.exe" e C:\\wvdagent.zip -oC:\\')
            utils_spice.wait_timeout(2)
            session.cmd_status("C:\\vdservice.exe install")
            #wait for vdservice to come up
            utils_spice.wait_timeout(5)
            logging.info(session.cmd("net start vdservice")) 
            logging.info(session.cmd("chdir"))

        #extract winqxl driver, place drivers in correct location & reboot
        #Note pnputil only works win 7+, need to find a way for win xp
        #Verify if virtio serial is already installed
        output = session.cmd(pnputil + " /e")
        if("System devices" in output):
            logging.info( "Virtio Serial already installed")
        else:
            session.cmd_status('"C:\\Program Files\\7-Zip\\7z.exe" e C:\\vioserial.zip -oC:\\')
            output = session.cmd(pnputil + " -i -a C:\\vioser.inf")
            logging.info("Virtio Serial status: " + output)
            #Make sure virtio install is complete
            utils_spice.wait_timeout(5)
        output = session.cmd(pnputil + " /e")
        if("Display adapters" in output):
            logging.info("QXL already installed")
        else:
            #winqxl
            session.cmd_status('"C:\\Program Files\\7-Zip\\7z.exe" e C:\\wqxl.zip -oC:\\')
            output = session.cmd(pnputil + " -i -a C:\\qxl.inf")
            logging.info( "Win QXL status: " + output )
            #Make sure qxl install is complete
            utils_spice.wait_timeout(5)
        vm.reboot()
         
        logging.info("Installation of Windows guest tools completed")

    logging.info("Setup complete")
Ejemplo n.º 24
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_misc.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
    try:
        client_session.cmd("startx &", timeout=15)
    except (ShellCmdError, ShellStatusError):
        logging.debug("Ignoring an Exception that Occurs from calling startx")

    utils_spice.wait_timeout(15)

    try:
        print_rv_version(client_session, rv_binary)
    except ShellStatusError:
        # 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)
    client_session.cmd(cmd)

    # client waits for user entry (authentication) if spice_password is set
    if ticket:
        utils_spice.wait_timeout(5)  # Wait for remote-viewer to launch
        send_ticket(client_vm, ticket)

    utils_spice.wait_timeout(5)  # Wait for conncetion to establish
    verify_established(client_session, host_ip, host_port, rv_binary)

    #prevent from kill remote-viewer after test finish
    cmd = "disown -ar"
    client_session.cmd(cmd)
Ejemplo n.º 25
0
def setup_vm_windows(test, params, env, vm):
    setup_type = vm.params.get("setup_type", None)
    logging.info("Setup type: %s" % setup_type)

    if vm.params.get("display", None) == "vnc":
        logging.info("Display of VM is VNC; assuming it is client")
        utils_spice.install_rv_win(vm, params.get("rv_installer"), env)
        utils_spice.install_usbclerk_win(vm, params.get("usb_installer"), env)
        return

    if setup_type == "guest_tools":
        logging.info("Installing Windows guest tools")
        session = vm.wait_for_login(
            timeout=int(params.get("login_timeout", 360)))
        winqxl = params.get("winqxl")
        winvdagent = params.get("winvdagent")
        vioserial = params.get("vioserial")
        pnputil = params.get("pnputil")
        winp7 = params.get("winp7zip")
        guest_script_req = params.get("guest_script_req")
        md5sumwin = params.get("md5sumwin")
        md5sumwin_dir = os.path.join("scripts", md5sumwin)
        guest_sr_dir = os.path.join("scripts", guest_script_req)
        guest_sr_path = utils_misc.get_path(test.virtdir, guest_sr_dir)
        md5sumwin_path = utils_misc.get_path(test.virtdir, md5sumwin_dir)
        winp7_path = os.path.join(test.virtdir, 'deps', winp7)
        winqxlzip = os.path.join(test.virtdir, 'deps', winqxl)
        winvdagentzip = os.path.join(test.virtdir, 'deps', winvdagent)
        vioserialzip = os.path.join(test.virtdir, 'deps', vioserial)
        #copy p7zip to windows and install it silently
        logging.info("Installing 7zip")
        vm.copy_files_to(winp7_path, "C:\\")
        session.cmd_status("start /wait msiexec /i C:\\7z920-x64.msi /qn")

        #copy over the winqxl, winvdagent, virtio serial
        vm.copy_files_to(winqxlzip, "C:\\")
        vm.copy_files_to(winvdagentzip, "C:\\")
        vm.copy_files_to(vioserialzip, "C:\\")
        vm.copy_files_to(guest_sr_path, "C:\\")
        vm.copy_files_to(md5sumwin_path, "C:\\")

        #extract winvdagent zip and start service if vdservice is not installed
        try:
            output = session.cmd('sc queryex type= service state= all' +
                                 ' | FIND "vdservice"')
        except aexpect.ShellCmdError:
            session.cmd_status(
                '"C:\\Program Files\\7-Zip\\7z.exe" e C:\\wvdagent.zip -oC:\\')
            utils_spice.wait_timeout(2)
            session.cmd_status("C:\\vdservice.exe install")
            #wait for vdservice to come up
            utils_spice.wait_timeout(5)
            logging.info(session.cmd("net start vdservice"))
            logging.info(session.cmd("chdir"))

        #extract winqxl driver, place drivers in correct location & reboot
        #Note pnputil only works win 7+, need to find a way for win xp
        #Verify if virtio serial is already installed
        output = session.cmd(pnputil + " /e")
        if ("System devices" in output):
            logging.info("Virtio Serial already installed")
        else:
            session.cmd_status(
                '"C:\\Program Files\\7-Zip\\7z.exe" e C:\\vioserial.zip -oC:\\'
            )
            output = session.cmd(pnputil + " -i -a C:\\vioser.inf")
            logging.info("Virtio Serial status: " + output)
            #Make sure virtio install is complete
            utils_spice.wait_timeout(5)
        output = session.cmd(pnputil + " /e")
        if ("Display adapters" in output):
            logging.info("QXL already installed")
        else:
            #winqxl
            session.cmd_status(
                '"C:\\Program Files\\7-Zip\\7z.exe" e C:\\wqxl.zip -oC:\\')
            output = session.cmd(pnputil + " -i -a C:\\qxl.inf")
            logging.info("Win QXL status: " + output)
            #Make sure qxl install is complete
            utils_spice.wait_timeout(5)
        vm.reboot()

        logging.info("Installation of Windows guest tools completed")

    logging.info("Setup complete")
Ejemplo n.º 26
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: KVM 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)))

    try:
        guest_session.cmd("startx &", timeout=15)
    except (aexpect.ShellCmdError, aexpect.ShellStatusError):
        logging.debug("Ignoring an Exception that Occurs from calling startx")
    # Sleep while X session starts
    utils_spice.wait_timeout(15)

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

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

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

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

    MAXindex = outputlist.index("maximum")
    maximum = outputlist[MAXindex + 1]
    maximum += outputlist[MAXindex + 2]
    maximum += outputlist[MAXindex + 3]

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

    @param test: KVM 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)))
    if guest_session.cmd("test -e /etc/redhat-release"):
        deploy_epel_repo(guest_session, params)

    try:
        guest_session.cmd("startx &", timeout=15)
    except (ShellCmdError, ShellStatusError):
        logging.debug("Ignoring an Exception that Occurs from calling startx")

    #Give some time to X
    utils_spice.wait_timeout(15)

    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.º 28
0
def run(test, params, env):
    """
    Simple setup test to create certs on the client to be passed to VM's
    smartcard.

    :param test: QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    # Get necessary params
    cert_list = params.get("gencerts").split(",")
    cert_db = params.get("certdb")
    self_sign = params.get("self_sign")
    cert_trustargs = params.get("trustargs")

    logging.debug("Cert List:")
    for cert in cert_list:
        logging.debug(cert)
        logging.debug(cert_trustargs)
        logging.debug("CN=%s", cert)
        logging.debug(cert_db)

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

    for vm in params.get("vms").split():
        utils_spice.clear_interface(env.get_vm(vm),
                                    int(params.get("login_timeout", "360")))

    # generate a random string, used to create a random key for the certs
    randomstring = utils_misc.generate_random_string(2048)
    cmd = "echo '" + randomstring + "' > /tmp/randomtext.txt"
    output = client_session.cmd(cmd)
    #output2 = client_session.cmd("cat /tmp/randomtext.txt")
    utils_spice.wait_timeout(5)

    # for each cert listed by the test, create it on the client
    for cert in cert_list:
        cmd = "certutil "
        if self_sign:
            cmd += " -x "
        cmd += "-t '" + cert_trustargs + "' -S -s " + "'CN=" + cert
        cmd += "' -n '" + cert + "' -d " + cert_db
        cmd += " -z " + "/tmp/randomtext.txt"
        logging.debug(cmd)
        output = client_session.cmd(cmd)
        logging.debug("Cert Created: %s", output)

    cmd = "certutil -L -d " + cert_db
    output = client_session.cmd(cmd)
    logging.info("Listing all certs on the client: %s", output)

    # Verify that all the certs have been generated on the client
    for cert in cert_list:
        if not (cert in output):
            test.fail("Certificate %s not found" % cert)

    client_session.close()
Ejemplo n.º 29
0
def run_rv_input(test, params, env):
    """
    Test for testing keyboard inputs through spice.
    Test depends on rv_connect test.

    @param test: KVM 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)))
    if guest_session.cmd("test -e /etc/redhat-release"):
        deploy_epel_repo(guest_session, params)

    try:
        guest_session.cmd("startx &", timeout=15)
    except (ShellCmdError, ShellStatusError):
        logging.debug("Ignoring an Exception that Occurs from calling startx")

    # Give some time to X
    utils_spice.wait_timeout(15)

    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.º 30
0
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)
Ejemplo n.º 31
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")
    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)
Ejemplo n.º 32
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: KVM 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)))

    try:
        guest_session.cmd("startx &", timeout=15)
    except (aexpect.ShellCmdError, aexpect.ShellStatusError):
        logging.debug("Ignoring an Exception that Occurs from calling startx")
    # Sleep while X session starts
    utils_spice.wait_timeout(15)

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

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

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

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

    MAXindex = outputlist.index("maximum")
    maximum = outputlist[MAXindex + 1]
    maximum += outputlist[MAXindex + 2]
    maximum += outputlist[MAXindex + 3]

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