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 test_02_add_repos(self): """create custom repos for testing""" for repo_id, repo_name in zip(self.test_repos, self.test_repo_names): RHUIManagerCLI.repo_create_custom(RHUA, repo_id, display_name=repo_name, protected=True)
def test_19_generate_certificate(self): '''generate an entitlement certificate''' # generate it for RH repos and the first protected custom repo # the label is the repo ID in the case of custom repos RHUIManagerCLI.client_cert(RHUA, self.yum_repo_labels + [CUSTOM_REPOS[1]], CLI_CFG[0], 365, "/tmp")
def test_27_upload_expired_cert(): '''check expired certificate handling''' try: RHUIManagerCLI.cert_upload(RHUA, "%s/%s" % (DATADIR, CERTS["expired"])) except RuntimeError as err: nose.tools.ok_("The provided certificate is expired or invalid" in str(err), msg="unexpected error: %s" % err)
def test_45_multi_repo_product(self): '''check that all repos in a multi-repo product get added''' # for RHBZ#1651638 RHUIManagerCLI.cert_upload(RHUA, "%s/%s" % (DATADIR, CERTS["Atomic"])) RHUIManagerCLI.repo_add(RHUA, self.product["name"]) # wait a few seconds for the repo to actually get added time.sleep(4) repolist_actual = RHUIManagerCLI.repo_list(RHUA, True).splitlines() nose.tools.eq_([self.product["id"]], repolist_actual)
def test_06_import_updateinfo(self): ''' import update info ''' # only doable in the CLI RHUIManagerCLI.repo_add_errata(RHUA, self.test["repo_id"], "/tmp/extra_rhui_files/%s/updateinfo.xml.gz" % \ self.test["repo_id"])
def test_31_register_subscription(): '''register the subscription using the fetched pool ID''' try: with open(AVAILABLE_POOL_FILE) as apf: available_pool = apf.read() except IOError: raise RuntimeError("pool ID was not fetched") nose.tools.ok_(re.match(r"^[0-9a-f]+$", available_pool), msg="invalid pool ID: '%s'" % available_pool) RHUIManagerCLI.subscriptions_register(RHUA, available_pool)
def test_22_create_cli_config_rpm(): '''create a client configuration RPM''' RHUIManagerCLI.client_rpm( RHUA, ["/tmp/%s.key" % CLI_CFG[0], "/tmp/%s.crt" % CLI_CFG[0]], CLI_CFG, "/tmp", [CUSTOM_REPOS[0]], "_none_") # check if the rpm was created conf_rpm = "/tmp/%s-%s/build/RPMS/noarch/%s-%s-%s.noarch.rpm" % tuple( CLI_CFG[:2] + CLI_CFG) Expect.expect_retval(RHUA, "test -f %s" % conf_rpm)
def test_35_unregister_subscription(): '''remove the subscription from RHUI''' try: with open(REGISTERED_POOL_FILE) as rpf: registered_pool = rpf.read() except IOError: raise RuntimeError("no known registered pool ID") nose.tools.ok_(re.match(r"^[0-9a-f]+$", registered_pool), msg="invalid pool ID: '%s'" % registered_pool) RHUIManagerCLI.subscriptions_unregister(RHUA, registered_pool)
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_28_upload_incompat_cert(): '''check incompatible certificate handling''' cert = "%s/%s" % (DATADIR, CERTS["incompatible"]) if Util.cert_expired(RHUA, cert): raise nose.exc.SkipTest( "The given certificate has already expired.") try: RHUIManagerCLI.cert_upload(RHUA, cert) except RuntimeError as err: nose.tools.ok_("does not contain any entitlements" in str(err), msg="unexpected error: %s" % err)
def test_44_upload_empty_cert(): '''check that an empty certificate is rejected (no traceback)''' # for RHBZ#1497028 cert = "%s/%s" % (DATADIR, CERTS["empty"]) if Util.cert_expired(RHUA, cert): raise nose.exc.SkipTest( "The given certificate has already expired.") try: RHUIManagerCLI.cert_upload(RHUA, cert) except RuntimeError as err: nose.tools.ok_("does not contain any entitlements" in str(err), msg="unexpected error: %s" % err)
def test_99_cleanup(self): '''cleanup: remove repos and temporary files''' RHUIManagerCLI.repo_delete(RHUA, self.product["id"]) RHUIManager.remove_rh_certs(RHUA) Expect.ping_pong( RHUA, "rm -rf /tmp/%s* ; " % CLI_CFG[0] + "ls /tmp/%s* 2>&1" % CLI_CFG[0], "No such file or directory") Expect.ping_pong( RHUA, "rm -f /tmp/repos.std{out,err} ; " + "ls /tmp/repos.std{out,err} 2>&1", "No such file or directory") Expect.ping_pong( RHUA, "rm -rf /tmp/%s* ; " % ALT_CONTENT_SRC_NAME + "ls /tmp/%s* 2>&1" % ALT_CONTENT_SRC_NAME, "No such file or directory") rmtree(TMPDIR)
def test_14_empty_comps(): """import a comps file containing no group and expect no problem and no repodata refresh""" # use the cached comps file for RH-Common, which is known to be empty original_comps_xml = "/var/cache/yum/x86_64/7Server/%s/*comps.xml" % EMP_REPO # re-use the big repo for testing # get the current comps file name for that repo in RHUI processed_comps_xml_before = Yummy.repodata_location( RHUA, BIG_REPO, "group") # import the empty comps; should be accepted RHUIManagerCLI.repo_add_comps(RHUA, BIG_REPO, original_comps_xml) # re-get the comps file in RHUI name after the import processed_comps_xml_after = Yummy.repodata_location( RHUA, BIG_REPO, "group") # should be the same; comparing just the file names as the directory is definitely identical nose.tools.eq_(basename(processed_comps_xml_before), basename(processed_comps_xml_after))
def test_05_check_custom_repos(): '''check if the custom repos were actually created''' # try a delimiter this time delimiter = "," repos_expected = delimiter.join(sorted(CUSTOM_REPOS)) repos_actual = RHUIManagerCLI.repo_list(RHUA, True, False, delimiter) nose.tools.eq_(repos_expected, repos_actual)
def test_17_check_package_in_repo(self): '''check a random package in the repo''' package_list = RHUIManagerCLI.packages_list(RHUA, self.yum_repo_ids[1]) test_package_list = [ package for package in package_list if package.startswith(OST_PKG) ] nose.tools.ok_(test_package_list, msg="no %s* in %s" % (OST_PKG, package_list))
def test_26_create_acs_config_rpm(self): '''create an alternate content source configuration RPM''' # for RHBZ#1695464 name = ALT_CONTENT_SRC_NAME RHUIManagerCLI.client_content_source(RHUA, self.yum_repo_labels, [name], "/tmp") # check that cmd = "rpm2cpio /tmp/%s-2.0/build/RPMS/noarch/%s-2.0-1.noarch.rpm | " % (name, name) + \ r"cpio -i --to-stdout \*.conf | " + \ "sed -n -e '/^paths:/,$p' | " + \ "sed s/paths://" _, stdout, _ = RHUA.exec_command(cmd) paths_actual_raw = stdout.read().decode().splitlines() # the paths are indented, let's get rid of the formatting paths_actual = [p.lstrip() for p in paths_actual_raw] # the OSTree repo must not be included paths_expected = [p for p in self.yum_repo_paths if OST_PKG not in p] nose.tools.eq_(paths_expected, paths_actual)
def test_34_check_reg_pool_for_rhui(self): '''check if the registered subscription's description is RHUI for CCSP''' reg_sub = RHUIManagerCLI.subscriptions_list(RHUA) nose.tools.ok_(reg_sub, msg="no subscription is registered") nose.tools.eq_( self.subscriptions["RHUI"], list(reg_sub.keys())[0], msg="Expected subscription not registered in RHUI! Got: %s" % reg_sub)
def test_13_uncompressed_xml(self): ''' also check if an uncompressed updateinfo.xml file can be used ''' # RHEL 6 uses the same set of errata; let's remove errata from MongoDB first so they # can actually be uploaded from the uncompressed XML if self.test["repo_id"] == self.test["uncompressed_updateinfo"]: Expect.expect_retval( RHUA, "mongo pulp_database --eval 'db.units_erratum.remove({})'") RHUIManagerCLI.repo_add_errata(RHUA, self.test["repo_id"], "/tmp/extra_rhui_files/%s/updateinfo.xml" % \ self.test["uncompressed_updateinfo"]) # not going to test that on a client, just checking the log Expect.expect_retval( RHUA, "tail -1 ~/.rhui/rhui.log | grep 'Import of erratum.*was successful'" )
def test_32_fetch_registered_pool(): '''fetch the registered pool ID''' registered_pools = RHUIManagerCLI.subscriptions_list( RHUA, "registered", True) nose.tools.ok_(registered_pools, msg="no registered pool") registered_pool = registered_pools[0] nose.tools.ok_(re.match(r"^[0-9a-f]+$", registered_pool), msg="invalid pool ID: '%s'" % registered_pool) with open(REGISTERED_POOL_FILE, "w") as rpf: rpf.write(registered_pool)
def test_30_fetch_available_pool(): '''fetch the available pool ID''' available_pools = RHUIManagerCLI.subscriptions_list( RHUA, "available", True) nose.tools.ok_(available_pools, msg="no available pool") available_pool = available_pools[0] nose.tools.ok_(re.match(r"^[0-9a-f]+$", available_pool), msg="invalid pool ID: '%s'" % available_pool) with open(AVAILABLE_POOL_FILE, "w") as apf: apf.write(available_pool)
def test_43_upload_semi_bad_cert(self): '''check that a partially invalid certificate can still be accepted''' # for RHBZ#1588931 & RHBZ#1584527 # delete currently used certificates and repos first RHUIManager.remove_rh_certs(RHUA) for repo in CUSTOM_REPOS + self.yum_repo_ids: RHUIManagerCLI.repo_delete(RHUA, repo) repolist = RHUIManagerCLI.repo_list(RHUA, True) nose.tools.ok_(not repolist, msg="can't continue as some repos remain: %s" % repolist) # try uploading the cert now cert = "%s/%s" % (DATADIR, CERTS["partial"]) if Util.cert_expired(RHUA, cert): raise nose.exc.SkipTest( "The given certificate has already expired.") RHUIManagerCLI.cert_upload(RHUA, cert) # the RHUI log must contain the fact that an invalid path was found in the cert Expect.ping_pong(RHUA, "tail /root/.rhui/rhui.log", "Invalid entitlement path") RHUIManager.remove_rh_certs(RHUA)
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 test_13_big_comps(): """import comps for the (big) RHEL 7Server repo and check if all its groups get processed""" # first force the RHUA to cache RHEL repodata # (using a recent 3.x AWS client RPM; remove this when such an RPM is common in RHEL 7 AMIs) Expect.expect_retval(RHUA, "yum -y update rh-amazon-rhui-client", timeout=60) Expect.expect_retval(RHUA, "yum repolist enabled", timeout=60) # get all groups from this repodata; using a wildcard as there's only one cached comps file original_comps_xml = "/var/cache/yum/x86_64/7Server/%s/*comps.xml" % BIG_REPO original_groups = Yummy.comps_xml_grouplist(RHUA, original_comps_xml, False) # create a custom repo for the 7Server repo, import the cached comps file RHUIManagerCLI.repo_create_custom(RHUA, BIG_REPO) RHUIManagerCLI.repo_add_comps(RHUA, BIG_REPO, original_comps_xml) # this can actually take a while to get fully processed, so better check for Pulp tasks RHUIManagerSync.wait_till_pulp_tasks_finish(RHUA) # get all groups from the imported metadata processed_comps_xml = Yummy.repodata_location(RHUA, BIG_REPO, "group") processed_groups = Yummy.comps_xml_grouplist(RHUA, processed_comps_xml, False) # compare the groups nose.tools.eq_(original_groups, processed_groups)
def test_12_additional_group(self): """import a comps file containing one more group and expect the group to be added""" # and nothing lost... # import the "updated" comps file repo = self.repo_with_mod_groups modified_comps_xml = "/tmp/extra_rhui_files/%s/mod-comps.xml" % repo RHUIManagerCLI.repo_add_comps(RHUA, repo, modified_comps_xml) # create a client configuration RPM, install it on the client RHUIManagerCLI.client_rpm(RHUA, [repo], [repo, "2.1"], "/tmp") Util.remove_rpm(CLI, [self.test_repos[1]]) Util.install_pkg_from_rhua(RHUA, CLI, "/tmp/%s-2.1/build/RPMS/noarch/%s-2.1-1.noarch.rpm" % \ (repo, repo)) # compare client's available groups with the *original* comps file, # expecting all the original groups plus the extra group groups_on_client = Yummy.yum_grouplist(CLI) original_comps_xml = "/tmp/extra_rhui_files/%s/comps.xml" % repo groups_in_xml = Yummy.comps_xml_grouplist(RHUA, original_comps_xml) # trick: put the extra group to the right place in the sorted list insort(groups_in_xml, self.test_group_mod) nose.tools.eq_(groups_on_client, groups_in_xml) nose.tools.ok_(self.test_group_mod in groups_on_client)
def repodata_location(connection, repo, datatype): """return the path to the repository file (on the RHUA) of the given data type""" # data types are : filelists, group, primary, updateinfo etc. base_path = "/var/lib/rhui/remote_share/published/yum/https/repos" relative_path = RHUIManagerCLI.repo_info(connection, repo)["relativepath"] repodata_file = "%s/%s/repodata/repomd.xml" % (base_path, relative_path) _, stdout, _ = connection.exec_command("cat %s " % repodata_file) repodata = xmltodict.parse(stdout.read()) location_list = [data["location"]["@href"] for data in repodata["repomd"]["data"] \ if data["@type"] == datatype] if location_list: location = location_list[0] wanted_file = "%s/%s/%s" % (base_path, relative_path, location) return wanted_file return None
def test_03_create_custom_repos(): '''create three custom repos for testing''' # the first repo will be unprotected, with default parameters RHUIManagerCLI.repo_create_custom(RHUA, CUSTOM_REPOS[0]) # the second repo will have a lot of custom parameters; it will be a protected repo RHUIManagerCLI.repo_create_custom(RHUA, repo_id=CUSTOM_REPOS[1], path="huh-%s" % CUSTOM_REPOS[1], display_name=CR_NAMES[1], legacy_md=True, protected=True, gpg_public_keys="%s/%s" % (DATADIR, KEYFILE)) # the third repo will also be protected RHUIManagerCLI.repo_create_custom(RHUA, repo_id=CUSTOM_REPOS[2], protected=True)
def test_02_check_empty_repo_list(): '''check if the repo list is empty''' repolist = RHUIManagerCLI.repo_list(RHUA, True) nose.tools.ok_(not repolist, msg="there are some repos already: %s" % repolist)
def test_37_resync_repo(self): '''sync the repo again''' RHUIManagerCLI.repo_sync(RHUA, self.yum_repo_ids[1], self.yum_repo_names[1])
def test_42_check_repo_sorting(self): '''check if repo lists are sorted''' # for RHBZ#1601478 repolist_expected = sorted(CUSTOM_REPOS + self.yum_repo_ids) repolist_actual = RHUIManagerCLI.repo_list(RHUA, True).splitlines() nose.tools.eq_(repolist_expected, repolist_actual)