Пример #1
0
 def delete(connection, node_type, hostnames="", force=False):
     '''
     Reinstall one or more CDS or HAProxy nodes.
     Return True if the command exited with 0, and False otherwise.
     Note to the caller: Trust no one! Check for yourself if the nodes have really been deleted.
     '''
     _validate_node_type(node_type)
     if not hostnames:
         if node_type == "cds":
             hostnames = ConMgr.get_cds_hostnames()
         elif node_type == "haproxy":
             hostnames = ConMgr.get_haproxy_hostnames()
     cmd = "rhui %s delete %s" % (node_type, " ".join(hostnames))
     if force:
         cmd += " -f"
     return connection.recv_exit_status(cmd, timeout=180) == 0
Пример #2
0
 def add(connection, node_type,
         hostname="", ssh_user=SUDO_USER_NAME, keyfile_path=SUDO_USER_KEY,
         force=False, unsafe=False):
     '''
     Add a CDS or HAProxy node.
     If hostname is empty, ConMgr will be used to determine the default one for the node type
     Return True if the command exited with 0, and False otherwise.
     Note to the caller: Trust no one! Check for yourself if the node has really been added.
     '''
     _validate_node_type(node_type)
     if not hostname:
         if node_type == "cds":
             hostname = ConMgr.get_cds_hostnames()[0]
         elif node_type == "haproxy":
             hostname = ConMgr.get_haproxy_hostnames()[0]
     cmd = "rhui %s add %s %s %s" % (node_type, hostname, ssh_user, keyfile_path)
     if force:
         cmd += " -f"
     if unsafe:
         cmd += " -u"
     return connection.recv_exit_status(cmd, timeout=300) == 0
Пример #3
0
import logging
from os.path import basename
import subprocess

import nose

from rhui3_tests_lib.conmgr import ConMgr
from rhui3_tests_lib.rhuimanager import RHUIManager
from rhui3_tests_lib.rhuimanager_instance import RHUIManagerInstance

logging.basicConfig(level=logging.DEBUG)

HOSTNAMES = {
    "RHUA": ConMgr.get_rhua_hostname(),
    "CDS": ConMgr.get_cds_hostnames(),
    "HAProxy": ConMgr.get_haproxy_hostnames()
}
PORTS = {"puppet": 8140, "https": 443, "crane": 5000}
PROTOCOL_TEST_CMD = "echo | openssl s_client -%s -connect %s:%s; echo $?"
# these are in fact the s_client options for protocols, just without the dash
PROTOCOLS = {"good": ["tls1_2"], "bad": ["ssl3", "tls1", "tls1_1"]}
RESULTS = {
    "good": "Secure Renegotiation IS supported",
    "bad": "Secure Renegotiation IS NOT supported"
}

# connections to the RHUA and the HAProxy nodes
RHUA = ConMgr.connect()
HAPROXIES = [ConMgr.connect(host) for host in HOSTNAMES["HAProxy"]]

Пример #4
0
 def add_instance(connection,
                  screen,
                  hostname="",
                  user_name=SUDO_USER_NAME,
                  ssh_key_path=SUDO_USER_KEY,
                  update=False):
     '''
     Register (add) a new CDS or HAProxy instance
     @param hostname instance, or the default value for the screen type as ConMgr knows it
     @param update: Bool; update the cds or hap if it is already tracked or raise an exception
     '''
     if not hostname:
         if screen == "cds":
             hostname = ConMgr.get_cds_hostnames()[0]
         elif screen == "loadbalancers":
             hostname = ConMgr.get_haproxy_hostnames()[0]
         else:
             raise ValueError("hostname not given and screen invalid")
     # first check if the RHUA knows the host's SSH key, because if so, rhui-manager
     # won't ask you to confirm the key
     key_check_cmd = "ssh-keygen -F %s" % hostname
     # check if the host is known
     known_host = connection.recv_exit_status(key_check_cmd) == 0
     # run rhui-manager and add the instance
     RHUIManager.screen(connection, screen)
     Expect.enter(connection, "a")
     Expect.expect(connection, ".*Hostname of the .*instance to register:")
     Expect.enter(connection, hostname)
     state = Expect.expect_list(connection, [ \
         (re.compile(".*Username with SSH access to %s and sudo privileges:.*" % hostname,
                     re.DOTALL), 1),
         (re.compile(r".*instance with that hostname exists.*Continue\?\s+\(y/n\): ",
                     re.DOTALL), 2)
                                            ])
     if state == 2:
         # cds or haproxy of the same hostname is already being tracked
         if not update:
             # but we don't wish to update its config: say no, quit rhui-manager, and raise
             # an exception
             Expect.enter(connection, "n")
             RHUIManager.quit(connection)
             raise InstanceAlreadyExistsError("%s already tracked but update wasn't required" % \
                                              hostname)
         else:
             # we wish to update, send 'y' answer
             Expect.enter(connection, "y")
             # the question about user name comes now
             Expect.expect(
                 connection,
                 "Username with SSH access to %s and sudo privileges:" %
                 hostname)
     # if the execution reaches here, uesername question was already asked
     Expect.enter(connection, user_name)
     Expect.expect(
         connection,
         "Absolute path to an SSH private key to log into %s as ec2-user:"******".*Cannot find file, please enter a valid path.*",
                      re.DOTALL), 1),
          (re.compile(".*Checking that instance ports are reachable.*",
                      re.DOTALL), 2)])
     if state == 1:
         # don't know how to continue with invalid path: raise an exception
         Expect.enter(connection, CTRL_C)
         Expect.enter(connection, "q")
         raise InvalidSshKeyPath(ssh_key_path)
     # all OK
     # if the SSH key is unknown, rhui-manager now asks you to confirm it; say yes
     if not known_host:
         Expect.enter(connection, "y")
     # some installation and configuration through Puppet happens here, let it take its time
     RHUIManager.quit(connection, "The .*was successfully configured.", 180)
Пример #5
0
import logging
import nose

from rhui3_tests_lib.conmgr import ConMgr
from rhui3_tests_lib.helpers import Helpers
from rhui3_tests_lib.rhui_cmd import RHUICLI
from rhui3_tests_lib.rhuimanager import RHUIManager
from rhui3_tests_lib.rhuimanager_instance import RHUIManagerInstance

logging.basicConfig(level=logging.DEBUG)

# check if (at least) two CDS nodes are actually available
CDS_HOSTNAMES = ConMgr.get_cds_hostnames()
CDS2_EXISTS = len(CDS_HOSTNAMES) > 1

HA_HOSTNAME = ConMgr.get_haproxy_hostnames()[0]

RHUA = ConMgr.connect()
HAPROXY = ConMgr.connect(HA_HOSTNAME)


def setup():
    """announce the beginning of the test run"""
    print("*** Running %s: *** " % basename(__file__))


def test_01_login_add_hap():
    """log in to RHUI, add an HAProxy Load-balancer"""
    RHUIManager.initial_run(RHUA)
    RHUIManagerInstance.add_instance(RHUA, "loadbalancers")