def test_get_default_config(self):
        from epumgmt.api import get_default_config

        epumgmt_home = "/path/to/epumgmt"
        default_conf_rel = "etc/main.conf"
        default_config = os.path.join(epumgmt_home, default_conf_rel)
        os.environ["EPUMGMT_HOME"] = epumgmt_home

        assert get_default_config() == default_config
Example #2
0
def core(opts, dbgmsgs=None):
    """Run epumgmt.
    
    From here 'down' there is no concept of a commandline program, only
    'args' which could be coming from any kind of protocol based request.
    
    To make such a thing, construct an opts object with the expected
    member names and values and pass it in to this method.
    
    See the 'em_args' module and the defaults 'Parameters' implementations to
    fully understand arg intake.  See the 'em_cmdline' module to see how args
    are taken in and how the result of the program (no exception or exception)
    is translated into a return code.
    """

    # -------------------------------------------------------------------------
    # SETUP Parameters
    # -------------------------------------------------------------------------

    if not opts:
        raise InvalidInput("No arguments")

    # in the default deployment, this is added by the .sh script wrapper
    if not opts.conf:
        config = get_default_config()
    else:
        config = opts.conf

    ac = get_all_configs(config)

    p_cls = get_class_by_keyword("Parameters", allconfigs=ac)
    p = p_cls(ac, opts)

    # -------------------------------------------------------------------------
    # REQUIRED arguments
    # -------------------------------------------------------------------------

    # --conf is also required; already checked for above

    given_action = p.get_arg_or_none(em_args.ACTION)
    if not given_action:
        em_optparse.print_help()
        msg = "You must specify an action as one of your arguments"
        raise InvalidInput(msg)

    action = validate_action(given_action)

    # -------------------------------------------------------------------------
    # Common
    # -------------------------------------------------------------------------

    c_cls = get_class_by_keyword("Common", allconfigs=ac)
    c = c_cls(p)

    # now there is a logger finally:
    if dbgmsgs:
        c.log.debug(dbgmsgs)

    try:
        _core(action, p, c)
    except:
        # Important for invocation logs to also record any problem
        c.log.exception("")
        raise