コード例 #1
0
ファイル: vm_actions_rv.py プロジェクト: spiceqa/tp-spice
def rv_url(vmi):
    """Cacert subj is in format for create certificate(with '/' delimiter)
    remote-viewer needs ',' delimiter. And also is needed to remove first
    character (it's '/').

    If it's invalid implicit, a remote-viewer connection will be attempted
    with the hostname, since ssl certs were generated with the ip address.

    """
    test = vmi.test
    port = test.kvm_g.spice_port
    tls_port = test.kvm_g.spice_tls_port
    #escape_char = test.cfg_c.shell_escape_char or '\\'
    host_ip = utils.get_host_ip(test)
    # SSL
    if utils.is_yes(vmi.test.kvm_g.spice_ssl):
        if vmi.cfg.ssltype == "invalid_implicit_hs" or \
                "explicit" in vmi.cfg.ssltype:
            hostname = socket.gethostname()
            url = "spice://%s?tls-port=%s&port=%s" % (hostname, tls_port,
                                                        port)
        else:
            url = "spice://%s?tls-port=%s&port=%s" % (host_ip, tls_port,
                                                        port)
        return url
    # No SSL
    url = "spice://%s?port=%s" % (host_ip, port)
    return url
コード例 #2
0
def rv_url(vmi):
    """Cacert subj is in format for create certificate(with '/' delimiter)
    remote-viewer needs ',' delimiter. And also is needed to remove first
    character (it's '/').

    If it's invalid implicit, a remote-viewer connection will be attempted
    with the hostname, since ssl certs were generated with the ip address.

    """
    test = vmi.test
    port = test.kvm_g.spice_port
    tls_port = test.kvm_g.spice_tls_port
    #escape_char = test.cfg_c.shell_escape_char or '\\'
    host_ip = utils.get_host_ip(test)
    # SSL
    if utils.is_yes(vmi.test.kvm_g.spice_ssl):
        if vmi.cfg.ssltype == "invalid_implicit_hs" or \
                "explicit" in vmi.cfg.ssltype:
            hostname = socket.gethostname()
            url = "spice://%s?tls-port=%s&port=%s" % (hostname, tls_port, port)
        else:
            url = "spice://%s?tls-port=%s&port=%s" % (host_ip, tls_port, port)
        return url
    # No SSL
    url = "spice://%s?port=%s" % (host_ip, port)
    return url
コード例 #3
0
def gen_vv_file(vmi):
    """Generates vv file for remote-viewer.

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

    """
    test = vmi.test
    cfg = vmi.cfg
    host_dir = os.path.expanduser('~')
    fpath = os.path.join(host_dir, cfg.rv_file)
    rv_file = open(fpath, 'w')
    rv_file.write("[virt-viewer]\n")
    rv_file.write("type=%s\n" % cfg.display)
    rv_file.write("host=%s\n" % utils.get_host_ip(test))
    rv_file.write("port=%s\n" % test.kvm_g.spice_port)
    if cfg.ticket_send:
        rv_file.write("password=%s\n" % cfg.ticket_send)
    if utils.is_yes(test.kvm_g.spice_ssl):
        rv_file.write("tls-port=%s\n" % test.kvm_g.spice_tls_port)
        rv_file.write("tls-ciphers=DEFAULT\n")
    host_subj = utils.get_host_subj(test)
    if host_subj:
        rv_file.write("host-subject=%s\n" % host_subj)
    cacert_host = utils.cacert_path_host(test)
    if cacert_host:
        cert = open(cacert_host)
        cert_auth = cert.read()
        cert_auth = cert_auth.replace('\n', r'\n')
        rv_file.write("ca=%s\n" % cert_auth)
    if cfg.full_screen:
        rv_file.write("fullscreen=1\n")
    if cfg.spice_proxy:
        rv_file.write("proxy=%s\n" % cfg.spice_proxy)
    if cfg.min_ver:
        if cfg.min_ver == "higher":
            real_ver = act.rpm_version(vmi, "virt-viewer")[0]
            v, rev = real_ver.split('.')
            ver = v + '.' + str(int(rev) + 1)
        else:
            ver = cfg.min_ver
        rv_file.write("versions=%s:%s\n" % (cfg.os_variant, ver))
    if cfg.new_ver:
        rv_file.write("newer-version-url=%s\n" % cfg.new_ver)
    if cfg.rv_debug:
        """TODO"""
        # rv_cmd.append("--spice-debug")  ..todo:: XXX TODO
    rv_file.close()
    return fpath
コード例 #4
0
ファイル: vm_actions_rv.py プロジェクト: spiceqa/tp-spice
def gen_vv_file(vmi):
    """Generates vv file for remote-viewer.

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

    """
    test = vmi.test
    cfg = vmi.cfg
    host_dir = os.path.expanduser('~')
    fpath = os.path.join(host_dir, cfg.rv_file)
    rv_file = open(fpath, 'w')
    rv_file.write("[virt-viewer]\n")
    rv_file.write("type=%s\n" % cfg.display)
    rv_file.write("host=%s\n" % utils.get_host_ip(test))
    rv_file.write("port=%s\n" % test.kvm_g.spice_port)
    if cfg.ticket_send:
        rv_file.write("password=%s\n" % cfg.ticket_send)
    if utils.is_yes(test.kvm_g.spice_ssl):
        rv_file.write("tls-port=%s\n" % test.kvm_g.spice_tls_port)
        rv_file.write("tls-ciphers=DEFAULT\n")
    host_subj = utils.get_host_subj(test)
    if host_subj:
        rv_file.write("host-subject=%s\n" % host_subj)
    cacert_host = utils.cacert_path_host(test)
    if cacert_host:
        cert = open(cacert_host)
        cert_auth = cert.read()
        cert_auth = cert_auth.replace('\n', r'\n')
        rv_file.write("ca=%s\n" % cert_auth)
    if cfg.full_screen:
        rv_file.write("fullscreen=1\n")
    if cfg.spice_proxy:
        rv_file.write("proxy=%s\n" % cfg.spice_proxy)
    if cfg.rv_debug:
        """TODO"""
        # rv_cmd.append("--spice-debug")  ..todo:: XXX TODO
    rv_file.close()
    return fpath
コード例 #5
0
ファイル: vm_actions_rv.py プロジェクト: spiceqa/tp-spice
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")
コード例 #6
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")