def packages_upload(connection, repo_id, path): ''' upload a package or a directory with packages to the custom repo ''' cmd = "rhui-manager packages upload --repo_id %s --packages %s" % ( repo_id, path) _, stdout, _ = connection.exec_command(cmd) output = stdout.read().decode().splitlines() successfully_uploaded_packages = [line.split()[0] for line in output \ if line.endswith("successfully uploaded")] if not successfully_uploaded_packages: raise RuntimeError("\n".join(output) or "no output from '%s'" % cmd) successfully_uploaded_packages.sort() path_type = Util.get_file_type(connection, path) if path_type == "regular file": expected_packages = [path] elif path_type == "directory": expected_packages = [ join(path, rpm) for rpm in Util.get_rpms_in_dir(connection, path) ] else: expected_packages = [] nose.tools.eq_(successfully_uploaded_packages, expected_packages)
def test_23_ensure_gpgcheck_config(self): '''ensure that GPG checking is configured in the client configuration as expected''' # for RHBZ#1428756 # we'll need the repo file in a few tests; fetch it now remote_repo_file = "/tmp/%s-%s/build/BUILD/%s-%s/rh-cloud.repo" % tuple( CLI_CFG[:2] * 2) try: Util.fetch(RHUA, remote_repo_file, YUM_REPO_FILE) except IOError: raise RuntimeError("configuration not created, can't test it") yum_cfg = ConfigParser() yum_cfg.read(YUM_REPO_FILE) # check RH repos: they all must have GPG checking enabled; get a list of those that don't bad = [ r for r in self.yum_repo_labels if not yum_cfg.getboolean("rhui-%s" % r, "gpgcheck") ] # check custom repos: the 2nd must have GPG checking enabled: if not yum_cfg.getboolean("rhui-custom-%s" % CUSTOM_REPOS[1], "gpgcheck"): bad.append(CUSTOM_REPOS[1]) # the first one mustn't: if yum_cfg.getboolean("rhui-custom-%s" % CUSTOM_REPOS[0], "gpgcheck"): bad.append(CUSTOM_REPOS[0]) nose.tools.ok_(not bad, msg="Unexpected GPG checking configuration for %s" % bad)
def test_99_cleanup(self): """clean up""" # remove the configuration RPM from the client Util.remove_rpm(CLI, [self.repo_with_mod_groups]) # remove comps info from MongoDB units = ["category", "environment", "group", "langpacks"] base_mongo_cmd = "db.units_package_%s.remove({})" all_mongo_cmds = [base_mongo_cmd % unit for unit in units] shell_cmd = "mongo pulp_database --eval '%s'" % "; ".join( all_mongo_cmds) Expect.expect_retval(RHUA, shell_cmd) # remove repos for repo in self.test_repos: RHUIManagerCLI.repo_delete(RHUA, repo) Expect.expect_retval(RHUA, "rm -rf /tmp/%s*" % repo) RHUIManagerCLI.repo_delete(RHUA, BIG_REPO) RHUIManagerCLI.repo_delete(RHUA, ZIP_REPO) # uninstall HAProxy & CDS, forget their keys if not getenv("RHUISKIPSETUP"): RHUICLI.delete(RHUA, "haproxy", force=True) RHUICLI.delete(RHUA, "cds", force=True) ConMgr.remove_ssh_keys(RHUA) # if running RHEL Beta, destroy the non-Beta repos again cmd = "if grep -c Beta /etc/redhat-release; then " \ "rm -f /etc/yum.repos.d/redhat-rhui.repo; fi" Expect.expect_retval(RHUA, cmd)
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 test_08_install_conf_rpm(self): """replace the 1st client configuration RPM with the 2nd one on the client""" # get rid of the first one before installing the second one Util.remove_rpm(CLI, [self.test_repos[0]]) Util.install_pkg_from_rhua(RHUA, CLI, "/tmp/%s-2.0/build/RPMS/noarch/%s-2.0-1.noarch.rpm" % \ (self.test_repos[1], self.test_repos[1]))
def test_10_install_conf_rpm(): ''' install configuration rpm to client ''' Util.install_pkg_from_rhua( connection, cli, "/root/test_cli_rpm-3.0/build/RPMS/noarch/test_cli_rpm-3.0-1.noarch.rpm" )
def test_10_install_atomic_pkg(): ''' install the Atomic client configuration package on the Atomic host ''' if AH_EXISTS: Util.install_pkg_from_rhua(RHUA, ATOMIC_CLI, "/root/test_atomic_pkg.tar.gz") else: raise nose.exc.SkipTest("No known Atomic host")
def test_13_inst_rpm_rh_repo(self): ''' install an RPM from the RH repo ''' Expect.expect_retval(CLI, "yum install -y %s" % self.test_package, timeout=20) # but make sure the RPM is taken from the RHUI Util.check_package_url(CLI, self.test_package, self.yum_repo_path)
def test_11_delete_one_repo(self): '''remove the Red Hat repo''' RHUIManagerRepo.delete_repo( RHUA, [Util.format_repo(self.yum_repo_name, self.yum_repo_version)]) repo_list = RHUIManagerRepo.list(RHUA) nose.tools.ok_( Util.format_repo(self.yum_repo_name, self.yum_repo_version) not in repo_list, msg="The repo wasn't removed. Actual repolist: %s" % repo_list)
def test_09_add_rh_repo_by_repo(self): '''add a Red Hat repo by its name''' RHUIManagerRepo.add_rh_repo_by_repo(RHUA, [ Util.format_repo(self.yum_repo_name, self.yum_repo_version, self.yum_repo_kind) ]) repo_list = RHUIManagerRepo.list(RHUA) nose.tools.ok_(Util.format_repo(self.yum_repo_name, self.yum_repo_version) in repo_list, msg="The repo wasn't added. Actual repolist: %s" % repo_list)
def test_16_install_docker_rpm(self): ''' install a docker client configuration RPM to client ''' if self.rhua_os_version < 7: raise nose.exc.SkipTest('Not supported on RHEL ' + str(self.rhua_os_version)) Util.install_pkg_from_rhua( connection, cli, "/root/test_docker_cli_rpm-4.0/build/RPMS/noarch/test_docker_cli_rpm-4.0-1.noarch.rpm" )
def test_99_cleanup(self): '''clean up''' Expect.expect_retval(CLI, "rhui-set-release --unset") Util.remove_rpm(CLI, [self.test_package, CONF_RPM_NAME]) RHUIManagerCLI.repo_delete(RHUA, self.repo_id) Expect.expect_retval(RHUA, "rm -rf /tmp/%s*" % CONF_RPM_NAME) if not getenv("RHUISKIPSETUP"): RHUIManager.remove_rh_certs(RHUA) RHUICLI.delete(RHUA, "haproxy", force=True) RHUICLI.delete(RHUA, "cds", force=True) ConMgr.remove_ssh_keys(RHUA)
def test_08_install_cli_rpm(self): ''' install the client configuration RPM ''' if not self.cli_supported: raise nose.exc.SkipTest("Not supported on RHEL %s" % self.cli_os_version) Util.install_pkg_from_rhua(RHUA, CLI, CONF_RPM_PATH) # restart the docker service for the configuration to take effect # (only clients running the docker service) Util.restart_if_present(CLI, "docker")
def test_11_sync_again(self): ''' sync the repo again (workaround for RHBZ#1427190) ''' atomic_repo_version = RHUIManagerRepo.get_repo_version( RHUA, self.atomic_repo_name) RHUIManagerSync.sync_repo( RHUA, [Util.format_repo(self.atomic_repo_name, atomic_repo_version)]) RHUIManagerSync.wait_till_repo_synced( RHUA, [Util.format_repo(self.atomic_repo_name, atomic_repo_version)])
def test_99_cleanup(self): ''' remove the repo, uninstall hap, cds, cli rpm artefacts; remove rpms from cli ''' Util.remove_rpm(CLI, [self.test["test_package"], self.test["repo_id"]]) # the errata must be removed in the DB directly: Expect.expect_retval( RHUA, "mongo pulp_database --eval 'db.units_erratum.remove({})'") RHUIManagerRepo.delete_all_repos(RHUA) Expect.expect_retval(RHUA, "rm -rf /tmp/%s*" % self.test["repo_id"]) if not getenv("RHUISKIPSETUP"): RHUIManagerInstance.delete_all(RHUA, "loadbalancers") RHUIManagerInstance.delete_all(RHUA, "cds")
def test_12_check_repo_sync_status(self): ''' check if RH repos were synced to install rpm ''' RHUIManager.initial_run(connection) if self.rhua_os_version < 7: RHUIManagerSync.wait_till_repo_synced(connection, [ Util.format_repo(self.yum_repo1_name, self.yum_repo1_version) ]) else: RHUIManagerSync.wait_till_repo_synced(connection, [ Util.format_repo(self.yum_repo2_name, self.yum_repo2_version) ])
def __init__(self): self.arch = Util.get_arch(CLI) self.version = Util.get_rhel_version(CLI)["major"] with open("/etc/rhui3_tests/tested_repos.yaml") as configfile: doc = yaml.load(configfile) try: self.test = doc["updateinfo"][self.version][self.arch] except KeyError: raise nose.SkipTest("No test repo defined for RHEL %s on %s" % \ (self.version, self.arch)) # the special "RHEL 0" repo contains updateinfo.xml instead of *.gz self.test["uncompressed_updateinfo"] = doc["updateinfo"][0]["all"][ "repo_id"]
def test_06_sync_containers(self): ''' sync the containers ''' quay_repo_name = Util.safe_pulp_repo_name(self.container_quay["name"]) docker_repo_name = Util.safe_pulp_repo_name( self.container_docker["name"]) RHUIManagerSync.sync_repo( RHUA, [self.container_displayname, quay_repo_name, docker_repo_name]) RHUIManagerSync.wait_till_repo_synced( RHUA, [self.container_displayname, quay_repo_name, docker_repo_name])
def test_05_add_upload_sync_stuff(self): ''' add a custom and RH content repos to protect by a cli entitlement cert, upload rpm, sync ''' RHUIManagerRepo.add_custom_repo(RHUA, CUSTOM_REPO, "", CUSTOM_PATH, "1", "y") RHUIManagerRepo.upload_content( RHUA, [CUSTOM_REPO], "%s/%s" % (CUSTOM_RPMS_DIR, self.custom_rpm)) RHUIManagerRepo.add_rh_repo_by_repo(RHUA, [ Util.format_repo(self.yum_repo_name, self.yum_repo_version, self.yum_repo_kind) ]) RHUIManagerSync.sync_repo( RHUA, [Util.format_repo(self.yum_repo_name, self.yum_repo_version)])
def initial_run(connection, username="******", password="******"): ''' Run rhui-manager and make sure we're logged in, then quit it. ''' Expect.enter(connection, "rhui-manager") state = Expect.expect_list( connection, [(re.compile(".*RHUI Username:.*", re.DOTALL), 1), (re.compile(r".*rhui \(home\) =>.*", re.DOTALL), 2)]) if state == 1: Expect.enter(connection, username) Expect.expect(connection, "RHUI Password:"******".*Invalid login.*", re.DOTALL), 1), (re.compile(r".*rhui \(home\) =>.*", re.DOTALL), 2)]) if password_state == 1: initial_password = Util.get_initial_password(connection) if not initial_password: raise RuntimeError( "Could not get the initial rhui-manager password.") Expect.enter(connection, "rhui-manager") Expect.expect(connection, ".*RHUI Username:"******"RHUI Password:"******"rhui \(home\) =>") Expect.enter(connection, "q")
def test_08_add_rh_repo_by_repository(self): '''Add a RH repo by repository''' RHUIManagerRepo.add_rh_repo_by_repo(connection, [ Util.format_repo(self.yum_repo_name, self.yum_repo_version, self.yum_repo_kind) ]) nose.tools.assert_not_equal(RHUIManagerRepo.list(connection), [])
def test_99_cleanup(): ''' clean up ''' Util.remove_rpm(CLI, [SIGNED_PACKAGE, "gpg-pubkey-%s" % SIG, REPO]) rhel = Util.get_rhel_version(CLI)["major"] if rhel <= 7: cache = "/var/cache/yum/x86_64/%sServer/rhui-custom-%s/" % (rhel, REPO) else: cache = "/var/cache/dnf/rhui-custom-%s*/" % REPO Expect.expect_retval(CLI, "rm -rf %s" % cache) RHUIManagerRepo.delete_all_repos(RHUA) Expect.expect_retval(RHUA, "rm -rf /tmp/%s*" % REPO) if not getenv("RHUISKIPSETUP"): RHUIManagerInstance.delete_all(RHUA, "loadbalancers") RHUIManagerInstance.delete_all(RHUA, "cds")
def initial_run(connection, crt="/etc/rhui/pem/ca.crt", key="/etc/rhui/pem/ca.key", cert_pw=None, days="", username="******", password="******"): ''' Do rhui-manager initial run ''' Expect.enter(connection, "rhui-manager") state = Expect.expect_list(connection, [(re.compile(".*Full path to the new signing CA certificate:.*", re.DOTALL), 1), (re.compile(".*RHUI Username:.*", re.DOTALL),2), (re.compile(".*rhui \(home\) =>.*", re.DOTALL), 3)]) if state in [1, 2]: if state == 1: # Need to answer sone first-run questions Expect.enter(connection, crt) Expect.expect(connection, "Full path to the new signing CA certificate private key:") Expect.enter(connection, key) Expect.expect(connection, "regenerated using rhui-manager.*:") Expect.enter(connection, days) Expect.expect(connection, "Enter pass phrase for.*:") if cert_pw: Expect.enter(connection, cert_pw) else: Expect.enter(connection, Util.get_ca_password(connection)) Expect.expect(connection, "RHUI Username:"******"RHUI Password:"******"rhui \(home\) =>") else: # initial step was already performed by someone pass
def repo_info(connection, repo_id, repo_name): ''' check if information about the given repo can be displayed ''' Expect.ping_pong(connection, "rhui-manager repo info --repo_id " + repo_id, "Name: *" + Util.esc_parentheses(repo_name))
def test_15_gzip(): """try using a compressed comps XML file, should be handled well""" # first force the RHUA to cache RHEL Optional repodata, which contains extra groups Expect.expect_retval(RHUA, "yum --enablerepo=%s repolist enabled" % ZIP_REPO, timeout=20) # get all groups from the cached file original_comps_xml = "/var/cache/yum/x86_64/7Server/%s/*comps.xml" % ZIP_REPO original_groups = Yummy.comps_xml_grouplist(RHUA, original_comps_xml, False) # prepare a temporary file and compress the original comps into it compressed_comps_xml = Util.mktemp_remote(RHUA, ".xml.gz") Expect.expect_retval( RHUA, "gzip -c %s > %s" % (original_comps_xml, compressed_comps_xml)) # create another test repo and add the compressed comps to it RHUIManagerCLI.repo_create_custom(RHUA, ZIP_REPO) RHUIManagerCLI.repo_add_comps(RHUA, ZIP_REPO, compressed_comps_xml) # get all groups from the imported metadata processed_comps_xml = Yummy.repodata_location(RHUA, ZIP_REPO, "group") processed_groups = Yummy.comps_xml_grouplist(RHUA, processed_comps_xml, False) # compare the groups nose.tools.eq_(original_groups, processed_groups) Expect.expect_retval(RHUA, "rm -f %s" % compressed_comps_xml)
def wait_till_pulp_tasks_finish(connection): ''' wait until there are no running Pulp tasks ''' # will be using pulp-admin, which requires you to log in to it # if the Pulp user cert has expired, delete it first of all; # if the Pulp user cert doesn't exist, use the one from rhui-manager # but create the .pulp directory (with the right perms) if it doesn't exist try: if Util.cert_expired(connection, "~/.pulp/user-cert.pem"): Expect.expect_retval(connection, "rm -f ~/.pulp/user-cert.pem") except OSError: pass rhua = ConMgr.get_rhua_hostname() Expect.expect_retval( connection, "if ! [ -e ~/.pulp/user-cert.pem ]; then " + "mkdir -p -m 700 ~/.pulp; " + "ln -s ~/.rhui/%s/user.crt ~/.pulp/user-cert.pem; " % rhua + "touch /tmp/pulploginhack; " + "fi") while connection.recv_exit_status( "pulp-admin tasks list | grep -q '^No tasks found'"): time.sleep(15) Expect.expect_retval( connection, "if [ -f /tmp/pulploginhack ]; then " + "rm -f ~/.pulp/user-cert.pem /tmp/pulploginhack; " + "fi")
def initial_run(connection, username="******", password="******"): ''' Do rhui-manager initial run ''' Expect.enter(connection, "rhui-manager") state = Expect.expect_list( connection, [(re.compile(".*RHUI Username:.*", re.DOTALL), 1), (re.compile(".*rhui \(home\) =>.*", re.DOTALL), 2)]) if state == 1: Expect.enter(connection, username) Expect.expect(connection, "RHUI Password:"******".*Invalid login.*", re.DOTALL), 1), (re.compile(".*rhui \(home\) =>.*", re.DOTALL), 2)]) if password_state == 1: initial_password = Util.get_initial_password(connection) Expect.enter(connection, "rhui-manager") Expect.expect(connection, ".*RHUI Username:"******"RHUI Password:"******"rhui \(home\) =>") else: pass else: # initial step was already performed by someone pass
def test_99_cleanup(self): ''' remove repos, certs, cli rpms; remove rpms from cli, uninstall cds, hap ''' test_rpm_name = self.custom_rpm.rsplit('-', 2)[0] RHUIManagerRepo.delete_all_repos(RHUA) nose.tools.assert_equal(RHUIManagerRepo.list(RHUA), []) Expect.expect_retval(RHUA, "rm -f /root/test_ent_cli*") Expect.expect_retval(RHUA, "rm -rf /root/test_cli_rpm-3.0/") Util.remove_rpm(CLI, [self.test_package, "test_cli_rpm", test_rpm_name]) rmtree(TMPDIR) Helpers.del_legacy_ca(CDS, LEGACY_CA_FILE) if not getenv("RHUISKIPSETUP"): RHUIManagerInstance.delete_all(RHUA, "loadbalancers") RHUIManagerInstance.delete_all(RHUA, "cds") RHUIManager.remove_rh_certs(RHUA)
def test_17_legacy_ca(): ''' check for bogus error messages if a legacy CA is used ''' # for RHBZ#1731856 # get the CA cert from the RHUA and upload it to the CDS # the cert is among the extra RHUI files, ie. in the directory also containing custom RPMs cds_lb = ConMgr.get_cds_lb_hostname() remote_ca_file = join(CUSTOM_RPMS_DIR, LEGACY_CA_FILE) local_ca_file = join(TMPDIR, LEGACY_CA_FILE) Util.fetch(RHUA, remote_ca_file, local_ca_file) Helpers.add_legacy_ca(CDS, local_ca_file) # re-fetch repodata on the client to trigger the OID validator on the CDS Expect.expect_retval(CLI, "yum clean all ; yum repolist enabled") Expect.expect_retval( CDS, "egrep 'Cert verification failed against [0-9]+ ca cert' " + "/var/log/httpd/%s_error_ssl.log" % cds_lb, 1)
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 test_25_register_system(): '''Register the system in RHSM, attach RHUI SKU''' # update subscription-manager first (due to RHBZ#1554482) rhua_os_version = Util.get_rhua_version(CONNECTION) if rhua_os_version["major"] == 7 and rhua_os_version["minor"] == 5: Expect.expect_retval(CONNECTION, "yum -y update subscription-manager", timeout=30) RHSMRHUI.register_system(CONNECTION) RHSMRHUI.attach_rhui_sku(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 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 check(cls, rs): """ Check """ if not 'rhrpm' in rs.config.keys(): raise nose.exc.SkipTest("can't test without RH-signed RPM") cls.rhrpm = rs.config['rhrpm'] (cls.rhrpmnvr, cls.rhrpmname) = Util.get_rpm_details(cls.rhrpm)