Exemple #1
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
    act.x_active(test.vmi_c)
    act.x_active(test.vmi_g)
    res_target = "1600x1200"
    res_reset = "640x480"
    act.set_resolution(test.vmi_c, res_target)
    act.set_resolution(test.vmi_g, res_reset)
    with act.new_ssn_context(test.vmi_c, name="Remote Viewer") as ssn:
        act.rv_connect(test.vmi_c, ssn)
        act.rv_chk_con(test.vmi_c)
        res_g = act.get_display_resolution(test.vmi_g)[0]
        res_c = act.get_display_resolution(test.vmi_c)[0]
    logger.info("Target: %s, client: %s, guest: %s.", res_target, res_c, res_g)
    err_info = "Guest res should have adjusted to client, but it hasn't."
    assert res_target == res_c == res_g, err_info
Exemple #2
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
    act.x_active(test.vmi_c)
    act.x_active(test.vmi_g)
    with act.new_ssn_context(test.vmi_c,
                             dogtail_ssn=test.vmi_c.vm.is_rhel8(),
                             name="Remote Viewer") as ssn:
        act.rv_connect(test.vmi_c, ssn)
        try:
            act.rv_chk_con(test.vmi_c)
        except utils.SpiceUtilsError as e:
            logger.info("Test failed as expected. Reason: %s", e)
        else:
            raise exceptions.TestFail(
                "RV connection was established when it was supposed to fail.")
Exemple #3
0
def run(vt_test, test_params, env):
    """Tests for Remote Desktop connection. Tests expect that remote-viewer
    will be executed from guest 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.

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

    """
    test = stest.ClientGuestTest(vt_test, test_params, env)
    cfg = test.cfg
    cmd_g = test.cmd_g
    test.cmd_c.reset_gui()
    cmd_g.reset_gui()
    rv_ssn.connect(test)
    if cfg.spice_vdagent_stop_log:
        logger.info("Inspect logs for stop action.")
        if not cmd_g.vdagent_is_running():
            cmd_g.start_vdagent()
        cmd_g.stop_vdagent()
        cmd = "tail -n 3 %s | grep 'vdagentd quiting'" % cfg.vdagent_log
        test.vm_g.assn_g.cmd(cmd)
    if cfg.spice_vdagent_start_log:
        logger.info("Inspect logs for start action.")
        if cmd_g.vdagent_is_active():
            cmd_g.stop_vdagent()
        cmd_g.start_vdagent()
        cmd = "tail -n 2 %s | grep 'opening vdagent virtio channel'" % \
            cfg.vdagent_log
        test.vm_g.assn_g.cmd(cmd)
    if cfg.spice_vdagent_restart_log:
        cmd_g.restart_vdagent()
        cmd = "tail -n 2 %s | grep 'opening vdagent virtio channel'" % \
            cfg.vdagent_log
        test.vm_g.assn_g.cmd(cmd)
    if cfg.spice_vdagent_copypaste:
        # Script location: avocado-vt/shared/scripts/cb.py
        script_path = os.path.join(test.virtdir, "scripts", cfg.guest_script)
        test.vm_g.copy_files_to(script_path, cfg.dst_dir)
        cmd = ('echo "SPICE_VDAGENTD_EXTRA_ARGS=-dd > '
               '/etc/sysconfig/spice-vdagentd')
        test.vm_g.assn_g.cmd(cmd)
        cmd_g.restart_vdagent()
        script_call = os.path.join(cfg.dst_dir, cfg.guest_script)
        cmd = "%s %s %s %s" % (cfg.interpreter, script_call, cfg.script_params,
                               cfg.text_to_test)
        test.vm_g.assn_g.cmd(cmd)
        cmd = "tail -n 3 " + cfg.vdagent_log + " | grep 'clipboard grab'"
        test.vm_g.assn_g.cmd(cmd)
Exemple #4
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)
    act.x_active(test.vmi_c)
    act.x_active(test.vmi_g)
    with act.new_ssn_context(test.vmi_c,
                             dogtail_ssn=test.vmi_c.vm.is_rhel8(),
                             name="Remote Viewer") as ssn:
        act.rv_connect(test.vmi_c, ssn)
        act.rv_chk_con(test.vmi_c)
Exemple #5
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.")
Exemple #6
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
    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.clear_cb(test.vmi_g)
    act.clear_cb(test.vmi_c)
    if cfg.vdagent_action:
        if cfg.vdagent_action == "stop":
            act.service_vdagent(test.vmi_g, "mask")
        act.service_vdagent(test.vmi_g, cfg.vdagent_action)
    if cfg.guest2client:
        src = test.vmi_g
        dst = test.vmi_c
    elif cfg.client2guest:
        src = test.vmi_c
        dst = test.vmi_g
    success = False
    if cfg.copy_text:
        act.text2cb(src, cfg.text)
        try:
            text = act.cb2text(dst)
        except aexpect.exceptions.ShellCmdError:
            logger.info('Cannot paste from buffer.')
        else:
            if cfg.text in text:
                success = True
    elif cfg.copy_text_big:
        act.gen_text2cb(src, cfg.kbytes)
        act.cb2file(src, cfg.dump_file)
        md5src = act.md5sum(src, cfg.dump_file)
        try:
            act.cb2file(dst, cfg.dump_file)
        except aexpect.exceptions.ShellCmdError:
            logger.info('Cannot paste from buffer.')
        else:
            md5dst = act.md5sum(dst, cfg.dump_file)
            if md5src == md5dst:
                success = True
    elif cfg.copy_img:
        dst_img = os.path.join(act.dst_dir(src), cfg.test_image)
        act.imggen(src, dst_img, cfg.test_image_size)
        act.img2cb(src, dst_img)
        act.cb2img(src, cfg.dump_img)
        try:
            act.cb2img(dst, cfg.dump_img)
        except aexpect.exceptions.ShellCmdError:
            logger.info('Cannot paste from buffer.')
        else:
            md5src = act.md5sum(src, cfg.dump_img)
            md5dst = act.md5sum(dst, cfg.dump_img)
            if md5src == md5dst:
                success = True

    if cfg.negative and success or not cfg.negative and not success:
        raise utils.SpiceTestFail(test, "Test failed.")
Exemple #7
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
Exemple #8
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.")
Exemple #9
0
def test(vt_test, test_params, env):
    """Playback of audio stream 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
    act.x_active(test.vmi_c)
    act.x_active(test.vmi_g)
    ssn_c = act.new_ssn(test.vmi_c)
    ssn_g = act.new_ssn(test.vmi_g)
    # Get default sink at the client.
    cmd = r"pacmd stat | grep 'Default sink name' | " \
        r"sed -e 's/^.*[[:space:]]//'"
    try:
        def_sink = ssn_c.cmd(cmd).rstrip('\r\n')
    except aexpect.ShellCmdError as excp:
        raise utils.SpiceTestFail(test, "Test failed: %s" % str(excp))
    logging.info("Default sink at client is: %s", def_sink)
    # Create RV session
    env_local = {}
    if cfg.rv_record:
        env_local["PULSE_SOURCE"] = "%s.monitor" % def_sink
    ssn = act.new_ssn(test.vmi_c)
    act.rv_connect(test.vmi_c, ssn, env=env_local)
    ret, out = commands.getstatusoutput(MAKE_WAV)
    if ret:
        errmsg = "Cannot generate specimen WAV file: %s" % out
        raise utils.SpiceTestFail(test, errmsg)
    play_cmd = "aplay %s &> /dev/null &" % cfg.audio_tgt
    rec_cmd = "arecord -d %s -f cd %s" % (cfg.audio_time, cfg.audio_rec)
    # Check test type
    if cfg.rv_record:
        logging.info("Recording test. Player is client. Recorder is guest.")
        player = ssn_c
        recorder = ssn_g
        vm_recorder = test.vm_g
        vm_player = test.vm_c
    else:
        logging.info("Playback test. Player is guest. Recorder is client.")
        env_var = "PULSE_SOURCE=%s.monitor" % def_sink
        rec_cmd = env_var + " " + rec_cmd
        player = ssn_g
        recorder = ssn_c
        vm_recorder = test.vm_c
        vm_player = test.vm_g
    vm_player.copy_files_to(SPECIMEN_FILE, cfg.audio_tgt)
    time.sleep(2)  # wait till everything is set up
    player.cmd(play_cmd)
    if cfg.config_test == "migration":
        bguest = utils_misc.InterruptedThread(test.vm_g.migrate, kwargs={})
        bguest.start()
    try:
        recorder.cmd(rec_cmd, timeout=500)
    except aexpect.ShellCmdError as excp:
        raise utils.SpiceTestFail(test, str(excp))
    if cfg.config_test == "migration":
        bguest.join()
    vm_recorder.copy_files_from(cfg.audio_rec, RECORDED_FILE)
    if not verify_recording(RECORDED_FILE, cfg):
        raise utils.SpiceTestFail(test, "Cannot verify recorded file.")
    if cfg.rv_reconnect:
        act.rv_disconnect(test.vmi_c)
        act.rv_connect(test.vmi_c, ssn)
        try:
            recorder.cmd(rec_cmd, timeout=500)
        except aexpect.ShellCmdError as excp:
            raise utils.SpiceTestFail(test, str(excp))
        vm_recorder.copy_files_from(cfg.audio_rec, RECORDED_FILE)
        if not verify_recording(RECORDED_FILE, cfg):
            raise utils.SpiceTestFail(test, "Cannot verify recorded file.")
Exemple #10
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.")