Exemplo n.º 1
0
def _main():
    """
    attempt to update with current, fallback to rpm
    attempt to collect and upload with new, then current, then rpm
    if an egg fails a phase never try it again
    """

    if not all([insights_uid, insights_gid, insights_grpid]):
        sys.exit("User and/or group 'insights' not found. Exiting.")

    validated_eggs = list(filter(gpg_validate, [STABLE_EGG, RPM_EGG]))

    if not validated_eggs:
        sys.exit("No GPG-verified eggs can be found")

    sys.path = validated_eggs + sys.path

    try:
        # flake8 complains because these imports aren't at the top
        import insights
        from insights.client import InsightsClient
        from insights.client.phase.v1 import get_phases

        # handle client instantation here so that it isn't done multiple times in __init__
        client = InsightsClient(True,
                                False)  # read config, but dont setup logging
        config = client.get_conf()

        # handle log rotation here instead of core
        if os.path.isfile(config['logging_file']):
            log_handler = logging.handlers.RotatingFileHandler(
                config['logging_file'], backupCount=3)
            log_handler.doRollover()
        # we now have access to the clients logging mechanism instead of using print
        client.set_up_logging()
        logging.root.debug("Loaded initial egg: %s",
                           os.path.dirname(insights.__file__))

        # check for insights user/group
        if not (insights_uid or insights_gid):
            log("WARNING: 'insights' user not found.  Using root to run all phases"
                )

        # check if the user is in the insights group
        # make sure they are not root
        in_insights_group = insights_grpid in curr_user_grps
        if not in_insights_group and os.geteuid() != 0:
            log("ERROR: user not in 'insights' group AND not root. Exiting.")
            return

        if config["version"]:
            from insights_client.constants import InsightsConstants as constants
            print("Client: %s" % constants.version)
            print("Core: %s" % client.version())
            return

        for p in get_phases():
            run_phase(p, client)
    except KeyboardInterrupt:
        sys.exit('Aborting.')
Exemplo n.º 2
0
def _main():
    """
    attempt to update with current, fallback to rpm
    attempt to collect and upload with new, then current, then rpm
    if an egg fails a phase never try it again
    """
    if os.getuid() != 0:
        sys.exit('Insights client must be run as root.')

    # sort rpm and stable eggs after verification
    validated_eggs = sorted_eggs(
        list(filter(gpg_validate, [STABLE_EGG, RPM_EGG])))
    # if ENV_EGG was specified and it's valid, add that to front of sys.path
    #  so it can be loaded initially. keep it in its own var so we don't
    #  pass it to run_phase where we load it again
    if gpg_validate(ENV_EGG):
        valid_env_egg = [ENV_EGG]
    else:
        valid_env_egg = []

    if not validated_eggs and not valid_env_egg:
        sys.exit("No GPG-verified eggs can be found")

    # ENV egg comes first
    sys.path = valid_env_egg + validated_eggs + sys.path

    try:
        # flake8 complains because these imports aren't at the top
        import insights
        from insights.client import InsightsClient
        from insights.client.phase.v1 import get_phases

        # handle client instantation here so that it isn't done multiple times in __init__
        client = InsightsClient(True,
                                False)  # read config, but dont setup logging
        config = client.get_conf()

        # handle log rotation here instead of core
        if os.path.isfile(config['logging_file']):
            log_handler = logging.handlers.RotatingFileHandler(
                config['logging_file'], backupCount=3)
            log_handler.doRollover()
        # we now have access to the clients logging mechanism instead of using print
        client.set_up_logging()
        logging.root.debug("Loaded initial egg: %s",
                           os.path.dirname(insights.__file__))

        if config["version"]:
            from insights_client.constants import InsightsConstants as constants
            print("Client: %s" % constants.version)
            print("Core: %s" % client.version())
            return

        for p in get_phases():
            run_phase(p, client, validated_eggs)
    except KeyboardInterrupt:
        sys.exit('Aborting.')
Exemplo n.º 3
0
 def _f():
     try:
         config = InsightsConfig().load_all()
     except ValueError as e:
         sys.stderr.write('ERROR: ' + str(e) + '\n')
         sys.exit(constants.sig_kill_bad)
     client = InsightsClient(config)
     client.set_up_logging()
     if config.debug:
         logger.info("Core path: %s", os.path.dirname(__file__))
     try_auto_configuration(config)
     try:
         func(client, config)
     except Exception:
         logger.exception("Fatal error")
         sys.exit(1)
     else:
         sys.exit()  # Exit gracefully