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 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 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 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 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_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_with_check(connection, "The following repositories will be deleted:", repolist, ["Red Hat Repositories", "Custom Repositories"]) RHUIManager.quit(connection)
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 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 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")) print reslist 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) Expect.enter(connection, 'q') return packagelist
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 install_rpm_from_rhua(rhua_connection, connection, rpmpath): ''' Transfer RPM package from RHUA host to the instance and install it @param rpmpath: path to RPM package on RHUA node ''' tfile = tempfile.NamedTemporaryFile(delete=False) tfile.close() rhua_connection.sftp.get(rpmpath, tfile.name) connection.sftp.put(tfile.name, tfile.name + ".rpm") os.unlink(tfile.name) Expect.ping_pong(connection, "rpm -i " + tfile.name + ".rpm" + " && echo SUCCESS", "[^ ]SUCCESS", 60)
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 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 _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 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 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 upload_content_cert(connection, certpath): ''' upload a new or updated Red Hat content certificate ''' if certpath[:1] == '/': Expect.enter(connection, "mkdir -p `dirname " + certpath + "` && echo SUCCESS") Expect.expect(connection, "[^ ]SUCCESS") connection.sftp.put(certpath, certpath) RHUIManager.screen(connection, "entitlements") Expect.enter(connection, "u") Expect.expect(connection, "Full path to the new content certificate:") Expect.enter(connection, certpath) RHUIManager.proceed_with_check(connection, "The RHUI will be updated with the following certificate:", [certpath]) RHUIManager.quit(connection, "Red Hat Entitlements.*Valid.*------------------")
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 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 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 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 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 list_custom_entitlements(connection): ''' list custom entitlements ''' RHUIManager.screen(connection, "entitlements") Expect.enter(connection, "c") match = Expect.match(connection, re.compile("c\r\n\r\nCustom Repository Entitlements\r\n\r\n(.*)" + RHUIManagerEntitlements.prompt, re.DOTALL))[0] repo_list = [] for line in match.splitlines(): if "Name:" in line: repo_list.append(line.replace("Name:", "").strip()) return sorted(repo_list)
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_rh_entitlements(connection): ''' list Red Hat entitlements ''' RHUIManager.screen(connection, "entitlements") Expect.enter(connection, "l") match = Expect.match(connection, re.compile("(.*)" + RHUIManagerEntitlements.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) entitlements_list = [] pattern = re.compile('(.*?\r\n.*?pem)', re.DOTALL) for entitlement in pattern.findall(matched_string): entitlements_list.append(entitlement.strip()) return entitlements_list
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 select_items(connection, *items): ''' Select list of items (multiple choice) ''' for item in items: index = 0 selected = False lines = RHUIManager.list_lines(connection, prompt=CONFIRM_PATTERN_STRING, enter_l=False) selected, index = item.selected(lines) if not selected: # insert the on-screen index nr to trigger item selection Expect.enter(connection, str(index)) lines = RHUIManager.list_lines(connection, prompt=CONFIRM_PATTERN_STRING, enter_l=False) selected, index = item.selected(lines) assert selected, 'item #%s %s not selected' % (index, item) # confirm selection Expect.enter(connection, "c")
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 select(connection, value_list): ''' Select list of items (multiple choice) ''' for value in value_list: match = Expect.match(connection, re.compile(".*-\s+([0-9]+)\s*:[^\n]*\s+" + value + "\s*\n.*for more commands:.*", re.DOTALL)) Expect.enter(connection, match[0]) match = Expect.match(connection, re.compile(".*x\s+([0-9]+)\s*:[^\n]*\s+" + value + "\s*\n.*for more commands:.*", re.DOTALL)) Expect.enter(connection, "l") Expect.enter(connection, "c")
def subscriptions_register(connection, pool): ''' register the subscription to RHUI ''' Expect.expect_retval( connection, "rhui-manager subscriptions register --pool %s" % pool)
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) RHUIManager.quit(connection, "Successfully created repository *") else: Expect.enter(connection, '\x03') RHUIManager.quit(connection)
def test_11_check_gpg_sig(): ''' check the signature in the installed package ''' Expect.expect_retval( CLI, "rpm -qi %s | grep ^Signature.*%s$" % (SIGNED_PACKAGE, SIG))
def unbreak_hostname(connection): """undo the changes made by break_hostname""" Expect.expect_retval(connection, "mv -f /etc/hosts.bak /etc/hosts") Expect.expect_retval(connection, "service named start")
def check_rhui_sos_script(connection): ''' check if the RHUI sosreport script is available ''' Expect.expect_retval(connection, "test -f /usr/share/rh-rhua/rhui-debug.py")
def proceed_without_check(connection): ''' Proceed without check (avoid this function when possible!) ''' Expect.expect(connection, r"Proceed\? \(y/n\)") Expect.enter(connection, "y")
def add_ssh_keys(connection, hostnames, keytype="rsa"): """gather SSH keys for the given hosts""" Expect.expect_retval( connection, "ssh-keyscan -t %s %s >> ~/.ssh/known_hosts" % (keytype, " ".join(hostnames)))
def test_05_login_with_wrong_pass(): ''' try logging in with the wrong password, should fail gracefully ''' # for RHBZ#1282522 Expect.enter(RHUA, "rhui-manager") Expect.expect(RHUA, ".*RHUI Username:.*") Expect.enter(RHUA, "admin") Expect.expect(RHUA, "RHUI Password:"******"wrong_pass") Expect.expect( RHUA, ".*Invalid login, please check the authentication credentials and try again." )
def generate_new(connection, days="", cert_pw=None): ''' generate a new identity certificate ''' RHUIManager.screen(connection, "identity") Expect.enter(connection, "g") Expect.expect(connection, "Proceed\? \[y/n\]") Expect.enter(connection, "y") 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)) RHUIManager.quit(connection, "Successfully regenerated RHUI Identity certificate", 30)
def _add_cds_part1(connection, cdsname, hostname="", displayname=""): ''' service function for add_cds ''' Expect.enter(connection, "a") Expect.expect(connection, "Hostname of the CDS to register:") Expect.enter(connection, cdsname) Expect.expect(connection, "Client hostname \(hostname clients will use to connect to the CDS\).*:") Expect.enter(connection, hostname) Expect.expect(connection, "Display name for the CDS.*:") Expect.enter(connection, displayname)
def info(connection, clusterlist): ''' display detailed information on a CDS clusters @param clusterlist - list of clusters to examine @returns a list of Cds instances ''' RHUIManager.screen(connection, "cds") Expect.enter(connection, "i") RHUIManager.select(connection, clusterlist) pattern = re.compile('.*-= RHUI CDS Clusters =-(.*)rhui\s* \(cds\)\s* =>', re.DOTALL) ret = Expect.match(connection, pattern, grouplist=[1])[0] reslist = ret.split("\r\n") i = 0 clusterlist = [] cluster = {} while i < len(reslist): line = reslist[i] # Readling lines and searching for clusters if line.strip() != '': if line[:2] == ' ' and not line[2:3] in [' ', '-']: # We've found a new cluster! if cluster != {}: clusterlist.append(cluster) cluster = {} cluster['Name'] = line[2:] i += 2 while reslist[i][:4] == ' ' or reslist[i] == '': if reslist[i] == '': i += 1 continue line = reslist[i].strip() if line == "CDS Instances": # Figuring out cds instances instances = [] i += 2 while reslist[i].strip() != "": # New cds cds = reslist[i].strip() hostname = reslist[i + 1].strip().split(':')[1].strip() client = reslist[i + 2].strip().split(':')[1].strip() instances.append(RhuiCds(name=reslist[i].strip(), hostname=hostname, client_hostname=client, description='RHUI CDS', cluster=cluster['Name'])) i += 3 cluster['Instances'] = sorted(instances) elif line == "Repositories": # Figuring out repositories repositories = [] i += 2 while reslist[i].strip() != "": # New repo repo = reslist[i].strip() i += 1 if repo == '(None)': # no repos, continue with next (empty) # line continue repositories.append(repo) cluster['Repositories'] = repositories # update all cluster CDSes with appropriate repo # records for cds in cluster['Instances']: cds.repos = repositories break else: i += 1 i += 1 if cluster != {}: clusterlist.append(cluster) cdses = [] for cluster in clusterlist: cdses.extend(cluster['Instances']) Expect.enter(connection, 'q') return cdses
def repo_delete(connection, repo_id): ''' delete the given repo ''' Expect.expect_retval(connection, "rhui-manager repo delete --repo_id %s" % repo_id)
def restore_rhui_tools_conf(connection): """restore the backup copy of the RHUI tools configuration file""" cfg_file = "/etc/rhui/rhui-tools.conf" Expect.expect_retval(connection, "mv -f %s.bak %s" % (cfg_file, cfg_file))
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)
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 test_06_pulp_server_rpm_v(): ''' verify that /etc/pki/pulp/rsa_pub.key is installed correctly ''' # for RHBZ#1578266 Expect.expect_retval(RHUA, "rpm -V pulp-server | grep /etc/pki/pulp/rsa_pub.key", 1)
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 test_12_check_gpg_pubkey(): ''' check if the public GPG key was imported ''' Expect.expect_retval(CLI, "rpm -q gpg-pubkey-%s" % SIG)
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) RHUIManager.quit(connection)
def test_05_celery_selinux(): ''' verify that no SELinux denial related to celery was logged ''' # for RHBZ#1608166 - anyway, only non-fatal denials are expected if everything else works Expect.ping_pong(RHUA, "grep celery /var/log/audit/audit.log | audit2allow", "Nothing to do")
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 break_hostname(connection, hostname): """override DNS by setting a fake IP address in /etc/hosts and stopping bind""" tweak_hosts_cmd = r"sed -i.bak 's/^[^ ]*\(.*%s\)$/256.0.0.0\1/' /etc/hosts" % hostname Expect.expect_retval(connection, tweak_hosts_cmd) Expect.expect_retval(connection, "service named stop")
def test_04_fabric_crypto_req(): ''' check if the fabric package requires python-crypto ''' # for RHBZ#1615907 Expect.expect_retval(RHUA, "rpm -qR fabric | grep python-crypto")
def test_01_install_wget(): ''' make sure wget is installed on the RHUA ''' Expect.expect_retval(RHUA, "yum -y install wget", timeout=30)
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 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 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 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.")
def test_10_install_signed_pkg(): ''' install the signed package from the custom repo (will import the GPG key) ''' Expect.expect_retval(CLI, "yum -y install %s" % SIGNED_PACKAGE)