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
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
from rhui3_tests_lib.rhuimanager_entitlement import RHUIManagerEntitlements from rhui3_tests_lib.rhuimanager_instance import RHUIManagerInstance from rhui3_tests_lib.rhuimanager_repo import RHUIManagerRepo from rhui3_tests_lib.rhuimanager_sync import RHUIManagerSync from rhui3_tests_lib.util import Util logging.basicConfig(level=logging.DEBUG) urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) RHUA = ConMgr.connect() # To make this script communicate with a client machine different from cli01.example.com, run: # export RHUICLI=hostname # in your shell before running this script, replacing "hostname" with the actual client host name. # This allows for multiple client machines in one stack. CLI = ConMgr.connect(getenv("RHUICLI", ConMgr.get_cli_hostnames()[0])) CDS = ConMgr.connect(ConMgr.get_cds_hostnames()[0]) CUSTOM_REPO = "custom-i386-x86_64" CUSTOM_PATH = CUSTOM_REPO.replace("-", "/") CUSTOM_RPMS_DIR = "/tmp/extra_rhui_files" LEGACY_CA_FILE = "legacy_ca.crt" TMPDIR = mkdtemp() class TestClient(object): ''' class for client tests ''' def __init__(self):
import csv 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"]]
from os.path import basename import random import logging import nose from stitches.expect import CTRL_C, Expect from rhui3_tests_lib.conmgr import ConMgr, SUDO_USER_NAME, SUDO_USER_KEY 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.util import Util logging.basicConfig(level=logging.DEBUG) CDS_HOSTNAMES = ConMgr.get_cds_hostnames() RHUA = ConMgr.connect() CDS = [ConMgr.connect(host) for host in CDS_HOSTNAMES] def setup(): ''' announce the beginning of the test run ''' print("*** Running %s: *** " % basename(__file__)) def test_01_init(): ''' log in to RHUI
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)
from stitches.expect import Expect from rhui3_tests_lib.conmgr import ConMgr from rhui3_tests_lib.helpers import Helpers from rhui3_tests_lib.rhuimanager import RHUIManager from rhui3_tests_lib.rhuimanager_instance import RHUIManagerInstance from rhui3_tests_lib.sos import Sos logging.basicConfig(level=logging.DEBUG) TMPDIR = mkdtemp() SOSREPORT_LOCATION_RHUA = join(TMPDIR, "sosreport_location_rhua") SOSREPORT_LOCATION_CDS = join(TMPDIR, "sosreport_location_cds") CONNECTION_RHUA = RHUA = ConMgr.connect() CONNECTION_CDS = ConMgr.connect(ConMgr.get_cds_hostnames()[0]) CDS_LB = ConMgr.get_cds_lb_hostname() WANTED_FILES_RHUA = [ "/etc/rhui-installer/answers.yaml", "/etc/rhui/rhui-tools.conf", "/root/.rhui/rhui.log", "/var/log/kafo/configuration.log", "/var/log/rhui-subscription-sync.log" ] WANTED_FILES_CDS = [ "/etc/httpd/conf.d/03-crane.conf", "/etc/httpd/conf.d/25-%s.conf" % CDS_LB, "/etc/pulp/", "/var/log/httpd/%s_access_ssl.log" % CDS_LB, "/var/log/httpd/%s_error_ssl.log" % CDS_LB ] CMD_RHUA = "rhui-manager status"