def check_custom_repos_are_valid(): """To prevent failures past the PONR, make sure that the enabled custom repositories are valid. What is meant by valid: - YUM/DNF is able to find the repoids (to rule out a typo) - the repository "baseurl" is accessible and contains repository metadata """ logger.task( "Prepare: Checking if --enablerepo repositories are accessible") if not tool_opts.no_rhsm: logger.info( "Skipping the check of repositories due to the use of RHSM for the conversion." ) return # Without clearing the metadata cache, the `yum makecache` command may return 0 (everything's ok) even when # the baseurl of a repository is not accessible. That would happen when the repository baseurl is changed but yum # still uses the previous baseurl stored in its cache. call_yum_cmd(command="clean", args=["metadata"], print_output=False) output, ret_code = call_yum_cmd( command="makecache", args=["-v", "--setopt=*.skip_if_unavailable=False"], print_output=False) if ret_code != 0: logger.critical( "Unable to access the repositories passed through the --enablerepo option. " "For more details, see YUM/DNF output:\n{0}".format(output)) else: logger.debug("Output of the previous yum command:\n{0}".format(output)) logger.info( "The repositories passed through the --enablerepo option are all accessible." )
def remove_subscription_manager(): loggerinst.info("Removing RHEL subscription-manager packages.") # python3-subscription-manager-rhsm, dnf-plugin-subscription-manager, subscription-manager-rhsm-certificates, etc. submgr_pkgs = pkghandler.get_installed_pkgs_by_fingerprint(system_info.fingerprints_rhel, "*subscription-manager*") if not submgr_pkgs: loggerinst.info("No packages related to subscription-manager installed.") return pkghandler.call_yum_cmd("remove", " ".join(submgr_pkgs), print_output=False)
def install_rhel_subscription_manager(): loggerinst = logging.getLogger(__name__) loggerinst.info("Installing subscription-manager RPMs.") rpms_to_install = [ os.path.join(SUBMGR_RPMS_DIR, filename) for filename in os.listdir(SUBMGR_RPMS_DIR) ] if not rpms_to_install: loggerinst.warn("No RPMs found in %s." % SUBMGR_RPMS_DIR) return _, ret_code = pkghandler.call_yum_cmd( # We're using distro-sync as there might be various versions of the subscription-manager pkgs installed # and we need these packages to be replaced with the provided RPMs from RHEL. "install", " ".join(rpms_to_install), # When installing subscription-manager packages, the RHEL repos are not available yet => we need to use # the repos that are available on the system enable_repos=[], disable_repos=[], # When using the original system repos, we need YUM/DNF to expand the $releasever by itself set_releasever=False) if ret_code: loggerinst.critical("Failed to install subscription-manager packages." " See the above yum output for details.") else: loggerinst.info("Packages installed:\n%s" % "\n".join(rpms_to_install))
def get_avail_repos(): """Get list of all the repositories (their IDs) currently available for the registered system. """ loggerinst = logging.getLogger(__name__) repos_raw, ret_code = pkghandler.call_yum_cmd(command="repolist -v ", print_output=False) if ret_code: loggerinst.critical("yum repolist command failed: \n\n" + repos_raw) line = "" repos = [] repo_id_prefix = "Repo-id : " for line in repos_raw.split("\n"): if (line.startswith(repo_id_prefix)): repoID = line.split(repo_id_prefix)[1] repos.append(repoID) return repos
def install_rhel_subscription_manager(): loggerinst.info("Checking for subscription-manager RPMs.") rpms_to_install = [ os.path.join(SUBMGR_RPMS_DIR, filename) for filename in os.listdir(SUBMGR_RPMS_DIR) ] if not rpms_to_install: loggerinst.warning("No RPMs found in %s." % SUBMGR_RPMS_DIR) return # These functions have to be called before installation of the # subscription-manager packages, otherwise # `pkghandler.filter_installed_pkgs()` would return every single package # that is listed in `rpms_to_install` and we don't want this to happen. We # want to know about the packages that were installed before the # installation of subscription-manager. pkg_names = pkghandler.get_pkg_names_from_rpm_paths(rpms_to_install) pkgs_to_not_track = pkghandler.filter_installed_pkgs(pkg_names) loggerinst.info("Installing subscription-manager RPMs.") _, ret_code = pkghandler.call_yum_cmd( # We're using distro-sync as there might be various versions of the subscription-manager pkgs installed # and we need these packages to be replaced with the provided RPMs from RHEL. command="install", args=rpms_to_install, print_output=True, # When installing subscription-manager packages, the RHEL repos are not available yet => we need to use # the repos that are available on the system enable_repos=[], disable_repos=[], # When using the original system repos, we need YUM/DNF to expand the $releasever by itself set_releasever=False, ) if ret_code: loggerinst.critical( "Failed to install subscription-manager packages. See the above yum output for details." ) loggerinst.info("\nPackages installed:\n%s" % "\n".join(rpms_to_install)) track_installed_submgr_pkgs(pkg_names, pkgs_to_not_track)
def test_call_yum_cmd(self): pkghandler.call_yum_cmd("install") self.assertEqual(utils.run_subprocess.cmd, "yum install -y")
def test_call_yum_cmd_with_submgr_enabled_repos(self): pkghandler.call_yum_cmd("install") self.assertEqual(utils.run_subprocess.cmd, "yum install -y --enablerepo=rhel-7-extras-rpm")