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 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 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" + "\) =>")
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 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 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) Expect.expect(connection, ".*rhui \(" + "repo" + "\) =>")
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 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_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) Expect.expect(connection, ".*rhui \(" + "repo" + "\) =>")
def check_detailed_information(connection, repo_data, type_data, gpg_data, package_count): ''' verify that a repository has the expected properties repo_data: [string, string] [0]: repo name [1]: relative path type_data: [bool, bool] [0]: True? Custom. False? Red Hat. [1]: True? Protected. False? Unprotected. (Only checked with a Custom repo.) gpg_data: [bool, string, bool] [0]: True? GPG Check Yes. False? GPG Check No. [1]: Custom GPG Keys (comma-separated names), or None. [2]: True? Red Hat GPG Key Yes. False? Red Hat GPG Key No. ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "i") RHUIManager.select(connection, [repo_data[0]]) pattern = re.compile(r".*(Name:.*)\r\n\r\n-+\r\nrhui\s* \(repo\)\s* =>", re.DOTALL) actual_responses = Expect.match(connection, pattern)[0].splitlines() Expect.enter(connection, "q") expected_responses = ["Name: " + repo_data[0]] if type_data[0]: repo_type = "Custom" if type_data[1]: relative_path = "protected/" + repo_data[1] else: relative_path = "unprotected/" + repo_data[1] else: repo_type = "Red Hat" relative_path = repo_data[1] expected_responses.append("Type: " + repo_type) expected_responses.append("Relative Path: " + relative_path) if gpg_data[0]: expected_responses.append("GPG Check: Yes") if gpg_data[1]: expected_responses.append("Custom GPG Keys: " + gpg_data[1]) else: expected_responses.append("Custom GPG Keys: (None)") if gpg_data[2]: expected_responses.append("Red Hat GPG Key: Yes") else: expected_responses.append("Red Hat GPG Key: No") else: expected_responses.append("GPG Check: No") expected_responses.append("Package Count: " + str(package_count)) if repo_type == "Red Hat": sync_data = actual_responses.pop() nose.tools.ok_("Next Sync:" in sync_data) sync_data = actual_responses.pop() nose.tools.ok_("Last Sync:" in sync_data) nose.tools.eq_(actual_responses, expected_responses)
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 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_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_-]*\\\\\) \\\\\(Yum\\\\\)", "", repo)) RHUIManager.proceed_with_check(connection, "The following product repositories will be deployed:", repolist_mod) Expect.expect(connection, ".*rhui \(" + "repo" + "\) =>")
def generate_ent_cert(connection, repolist, certname, dirname, validity_days="", cert_pw=None): """ 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) Expect.expect(connection, ".*rhui \(" + "client" + "\) =>")
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_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 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) Expect.expect(connection, ".*rhui \(" + "client" + "\) =>")
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 create_conf_rpm(connection, dirname, certpath, certkey, rpmname, rpmversion="", rpmrelease="", 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, "Release of the configuration RPM.*:") Expect.enter(connection, rpmrelease) 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) if not rpmversion: rpmversion = "2.0" if not rpmrelease: rpmrelease = "1" Expect.expect(connection, "Location: %s/%s-%s/build/RPMS/noarch/%s-%s-%s.noarch.rpm" % \ (dirname, rpmname, rpmversion, rpmname, rpmversion, rpmrelease)) Expect.enter(connection, "q")
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)