コード例 #1
0
def rv_run(vmi, rcmd, ssn, env=None):
    env = env or {}
    cfg = vmi.cfg
    if cfg.rv_ld_library_path:
        cmd = utils.Cmd("export")
        cmd.append("LD_LIBRARY_PATH=%s" % cfg.rv_ld_library_path)
        act.run(vmi, cmd, ssn=ssn)
    if cfg.spice_proxy and cfg.rv_parameters_from != "file":
        cmd = utils.Cmd("export")
        cmd.append("SPICE_PROXY=%s" % cfg.spice_proxy)
        act.run(vmi, cmd, ssn=ssn)
    for key in env:
        cmd = utils.Cmd("export", "%s=%s" % (key, env[key]))
        act.run(vmi, cmd, ssn=ssn)
    if cfg.usb_redirection_add_device:
        # USB was created by qemu (root). This prevents right issue.
        # ..todo:: must be root session
        cmd = utils.Cmd("chown", cfg.username, cfg.file_path)
        act.run(vmi, cmd)
        if not act.check_usb_policy(vmi):
            act.add_usb_policy(vmi)
    try:
        pid = ssn.get_pid()
        logger.info("shell pid id: %s", pid)
        ssn.sendline(str(rcmd))
    except aexpect.ShellStatusError:
        logger.debug("Ignoring a status exception, will check connection"
                     "of remote-viewer later")
コード例 #2
0
def rv_basic_opts(vmi):
    """Command line parameters for RV.

    """
    cfg = vmi.cfg
    rv_cmd = utils.Cmd()
    rv_cmd.append(cfg.rv_binary)
    if cfg.rv_debug:
        rv_cmd.append("--spice-debug")
    if cfg.full_screen:
        rv_cmd.append("--full-screen")
    if cfg.disable_audio:
        rv_cmd.append("--spice-disable-audio")
    if cfg.smartcard:
        rv_cmd.append("--spice-smartcard")
        if cfg.certdb:
            rv_cmd.append("--spice-smartcard-db")
            rv_cmd.append(cfg.certdb)
        if cfg.gencerts:
            rv_cmd.append("--spice-smartcard-certificates")
            rv_cmd.append(cfg.gencerts)
    if cfg.usb_redirection_add_device:
        logger.info("Auto USB redirect for devices class == 0x08.")
        opt = r'--spice-usbredir-redirect-on-connect="0x08,-1,-1,-1,1"'
        rv_cmd.append(opt)
    if utils.is_yes(vmi.test.kvm_g.spice_ssl):
        cacert_host = utils.cacert_path_host(vmi.test)
        cacert_client = act.cp_file(vmi, cacert_host)
        opt = "--spice-ca-file=%s" % cacert_client
        rv_cmd.append(opt)
        if cfg.spice_client_host_subject:
            host_subj = utils.get_host_subj(vmi.test)
            opt = '--spice-host-subject=%s' % host_subj
            rv_cmd.append(opt)
    return rv_cmd
コード例 #3
0
def run(vt_test, test_params, env):
    """Inspects Xorg logs for QLX presence.

    Parameters
    ----------
    vt_test : avocado.core.plugins.vt.VirtTest
        QEMU test object.
    test_params : virttest.utils_params.Params
        Dictionary with the test parameters.
    env : virttest.utils_env.Env
        Dictionary with test environment.

    Raises
    ------
    TestFail
        Test fails for some reason.

    """
    test = stest.GuestTest(vt_test, test_params, env)
    cfg = test.cfg
    act.x_active(test.vmi)
    cmd = utils.Cmd("grep", "-i", "qxl", cfg.qxl_log)
    exit_code, output = act.rstatus(test.vmi, cmd, admin=True)
    assert exit_code == 0
    act.info(test.vmi, "Mention about qxl: %s." % output)
コード例 #4
0
def rv_connect_file(vmi, ssn, env):
    cmd = utils.Cmd(vmi.cfg.rv_binary)
    vv_file_host = act.gen_vv_file(vmi)
    with open(vv_file_host, 'r') as rvfile:
        file_contents = rvfile.read()
        act.info(vmi, "RV file contents:\n%s", file_contents)
    vv_file_client = act.cp_file(vmi, vv_file_host)
    cmd.append(vv_file_client)
    utils.set_ticket(vmi.test)
    cmd = utils.combine(cmd, "2>&1")
    act.info(vmi, "Final RV command: %s", cmd)
    act.rv_run(vmi, cmd, ssn, env)
コード例 #5
0
ファイル: vm_actions.py プロジェクト: spiceqa/tp-spice
def new_ssn(vmi, admin=False, dogtail_ssn=False):
    if admin:
        username = vmi.cfg.rootuser
        password = vmi.cfg.rootpassword
        utils.debug(vmi, "Open a new session for: admin.")
    else:
        username = vmi.cfg.username
        password = vmi.cfg.password
        utils.debug(vmi, "Open a new session for: user.")
    ssn = vmi.vm.wait_for_login(username=username,
                                password=password,
                                timeout=int(vmi.cfg.login_timeout))
    if dogtail_ssn:
        dogtail_cmd = utils.Cmd("dogtail-run-headless-next", "--dont-start",
                                "--dont-kill", "/bin/bash")
        act.run(vmi, dogtail_cmd, ssn=ssn)
    act.export_vars(vmi, ssn)
    return ssn
コード例 #6
0
def get_ip(vmi):
    """Get IP for VM.

    Notes
    -----

        * At this moment we use Ovirt ReST API. We need to know only VMs IP.
        If it is necessary to send more complex requests consider to switch to
        Ovirt Python SDK.

        * This function requires to installed and running a daemon from RPM
        rhevm-guest-agent-common or GuestTools for Windows.:

            28236 ?        Ssl   34:36 /usr/bin/python /usr/share/ovirt-guest-agent/ovirt-guest-agent.py

        * Will be called next command:

        curl \
            --insecure \
            --request GET \
            --header "Filter: true" \
            --header "Accept: application/xml" \
            --user "[email protected]:redhat" \
            'https://rhevm36.spice.brq.redhat.com/ovirt-engine/api/vms/?search=auto_pool_06_rhel72' \
            | xmllint --xpath 'string(/vms/vm/guest_info/ips/ip/@address)' -

    Returns
    -------
    str
        String with IP address of a VM.

    Raises
    ------
    Exception
        Cannot get IP for VM.
    """
    cfg = vmi.cfg
    cmd1 = utils.Cmd("curl")
    cmd1.append("--insecure")
    cmd1.append("--request")
    cmd1.append("GET")
    cmd1.append("--header")
    cmd1.append("Filter: true")
    cmd1.append("--header")
    cmd1.append("Accept: application/xml")
    cmd1.append("--user")
    user = "******".format(user=cfg.ovirt_user,
                                             profile=cfg.ovirt_profile,
                                             passw=cfg.ovirt_password)
    cmd1.append(user)
    if cfg.ovirt_vm_name:
        # The same syntax as in admin portal search bar.
        search = "name=%s" % cfg.ovirt_vm_name
    elif cfg.ovirt_pool_name:
        search = "pool=%s" % cfg.ovirt_pool_name
    else:
        raise Exception("Not defined: VM or pool name.")
    url = "{ovirt_engine}/api/vms/?search={search}".format(
        ovirt_engine=cfg.ovirt_engine_url,
        search=search)
    cmd1.append(url)
    cmd2 = utils.Cmd("xmllint",
                     "--xpath",
                     "string(/vms/vm/guest_info/ips/ip/@address)",
                     "-")
    cmd_get_ip = utils.combine(cmd1, "|", cmd2)
    out = subprocess.check_output(cmd_get_ip, shell=True)
    return out
コード例 #7
0
def run(vt_test, test_params, env):
    """GUI tests for remote-viewer.

    Parameters
    ----------
    vt_test : avocado.core.plugins.vt.VirtTest
        QEMU test object.
    test_params : virttest.utils_params.Params
        Dictionary with the test parameters.
    env : virttest.utils_env.Env
        Dictionary with test environment.

    Raises
    ------
    TestFail
        Test fails for expected behaviour.

    """
    test = stest.ClientGuestTest(vt_test, test_params, env)
    cfg = test.cfg
    vmi_c = test.vmi_c
    vmi_g = test.vmi_g
    vm_c = test.vm_c
    # Screen lock is now disabled in kickstart file for source QCOW images of
    # SPICE-QE team (https://gitlab.cee.redhat.com/spiceqe/install-compose/ks).
    # act.lock_scr_off(vmi_c)
    act.turn_accessibility(vmi_c)
    act.x_active(vmi_c)
    act.x_active(vmi_g)
    if utils.vm_is_rhel8(vm_c):
        act.set_alt_python(vmi_c, "/usr/bin/python3")
    else:
        act.install_rpm(vmi_c, test.cfg_c.epel_rpm)
        act.install_rpm(vmi_c, test.cfg_c.dogtail_rpm)
        act.install_rpm(vmi_c, "xdotool")
    if utils.vm_is_rhel6(vm_c):
        # Activate accessibility for rhel6
        act.reset_gui(vmi_c)

    # Copy tests to client VM.
    # Some tests could require established RV session, some of them, don't.
    is_connected = False
    if cfg.make_rv_connect:
        ssn = act.new_ssn(vmi_c, dogtail_ssn=vmi_c.vm.is_rhel8())
        act.rv_connect(vmi_c, ssn)
        if not cfg.negative:
            act.rv_chk_con(vmi_c)
            is_connected = True
    logging.getLogger().setLevel(logging.DEBUG)
    tdir = act.cp2vm(vmi_c, cfg.client_tests)
    tpath = os.path.join(tdir, cfg.script)
    cmd = utils.Cmd('python', *tpath.split())
    try:
        status, _ = act.rstatus(vmi_c, cmd, dogtail_ssn=vmi_c.vm.is_rhel8())
    except Exception as e:
        a = traceback.format_exc()
        logger.info("Exception: %s: %s.", repr(e), a)
    if cfg.make_rv_connect:
        out = ssn.read_nonblocking()
        logger.info("RV log: %s.", str(out))
    if status:
        raise utils.SpiceTestFail(test, "Test failed.")
コード例 #8
0
ファイル: rv_input.py プロジェクト: spiceqa/tp-spice
def run(vt_test, test_params, env):
    """Test for testing keyboard inputs through spice.

    Parameters
    ----------
    vt_test : avocado.core.plugins.vt.VirtTest
        QEMU test object.
    test_params : virttest.utils_params.Params
        Dictionary with the test parameters.
    env : virttest.utils_env.Env
        Dictionary with test environment.

    """
    test = stest.ClientGuestTest(vt_test, test_params, env)
    cfg = test.cfg
    #test.cmd_g.install_rpm(cfg.xev)
    act.x_active(test.vmi_c)
    act.x_active(test.vmi_g)
    ssn = act.new_ssn(test.vmi_c, dogtail_ssn=test.vmi_c.vm.is_rhel8())
    act.rv_connect(test.vmi_c, ssn)
    act.rv_chk_con(test.vmi_c)

    if cfg.ttype == 'type_and_func_keys':
        """Test typewriter and functional keys."""
        keycodes = range(1, 69)
        # Skip Ctrl, RSH, LSH, PtScr, Alt, CpsLk
        skip = [29, 42, 54, 55, 56, 58]
        send_keys = [hex(k) for k in keycodes if k not in skip]
        expected_keysyms = [
            65307, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 45, 61, 65288,
            65289, 113, 119, 101, 114, 116, 121, 117, 105, 111, 112, 91, 93,
            65293, 97, 115, 100, 102, 103, 104, 106, 107, 108, 59, 39, 96, 92,
            122, 120, 99, 118, 98, 110, 109, 44, 46, 47, 32, 65470, 65471,
            65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479
        ]
        test_seq(test, send_keys, expected_keysyms)

    if cfg.ttype == 'leds_and_esc_keys':
        escaped = [
            'insert', 'delete', 'home', 'end', 'pgup', 'pgdn', 'up', 'down',
            'right', 'left'
        ]
        expected_keysyms = [
            65379, 65535, 65360, 65367, 65365, 65366, 65362, 65364, 65363,
            65361
        ]
        test_seq(test, escaped, expected_keysyms)

        shortcuts = [
            'a', 'shift-a', 'shift_r-a', 'ctrl-a', 'ctrl-c', 'ctrl-v', 'alt-x'
        ]
        expected_keysyms = [
            97, 65505, 65, 65506, 65, 65507, 97, 65507, 99, 65507, 118, 65513,
            120
        ]
        test_seq(test, shortcuts, expected_keysyms)

        leds = [
            'a', 'caps_lock', 'a', 'caps_lock', 'num_lock', 'kp_1', 'num_lock',
            'kp_1'
        ]
        expected_keysyms = [97, 65509, 65, 65509, 65407, 65457, 65407, 65436]
        test_seq(test, leds, expected_keysyms)
    if cfg.ttype == 'nonus_layout':
        cmd = utils.Cmd("setxkbmap", "cz")
        act.run(test.vmi_g, cmd)
        keys = ['7', '8', '9', '0', 'alt_r-x', 'alt_r-c', 'alt_r-v']
        expected_keysyms = [
            253, 225, 237, 233, 65027, 35, 65027, 38, 65027, 64
        ]
        test_seq(test, keys, expected_keysyms)
        cmd = utils.Cmd("setxkbmap", "de")
        act.run(test.vmi_g, cmd)
        keys = ['minus', '0x1a', 'alt_r-q', 'alt_r-m']
        expected_keysyms = [223, 252, 65027, 64, 65027, 181]
        test_seq(test, keys, expected_keysyms)
        cmd = utils.Cmd("setxkbmap", "us")
        act.run(test.vmi_g, cmd)
    if cfg.ttype == "leds_migration":
        if test.vm_c.is_rhel6():
            test.vm_c.send_key('num_lock')
        keys1 = ['a', 'kp_1', 'caps_lock', 'num_lock', 'a', 'kp_1']
        keys2 = ['a', 'kp_1', 'caps_lock', 'num_lock']
        expected_keysyms = [
            '97', '65457', '65509', '65407', '65', '65436', '65', '65436',
            '65509', '65407'
        ]
        ssn = act.klogger_start(test.vmi_g)
        for i in keys1:
            test.vm_c.send_key(i)
        test.vm_g.migrate()
        for i in keys2:
            test.vm_c.send_key(i)
        logged_keys = act.klogger_stop(test.vmi_g, ssn)
        ssn.close()
        keysyms = [key[1] for key in logged_keys]
        assert keysyms == expected_keysyms
コード例 #9
0
def rv_chk_con(vmi):
    """Tests if connection is active.

    .. todo:: rewrte to test per session.

    Parameters
    ----------
    test : SpiceTest
        Spice test object.

    Raises
    ------
    RVSessionConnect
        RV session is not establised. Or established in unexpected way.
    RVSessionError
        Something goes wrong.
    """
    test = vmi.test
    cfg = test.cfg
    proxy_port = None
    if vmi.cfg.ssltype == "invalid_implicit_hs" or \
            "explicit" in vmi.cfg.ssltype:
        hostname = socket.gethostname()  # See rv_url() function
        remote_ip = socket.gethostbyname(hostname)
    elif cfg.spice_proxy:
        remote_ip, proxy_port = utils.URL_parse(cfg.spice_proxy,
                                                cfg.http_proxy_port)
        logger.info("Proxy port to inspect: %s, proxy IP: %s", proxy_port,
                    remote_ip)
    else:
        remote_ip = utils.get_host_ip(test)
    rv_binary = os.path.basename(cfg.rv_binary)
    cmd1 = utils.Cmd("ss", "-n", "-p", "-t", "state", "all")
    grep_regex = "%s.*%s" % (remote_ip, rv_binary)
    cmd2 = utils.Cmd("grep", "-e", grep_regex)
    cmd3 = utils.Cmd("grep", "-v", "CLOSE-WAIT")
    cmd = utils.combine(cmd1, "|", cmd2, "|", cmd3)
    status, ss_out = act.rstatus(vmi, cmd, admin=True)
    if status:
        logger.info("ss output: %s", ss_out)
        raise utils.SpiceUtilsError("No active RV connections.")
    proxy_port_count = 0
    if cfg.spice_proxy:
        proxy_port_count = ss_out.count(proxy_port)
        test.vm_g.info("Active proxy ports %s: %s", proxy_port,
                       proxy_port_count)
    port = test.kvm_g.spice_port
    tls_port = test.kvm_g.spice_tls_port
    if port == 'no':
        port_count = 0
    else:
        port_count = ss_out.count(port)
    test.vm_g.info("Active ports %s: %s", port, port_count)
    tls_port_count = 0
    if tls_port:
        tls_port_count = ss_out.count(tls_port)
    test.vm_g.info("Active TLS ports %s: %s", tls_port, tls_port_count)
    opened_ports = port_count + tls_port_count + proxy_port_count
    if opened_ports < 4:
        raise RVSessionConnect(
            test,
            "Total links per session is less then 4 (%s)." % opened_ports)
    if cfg.spice_secure_channels:
        tls_port_expected = len(cfg.spice_secure_channels.split(','))
        if tls_port_count < tls_port_expected:
            msg = "Secure links per session is less then expected. %s (%s)" % (
                tls_port_count, tls_port_expected)
            raise RVSessionConnect(test, msg)
    if cfg.spice_plaintext_channels:
        plaintext_port_expected = len(cfg.spice_plaintext_channels.split(','))
        if port_count < plaintext_port_expected:
            msg = (
                "Plaintext links per session is less then expected. %s (%s)" %
                (port_count, plaintext_port_expected))
            raise RVSessionConnect(test, msg)
    for line in ss_out.split('\n'):
        for p in port, tls_port, proxy_port:
            if p and p in line and "ESTAB" not in line:
                raise RVSessionConnect(test, "Missing active link at port %s",
                                       p)
    output = test.vm_g.monitor.info("spice")
    logger.info(output)
    # Check to see if ipv6 address is reported back from qemu monitor
    if cfg.spice_info == "ipv6":
        # Remove brackets from ipv6 host ip
        host_ip = utils.get_host_ip(test)
        logger.info('host ip = %s', host_ip)
        if host_ip[1:len(host_ip) - 1] in str(output):
            logger.info(
                "Reported ipv6 address found in output from 'info spice'")
        else:
            raise RVSessionConnect("ipv6 address not found from qemu monitor"
                                   " command: 'info spice'")
    logger.debug("RV connection checking pass")
コード例 #10
0
ファイル: rv_filexfer.py プロジェクト: spiceqa/tp-spice
def run(vt_test, test_params, env):
    """Run remote-viewer at client VM.

    Parameters
    ----------
    vt_test : avocado.core.plugins.vt.VirtTest
        QEMU test object.
    test_params : virttest.utils_params.Params
        Dictionary with the test parameters.
    env : virttest.utils_env.Env
        Dictionary with test environment.

    """
    test = stest.ClientGuestTest(vt_test, test_params, env)
    cfg = test.cfg
    vmi_c = test.vmi_c
    vmi_g = test.vmi_g
    homedir_g = act.home_dir(vmi_g)
    success = False
    act.turn_accessibility(vmi_c)
    if utils.vm_is_rhel6(test.vm_c):
        # Activate accessibility for rhel6, BZ#1340160 for rhel7
        act.reset_gui(vmi_c)
    act.x_active(vmi_c)
    act.x_active(vmi_g)
    ssn = act.new_ssn(vmi_c)
    act.rv_connect(vmi_c, ssn)
    # Nautilus cannot be docked to side when default resolution
    act.set_resolution(vmi_c, "1280x1024")
    if not utils.vm_is_rhel8(test.vm_c):
        act.install_rpm(vmi_c, vmi_c.cfg.dogtail_rpm)
    dst_script = act.chk_deps(vmi_c, cfg.helper_c)
    if cfg.locked:
        # enable screen lock
        cmd = utils.Cmd('rm', '-I', '/etc/dconf/db/local.d/screensaver')
        act.run(vmi_g, cmd, admin=True)
        cmd = utils.Cmd('dconf', 'update')
        act.run(vmi_g, cmd, admin=True)
        cmd = utils.Cmd('loginctl', 'lock-sessions')
        act.run(vmi_g, cmd, admin=True)
        logging.info('Locking gnome session on guest')
    if 'generate' in cfg.test_xfer_file:
        if cfg.copy_img:
            test_xfer_file = 'test.png'
            act.imggen(vmi_c, test_xfer_file, cfg.test_image_size)
        else:
            test_xfer_file = 'test.txt'
            act.gen_rnd_file(vmi_c, test_xfer_file, cfg.xfer_kbytes)
    elif 'http' in cfg.test_xfer_file:
        cmd = utils.Cmd('wget', cfg.test_xfer_file)
        act.run(vmi_c, cmd)
        test_xfer_file = os.path.basename(cfg.test_xfer_file)
        logger.info('Downloading %s', test_xfer_file)
    act.run(vmi_c, "nautilus 2>/dev/null &")
    if cfg.xfer_args:
        cmd = utils.Cmd(dst_script, cfg.xfer_args, test_xfer_file)
    else:
        cmd = utils.Cmd(dst_script, test_xfer_file)
    logger.info('Sending command to client: %s', cmd)
    try:
        act.run(vmi_c, cmd)
    except aexpect.exceptions.ShellCmdError:
        logger.info('Cannot transfer a file.')
        utils.SpiceTestFail(test, "Test failed.")
    md5src = act.md5sum(vmi_c, test_xfer_file)
    try:
        md5dst = act.md5sum(
            vmi_g, os.path.join(homedir_g, 'Downloads', test_xfer_file))
    except aexpect.exceptions.ShellCmdError:
        logger.info('File is not transferred.')
        md5dst = None
    if md5src == md5dst:
        logger.info('%s transferred to guest VM', test_xfer_file)
        cmd1 = utils.Cmd('lsof')
        cmd2 = utils.Cmd('grep', '-q', '-s', test_xfer_file)
        cmd = utils.combine(cmd1, '|', cmd2)
        status, _ = act.rstatus(vmi_g, cmd)
        if status:
            logger.info('Transferred file %s is closed.', test_xfer_file)
            success = True
    elif cfg.xfer_args == '--negative':
        logger.info('File %s was not transferred.', test_xfer_file)
        success = True
    if not success:
        raise utils.SpiceTestFail(test, "Test failed.")