Ejemplo n.º 1
0
def install_rpm(vmi, rpm):
    """Install RPM package on a VM.

    Parameters
    ----------
    rpm : str
        Path to RPM to be installed. It could be path to .rpm file, or RPM
        name or URL.

    """
    utils.info(vmi, "Install RPM : %s.", rpm)
    pkg = rpm
    if rpm.endswith(".rpm"):
        pkg = os.path.split(rpm)[1]
        pkg = pkg[:-4]
    cmd = utils.Cmd("rpm", "-q", pkg)
    status, _ = act.rstatus(vmi, cmd)
    if status == 0:
        utils.info(vmi, "RPM %s is already installed.", pkg)
        return
    if utils.url_regex.match(rpm):
        utils.info(vmi, "Download RPM: %s.", rpm)
        cmd = utils.Cmd("curl", "-s", "-O", rpm)
        act.run(vmi, cmd, admin=True, timeout=500)
        rpm = os.path.split(rpm)[1]
    act.run(vmi, "yes | yum -y install %s" % rpm, admin=True, timeout=500)
Ejemplo n.º 2
0
def verify_virtio(vmi):
    """Verify Virtio-Serial linux driver is properly loaded.

    """
    cmd = ["lsmod", "|", "grep", "virtio_console"]
    cmd = ["ls", "/dev/virtio-ports/"]
    act.run(vmi, cmd)
Ejemplo n.º 3
0
def firefox_auto_open_vv(vmi):
    """Automatically open remote-viewer for proposed .vv file.

    Doesn't work as expected. See:

        https://github.com/SeleniumHQ/selenium/issues/3013

    See content type at:

        ~/.mozilla/firefox/<profile_name>/mimeTypes.rdf
        application/x-virt-viewer
    """
    pdir = vmi.firefox_profile_dir
    if not pdir:
        vmi.vm.error("Firefox profile dir is not defined")
        return
    user_js = os.path.join(pdir, "user.js")
    opts = []
    opts.append("browser.helperApps.neverAsk.saveToDisk")
    opts.append("browser.helperApps.neverAsk.openFile")
    cmd = utils.Cmd("test", "-e", user_js)
    status, _ = act.rstatus(vmi, cmd)
    if status == 0:
        for o in opts:
            utils.info(vmi, "Remove old value %s from Firefox profile: %s", o, user_js)
            cmd = utils.Cmd("sed", "-i", "-e", "/%s/d" % o, user_js)
            act.run(vmi, cmd)
    line = 'user_pref("browser.helperApps.neverAsk.openFile",' '"application/x-virt-viewer");'
    cmd1 = utils.Cmd("echo", line)
    cmd2 = utils.Cmd(user_js)
    cmd = utils.combine(cmd1, ">>", cmd2)
    utils.info(vmi, "Add new line %s to Firefox profile: %s", line, user_js)
    act.run(vmi, cmd)
Ejemplo n.º 4
0
def turn_firewall(vmi, state):
    utils.info(vmi, "Turn firewall: %r.", state)
    if utils.is_yes(state):
        raise NotImplemented
    else:
        cmd = utils.Cmd("iptables", "-F")
        act.run(vmi, cmd, admin=True)
Ejemplo n.º 5
0
def clear_cb(vmi):
    """Use the script to clear clipboard.
    """
    script = vmi.cfg.helper_cb
    dst_script = act.chk_deps(vmi, script)
    cmd = utils.Cmd(dst_script, "--clear")
    utils.info(vmi, "Clear clipboard.")
    act.run(vmi, cmd)
Ejemplo n.º 6
0
def imggen(vmi, img, size):
    """Generate an image file.
    """
    script = vmi.cfg.helper_cb
    dst_script = act.chk_deps(vmi, script)
    cmd = utils.Cmd(dst_script, "--genimg", size, img)
    utils.info(vmi, "Generate an %s image of %s size %s.", img, size)
    act.run(vmi, cmd)
Ejemplo n.º 7
0
def proc_is_active(vmi, pname):
    try:
        cmd = utils.Cmd("pgrep", "pname")
        act.run(vmi, cmd)
        res = True
    except aexpect.ShellCmdError:
        res = False
    return res
Ejemplo n.º 8
0
def img2cb(vmi, img):
    """Use the clipboard script to copy an image into the clipboard.
    """
    script = vmi.cfg.helper_cb
    dst_script = act.chk_deps(vmi, script)
    cmd = utils.Cmd(dst_script, "--img2cb", img)
    utils.info(vmi, "Put image %s in clipboard.", img)
    act.run(vmi, cmd, timeout=60)
Ejemplo n.º 9
0
def verify_vdagent(vmi):
    """Verifying vdagent is installed on a VM.

    """
    cmd1 = utils.Cmd("rpm", "-qa")
    cmd2 = utils.Cmd("grep", "spice-vdagentd")
    cmd = utils.combine(cmd1, "|", cmd2)
    act.run(vmi, cmd)
Ejemplo n.º 10
0
def text2cb(vmi, text):
    """Use the clipboard script to copy an image into the clipboard.
    """
    script = vmi.cfg.helper_cb
    dst_script = act.chk_deps(vmi, script)
    params = "--txt2cb"
    cmd = utils.Cmd(dst_script, "--txt2cb", text)
    utils.info(vmi, "Put in clipboard: %s", text)
    act.run(vmi, cmd)
Ejemplo n.º 11
0
 def is_active():
     utils.info(vmi, "Test if window is active: %s", pattern)
     win_id = act.run(vmi, cmd_win_id)  # Active windows ID.
     cmd = utils.Cmd("xprop", "-notype", "-id", win_id, prop)
     output = act.run(vmi, cmd)
     utils.info(vmi, "Current win name: %s", output)
     if pattern not in output:
         msg = "Can't find active window with pattern %s." % pattern
         raise utils.SpiceUtilsError(msg)  # TODO
     utils.info(vmi, "Found active window: %s.", pattern)
Ejemplo n.º 12
0
def dst_dir(vmi):
    dst_dir = vmi.cfg.dst_dir
    if dst_dir:
        return dst_dir
    cmd1 = utils.Cmd("getent", "passwd", vmi.cfg.username)
    cmd2 = utils.Cmd("cut", "-d:", "-f6")
    cmd = utils.combine(cmd1, "|", cmd2)
    out = act.run(vmi, cmd)
    home_dir = out.rstrip("\r\n")
    dst_dir = os.path.join(home_dir, "tp-spice")
    cmd = utils.Cmd("mkdir", "-p", dst_dir)
    act.run(vmi, cmd)
    vmi.cfg.dst_dir = dst_dir
    return dst_dir
Ejemplo n.º 13
0
def cb2img(vmi, img):
    """

    Parameters
    ----------
    img : str
        Where to save img.

    """
    script = vmi.cfg.helper_cb
    dst_script = act.chk_deps(vmi, script)
    cmd = utils.Cmd(dst_script, "--cb2img", img)
    utils.info(vmi, "Dump clipboard to image %s.", img)
    act.run(vmi, cmd, timeout=60)
Ejemplo n.º 14
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")
Ejemplo n.º 15
0
def rv_run(vmi, rcmd, ssn, env={}):
    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")
Ejemplo n.º 16
0
def turn_accessibility(vmi, on=True):
    """Turn accessibility on vm.

    Parameters
    ----------
    on : str
        Spice test object.

    """
    if utils.is_yes(on):
        val = "true"
    else:
        val = "false"
    cmd = utils.Cmd("gsettings", "set", "org.gnome.desktop.interface", "toolkit-accessibility", val)
    act.run(vmi, cmd)
Ejemplo n.º 17
0
def cb2text(vmi):
    script = vmi.cfg.helper_cb
    dst_script = act.chk_deps(vmi, script)
    cmd = utils.Cmd(dst_script, "--cb2stdout")
    text = act.run(vmi, cmd)
    utils.info(vmi, "Get from clipboard: %s", text)
    return text
Ejemplo n.º 18
0
def get_corners(vmi, win_title):
    """Gets the coordinates of the 4 corners of the window.

    Info
    ----
    http://www.x.org/archive/X11R6.8.0/doc/X.7.html#sect6

    Parameters
    ----------
    win_title : str
        XXX.

    Return
    ------
    list
        Corners in format: [('+470', '+187'), ('-232', '+187'),
                            ('-232', '-13'), ('+470', '-13')]

    """
    rv_xinfo_cmd = "xwininfo -name %s" % win_title
    rv_xinfo_cmd += " | grep Corners"
    cmd1 = utils.Cmd("xwininfo", "-name", win_title)
    cmd2 = utils.Cmd("grep", "Corners")
    cmd = utils.combine(cmd1, "|", cmd2)
    # Expected format:   Corners:  +470+187  -232+187  -232-13  +470-13
    raw_out = act.run(vmi, cmd)
    line = raw_out.strip()
    corners = [tuple(re.findall("[+-]\d+", i)) for i in line.split()[1:]]
    return corners
Ejemplo n.º 19
0
def set_resolution(vmi, res, display=None):
    """Sets resolution of qxl device on a VM.

    Parameters
    ----------
    res : str
        Resolution.
    display : str
        Target display.

    """

    if not display:
        display = act.get_connected_displays(vmi)[0]
    utils.info(vmi, "Setting resolution to %s.", res)
    cmd = utils.Cmd("xrandr", "--output", display, "--mode", res)
    act.run(vmi, cmd)
Ejemplo n.º 20
0
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
Ejemplo n.º 21
0
def print_rv_version(vmi):
    """Prints remote-viewer and spice-gtk version available inside.

    Parameters
    ----------
    rv_binary : str
        remote-viewer binary.

        if cfg.rv_ld_library_path:
            xxcmd = "LD_LIBRARY_PATH=/usr/local/lib %s" % cfg.rv_binary
        else:
            xxcmd = cfg.rv_binary
        try:
    """
    cmd = utils.Cmd(vmi.cfg.rv_binary, "-V")
    rv_ver = act.run(vmi, cmd)
    cmd = utils.Cmd(vmi.cfg.rv_binary, "--spice-gtk-version")
    spice_gtk_ver = act.run(vmi, cmd)
    utils.info(vmi, "remote-viewer version: %s", rv_ver)
    utils.info(vmi, "spice-gtk version: %s", spice_gtk_ver)
Ejemplo n.º 22
0
def get_wininfo(vmi, win_id):
    """Get xwininfo for windows of a specified ID.

    Return
    ------
        Output xwininfo -id %id on the session.

    """
    cmd = utils.Cmd("xwininfo", "-id", win_id)
    raw = act.run(vmi, cmd)
    return raw
Ejemplo n.º 23
0
def turn_accessibility(vmi, on=True):
    """Turn accessibility on vm.

    Parameters
    ----------
    on : str
        Spice test object.

    """
    if utils.is_yes(on):
        val = "true"
    else:
        val = "false"
    # gconftool-2 --get "/desktop/gnome/interface/accessibility"
    # temporarily (for a single session) enable Accessibility:
    # GNOME_ACCESSIBILITY=1
    # session.cmd("gconftool-2 --shutdown")
    utils.info(vmi, "Turning accessibility: %s.", val)
    cmd = utils.Cmd("gconftool-2", "--set", "/desktop/gnome/interface/accessibility", "--type", "bool", val)
    act.run(vmi, cmd)
Ejemplo n.º 24
0
def get_display_resolution(vmi):
    """Returns list of resolutions on all displays of a VM.

    Return
    ------
        List of resolutions.

    """
    cmd1 = utils.Cmd("xrandr")
    cmd2 = utils.Cmd("grep", "*")
    cmd = utils.combine(cmd1, "|", cmd2)
    raw = act.run(vmi, cmd)
    res = [a.split()[0] for a in raw.split("\n") if a is not ""]
    return res
Ejemplo n.º 25
0
def export_x2ssh(vmi, var_name, fallback=None, ssn=None):
    """Take value from X session and export it to ssh session. Useful to
    export variables such as 'DBUS_SESSION_BUS_ADDRESS', 'AT_SPI_BUS'.

    Parameters
    ----------
    var : str
        Variable name.
    fallback : Optional[str]
        If value is absent in X session, then use this value.

    """
    var_val = act.get_x_var(vmi, var_name)
    if not var_val:
        var_val = fallback
    if not ssn:
        ssn = act.new_ssn(vmi)
    if var_val:
        utils.info(vmi, "Export %s == %s", var_name, var_val)
        cmd = utils.Cmd("export", "%s=%s" % (var_name, var_val))
        act.run(vmi, cmd, ssn=ssn)
    else:
        utils.info(vmi, "Do not export %s var.", var_name)
Ejemplo n.º 26
0
def get_connected_displays(vmi):
    """Get list of video devices on a VM.

    Return
    ------
        List of active displays on the VM.

    """
    cmd1 = utils.Cmd("xrandr")
    cmd2 = utils.Cmd("grep", "-E", "[[:space:]]connected[[:space:]]")
    cmd = utils.combine(cmd1, "|", cmd2)
    raw = act.run(vmi, cmd)
    displays = [a.split()[0] for a in raw.split("n") if a is not ""]
    return displays
Ejemplo n.º 27
0
def lock_scr_off(vmi):
    """
    Info
    ----
        See: gsettings list-recursively or use dconf-editor.

        https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Desktop_Migration_and_Administration_Guide/custom-default-values-system-settings.html

        $ dconf dump /
    """
    utils.info(vmi, "Disable lock screen.")
    # The number of seconds of inactivity before the session is considered idle.
    cmd = utils.Cmd("gsettings", "set", "org.gnome.desktop.session", "idle-delay", "0")
    act.run(vmi, cmd)
    # Prevent the user to lock his screen.
    cmd = utils.Cmd("gsettings", "set", "org.gnome.desktop.lockdown", "disable-lock-screen", "true")
    act.run(vmi, cmd)
    act.run(vmi, cmd)
    # Set this to TRUE to lock the screen when the screensaver goes active.
    cmd = utils.Cmd("gsettings", "set", "org.gnome.desktop.screensaver", "lock-enabled", "false")
    act.run(vmi, cmd)
    # Whether this plugin would be activated by gnome-settings-daemon or not.
    cmd = utils.Cmd("gsettings", "set", "org.gnome.settings-daemon.plugins.power", "active", "false")
    act.run(vmi, cmd)
Ejemplo n.º 28
0
def get_window_props(vmi, win_id):
    """Get full properties of a window with speficied ID.

    Parameters
    ----------
    win_id : str
        X server id of a window.

    Return
    ------
        Returns output of xprop -id.

    """
    cmd = utils.Cmd("xprop", "-id", win_id)
    raw = act.run(vmi, cmd)
    return raw
Ejemplo n.º 29
0
def get_res(vmi):
    """Gets the resolution of a VM

    ..todo:: ? MONITOR # ?

    Return
    ------

    """
    cmd1 = utils.Cmd("xrandr", "-d", ":0")
    cmd1.append_raw("2>/dev/null")
    cmd2 = utils.Cmd("grep", "*")
    cmd = utils.combine(cmd1, "|", cmd2)
    guest_res_raw = act.run(vmi, cmd)
    guest_res = guest_res_raw.split()[0]
    return guest_res
Ejemplo n.º 30
0
def kill_by_name(vmi, app_name):
    """Kill selected app on selected VM.

    Parameters
    ----------
    app_name : str
        Name of the binary.
    XXX
    """
    cmd = utils.Cmd("pkill", app_name.split(os.path.sep)[-1])
    try:
        output = act.run(vmi, cmd)
    except aexpect.ShellCmdError:
        if output == 1:
            pass
        else:
            raise utils.SpiceUtilsError("Cannot kill it.")  # TODO
Ejemplo n.º 31
0
def run(vt_test, test_params, env):
    """Tests for SPICE remote-viewer client side.

    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.ClientTest(vt_test, test_params, env)
    vmi = test.vmi
    act.x_active(vmi)
    out = act.run(vmi, test_params['client_cmd'])
    assert test_params['client_output'] == out.rstrip()
Ejemplo n.º 32
0
def get_geom(vmi, win_title):
    """Gets the geometry of the rv_window.

    Parameters
    ----------
    win_title : str
        XXX.

    Returns
    -------
    tuple
        Geometry of RV window. (x,y)

    """
    xinfo_cmd = "xwininfo -name %s" % win_title
    cmd = utils.Cmd("xwininfo", "-name", win_title)
    cmd1 = utils.Cmd("grep", "geometry")
    xinfo_cmd += " | grep geometry"
    # Expected '  -geometry 898x700+470-13'
    out = act.run(vmi, cmd)
    res = re.findall("\d+x\d+", out)[0]
    utils.info(vmi, "Window %s has geometry: %s", win_title, res)
    return utils.str2res(res)
Ejemplo n.º 33
0
def get_x_var(vmi, var_name):
    """Gets the env variable value by its name from X session.

    Info
    ----
    It is no straight way to get variable value from X session. If you try to
    read var value from SSH session it could be different from X session var or
    absent. The strategy used in this function is:

        1. Find nautilus process.
        2. Read its /proc/$PID/environ

    Parameters
    ----------
    var_name : str
        Spice test object.

    Returns
    -------
    str
        Env variable value.

    """
    pattern = "(?<=(?:^{0}=|(?<=\n){0}=))[^\n]+".format(var_name)
    pids = act.wait_for_prog(vmi, "nautilus")
    ret = ""
    for pid in pids:
        cmd1 = utils.Cmd("cat", "/proc/%s/environ" % pid)
        cmd2 = utils.Cmd("xargs", "-n", "1", "-0", "echo")
        cmd = utils.combine(cmd1, "|", cmd2)
        out = act.run(vmi, cmd)
        val = re.findall(pattern, out)
        if val:
            ret = val[0]
    utils.info(vmi, "export %s=%s", var_name, ret)
    return ret
Ejemplo n.º 34
0
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.")
Ejemplo n.º 35
0
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.

    Notes
    -----
    Tests clean exit after shutting down the VM. Covers two cases:

        * Shutdown from the command line of the guest.
        * Shutdown from the qemu monitor.

    Verify after the shutdown:

        * Verifying the guest is down.
        * Verify the spice connection to the guest is no longer established.
        * Verify the remote-viewer process is not running.

    """
    test = stest.ClientGuestTest(vt_test, test_params, env)
    cfg = test.cfg
    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 test.cfg.shutdown_cmdline:
        test.vm_g.info("Shutting down from command line.")
        try:
            cmd = test.cfg_g.shutdown_command
            act.run(test.vmi_g, cmd, admin=True)
        except aexpect.ShellProcessTerminatedError:
            pass
    elif test.cfg.shutdown_qemu:
        test.vm_g.info("Shutting down from qemu monitor.")
        test.vm_g.monitor.system_powerdown()
    else:
        raise utils.SpiceTestFail(test, "Bad config.")
    # Test: guest VM is dead.

    @deco.retry(8, exceptions=(AssertionError, ))
    def is_dead():
        assert test.vm_g.is_dead(), "VM is alive."

    is_dead()
    test.vm_g.info("VM is dead.")
    # Test: no network connection.
    try:
        act.rv_chk_con(test.vmi_c)
    except utils.SpiceUtilsError:
        pass
    else:
        raise utils.SpiceTestFail(test, "RV still connected.")
    # Test: no RV proccess on client.
    if act.proc_is_active(test.vmi_c, 'remote-viewer'):
        raise utils.SpiceTestFail(test, "RV is still running on the client.")
Ejemplo n.º 36
0
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