def upload_content(connection, repolist, path): ''' upload content to a custom repository ''' # Check whether "path" is a file or a directory. # If it is a directory, get a list of *.rpm files in it. path_type = Util.get_file_type(connection, path) if path_type == "regular file": content = [basename(path)] elif path_type == "directory": content = Util.get_rpms_in_dir(connection, path) 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 = [] # Continue in rhui-manager. 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, timeout=60)
def create_conf_rpm(connection, dirname, certpath, certkey, rpmname, rpmversion="", unprotected_repos=None): ''' create a client configuration RPM from an entitlement certificate ''' RHUIManager.screen(connection, "client") Expect.enter(connection, "c") Expect.expect(connection, "Full path to local directory.*:") Expect.enter(connection, dirname) Expect.expect(connection, "Name of the RPM:") Expect.enter(connection, rpmname) Expect.expect(connection, "Version of the configuration RPM.*:") Expect.enter(connection, rpmversion) Expect.expect(connection, "Full path to the entitlement certificate.*:") Expect.enter(connection, certpath) Expect.expect( connection, "Full path to the private key for the above entitlement certificate:" ) Expect.enter(connection, certkey) if unprotected_repos: RHUIManager.select(connection, unprotected_repos) RHUIManager.quit(connection)
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)
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
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)
def delete_cdses(connection, *cdses): ''' unregister (delete) CDS instance from the RHUI ''' RHUIManager.screen(connection, "cds") Expect.enter(connection, "d") RHUIManager.select_items(connection, *cdses) RHUIManager.quit(connection, timeout=30)
def delete_repo(connection, repolist): ''' delete a repository from the RHUI ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "d") RHUIManager.select(connection, repolist) RHUIManager.proceed_without_check(connection) RHUIManager.quit(connection)
def sync_cluster(connection, clusterlist): ''' sync a CDS cluster immediately ''' RHUIManager.screen(connection, "sync") Expect.enter(connection, "sl") RHUIManager.select(connection, clusterlist) RHUIManager.proceed_with_check(connection, "The following CDS clusters will be scheduled for synchronization:", clusterlist) RHUIManager.quit(connection)
def delete(connection, screen, instances): ''' unregister (delete) CDS instance from the RHUI ''' RHUIManager.screen(connection, screen) Expect.enter(connection, "d") RHUIManager.select_items(connection, instances) Expect.enter(connection, "y") RHUIManager.quit(connection, "Unregistered", 180)
def sync_cds(connection, cdslist): ''' sync an individual CDS immediately ''' RHUIManager.screen(connection, "sync") Expect.enter(connection, "sc") RHUIManager.select(connection, cdslist) RHUIManager.proceed_with_check(connection, "The following CDS instances will be scheduled for synchronization:", cdslist) RHUIManager.quit(connection)
def add_rh_repo_all(connection): ''' add a new Red Hat content repository (All in Certificate) ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "a") Expect.expect(connection, "Import Repositories:.*to abort:", 660) Expect.enter(connection, "1") RHUIManager.proceed_without_check(connection) RHUIManager.quit(connection, "", 180)
def subscriptions_unregister(connection, names): ''' unregister a Red Hat subscription from RHUI ''' RHUIManager.screen(connection, "subscriptions") Expect.enter(connection, "d") RHUIManager.select(connection, names) RHUIManager.proceed_with_check(connection, "The following subscriptions will be unregistered:", names) RHUIManager.quit(connection)
def sync_repo(connection, repolist): ''' sync an individual repository immediately ''' RHUIManager.screen(connection, "sync") Expect.enter(connection, "sr") Expect.expect(connection, "Select one or more repositories.*for more commands:", 60) Expect.enter(connection, "l") RHUIManager.select(connection, repolist) RHUIManager.proceed_with_check(connection, "The following repositories will be scheduled for synchronization:", repolist) RHUIManager.quit(connection)
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)
def _sync_cds(self, cdslist): """ Sync cds """ if (not "RHUA" in self.rs.Instances.keys()) or len(self.rs.Instances["RHUA"]) < 1: raise nose.exc.SkipTest("can't test without RHUA!") try: RHUIManagerSync.sync_cds(self.rs.Instances["RHUA"][0], cdslist) except ExpectFailed: # The CDS is not available for syncing so most probably it's syncing right now # Trying to check the status Expect.enter(self.rs.Instances["RHUA"][0], "b") RHUIManager.quit(self.rs.Instances["RHUA"][0]) self._sync_wait_cds(cdslist)
def delete_all(connection, screen): ''' unregister (delete) all CDS or HAProxy instances from the RHUI ''' RHUIManager.screen(connection, screen) Expect.enter(connection, "d") Expect.expect(connection, "Enter value .*:") Expect.enter(connection, "a") Expect.expect(connection, "Enter value .*:") Expect.enter(connection, "c") Expect.expect(connection, "Are you sure .*:") Expect.enter(connection, "y") RHUIManager.quit(connection, "Unregistered")
def subscriptions_unregister(connection, names): """unregister one or more Red Hat subscriptions from RHUI""" RHUIManager.screen(connection, "subscriptions") Expect.enter(connection, "d") try: RHUIManager.select(connection, names) except ExpectFailed: Expect.enter(connection, "q") raise RuntimeError("subscription(s) not registered: %s" % names) RHUIManager.proceed_with_check( connection, "The following subscriptions will be unregistered:", names) RHUIManager.quit(connection)
def add_rh_repo_by_product(connection, productlist): ''' add a new Red Hat content repository (By Product) ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "a") Expect.expect(connection, "Import Repositories:.*to abort:", 660) Expect.enter(connection, "2") RHUIManager.select(connection, productlist) RHUIManager.proceed_with_check(connection, "The following products will be deployed:", productlist) RHUIManager.quit(connection)
def get_cds_status(connection, cdsname): ''' display CDS sync summary ''' RHUIManager.screen(connection, "sync") Expect.enter(connection, "dc") res_list = Expect.match(connection, re.compile(".*\n" + cdsname.replace(".", "\.") + "[\.\s]*\[([^\n]*)\].*" + cdsname.replace(".", "\.") + "\s*\r\n([^\n]*)\r\n", re.DOTALL), [1, 2], 60) connection.cli.exec_command("killall -s SIGINT rhui-manager") ret_list = [] for val in [res_list[0]] + res_list[1].split(" "): val = Util.uncolorify(val.strip()) ret_list.append(val) RHUIManager.quit(connection) return ret_list
def delete(connection, screen, instances): ''' unregister (delete) one or more CDS or HAProxy instances from the RHUI ''' # first check if the instances are really tracked tracked_instances = RHUIManagerInstance.list(connection, screen) hostnames = [instance.host_name for instance in tracked_instances] bad_instances = [i for i in instances if i not in hostnames] if bad_instances: raise NoSuchInstance(bad_instances) RHUIManager.screen(connection, screen) Expect.enter(connection, "d") RHUIManager.select_items(connection, instances) Expect.enter(connection, "y") RHUIManager.quit(connection, "Unregistered", 180)
def delete_all_repos(connection): ''' delete all repositories from the RHUI ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "d") Expect.expect(connection, "Enter value .*:", 360) 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 len(RHUIManagerRepo.list(connection)) != 0: time.sleep(10)
def get_repo_status(connection, reponame): ''' display repo sync summary ''' RHUIManager.screen(connection, "sync") Expect.enter(connection, "dr") reponame_quoted = reponame.replace(".", "\.") res = Expect.match(connection, re.compile(".*" + reponame_quoted + "\s*\r\n([^\n]*)\r\n.*", re.DOTALL), [1], 60)[0] connection.cli.exec_command("killall -s SIGINT rhui-manager") res = Util.uncolorify(res) ret_list = res.split(" ") for i in range(len(ret_list)): ret_list[i] = ret_list[i].strip() RHUIManager.quit(connection) return ret_list
def sync_repo(connection, repolist): ''' sync an individual repository immediately ''' RHUIManager.screen(connection, "sync") Expect.enter(connection, "sr") Expect.expect(connection, "Select one or more repositories.*for more commands:", 60) Expect.enter(connection, "l") RHUIManager.select(connection, repolist) RHUIManager.proceed_with_check( connection, "The following repositories will be scheduled " + "for synchronization:", repolist) RHUIManager.quit(connection)
def _sync_repo(self, repolist): """ Sync repo """ if (not "RHUA" in self.rs.Instances.keys()) or len(self.rs.Instances["RHUA"]) < 1: raise nose.exc.SkipTest("can't test without RHUA!") try: RHUIManagerSync.sync_repo(self.rs.Instances["RHUA"][0], repolist) except ExpectFailed: # The repo is not available for syncing so most probably it's syncing right now # Trying to check the status Expect.enter(self.rs.Instances["RHUA"][0], "b") RHUIManager.quit(self.rs.Instances["RHUA"][0]) for repo in repolist: reposync = ["In Progress", "", ""] while reposync[0] in ["In Progress", "Never"]: time.sleep(10) reposync = RHUIManagerSync.get_repo_status(self.rs.Instances["RHUA"][0], repo) nose.tools.assert_equal(reposync[2], "Success")
def add_rh_repo_by_repo(connection, repolist): ''' add a new Red Hat content repository (By Repository) ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "a") Expect.expect(connection, "Import Repositories:.*to abort:", 660) Expect.enter(connection, "3") RHUIManager.select(connection, repolist) repolist_mod = list(repolist) for repo in repolist: repolist_mod.append( re.sub(" \([a-zA-Z0-9_-]*\) \([a-zA-Z]*\)", "", repo)) RHUIManager.proceed_with_check( connection, "The following product repositories will be deployed:", repolist_mod) RHUIManager.quit(connection)
def add_container(connection, containername, containerid="", displayname="", credentials=""): ''' add a new Red Hat container ''' default_registry = Helpers.get_registry_url("default", connection) # if the credentials parameter is supplied, it's supposed to be a list containing: # 0 - registry hostname if not using the default one # 1 - username (if required; the default registry requires the RH (CCSP) login) # 2 - password (if required) # do NOT supply them if they're in rhui-tools.conf and you want to use the default registry; # this method will fail otherwise, because it will expect rhui-manager to ask for them RHUIManager.screen(connection, "repo") Expect.enter(connection, "ad") Expect.expect(connection, "Specify URL of registry .*:") if credentials and credentials[0]: registry = credentials[0] Expect.enter(connection, registry) else: registry = default_registry Expect.enter(connection, "") Expect.expect(connection, "Name of the container in the registry:") Expect.enter(connection, containername) Expect.expect(connection, "Unique ID for the container .*]", 60) Expect.enter(connection, containerid) Expect.expect(connection, "Display name for the container.*]:") Expect.enter(connection, displayname) # login & password provided, or a non-default registry specified if credentials or registry != default_registry: Expect.expect(connection, "Registry username:"******"Registry password:"******"") if not containerid: containerid = Util.safe_pulp_repo_name(containername) if not displayname: displayname = Util.safe_pulp_repo_name(containername) RHUIManager.proceed_with_check(connection, "The following container will be added:", ["Registry URL: " + registry, "Container Id: " + containerid, "Display Name: " + displayname, "Upstream Container Name: " + containername]) RHUIManager.quit(connection)
def create_docker_conf_rpm(connection, dirname, rpmname, rpmversion="", dockerport=""): ''' create a docker client configuration RPM ''' RHUIManager.screen(connection, "client") Expect.enter(connection, "d") Expect.expect(connection, "Full path to local directory.*:") Expect.enter(connection, dirname) Expect.expect(connection, "Name of the RPM:") Expect.enter(connection, rpmname) Expect.expect(connection, "Version of the configuration RPM.*:") Expect.enter(connection, rpmversion) Expect.expect(connection, "Port to serve Docker content on .*:") Expect.enter(connection, dockerport) RHUIManager.quit(connection)
def add_rh_repo_by_repo(connection, repolist): ''' add a new Red Hat content repository (By Repository) ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "a") Expect.expect(connection, "Import Repositories:.*to abort:", 660) Expect.enter(connection, "3") RHUIManager.select(connection, repolist) repolist_mod = list(repolist) for repo in repolist: # strip " (kind)" repo_stripped = re.sub(r" \([a-zA-Z]*\)$", "", repo) # strip " (version)" if present (if "(RPMs)" isn't there instead) repo_stripped = re.sub(r" \((?!RPMs)[a-zA-Z0-9_-]*\)$", "", repo_stripped) repolist_mod.append(repo_stripped) RHUIManager.proceed_with_check(connection, "The following product repositories will be deployed:", repolist_mod) RHUIManager.quit(connection)
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)
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)
def create_atomic_conf_pkg(connection, dirname, tarname, certpath, certkey, dockerport=""): ''' create an atomic client configuration package (RHEL 7+ only) ''' RHUIManager.screen(connection, "client") Expect.enter(connection, "o") Expect.expect(connection, "Full path to local directory.*:") Expect.enter(connection, dirname) Expect.expect(connection, "Name of the tar file.*:") Expect.enter(connection, tarname) Expect.expect(connection, "Full path to the entitlement certificate.*:") Expect.enter(connection, certpath) Expect.expect(connection, "Full path to the private key.*:") Expect.enter(connection, certkey) Expect.expect(connection, "Port to serve Docker content on .*:") Expect.enter(connection, dockerport) RHUIManager.quit(connection)
def add_docker_container(connection, containername, containerid="", displayname=""): ''' add a new Red Hat docker container ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "ad") Expect.expect(connection, "Name of the container in the registry:") Expect.enter(connection, containername) Expect.expect(connection, "Unique ID for the container .*]", 60) Expect.enter(connection, containerid) Expect.expect(connection, "Display name for the container.*]:") Expect.enter(connection, displayname) RHUIManager.proceed_with_check( connection, "The following container will be added:", [ "Container Id: " + containername.replace("/", "_").replace(".", "_"), "Display Name: " + displayname, "Upstream Container Name: " + containername ]) RHUIManager.quit(connection)
def generate_ent_cert(connection, repolist, certname, dirname, validity_days=""): ''' generate an entitlement certificate ''' RHUIManager.screen(connection, "client") Expect.enter(connection, "e") RHUIManager.select(connection, repolist) Expect.expect(connection, "Name of the certificate.*contained with it:") Expect.enter(connection, certname) Expect.expect( connection, "Local directory in which to save the generated certificate.*:") Expect.enter(connection, dirname) Expect.expect(connection, "Number of days the certificate should be valid.*:") Expect.enter(connection, validity_days) RHUIManager.proceed_without_check(connection) RHUIManager.quit(connection)
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()
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)