def check_for_package(connection, reponame, package): ''' list packages in a repository ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "p") RHUIManager.select_one(connection, reponame) Expect.expect(connection, "\(blank line for no filter\):") Expect.enter(connection, package) pattern = re.compile('.*only\.\r\n(.*)\r\n-+\r\nrhui\s* \(repo\)\s* =>', re.DOTALL) ret = Expect.match(connection, pattern, grouplist=[1])[0] reslist = map(lambda x: x.strip(), ret.split("\r\n")) packagelist = [] for line in reslist: if line == '': continue if line == 'Packages:': continue if line == 'No packages found that match the given filter.': continue if line == 'No packages in the repository.': continue packagelist.append(line) return packagelist
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")
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 remove_rh_certs(connection): ''' Remove all RH certificates from RHUI ''' Expect.enter(connection, "find /etc/pki/rhui/redhat/ -name '*.pem' -delete") Expect.expect(connection, "root@")
def list(connection): ''' list repositories ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "l") # eating prompt!! pattern = re.compile('l\r\n(.*)\r\n-+\r\nrhui\s* \(repo\)\s* =>', re.DOTALL) ret = Expect.match(connection, pattern, grouplist=[1])[0] print ret reslist = map(lambda x: x.strip(), ret.split("\r\n")) print reslist repolist = [] for line in reslist: # Readling lines and searching for repos if line == '': continue if "Custom Repositories" in line: continue if "Red Hat Repositories" in line: continue if "No repositories are currently managed by the RHUI" in line: continue repolist.append(line) Expect.enter(connection, 'q') return repolist
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")
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 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 select_all(connection): ''' Select all items ''' Expect.expect(connection, "Enter value .*:") Expect.enter(connection, "a") Expect.expect(connection, "Enter value .*:") Expect.enter(connection, "c")
def remove_conf_rpm(connection): ''' Remove RHUI configuration rpm from instance (which owns /etc/yum/pluginconf.d/rhui-lb.conf file) ''' Expect.enter(connection, "") Expect.expect(connection, "root@") Expect.enter(connection, "([ ! -f /etc/yum/pluginconf.d/rhui-lb.conf ] && echo SUCCESS ) || (rpm -e `rpm -qf --queryformat %{NAME} /etc/yum/pluginconf.d/rhui-lb.conf` && echo SUCCESS)") Expect.expect(connection, "[^ ]SUCCESS.*root@", 60)
def logout(connection, prefix=""): ''' Logout from rhui-manager Use @param prefix to specify something to expect before exiting ''' Expect.expect(connection, prefix + ".*rhui \(.*\) =>") Expect.enter(connection, "logout")
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 list(connection): ''' return the list of entitlements ''' RHUIManager.screen(connection, "entitlements") lines = RHUIManager.list_lines(connection, prompt=PROMPT) Expect.enter(connection, 'q') return lines
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_cdses(connection, *cdses): ''' unregister (delete) CDS instance from the RHUI ''' RHUIManager.screen(connection, "cds") Expect.enter(connection, "d") RHUIManager.select_items(connection, *cdses) Expect.enter(connection, "y") Expect.expect(connection, "Unregistered" + ".*rhui \(.*\) =>", 180)
def delete_haps(connection, *hapes): ''' unregister (delete) HAP instance from the RHUI ''' RHUIManager.screen(connection, "loadbalancers") Expect.enter(connection, "d") RHUIManager.select_items(connection, *hapes) Expect.enter(connection, "y") Expect.expect(connection, "Unregistered" + ".*rhui \(.*\) =>", 180)
def list_lines(connection, prompt='', enter_l=True): ''' list items on screen returning a list of lines seen eats prompt!!! ''' if enter_l: Expect.enter(connection, "l") match = Expect.match(connection, re.compile("(.*)" + prompt, re.DOTALL)) return match[0].split('\r\n')
def quit(connection, prefix="", timeout=10): ''' Quit from rhui-manager Use @param prefix to specify something to expect before exiting Use @param timeout to specify the timeout ''' Expect.expect(connection, prefix + ".*rhui \(.*\) =>", timeout) Expect.enter(connection, "q")
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_repo(connection, repolist): ''' delete a repository from the RHUI ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "d") RHUIManager.select(connection, repolist) RHUIManager.proceed_with_check(connection, "The following repositories will be deleted:", repolist, ["Red Hat Repositories", "Custom Repositories"]) RHUIManager.quit(connection)
def select_one(connection, item): ''' Select one item (single choice) ''' match = Expect.match( connection, re.compile(".*([0-9]+)\s+-\s+" + item + "\s*\n.*to abort:.*", re.DOTALL)) Expect.enter(connection, match[0])
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 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 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) Expect.expect(connection, ".*rhui \(" + "repo" + "\) =>", 180)
def _get_repo_status(connection, repo_name): ''' get the status of the given repository ''' Expect.enter(connection, "rhui-manager status") status = Expect.match( connection, re.compile(".*%s[^A-Z]*([A-Za-z]*).*" % re.escape(repo_name), re.DOTALL))[0] return status
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 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:", 180) Expect.enter(connection, "1") RHUIManager.proceed_without_check(connection) RHUIManager.quit(connection, "Content will not be downloaded", 45)
def remove_conf_rpm(connection): ''' Remove RHUI configuration rpm from instance (which owns /etc/yum/pluginconf.d/rhui-lb.conf file) ''' Expect.enter(connection, "") Expect.expect(connection, "root@") Expect.enter( connection, "([ ! -f /etc/yum/pluginconf.d/rhui-lb.conf ] && echo SUCCESS ) || (rpm -e `rpm -qf --queryformat %{NAME} /etc/yum/pluginconf.d/rhui-lb.conf` && echo SUCCESS)" ) Expect.expect(connection, "[^ ]SUCCESS.*root@", 60)
def upload_content(connection, repolist, path): ''' upload content to a custom repository ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "u") RHUIManager.select(connection, repolist) Expect.expect(connection, "will be uploaded:") Expect.enter(connection, path) RHUIManager.proceed_without_check(connection) RHUIManager.quit(connection)
def list(connection, screen): ''' return the list of currently managed CDSes ''' RHUIManager.screen(connection, screen) # eating prompt!! lines = RHUIManager.list_lines(connection, "rhui \(" + screen + "\) => ") ret = Instance.parse(lines) Expect.enter(connection, 'q') return [cds for _, cds in ret]
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:", 180) Expect.enter(connection, "2") RHUIManager.select(connection, productlist) RHUIManager.proceed_with_check(connection, "The following products will be deployed:", productlist) RHUIManager.quit(connection, "Content will not be downloaded", 45)
def associate_repo_cds(connection, clustername, repolist): ''' associate a repository with a CDS cluster ''' RHUIManager.screen(connection, "cds") Expect.enter(connection, "s") RHUIManager.select_one(connection, clustername) RHUIManager.select(connection, repolist) RHUIManager.proceed_with_check(connection, "The following repositories will be associated with the " + clustername + " cluster:", repolist, ["Red Hat Repositories", "Custom Repositories"]) RHUIManager.quit(connection)
def list(connection): ''' return the list of currently managed CDSes ''' RHUIManager.screen(connection, "cds") # eating prompt!! lines = RHUIManager.list_lines(connection, prompt=RHUIManagerCds.prompt) ret = Cds.parse(lines) # custom quitting; have eaten the prompt Expect.enter(connection, 'q') return [cds for _, cds in ret]
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 delete_repo(connection, repolist): ''' delete a repository from the RHUI ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "d") RHUIManager.select(connection, repolist) RHUIManager.proceed_with_check( connection, "The following repositories will be deleted:", repolist, ["Red Hat Repositories", "Custom Repositories"]) RHUIManager.quit(connection)
def get_repo_status(connection, repo_name): ''' (internally used) method to get the status of the given repository ''' Expect.enter(connection, "rhui-manager status") status = Expect.match( connection, re.compile( ".*" + Util.esc_parentheses(repo_name) + "[^A-Z]*([A-Za-z]*).*", re.DOTALL))[0] return status
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 info(connection, repolist): ''' detailed information about repositories Method returns list of items from rhui-manager info screen. Some of them are variable and these are replaced by "rh_repo" constant. ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "i") RHUIManager.select(connection, repolist) try: pattern = re.compile( '.*for more commands: \r\n\r\nName:\s(.*)\r\n-+\r\nrhui\s* \(repo\)\s* =>', re.DOTALL) ret = Expect.match(connection, pattern, grouplist=[1])[0] print ret res = map(lambda x: x.strip(), ret.split("\r\n")) reslist = ["Name:"] for line in res: reslist.extend( map(lambda y: y.strip(), re.split("\s{3}", line))) print reslist repoinfo = [] rh_repo = 0 rh_repo_info = 0 for line in reslist: # Readling lines if line == '': continue if rh_repo_info == 1: line = "rh_repo" rh_repo_info = 0 if line == "Red Hat": rh_repo = 1 if "Relative Path:" in line: if rh_repo == 1: rh_repo_info = 1 if "Package Count:" in line: if rh_repo == 1: rh_repo_info = 1 if "Last Sync:" in line: if rh_repo == 1: rh_repo_info = 1 if "Next Sync:" in line: if rh_repo == 1: rh_repo_info = 1 repoinfo.append(line) print repoinfo except: repoinfo = [] Expect.enter(connection, 'q') return repoinfo
def move_cds(connection, cdslist, clustername): ''' move the CDSes to clustername ''' RHUIManager.screen(connection, "cds") Expect.enter(connection, "m") RHUIManager.select(connection, cdslist) RHUIManagerCds._select_cluster(connection, clustername) RHUIManager.proceed_with_check(connection, "The following Content Delivery Servers will be moved to the %s cluster:\r\n.*-+" % clustername, cdslist) RHUIManager.quit(connection, "successfully moved CDS")
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 _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 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 screen(connection, screen_name): ''' Open specified rhui-manager screen ''' if screen_name in ["repo", "cds", "loadbalancers", "sync", "identity", "users"]: key = screen_name[:1] elif screen_name == "client": key = "e" elif screen_name == "entitlements": key = "n" Expect.enter(connection, key) Expect.expect(connection, "rhui \(" + screen_name + "\) =>")
def command_output(connection, command, pattern_tuple, username="******", password="******"): """return output of a command based on pattern_tuple provided. Output is split to lines""" Expect.enter(connection, "pulp-admin -u %s -p %s %s" % \ (username, password, command)) # eats prompt! pattern, group_index = pattern_tuple ret = Expect.match(connection, pattern, grouplist=[group_index])[0] # reset prompt Expect.enter(connection, "") return ret.split('\r\n')
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 info(connection, repolist): ''' detailed information about repositories Method returns list of items from rhui-manager info screen. Some of them are variable and these are replaced by "rh_repo" constant. ''' RHUIManager.screen(connection, "repo") Expect.enter(connection, "i") RHUIManager.select(connection, repolist) try: pattern = re.compile('.*for more commands: \r\n\r\nName:\s(.*)\r\n-+\r\nrhui\s* \(repo\)\s* =>', re.DOTALL) ret = Expect.match(connection, pattern, grouplist=[1])[0] print ret res = map(lambda x: x.strip(), ret.split("\r\n")) reslist = ["Name:"] for line in res: reslist.extend(map(lambda y: y.strip(), re.split("\s{3}", line))) print reslist repoinfo = [] rh_repo = 0 rh_repo_info = 0 for line in reslist: # Readling lines if line == '': continue if rh_repo_info == 1: line = "rh_repo" rh_repo_info = 0 if line == "Red Hat": rh_repo = 1 if "Relative Path:" in line: if rh_repo == 1: rh_repo_info = 1 if "Package Count:" in line: if rh_repo == 1: rh_repo_info = 1 if "Last Sync:" in line: if rh_repo == 1: rh_repo_info = 1 if "Next Sync:" in line: if rh_repo == 1: rh_repo_info = 1 repoinfo.append(line) print repoinfo except: repoinfo = [] Expect.enter(connection, 'q') return repoinfo
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 list(connection): """ return the list currently managed CDSes and clusters as it is provided by the cds list command """ RHUIManager.screen(connection, "cds") Expect.enter(connection, "l") # eating prompt!! pattern = re.compile("l(\r\n)+(.*)rhui\s* \(cds\)\s* =>", re.DOTALL) ret = Expect.match(connection, pattern, grouplist=[2])[0] # custom quitting; have eaten the prompt Expect.enter(connection, "q") return ret
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 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 move_cds(connection, cdslist, clustername): """ move the CDSes to clustername """ RHUIManager.screen(connection, "cds") Expect.enter(connection, "m") RHUIManager.select(connection, cdslist) RHUIManagerCds._select_cluster(connection, clustername) RHUIManager.proceed_with_check( connection, "The following Content Delivery Servers will be moved to the %s cluster:\r\n.*-+" % clustername, cdslist, ) RHUIManager.quit(connection, "successfully moved CDS")