Exemple #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)
Exemple #2
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)
    assert exit_code == 0
    act.info(test.vmi, "Mention about qxl: %s." % output)
Exemple #3
0
def deploy_epel_repo(vmi):
    """Deploy epel repository to RHEL VM.

    """
    # Check existence of epel repository
    cmd = utils.Cmd("test", "-f", "/etc/yum.repos.d/epel.repo")
    status, _ = act.rstatus(vmi, cmd)
    if status:
        arch = vmi.ssn.cmd("arch")
        if "i686" in arch:
            arch = "i386"
        else:
            arch = arch[:-1]
        if "release 5" in vmi.ssn.cmd("cat /etc/redhat-release"):
            cmd = (
                "yum -y localinstall http://download.fedoraproject.org/"
                "pub/epel/5/%s/epel-release-5-4.noarch.rpm 2>&1" % arch
            )
            utils.info(vmi, "Installing EPEL repository.")
            vmi.ssn.cmd(cmd)
        elif "release 6" in vmi.ssn.cmd("cat /etc/redhat-release"):
            cmd = (
                "yum -y localinstall http://download.fedoraproject.org/"
                "pub/epel/6/%s/epel-release-6-8.noarch.rpm 2>&1" % arch
            )
            utils.info(vmi, "Installing EPEL repository.")
            vmi.ssn.cmd(cmd)
        else:
            raise Exception("Unsupported RHEL guest")
Exemple #4
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)
Exemple #5
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)
Exemple #6
0
def chk_deps(vmi, fname, dst_dir=None):
    if not dst_dir:
        dst_dir = act.dst_dir(vmi)
    dst_path = os.path.join(dst_dir, fname)
    cmd = utils.Cmd("test", "-e", dst_path)
    status, _ = act.rstatus(vmi, cmd)
    if status != 0:
        act.cp_deps(vmi, fname, dst_path)
    return dst_path
Exemple #7
0
def x_active(vmi):
    """Test if X session is active. Do nothing is X active. Othrerwise
    throw exception.
    """
    cmd = utils.Cmd("gnome-terminal", "-e", "/bin/true")
    status, _ = act.rstatus(vmi, cmd)
    if status:
        raise utils.SpiceUtilsError("X session is not present.")
    utils.info(vmi, "X session is present.")
Exemple #8
0
def x_turn_on(vmi):
    ssn = act.new_admin_ssn(vmi)
    runner = remote.RemoteRunner(session=ssn)
    srv_mng = service.Factory.create_service(run=runner.run)
    srv_mng.set_target("graphical.target")  # pylint: disable=no-member
    cmd1 = utils.Cmd("ss", "-x", "src", "*X11-unix*")
    cmd2 = utils.Cmd("grep", "-q", "-s", "X11")
    cmd = utils.combine(cmd1, "|", cmd2)
    status, _ = act.rstatus(vmi, cmd)
    assert status == 0, "X is: off. But it should not."  # TODO
    utils.info(vmi, "X is: on.")
Exemple #9
0
def check_usb_policy(vmi):
    """Check USB policy in polkit file.

    Returns
    -------
    bool
        Status of grep command. If pattern is found 0 is returned. 0 in python
        is False so negative of grep is returned.

        .. todo: Move USB_POLICY_FILE to cfg.

    """
    cmd = utils.Cmd("grep", "<allow_any>yes", USB_POLICY_FILE)  # TODO
    status, _ = act.rstatus(vmi, cmd)
    utils.info(vmi, "USB policy is: %s.", status)
    return not status
Exemple #10
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:
        proxy_port = "3128"
        if "http" in cfg.spice_proxy:
            split = cfg.spice_proxy.split('//')[1].split(':')
        else:
            split = cfg.spice_proxy.split(':')
        remote_ip = split[0]
        if len(split) > 1:
            proxy_port = split[1]
        logger.info("Proxy port to inspect: %s", proxy_port)
    else:
        remote_ip = utils.get_host_ip(test)
    rv_binary = os.path.basename(cfg.rv_binary)
    cmd1 = utils.Cmd("netstat", "-p", "-n")
    grep_regex = "^tcp.*:.*%s.*ESTABLISHED.*%s.*" % (remote_ip, rv_binary)
    cmd2 = utils.Cmd("grep", "-e", grep_regex)
    cmd = utils.combine(cmd1, "|", cmd2)
    time.sleep(5)  # Wait all RV Spice links raise up.
    status, netstat_out = act.rstatus(vmi, cmd, admin=True)
    if status:
        raise utils.SpiceUtilsError("No active RV connections.")
    proxy_port_count = 0
    if cfg.spice_proxy:
        proxy_port_count = netstat_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
    port_count = netstat_out.count(port)
    test.vm_g.info("Active ports %s: %s", port, port_count)
    tls_port_count = 0
    if tls_port:
        tls_port_count = netstat_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)
    for line in netstat_out.split('\n'):
        for p in port, tls_port, proxy_port:
            if p and p in line and "ESTABLISHED" not in line:
                raise RVSessionConnect(test, "Missing active link at port %s",
                                       p)
    output = test.vm_g.monitor.cmd("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)
        if host_ip[1:len(host_ip) - 1] in 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")
Exemple #11
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 #12
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")
Exemple #13
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.")