Example #1
0
def main():
    """Perform all steps for the entire conversion process."""
    process_phase = ConversionPhase.INIT
    # initialize logging
    logger.initialize_logger("convert2rhel.log")
    # get module level logger (inherits from root logger)
    loggerinst = logging.getLogger(__name__)

    try:
        # handle command line arguments
        toolopts.CLI()

        process_phase = ConversionPhase.POST_CLI

        # the tool will not run if not executed under the root user
        utils.require_root()

        # license agreement
        loggerinst.task("Prepare: End user license agreement")
        user_to_accept_eula()

        # gather system information
        loggerinst.task("Prepare: Gather system information")
        systeminfo.system_info.resolve_system_info()
        loggerinst.task("Prepare: Determine RHEL variant")
        rhelvariant.determine_rhel_variant()

        # backup system release file before starting conversion process
        loggerinst.task("Prepare: Backup System")
        redhatrelease.system_release_file.backup()
        redhatrelease.yum_conf.backup()

        # begin conversion process
        process_phase = ConversionPhase.PRE_PONR_CHANGES
        pre_ponr_conversion()

        loggerinst.warning("The tool allows rollback of any action until this"
                           " point.")
        loggerinst.warning("By continuing all further changes on the system"
                           " will need to be reverted manually by the user,"
                           " if necessary.")
        utils.ask_to_continue()

        process_phase = ConversionPhase.POST_PONR_CHANGES
        post_ponr_conversion()

        # recommend non-interactive command
        loggerinst.task("Final: Non-interactive mode")
        toolopts.print_non_interactive_opts()

        # restart system if required
        utils.restart_system()

    except (Exception, SystemExit, KeyboardInterrupt), err:
        # Catching the three exception types separately due to python 2.4
        # (RHEL 5) - 2.7 (RHEL 7) compatibility.

        utils.log_traceback(toolopts.tool_opts.debug)

        print("\n")
        if is_help_msg_exit(process_phase, err):
            return 0
        elif process_phase in (ConversionPhase.INIT, ConversionPhase.POST_CLI):
            print("No changes were made to the system.")
        elif process_phase == ConversionPhase.PRE_PONR_CHANGES:
            rollback_changes()
        elif process_phase == ConversionPhase.POST_PONR_CHANGES:
            # After the process of subscription is done and the mass update of
            # packages is started convert2rhel will not be able to guarantee a
            # system rollback without user intervation. If a proper rollback
            # solution is necessary it will need to be future implemented here
            # or with the use of other backup tools.
            print("Conversion process interrupted and manual user intervation"
                  " will be necessary.")

        return 1
Example #2
0
def main():
    """Perform all steps for the entire conversion process."""

    # handle command line arguments
    toolopts.CLI()

    # the tool will not run if not executed under the root user
    utils.require_root()

    process_phase = ConversionPhase.INIT
    # initialize logging
    logger.initialize_logger("convert2rhel.log")
    # get module level logger (inherits from root logger)

    try:
        process_phase = ConversionPhase.POST_CLI

        # license agreement
        loggerinst.task("Prepare: Show Red Hat software EULA")
        show_eula()

        # gather system information
        loggerinst.task("Prepare: Gather system information")
        systeminfo.system_info.resolve_system_info()

        # check the system prior the conversion (possible inhibit)
        loggerinst.task("Prepare: Initial system checks before conversion")
        checks.perform_pre_checks()

        # backup system release file before starting conversion process
        loggerinst.task("Prepare: Backup System")
        redhatrelease.system_release_file.backup()
        redhatrelease.yum_conf.backup()
        repo.backup_yum_repos()

        loggerinst.task("Prepare: Clear YUM/DNF version locks")
        pkghandler.clear_versionlock()

        # begin conversion process
        process_phase = ConversionPhase.PRE_PONR_CHANGES
        pre_ponr_conversion()

        loggerinst.warning(
            "********************************************************")
        loggerinst.warning(
            "The tool allows rollback of any action until this point.")
        loggerinst.warning("By continuing all further changes on the system"
                           " will need to be reverted manually by the user,"
                           " if necessary.")
        loggerinst.warning(
            "********************************************************")
        utils.ask_to_continue()

        process_phase = ConversionPhase.POST_PONR_CHANGES
        post_ponr_conversion()

        loggerinst.task("Final: rpm files modified by the conversion")
        systeminfo.system_info.modified_rpm_files_diff()

        # recommend non-interactive command
        loggerinst.task("Final: Non-interactive mode")
        toolopts.print_non_interactive_opts()

        # restart system if required
        utils.restart_system()

    except (Exception, SystemExit, KeyboardInterrupt) as err:
        # Catching the three exception types separately due to python 2.4
        # (RHEL 5) - 2.7 (RHEL 7) compatibility.

        utils.log_traceback(toolopts.tool_opts.debug)
        no_changes_msg = "No changes were made to the system."

        if is_help_msg_exit(process_phase, err):
            return 0
        elif process_phase == ConversionPhase.INIT:
            print(no_changes_msg)
        elif process_phase == ConversionPhase.POST_CLI:
            loggerinst.info(no_changes_msg)
        elif process_phase == ConversionPhase.PRE_PONR_CHANGES:
            rollback_changes()
        elif process_phase == ConversionPhase.POST_PONR_CHANGES:
            # After the process of subscription is done and the mass update of
            # packages is started convert2rhel will not be able to guarantee a
            # system rollback without user intervention. If a proper rollback
            # solution is necessary it will need to be future implemented here
            # or with the use of other backup tools.
            loggerinst.warning(
                "Conversion process interrupted and manual user intervention will be necessary."
            )

        return 1

    return 0