Beispiel #1
0
def _get_rhsm_cert_on_centos_7():
    """There's a RHSM-related bug on CentOS 7: https://bugs.centos.org/view.php?id=14785
    - The subscription-manager-rhsm-certificates is missing the necessary /etc/rhsm/ca/redhat-uep.pem.
    - This cert is still available in the python-rhsm-certificates package which is not possible to install
      (because it is obsoleted by the subscription-manager-rhsm-certificates).
    The workaround is to download the python-rhsm-certificates and extract the certificate from it.
    """
    loggerinst = logging.getLogger(__name__)
    cert_pkg_path = utils.download_pkg(pkg="python-rhsm-certificates",
                                       dest=_RHSM_TMP_DIR,
                                       reposdir=_RHSM_TMP_DIR)
    exit_on_failed_download([cert_pkg_path])

    output, ret_code = utils.run_subprocess("rpm2cpio %s" % cert_pkg_path,
                                            print_output=False)
    if ret_code != 0:
        loggerinst.critical(
            "Failed to extract cpio archive from the %s package." %
            cert_pkg_path)

    cpio_filepath = cert_pkg_path + ".cpio"
    utils.store_content_to_file(filename=cpio_filepath, content=output)

    cert_path = "/etc/rhsm/ca/redhat-uep.pem"
    utils.mkdir_p("/etc/rhsm/ca/")
    output, ret_code = utils.run_subprocess(
        "cpio --quiet -F %s -iv --to-stdout .%s" % (cpio_filepath, cert_path),
        print_output=False)
    # cpio return code 0 even if the requested file is not in the archive - but then the output is 0 chars
    if ret_code != 0 or not output:
        loggerinst.critical(
            "Failed to extract the %s certificate from the %s archive." %
            (cert_path, cpio_filepath))
    utils.store_content_to_file(cert_path, output)
Beispiel #2
0
def _download_rhsm_pkgs(pkgs_to_download, repo_path, repo_content):
    downloaddir = os.path.join(utils.DATA_DIR, "subscription-manager")
    utils.store_content_to_file(filename=repo_path, content=repo_content)
    paths = utils.download_pkgs(pkgs_to_download,
                                dest=downloaddir,
                                reposdir=_RHSM_TMP_DIR)
    exit_on_failed_download(paths)
Beispiel #3
0
def fix_default_kernel():
    """
    Systems converted from Oracle Linux or CentOS Linux may have leftover kernel-uek or kernel-plus in
    /etc/sysconfig/kernel as DEFAULTKERNEL.
    This function fixes that by replacing the DEFAULTKERNEL setting from kernel-uek or kernel-plus to kernel for RHEL 6,7 and kernel-core for RHEL 8
    """
    loggerinst = logging.getLogger(__name__)

    loggerinst.info("Checking for incorrect boot kernel")
    kernel_sys_cfg = utils.get_file_content("/etc/sysconfig/kernel")

    possible_kernels = ["kernel-uek", "kernel-plus"]
    kernel_to_change = next(
        iter(kernel for kernel in possible_kernels
             if kernel in kernel_sys_cfg), None)
    if kernel_to_change:
        loggerinst.warning(
            "Detected leftover boot kernel, changing to RHEL kernel")
        # need to change to "kernel" in rhel6, 7 and "kernel-core" in rhel8
        new_kernel_str = "DEFAULTKERNEL=" + (
            "kernel" if system_info.version.major in [6, 7] else "kernel-core")

        kernel_sys_cfg = kernel_sys_cfg.replace(
            "DEFAULTKERNEL=" + kernel_to_change, new_kernel_str)
        utils.store_content_to_file("/etc/sysconfig/kernel", kernel_sys_cfg)
        loggerinst.info("Boot kernel %s was changed to %s" %
                        (kernel_to_change, new_kernel_str))
    else:
        loggerinst.debug("Boot kernel validated.")
Beispiel #4
0
    def _generate_rpm_va(self):
        """Verify the installed files on the system with the rpm metadata
        for debug and support purposes."""
        if tool_opts.no_rpm_va:
            self.logger.info("Skipping execution of 'rpm -Va'.")
            return

        self.logger.info("Running the 'rpm -Va' command which can take several"
                         " minutes. It can be disabled by using the"
                         " --no-rpm-va option.")
        rpm_va, _ = utils.run_subprocess("rpm -Va", print_output=False)
        output_file = os.path.join(logger.LOG_DIR, "rpm_va.log")
        utils.store_content_to_file(output_file, rpm_va)
        self.logger.info("The 'rpm -Va' output has been stored in the %s file"
                         % output_file)
Beispiel #5
0
    def generate_rpm_va(self, log_filename=PRE_RPM_VA_LOG_FILENAME):
        """RPM is able to detect if any file installed as part of a package has been changed in any way after the
        package installation.

        Here we are getting a list of changed package files of all the installed packages. Such a list is useful for
        debug and support purposes. It's being saved to the default log folder as log_filename."""
        if tool_opts.no_rpm_va:
            self.logger.info("Skipping the execution of 'rpm -Va'.")
            return

        self.logger.info("Running the 'rpm -Va' command which can take several"
                         " minutes. It can be disabled by using the"
                         " --no-rpm-va option.")
        rpm_va, _ = utils.run_subprocess("rpm -Va", print_output=False)
        output_file = os.path.join(logger.LOG_DIR, log_filename)
        utils.store_content_to_file(output_file, rpm_va)
        self.logger.info("The 'rpm -Va' output has been stored in the %s file" % output_file)