コード例 #1
0
 def initial_run(connection, username="******", password="******"):
     '''
     Run rhui-manager and make sure we're logged in, then quit it.
     '''
     Expect.enter(connection, "rhui-manager")
     state = Expect.expect_list(
         connection, [(re.compile(".*RHUI Username:.*", re.DOTALL), 1),
                      (re.compile(r".*rhui \(home\) =>.*", re.DOTALL), 2)])
     if state == 1:
         Expect.enter(connection, username)
         Expect.expect(connection, "RHUI Password:"******".*Invalid login.*", re.DOTALL), 1),
              (re.compile(r".*rhui \(home\) =>.*", re.DOTALL), 2)])
         if password_state == 1:
             initial_password = Util.get_initial_password(connection)
             if not initial_password:
                 raise RuntimeError(
                     "Could not get the initial rhui-manager password.")
             Expect.enter(connection, "rhui-manager")
             Expect.expect(connection, ".*RHUI Username:"******"RHUI Password:"******"rhui \(home\) =>")
     Expect.enter(connection, "q")
コード例 #2
0
 def initial_run(connection, username="******", password="******"):
     '''
     Do rhui-manager initial run
     '''
     Expect.enter(connection, "rhui-manager")
     state = Expect.expect_list(
         connection, [(re.compile(".*RHUI Username:.*", re.DOTALL), 1),
                      (re.compile(".*rhui \(home\) =>.*", re.DOTALL), 2)])
     if state == 1:
         Expect.enter(connection, username)
         Expect.expect(connection, "RHUI Password:"******".*Invalid login.*", re.DOTALL), 1),
              (re.compile(".*rhui \(home\) =>.*", re.DOTALL), 2)])
         if password_state == 1:
             initial_password = Util.get_initial_password(connection)
             Expect.enter(connection, "rhui-manager")
             Expect.expect(connection, ".*RHUI Username:"******"RHUI Password:"******"rhui \(home\) =>")
         else:
             pass
     else:
         # initial step was already performed by someone
         pass
コード例 #3
0
    def add_instance(connection,
                     screen,
                     hostname,
                     user_name="ec2-user",
                     ssh_key_path="/root/.ssh/id_rsa_rhua",
                     update=False):
        '''
        Register (add) a new CDS or HAProxy instance
        @param hostname instance
        @param update: Bool; update the cds or hap if it is already tracked or raise ExpectFailed
        '''

        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(".*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: raise
                raise ExpectFailed(
                    "%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),
                                                (PROCEED_PATTERN, 2)])
        if state == 1:
            # don't know how to continue with invalid path: raise
            Expect.enter(connection, CTRL_C)
            Expect.enter(connection, "q")
            raise InvalidSshKeyPath(ssh_key_path)
        # all OK, confirm
        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)
コード例 #4
0
 def add_cds(connection, clustername, cdsname, hostname="", displayname=""):
     '''
     register (add) a new CDS instance
     '''
     RHUIManager.screen(connection, "cds")
     RHUIManagerCds._add_cds_part1(connection, cdsname, hostname, displayname)
     state = Expect.expect_list(connection, [(re.compile(".*Enter a CDS cluster name:.*", re.DOTALL), 1),
                                             (re.compile(".*Select a CDS cluster or enter a new one:.*", re.DOTALL), 2)])
     if state == 1:
         Expect.enter(connection, clustername)
     else:
         Expect.enter(connection, 'b')
         Expect.expect(connection, "rhui \(cds\) =>")
         RHUIManagerCds._add_cds_part1(connection, cdsname, hostname, displayname)
         RHUIManagerCds._select_cluster(connection, clustername)
     # We need to compare the output before proceeding
     checklist = ["Hostname: " + cdsname]
     if hostname != "":
         checklist.append("Client Hostname: " + hostname)
     else:
         checklist.append("Client Hostname: " + cdsname)
     if displayname != "":
         checklist.append("Name: " + displayname)
     else:
         checklist.append("Name: " + cdsname)
     checklist.append("Cluster: " + clustername)
     RHUIManager.proceed_with_check(connection, "The following CDS instance will be registered:", checklist)
     RHUIManager.quit(connection, "Successfully registered")
コード例 #5
0
def test_14_verbose_reporting():
    '''
    check if a failure is reported properly (if puppet is verbose)
    '''
    # for RHBZ#1751378
    # choose a random CDS and open port 443 on it, which will later prevent Apache from starting
    cds = random.choice(CDS)
    Expect.enter(cds, "ncat -l 443 --keep-open")
    # try adding the CDS and check for the specific error message in the output
    error_msg = "change from stopped to running failed"
    RHUIManager.screen(RHUA, "cds")
    Expect.enter(RHUA, "a")
    Expect.expect(RHUA, "Hostname")
    Expect.enter(RHUA, cds.hostname)
    Expect.expect(RHUA, "Username")
    Expect.enter(RHUA, SUDO_USER_NAME)
    Expect.expect(RHUA, "Absolute")
    Expect.enter(RHUA, SUDO_USER_KEY)
    Expect.expect(RHUA, "Proceed")
    Expect.enter(RHUA, "y")
    state = Expect.expect_list(RHUA,
                               [(re.compile(".*%s.*" % error_msg, re.DOTALL), 1),
                                (re.compile(".*Aborting.*", re.DOTALL), 2),
                                (re.compile(".*was successfully configured.*", re.DOTALL), 3)],
                               timeout=180)
    # quit rhui-manager, clean up, fail if the error message didn't appear
    Expect.enter(RHUA, "q")
    Expect.enter(cds, CTRL_C)
    cds_list = RHUIManagerInstance.list(RHUA, "cds")
    if cds_list:
        RHUIManagerInstance.delete_all(RHUA, "cds")
    if state != 1:
        raise AssertionError("The expected error message was not seen in rhui-manager's output.")
コード例 #6
0
def test_13_delete_select_0():
    '''
    add a CDS and see if no issue occurs if it and "a zeroth" (ghost) CDSs are selected for deletion
    '''
    # for RHBZ#1305612
    # choose a random CDS and add it
    cds = random.choice(CDS_HOSTNAMES)
    RHUIManagerInstance.add_instance(RHUA, "cds", cds)
    cds_list = RHUIManagerInstance.list(RHUA, "cds")
    nose.tools.assert_not_equal(cds_list, [])

    # try the deletion
    RHUIManager.screen(RHUA, "cds")
    Expect.enter(RHUA, "d")
    Expect.expect(RHUA, "Enter value")
    Expect.enter(RHUA, "0")
    Expect.expect(RHUA, "Enter value")
    Expect.enter(RHUA, "1")
    Expect.expect(RHUA, "Enter value")
    Expect.enter(RHUA, "c")
    state = Expect.expect_list(RHUA,
                               [(re.compile(".*Are you sure.*", re.DOTALL), 1),
                                (re.compile(".*An unexpected error.*", re.DOTALL), 2)])
    if state == 1:
        Expect.enter(RHUA, "y")
        RHUIManager.quit(RHUA, timeout=180)
    else:
        Expect.enter(RHUA, "q")

    # the CDS list ought to be empty now; if not, delete the CDS and fail
    cds_list = RHUIManagerInstance.list(RHUA, "cds")
    if cds_list:
        RHUIManagerInstance.delete_all(RHUA, "cds")
        raise AssertionError("The CDS list is not empty after the deletion attempt: %s." % cds_list)
コード例 #7
0
 def upload_content(connection, repolist, path):
     '''
     upload content to a custom repository
     '''
     # Temporarily quit rhui-manager and check whether "path" is a file or a directory.
     # If it is a directory, get a list of *.rpm files in it.
     Expect.enter(connection, 'q')
     Expect.enter(connection, "stat -c %F " + path)
     path_type = Expect.expect_list(
         connection, [(re.compile(".*regular file.*", re.DOTALL), 1),
                      (re.compile(".*directory.*", re.DOTALL), 2)])
     if path_type == 1:
         content = [basename(path)]
     elif path_type == 2:
         Expect.enter(connection, "echo " + path + "/*.rpm")
         output = Expect.match(connection, re.compile("(.*)", re.DOTALL))[0]
         rpm_files = output.splitlines()[1]
         content = []
         for rpm_file in rpm_files.split():
             content.append(basename(rpm_file))
     else:
         # This should not happen. Getting here means that "path" is neither a file nor a directory.
         # Anyway, going on with no content, leaving it up to proceed_with_check() to handle this situation.
         content = []
     # Start rhui-manager again and continue.
     RHUIManager.initial_run(connection)
     RHUIManager.screen(connection, "repo")
     Expect.enter(connection, "u")
     RHUIManager.select(connection, repolist)
     Expect.expect(connection, "will be uploaded:")
     Expect.enter(connection, path)
     RHUIManager.proceed_with_check(connection,
                                    "The following RPMs will be uploaded:",
                                    content)
     RHUIManager.quit(connection)
コード例 #8
0
 def upload_content(connection, repolist, path):
     '''
     upload content to a custom repository
     '''
     # Temporarily quit rhui-manager and check whether "path" is a file or a directory.
     # If it is a directory, get a list of *.rpm files in it.
     Expect.enter(connection, 'q')
     Expect.enter(connection, "stat -c %F " + path)
     path_type = Expect.expect_list(connection, [(re.compile(".*regular file.*", re.DOTALL), 1), (re.compile(".*directory.*", re.DOTALL), 2)])
     if path_type == 1:
         content = [basename(path)]
     elif path_type == 2:
         Expect.enter(connection, "echo " + path + "/*.rpm")
         output = Expect.match(connection, re.compile("(.*)", re.DOTALL))[0]
         rpm_files = output.splitlines()[1]
         content = []
         for rpm_file in rpm_files.split():
             content.append(basename(rpm_file))
     else:
         # This should not happen. Getting here means that "path" is neither a file nor a directory.
         # Anyway, going on with no content, leaving it up to proceed_with_check() to handle this situation.
         content = []
     # Start rhui-manager again and continue.
     RHUIManager.initial_run(connection)
     RHUIManager.screen(connection, "repo")
     Expect.enter(connection, "u")
     RHUIManager.select(connection, repolist)
     Expect.expect(connection, "will be uploaded:")
     Expect.enter(connection, path)
     RHUIManager.proceed_with_check(connection, "The following RPMs will be uploaded:", content)
     Expect.expect(connection, "rhui \(" + "repo" + "\) =>")
コード例 #9
0
    def upload_rh_certificate(connection, certificate_file="/tmp/extra_rhui_files/rhcert.pem"):
        '''
        upload a new or updated Red Hat content certificate
        '''
        bad_cert_msg = "The provided certificate is expired or invalid"
        incompatible_cert_msg = "does not contain any entitlements"

        RHUIManager.screen(connection, "entitlements")
        Expect.enter(connection, "u")
        Expect.expect(connection, "Full path to the new content certificate:")
        Expect.enter(connection, certificate_file)
        state = Expect.expect_list(connection,
                                   [(re.compile(".*The RHUI will be updated.*", re.DOTALL), 1),
                                    (re.compile(".*Cannot find file.*", re.DOTALL), 2)])
        if state == 2:
            Expect.enter(connection, CTRL_C)
            RHUIManager.quit(connection)
            raise MissingCertificate("No such certificate file: %s" % certificate_file)
        Expect.enter(connection, "y")
        match = Expect.match(connection,
                             re.compile("(.*)" + PROMPT, re.DOTALL))
        matched_string = match[0].replace('l\r\n\r\nRed Hat Entitlements\r\n\r\n  ' +
                                          '\x1b[92mValid\x1b[0m\r\n    ', '', 1)
        if bad_cert_msg in matched_string:
            Expect.enter(connection, 'q')
            raise BadCertificate()
        if incompatible_cert_msg in matched_string:
            Expect.enter(connection, 'q')
            raise IncompatibleCertificate()
        entitlements_list = []
        pattern = re.compile('(.*?\r\n.*?pem)', re.DOTALL)
        for entitlement in pattern.findall(matched_string):
            entitlements_list.append(entitlement.strip())
        Expect.enter(connection, 'q')
        return entitlements_list
コード例 #10
0
 def add_cds(connection, clustername, cdsname, hostname="", displayname=""):
     """
     register (add) a new CDS instance
     """
     RHUIManager.screen(connection, "cds")
     RHUIManagerCds._add_cds_part1(connection, cdsname, hostname, displayname)
     state = Expect.expect_list(
         connection,
         [
             (re.compile(".*Enter a CDS cluster name:.*", re.DOTALL), 1),
             (re.compile(".*Select a CDS cluster or enter a new one:.*", re.DOTALL), 2),
         ],
     )
     if state == 1:
         Expect.enter(connection, clustername)
     else:
         Expect.enter(connection, "b")
         Expect.expect(connection, "rhui \(cds\) =>")
         RHUIManagerCds._add_cds_part1(connection, cdsname, hostname, displayname)
         RHUIManagerCds._select_cluster(connection, clustername)
     # We need to compare the output before proceeding
     checklist = ["Hostname: " + cdsname]
     if hostname != "":
         checklist.append("Client Hostname: " + hostname)
     else:
         checklist.append("Client Hostname: " + cdsname)
     if displayname != "":
         checklist.append("Name: " + displayname)
     else:
         checklist.append("Name: " + cdsname)
     checklist.append("Cluster: " + clustername)
     RHUIManager.proceed_with_check(connection, "The following CDS instance will be registered:", checklist)
     RHUIManager.quit(connection, "Successfully registered")
コード例 #11
0
ファイル: rhuimanager.py プロジェクト: vex21/rhui3-automation
 def initial_run(connection, crt="/etc/rhui/pem/ca.crt", key="/etc/rhui/pem/ca.key", cert_pw=None, days="", username="******", password="******"):
     '''
     Do rhui-manager initial run
     '''
     Expect.enter(connection, "rhui-manager")
     state = Expect.expect_list(connection, [(re.compile(".*Full path to the new signing CA certificate:.*", re.DOTALL), 1),
                                             (re.compile(".*RHUI Username:.*", re.DOTALL),2),
                                             (re.compile(".*rhui \(home\) =>.*", re.DOTALL), 3)])
     if state in [1, 2]:
         if state == 1:
             # Need to answer sone first-run questions
             Expect.enter(connection, crt)
             Expect.expect(connection, "Full path to the new signing CA certificate private key:")
             Expect.enter(connection, key)
             Expect.expect(connection, "regenerated using rhui-manager.*:")
             Expect.enter(connection, days)
             Expect.expect(connection, "Enter pass phrase for.*:")
             if cert_pw:
                 Expect.enter(connection, cert_pw)
             else:
                 Expect.enter(connection, Util.get_ca_password(connection))
             Expect.expect(connection, "RHUI Username:"******"RHUI Password:"******"rhui \(home\) =>")
     else:
         # initial step was already performed by someone
         pass
     Expect.enter(connection, "q")
コード例 #12
0
 def add_hap(connection, hap=Hap(), update=False):
     '''
     Register (add) a new HAP instance
     @param hap: rhuilib.hap.Hap instance
     @param update: Bool; update the hap if it is already tracked or raise ExpectFailed
     '''
     
     RHUIManager.screen(connection, "loadbalancers")
     Expect.enter(connection, "a")
     Expect.expect(connection, ".*Hostname of the HAProxy Load-balancer instance to register:")
     Expect.enter(connection, hap.host_name)
     state = Expect.expect_list(connection, [ \
         (re.compile(".*Username with SSH access to %s and sudo privileges:.*" % hap.host_name, re.DOTALL), 1),
         (re.compile(".*A HAProxy Load-balancer instance with that hostname exists.*Continue\?\s+\(y/n\): ", re.DOTALL), 2)
     ])
     if state == 2:
         # hap of the same hostname is already being tracked
         if not update:
             # but we don't wish to update its config: raise
             raise ExpectFailed("%s already tracked but update wasn't required" % hap.host_name)
         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:" % hap.host_name)
     # if the execution reaches here, uesername question was already asked
     Expect.enter(connection, hap.user_name)
     Expect.expect(connection, "Absolute path to an SSH private key to log into %s as %s:" % (hap.host_name, hap.user_name))
     Expect.enter(connection, hap.ssh_key_path)
     state = Expect.expect_list(connection, [
         (re.compile(".*Cannot find file, please enter a valid path.*", re.DOTALL), 1),
         (PROCEED_PATTERN, 2)
     ])
     if state == 1:
         # don't know how to continue with invalid path: raise
         Expect.enter(connection, CTRL_C)
         Expect.enter(connection, "q")
         raise InvalidSshKeyPath(hap.ssh_key_path)
     # all OK, confirm
     Expect.enter(connection, "y")
     # some installation and configuration through Puppet happens here, let it take its time
     Expect.expect(connection, "The HAProxy Load-balancer was successfully configured." + ".*rhui \(.*\) =>", 180)
コード例 #13
0
 def add_cds(connection, cds=Cds(), update=False):
     '''
     Register (add) a new CDS instance
     @param cds: rhuilib.cds.Cds instance
     @param update: Bool; update the cds if it is already tracked or rise ExpectFailed
     '''
     RHUIManager.screen(connection, "cds")
     Expect.enter(connection, "a")
     Expect.expect(connection, "Hostname of the Content Delivery Server instance to register:")
     Expect.enter(connection, cds.host_name)
     state = Expect.expect_list(connection, [ \
         (re.compile(".*Username with SSH access to %s and sudo privileges:.*" % cds.host_name, re.DOTALL), 1),
         (re.compile(".*A Content Delivery Server instance with that hostname exists.*Continue\?\s+\(y/n\): ", re.DOTALL), 2)
     ])
     if state == 2:
         # cds of the same hostname is already being tracked
         if not update:
             # but we don't wish to update its config: raise
             raise ExpectFailed("%s already tracked but update wasn't required" % cds.host_name)
         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:" % cds.host_name)
     # if the execution reaches here, uesername question was already asked
     Expect.enter(connection, cds.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),
         (PROCEED_PATTERN, 2)
     ])
     if state == 1:
         # don't know how to continue with invalid path: raise
         Expect.enter(connection, CTRL_C)
         Expect.enter(connection, "q")
         raise InvalidSshKeyPath(cds.ssh_key_path)
     # all OK, confirm
     Expect.enter(connection, "y")
     # some installation and configuration through Puppet happens here, let it take its time
     RHUIManager.quit(connection, "The Content Delivery Server was successfully configured.", timeout=180)
コード例 #14
0
 def initial_run(connection,
                 crt="/etc/rhui/pem/ca.crt",
                 key="/etc/rhui/pem/ca.key",
                 cert_pw=None,
                 days="",
                 username="******",
                 password="******"):
     '''
     Do rhui-manager initial run
     '''
     Expect.enter(connection, "rhui-manager")
     state = Expect.expect_list(
         connection,
         [(re.compile(".*Full path to the new signing CA certificate:.*",
                      re.DOTALL), 1),
          (re.compile(".*RHUI Username:.*", re.DOTALL), 2),
          (re.compile(".*rhui \(home\) =>.*", re.DOTALL), 3)])
     if state in [1, 2]:
         if state == 1:
             # Need to answer sone first-run questions
             Expect.enter(connection, crt)
             Expect.expect(
                 connection,
                 "Full path to the new signing CA certificate private key:")
             Expect.enter(connection, key)
             Expect.expect(connection, "regenerated using rhui-manager.*:")
             Expect.enter(connection, days)
             Expect.expect(connection, "Enter pass phrase for.*:")
             if cert_pw:
                 Expect.enter(connection, cert_pw)
             else:
                 Expect.enter(connection, Util.get_ca_password(connection))
             Expect.expect(connection, "RHUI Username:"******"RHUI Password:"******"rhui \(home\) =>")
     else:
         # initial step was already performed by someone
         pass
     Expect.enter(connection, "q")
コード例 #15
0
 def delete_all_repos(connection):
     '''
     delete all repositories from the RHUI
     '''
     RHUIManager.screen(connection, "repo")
     Expect.enter(connection, "d")
     status = Expect.expect_list(connection,
                                 [(re.compile(".*No repositories.*", re.DOTALL), 1),
                                  (re.compile(".*Enter value.*", re.DOTALL), 2)],
                                 360)
     if status == 1:
         RHUIManager.quit(connection)
         return
     Expect.enter(connection, "a")
     Expect.expect(connection, "Enter value .*:")
     Expect.enter(connection, "c")
     RHUIManager.proceed_without_check(connection)
     # Wait until all repos are deleted
     RHUIManager.quit(connection, "", 360)
     while RHUIManagerRepo.list(connection):
         time.sleep(10)
コード例 #16
0
 def repo_create_custom(connection,
                        repo_id,
                        path="",
                        display_name="",
                        entitlement="",
                        legacy_md=False,
                        redhat_content=False,
                        protected=False,
                        gpg_public_keys=""):
     '''
     create a custom repo
     '''
     # compose the command
     cmd = "rhui-manager repo create_custom --repo_id %s" % repo_id
     if path:
         cmd += " --path %s" % path
     if display_name:
         cmd += " --display_name '%s'" % display_name
     if entitlement:
         cmd += " --entitlement %s" % entitlement
     if legacy_md:
         cmd += " --legacy_md"
     if redhat_content:
         cmd += " --redhat_content"
     if protected:
         cmd += " --protected"
     if gpg_public_keys:
         cmd += " --gpg_public_keys %s" % gpg_public_keys
     # get a list of invalid GPG key files (will be implicitly empty if that option isn't used)
     key_list = gpg_public_keys.split(",")
     bad_keys = [
         key for key in key_list
         if connection.recv_exit_status("test -f %s" % key)
     ]
     # possible output (more or less specific):
     out = {
         "missing_options":
         "Usage:",
         "invalid_id":
         "Only.*valid in a repository ID",
         "repo_exists":
         "A repository with ID \"%s\" already exists" % repo_id,
         "bad_gpg":
         "The following files are unreadable:\r\n\r\n%s" %
         "\r\n".join(bad_keys),
         "success":
         "Successfully created repository \"%s\"" %
         (display_name or repo_id)
     }
     # run the command and see what happens
     Expect.enter(connection, cmd)
     state = Expect.expect_list(
         connection,
         [(re.compile(".*%s.*" % out["missing_options"], re.DOTALL), 1),
          (re.compile(".*%s.*" % out["invalid_id"], re.DOTALL), 2),
          (re.compile(".*%s.*" % out["repo_exists"], re.DOTALL), 3),
          (re.compile(".*%s.*" % out["bad_gpg"], re.DOTALL), 4),
          (re.compile(".*%s.*" % out["success"], re.DOTALL), 5)])
     if state == 1 or state == 2:
         raise ValueError("the given repo ID is unusable")
     if state == 3:
         raise CustomRepoAlreadyExists()
     if state == 4:
         raise CustomRepoGpgKeyNotFound()
     # make sure rhui-manager reported success
     nose.tools.assert_equal(state, 5)
コード例 #17
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)
コード例 #18
0
    def add_custom_repo(connection,
                        reponame,
                        displayname="",
                        path="",
                        checksum_alg="1",
                        entitlement="y",
                        entitlement_path="",
                        redhat_gpg="y",
                        custom_gpg=None):
        '''
        create a new custom repository
        '''
        RHUIManager.screen(connection, "repo")
        Expect.enter(connection, "c")
        Expect.expect(connection, "Unique ID for the custom repository.*:")
        Expect.enter(connection, reponame)
        checklist = ["ID: " + reponame]
        state = Expect.expect_list(connection,
                                   [(re.compile(".*Display name for the custom repository.*:",
                                                re.DOTALL),
                                     1),
                                    (re.compile(".*repository.*already exists.*Unique ID.*:",
                                                re.DOTALL),
                                     2)])
        if state == 1:
            Expect.enter(connection, displayname)
            if displayname != "":
                checklist.append("Name: " + displayname)
            else:
                checklist.append("Name: " + reponame)
            Expect.expect(connection, "Unique path at which the repository will be served.*:")
            Expect.enter(connection, path)
            if path != "":
                path_real = path
            else:
                path_real = reponame
            checklist.append("Path: " + path_real)
            Expect.expect(connection, "Enter value.*:")
            Expect.enter(connection, checksum_alg)
            Expect.expect(connection,
                          "Should the repository require an entitlement certificate " +
                          r"to access\? \(y/n\)")
            Expect.enter(connection, entitlement)
            if entitlement == "y":
                Expect.expect(connection,
                              "Path that should be used when granting an entitlement " +
                              "for this repository.*:")
                Expect.enter(connection, entitlement_path)
                if entitlement_path != "":
                    checklist.append("Entitlement: " + entitlement_path)
                else:
                    educated_guess, replace_count = re.subn("(i386|x86_64)", "$basearch", path_real)
                    if replace_count > 1:
                        # bug 815975
                        educated_guess = path_real
                    checklist.append("Entitlement: " + educated_guess)
            Expect.expect(connection, r"packages are signed by a GPG key\? \(y/n\)")
            if redhat_gpg == "y" or custom_gpg:
                Expect.enter(connection, "y")
                checklist.append("GPG Check Yes")
                Expect.expect(connection,
                              "Will the repository be used to host any " +
                              r"Red Hat GPG signed content\? \(y/n\)")
                Expect.enter(connection, redhat_gpg)
                if redhat_gpg == "y":
                    checklist.append("Red Hat GPG Key: Yes")
                else:
                    checklist.append("Red Hat GPG Key: No")
                Expect.expect(connection,
                              "Will the repository be used to host any " +
                              r"custom GPG signed content\? \(y/n\)")
                if custom_gpg:
                    Expect.enter(connection, "y")
                    Expect.expect(connection,
                                  "Enter the absolute path to the public key of the GPG keypair:")
                    Expect.enter(connection, custom_gpg)
                    Expect.expect(connection,
                                  r"Would you like to enter another public key\? \(y/n\)")
                    Expect.enter(connection, "n")
                    checklist.append("Custom GPG Keys: '" + custom_gpg + "'")
                else:
                    Expect.enter(connection, "n")
                    checklist.append("Custom GPG Keys: (None)")
            else:
                Expect.enter(connection, "n")
                checklist.append("GPG Check No")
                checklist.append("Red Hat GPG Key: No")

            RHUIManager.proceed_with_check(connection,
                                           "The following repository will be created:",
                                           checklist)
            RHUIManager.quit(connection, "Successfully created repository *")
        else:
            Expect.enter(connection, CTRL_C)
            RHUIManager.quit(connection)
            raise AlreadyExistsError()
コード例 #19
0
 def add_custom_repo(connection, reponame, displayname="", path="", checksum_alg="1", entitlement="y", entitlement_path="", redhat_gpg="y", custom_gpg=None):
     '''
     create a new custom repository
     '''
     RHUIManager.screen(connection, "repo")
     Expect.enter(connection, "c")
     Expect.expect(connection, "Unique ID for the custom repository.*:")
     Expect.enter(connection, reponame)
     checklist = ["ID: " + reponame]
     state = Expect.expect_list(connection, [(re.compile(".*Display name for the custom repository.*:", re.DOTALL), 1),\
                                            (re.compile(".*Unique ID for the custom repository.*:", re.DOTALL), 2)])
     if state == 1:
         Expect.enter(connection, displayname)
         if displayname != "":
             checklist.append("Name: " + displayname)
         else:   
             checklist.append("Name: " + reponame)
         Expect.expect(connection, "Unique path at which the repository will be served.*:")
         Expect.enter(connection, path)
         if path != "":
             path_real = path
         else:   
             path_real = reponame
         checklist.append("Path: " + path_real)
         Expect.expect(connection, "Enter value.*:")
         Expect.enter(connection, checksum_alg)
         Expect.expect(connection, "Should the repository require an entitlement certificate to access\? \(y/n\)")
         Expect.enter(connection, entitlement)
         if entitlement == "y":
             Expect.expect(connection, "Path that should be used when granting an entitlement for this repository.*:")
             Expect.enter(connection, entitlement_path)
             if entitlement_path != "":
                 checklist.append("Entitlement: " + entitlement_path)
             else:       
                 educated_guess, replace_count = re.subn("(i386|x86_64)", "$basearch", path_real)
                 if replace_count > 1:
                     # bug 815975
                     educated_guess = path_real
                 checklist.append("Entitlement: " + educated_guess)
         Expect.expect(connection, "packages are signed by a GPG key\? \(y/n\)")
         if redhat_gpg == "y" or custom_gpg:
             Expect.enter(connection, "y")
             checklist.append("GPG Check Yes")
             Expect.expect(connection, "Will the repository be used to host any Red Hat GPG signed content\? \(y/n\)")
             Expect.enter(connection, redhat_gpg)
             if redhat_gpg == "y":
                 checklist.append("Red Hat GPG Key: Yes")
             else:       
                 checklist.append("Red Hat GPG Key: No")
             Expect.expect(connection, "Will the repository be used to host any custom GPG signed content\? \(y/n\)")
             if custom_gpg:
                 Expect.enter(connection, "y")
                 Expect.expect(connection, "Enter the absolute path to the public key of the GPG keypair:")
                 Expect.enter(connection, custom_gpg)
                 Expect.expect(connection, "Would you like to enter another public key\? \(y/n\)")
                 Expect.enter(connection, "n")
                 checklist.append("Custom GPG Keys: '" + custom_gpg + "'")
             else:       
                 Expect.enter(connection, "n")
                 checklist.append("Custom GPG Keys: \(None\)")
         else:           
             Expect.enter(connection, "n")
             checklist.append("GPG Check No") 
             checklist.append("Red Hat GPG Key: No")
 
         RHUIManager.proceed_with_check(connection, "The following repository will be created:", checklist)
         Expect.expect(connection, "Successfully created repository *")
         Expect.enter(connection, "home")
     else:      
         Expect.enter(connection, '\x03')
         Expect.expect(connection, "rhui \(" + "repo" + "\) =>")