def call_yum_cmd_w_downgrades(cmd, pkgs): """Calling yum command is prone to end up with an error due to unresolved dependencies, especially when it tries to downgrade pkgs. This function tries to resolve the dependency errors where yum is not able to. """ for _ in range(MAX_YUM_CMD_CALLS): output, ret_code = call_yum_cmd(cmd, "%s" % (" ".join(pkgs))) loggerinst.info("Received return code: %s\n" % str(ret_code)) # handle success condition #1 if ret_code == 0: break # handle success condition #2 # false positive: yum returns non-zero code when there is nothing to do nothing_to_do_error_exists = output.endswith("Error: Nothing to do\n") if ret_code == 1 and nothing_to_do_error_exists: break # handle error condition loggerinst.info("Resolving dependency errors ... ") resolve_dep_errors(output, []) # if we have problematic packages, remove them problematic_pkgs = get_problematic_pkgs(output, []) if problematic_pkgs["errors"]: loggerinst.warning( "Removing problematic packages to continue with conversion:\n%s" % "\n".join(problematic_pkgs["errors"])) utils.remove_pkgs(problematic_pkgs['errors'], critical=False) else: loggerinst.critical("Could not resolve yum errors.") return
def remove_blacklisted_pkgs(): """Certain packages need to be removed before the system conversion, depending on the system to be converted. At least removing <os>-release package is a must. """ loggerinst = logging.getLogger(__name__) installed_blacklisted_pkgs = [] loggerinst.info("Searching for the following blacklisted packages:\n") for blacklisted_pkg in system_info.pkg_blacklist: temp = '.' * (50 - len(blacklisted_pkg) - 2) pkg_objects = get_installed_pkg_objects(blacklisted_pkg) installed_blacklisted_pkgs.extend(pkg_objects) loggerinst.info("%s %s %s" % (blacklisted_pkg, temp, str(len(pkg_objects)))) if not installed_blacklisted_pkgs: loggerinst.info("\nNothing to do.") return loggerinst.info("\n") loggerinst.warning("The following packages will be removed...") loggerinst.info("\n") print_pkg_info(installed_blacklisted_pkgs) utils.ask_to_continue() utils.remove_pkgs( [get_pkg_nvra(pkg) for pkg in installed_blacklisted_pkgs]) return
def test_remove_pkgs_without_backup(self): pkgs = ['pkg1', 'pkg2', 'pkg3'] utils.remove_pkgs(pkgs, False) self.assertEqual( utils.ChangedRPMPackagesController.backup_and_track_removed_pkg.called, 0) self.assertEqual(utils.run_subprocess.called, len(pkgs)) rpm_remove_cmd = "rpm -e --nodeps" self.assertTrue(re.search(r"^%s pkg" % rpm_remove_cmd, utils.run_subprocess.cmds, re.MULTILINE))
def remove_non_rhel_kernels(): loggerinst.info("Searching for non-RHEL kernels ...") non_rhel_kernels = get_installed_pkgs_w_different_fingerprint( system_info.fingerprints_rhel, "kernel*") if non_rhel_kernels: loggerinst.info("Removing non-RHEL kernels") print_pkg_info(non_rhel_kernels) utils.remove_pkgs(pkgs_to_remove=[get_pkg_nvra(pkg) for pkg in non_rhel_kernels], backup=False) else: loggerinst.info("None found.") return non_rhel_kernels
def remove_original_subscription_manager(): loggerinst.info("Removing non-RHEL subscription-manager packages.") # python3-subscription-manager-rhsm, dnf-plugin-subscription-manager, subscription-manager-rhsm-certificates, etc. submgr_pkgs = pkghandler.get_installed_pkgs_w_different_fingerprint( system_info.fingerprints_rhel, "*subscription-manager*") if not submgr_pkgs: loggerinst.info("No packages related to subscription-manager installed.") return loggerinst.info("Upon continuing, we will uninstall the following subscription-manager pkgs:\n") pkghandler.print_pkg_info(submgr_pkgs) utils.ask_to_continue() submgr_pkg_names = [pkg.name for pkg in submgr_pkgs] utils.remove_pkgs(submgr_pkg_names, critical=False)
def remove_pkgs_with_confirm(pkgs, backup=True): """ Remove selected packages with a breakdown and user confirmation prompt. """ pkgs_to_remove = [] for pkg in pkgs: temp = '.' * (50 - len(pkg) - 2) pkg_objects = get_installed_pkgs_w_different_fingerprint(system_info.fingerprints_rhel, pkg) pkgs_to_remove.extend(pkg_objects) loggerinst.info("%s %s %s" % (pkg, temp, str(len(pkg_objects)))) if not pkgs_to_remove: loggerinst.info("\nNothing to do.") return loggerinst.info("\n") loggerinst.warning("The following packages will be removed...") print_pkg_info(pkgs_to_remove) utils.ask_to_continue() utils.remove_pkgs([get_pkg_nvra(pkg) for pkg in pkgs_to_remove], backup=backup) loggerinst.debug("Successfully removed %s packages" % str(len(pkgs_to_remove)))
def handle_no_newer_rhel_kernel_available(): """Handle cases when the installed third party (non-RHEL) kernel has the same version as (or newer than) the RHEL one available in the RHEL repo(s). """ installed, available = get_kernel_availability() to_install = [kernel for kernel in available if kernel not in installed] if not to_install: # All the available RHEL kernel versions are already installed if len(installed) > 1: # There's more than one installed non-RHEL kernel. We'll remove one # of them - the one that has the same version as the available RHEL # kernel older = available[-1] utils.remove_pkgs(pkgs_to_remove=["kernel-%s" % older], should_backup=False) call_yum_cmd(command="install", args="kernel-%s" % older) else: replace_non_rhel_installed_kernel(installed[0]) return # Install the latest out of the available non-clashing RHEL kernels call_yum_cmd(command="install", args="kernel-%s" % to_install[-1])
def test_remove_pkgs_with_empty_list(self): utils.remove_pkgs([]) self.assertEqual(utils.run_subprocess.called, 0)