Ejemplo n.º 1
0
def test_enable_repos_toolopts_enablerepo(
    toolopts_enablerepo,
    subprocess,
    should_raise,
    expected,
    expected_message,
    tool_opts,
    monkeypatch,
    caplog,
):
    cmd_mock = ["subscription-manager", "repos"]
    for repo in toolopts_enablerepo:
        cmd_mock.append("--enable=%s" % repo)

    run_subprocess_mock = mock.Mock(
        side_effect=unit_tests.run_subprocess_side_effect((cmd_mock,
                                                           subprocess), ))
    monkeypatch.setattr(
        utils,
        "run_subprocess",
        value=run_subprocess_mock,
    )
    tool_opts.enablerepo = toolopts_enablerepo
    # monkeypatch.setattr(tool_opts, "enablerepo", toolopts_enablerepo)

    if should_raise:
        with pytest.raises(SystemExit):
            subscription.enable_repos(rhel_repoids=None)
    else:
        subscription.enable_repos(rhel_repoids=None)
        assert system_info.submgr_enabled_repos == expected

    assert expected_message in caplog.records[-1].message
    assert run_subprocess_mock.call_count == 1
Ejemplo n.º 2
0
def test_enable_repos_rhel_repoids_fallback_default_rhsm(
    pretend_os,
    rhel_repoids,
    default_rhsm_repoids,
    subprocess,
    subprocess2,
    should_raise,
    expected,
    monkeypatch,
    caplog,
):
    cmd_mock = ["subscription-manager", "repos"]
    for repo in rhel_repoids:
        cmd_mock.append("--enable=%s" % repo)

    run_subprocess_mock = mock.Mock(side_effect=[subprocess, subprocess2])
    monkeypatch.setattr(
        utils,
        "run_subprocess",
        value=run_subprocess_mock,
    )
    monkeypatch.setattr(system_info,
                        "default_rhsm_repoids",
                        value=default_rhsm_repoids)

    if should_raise:
        with pytest.raises(SystemExit):
            subscription.enable_repos(rhel_repoids=rhel_repoids)
    else:
        subscription.enable_repos(rhel_repoids=rhel_repoids)
        assert system_info.submgr_enabled_repos == default_rhsm_repoids

    assert expected in caplog.records[-1].message
    assert run_subprocess_mock.call_count == 2
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()

    # 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.º 4
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.º 5
0
def pre_ponr_conversion():
    """Perform steps and checks to guarantee system is ready for conversion."""
    loggerinst = logging.getLogger(__name__)

    # remove blacklisted packages
    loggerinst.task("Convert: Remove blacklisted packages")
    pkghandler.remove_blacklisted_pkgs()

    # checking RHN Classic
    loggerinst.task("Checking RHN Classic")
    subscription.unregister_from_rhn_classic()

    # install redhat release package
    loggerinst.task("Convert: Install Red Hat release package")
    redhatrelease.install_release_pkg()
    # replace distroverpkg variable in yum.conf
    loggerinst.task("Convert: Patch yum configuration file")
    redhatrelease.YumConf().patch()

    if systeminfo.system_info.version == "5":
        cert.copy_cert_for_rhel_5()

    # package analysis
    loggerinst.task("Convert: Package analysis")
    repos_needed = repo.package_analysis()

    if toolopts.tool_opts.disable_submgr:
        loggerinst.task("Convert: Check required repos")
        repo.check_needed_repos_availability(repos_needed)
    else:
        loggerinst.task("Convert: Subscription Manager - Install")
        subscription.install_subscription_manager()
        loggerinst.task("Convert: Subscription Manager - Subscribe system")
        subscription.subscribe_system()
        loggerinst.task("Convert: Subscription Manager - Check required repos")
        repo.check_needed_repos_availability(repos_needed)
        loggerinst.task("Convert: Subscription Manager - Disable all repos")
        subscription.disable_repos()
        loggerinst.task("Convert: Subscription Manager - Enable needed repos")
        subscription.enable_repos(repos_needed)
        # TODO: Replace renaming .repo files by using --enable for yum command
        loggerinst.task("Convert: Subscription Manager - Rename repos")
        subscription.rename_repo_files()
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 pre_ponr_conversion():
    """Perform steps and checks to guarantee system is ready for conversion."""
    loggerinst = logging.getLogger(__name__)

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

    # install redhat release package
    loggerinst.task("Convert: Install Red Hat release package")
    redhatrelease.install_release_pkg()
    # replace distroverpkg variable in yum.conf
    loggerinst.task("Convert: Patch yum configuration file")
    redhatrelease.YumConf().patch()

    # package analysis
    loggerinst.task("Convert: List third-party packages")
    pkghandler.list_third_party_pkgs()
    if not toolopts.tool_opts.disable_submgr:
        loggerinst.task("Convert: Subscription Manager - Install")
        subscription.install_subscription_manager()
        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)
        # TODO: Replace renaming .repo files by using --enable for yum command
        loggerinst.task("Convert: Subscription Manager - Rename repositories")
        subscription.rename_repo_files()