Ejemplo n.º 1
0
def pre_ponr_conversion():
    """Perform steps and checks to guarantee system is ready for conversion."""

    # check if user pass some repo to both disablerepo and enablerepo options
    pkghandler.has_duplicate_repos_across_disablerepo_enablerepo_options()

    # checking if /mnt and /sys are read-write
    loggerinst.task("Convert: Checking /mnt and /sys are read-write")
    utils.check_readonly_mounts()

    # package analysis
    loggerinst.task("Convert: List third-party packages")
    pkghandler.list_third_party_pkgs()

    # remove excluded packages
    loggerinst.task("Convert: Remove excluded packages")
    pkghandler.remove_excluded_pkgs()

    # handle special cases
    loggerinst.task("Convert: resolve possible edge cases")
    special_cases.check_and_resolve()

    if not toolopts.tool_opts.disable_submgr:
        loggerinst.task("Convert: Subscription Manager - Download packages")
        subscription.download_rhsm_pkgs()
        loggerinst.task("Convert: Subscription Manager - Replace")
        subscription.replace_subscription_manager()
        loggerinst.task("Convert: Install RHEL certificates for RHSM")
        system_cert = cert.SystemCert()
        system_cert.install()
        loggerinst.task("Convert: Subscription Manager - Subscribe system")
        subscription.subscribe_system()
        loggerinst.task("Convert: Get RHEL repository IDs")
        rhel_repoids = repo.get_rhel_repoids()
        loggerinst.task(
            "Convert: Subscription Manager - Check required repositories")
        subscription.check_needed_repos_availability(rhel_repoids)
        loggerinst.task(
            "Convert: Subscription Manager - Disable all repositories")
        subscription.disable_repos()
        loggerinst.task(
            "Convert: Subscription Manager - Enable RHEL repositories")
        subscription.enable_repos(rhel_repoids)

    # remove non-RHEL packages containing repofiles or affecting variables in the repofiles
    loggerinst.task("Convert: Remove packages containing repofiles")
    pkghandler.remove_repofile_pkgs()

    # comment out the distroverpkg variable in yum.conf
    loggerinst.task("Convert: Patch yum configuration file")
    redhatrelease.YumConf().patch()

    # perform final checks before the conversion
    loggerinst.task("Convert: Final system checks before main conversion")
    checks.perform_pre_ponr_checks()
Ejemplo n.º 2
0
 def test_get_cert_path(self):
     # Check there are certificates for all the supported RHEL variants
     for arch, rhel_versions in self.certs.items():
         for rhel_version, pem in rhel_versions.items():
             utils.DATA_DIR = os.path.join(self.base_data_dir, rhel_version,
                                           arch)
             system_cert = cert.SystemCert()
             cert_path = system_cert._source_cert_path
             self.assertEqual(
                 cert_path,
                 "{0}/rhel-certs/{1}".format(utils.DATA_DIR, pem))
Ejemplo n.º 3
0
def pre_ponr_conversion():
    """Perform steps and checks to guarantee system is ready for conversion."""

    # check if user pass some repo to both disablerepo and enablerepo options
    pkghandler.has_duplicate_repos_across_disablerepo_enablerepo_options()

    # package analysis
    loggerinst.task("Convert: List third-party packages")
    pkghandler.list_third_party_pkgs()

    # remove excluded packages
    loggerinst.task("Convert: Remove excluded packages")
    pkghandler.remove_excluded_pkgs()

    # handle special cases
    loggerinst.task("Convert: Resolve possible edge cases")
    special_cases.check_and_resolve()

    rhel_repoids = []
    if not toolopts.tool_opts.no_rhsm:
        loggerinst.task("Convert: Subscription Manager - Download packages")
        subscription.download_rhsm_pkgs()
        loggerinst.task("Convert: Subscription Manager - Replace")
        subscription.replace_subscription_manager()
        loggerinst.task("Convert: Subscription Manager - Verify installation")
        subscription.verify_rhsm_installed()
        loggerinst.task("Convert: Install RHEL certificates for RHSM")
        system_cert = cert.SystemCert()
        system_cert.install()
        loggerinst.task("Convert: Subscription Manager - Subscribe system")
        subscription.subscribe_system()
        loggerinst.task("Convert: Get RHEL repository IDs")
        rhel_repoids = repo.get_rhel_repoids()
        loggerinst.task(
            "Convert: Subscription Manager - Check required repositories")
        subscription.check_needed_repos_availability(rhel_repoids)
        loggerinst.task(
            "Convert: Subscription Manager - Disable all repositories")
        subscription.disable_repos()

    # remove non-RHEL packages containing repofiles or affecting variables in the repofiles
    loggerinst.task("Convert: Remove packages containing .repo files")
    pkghandler.remove_repofile_pkgs()

    # we need to enable repos after removing repofile pkgs, otherwise we don't get backups
    # to restore from on a rollback
    if not toolopts.tool_opts.no_rhsm:
        loggerinst.task(
            "Convert: Subscription Manager - Enable RHEL repositories")
        subscription.enable_repos(rhel_repoids)

    # perform final checks before the conversion
    loggerinst.task("Convert: Final system checks before main conversion")
    checks.perform_pre_ponr_checks()
Ejemplo n.º 4
0
    def test_install_cert(self):
        # By initializing the cert object we get a path to an existing
        # certificate based on the mocked parameters above
        system_cert = cert.SystemCert()
        system_cert._target_cert_dir = unit_tests.TMP_DIR

        system_cert.install()

        installed_cert_path = os.path.join(system_cert._target_cert_dir,
                                           system_cert._cert_filename)
        self.assertTrue(os.path.exists(installed_cert_path))
        shutil.rmtree(unit_tests.TMP_DIR)
Ejemplo n.º 5
0
def rollback_changes():
    """Perform a rollback of changes made during conversion."""

    loggerinst.warning("Abnormal exit! Performing rollback ...")
    subscription.rollback()
    backup.changed_pkgs_control.restore_pkgs()
    repo.restore_yum_repos()
    redhatrelease.system_release_file.restore()
    redhatrelease.os_release_file.restore()
    special_cases.shim_x64_pkg_protection_file.restore()
    pkghandler.versionlock_file.restore()
    system_cert = cert.SystemCert()
    system_cert.remove()

    return
Ejemplo n.º 6
0
def pre_ponr_conversion():
    """Perform steps and checks to guarantee system is ready for conversion."""
    loggerinst = logging.getLogger(__name__)

    # check if user pass some repo to both disablerepo and enablerepo options
    pkghandler.has_duplicate_repos_across_disablerepo_enablerepo_options()

    # package analysis
    loggerinst.task("Convert: List third-party packages")
    pkghandler.list_third_party_pkgs()

    # remove excluded packages
    loggerinst.task("Convert: Remove excluded packages")
    pkghandler.remove_excluded_pkgs()

    if not toolopts.tool_opts.disable_submgr:
        loggerinst.task("Convert: Subscription Manager - Replace")
        subscription.replace_subscription_manager()
        loggerinst.task("Convert: Install RHEL certificates for RHSM")
        system_cert = cert.SystemCert()
        system_cert.install()
        loggerinst.task("Convert: Subscription Manager - Subscribe system")
        subscription.subscribe_system()
        loggerinst.task("Convert: Get RHEL repository IDs")
        rhel_repoids = repo.get_rhel_repoids()
        loggerinst.task(
            "Convert: Subscription Manager - Check required repositories")
        subscription.check_needed_repos_availability(rhel_repoids)
        loggerinst.task(
            "Convert: Subscription Manager - Disable all repositories")
        subscription.disable_repos()
        loggerinst.task(
            "Convert: Subscription Manager - Enable RHEL repositories")
        subscription.enable_repos(rhel_repoids)

    # remove non-RHEL packages containing repofiles or affecting variables in the repofiles
    loggerinst.task("Convert: Remove packages containing repofiles")
    pkghandler.remove_repofile_pkgs()

    # comment out the distroverpkg variable in yum.conf
    loggerinst.task("Convert: Patch yum configuration file")
    redhatrelease.YumConf().patch()
Ejemplo n.º 7
0
def test_remove_cert(
    monkeypatch,
    create_file,
    expected_text_in_logs,
    caplog,
    tmpdir,
):
    tmp_file = tmpdir / "filename"
    if create_file:
        tmp_file.write(b"some content")

    monkeypatch.setattr(cert.SystemCert,
                        "_get_cert",
                        value=mock.Mock(return_value=("anything", "anything")))
    monkeypatch.setattr(cert.SystemCert,
                        "_get_target_cert_path",
                        value=mock.Mock(return_value=str(tmp_file)))

    sys_cert = cert.SystemCert()
    sys_cert.remove()
    assert expected_text_in_logs in caplog.messages[-1]