Ejemplo n.º 1
0
def initialize(args=None):
    """
    Initialize Stolos.  This function must be called before Stolos's api is
    usable.  It fetches all required configuration variables to use stolos's
    library.  Will not load namespace options required by Stolos plugins.

    `args` - (optional).  Define command-line arguments to use.
        Default to sys.argv (which is what argparse does).
        Explicitly pass args=[] to not read command-line arguments, and instead
        expect that all arguments are passed in as environment variables.
        To guarantee NO arguments are read from sys.argv, set args=[]
        Example:  args=['--option1', 'val', ...]
    """
    _initialize([_dt, _cb, _qb], args=args)
Ejemplo n.º 2
0
Archivo: api.py Proyecto: kszucs/stolos
def initialize(args=None):
    """
    Initialize Stolos.  This function must be called before Stolos's api is
    usable.  It fetches all required configuration variables to use stolos's
    library.  Will not load namespace options required by Stolos plugins.

    `args` - (optional).  Define command-line arguments to use.
        Default to sys.argv (which is what argparse does).
        Explicitly pass args=[] to not read command-line arguments, and instead
        expect that all arguments are passed in as environment variables.
        To guarantee NO arguments are read from sys.argv, set args=[]
        Example:  args=['--option1', 'val', ...]
    """
    _initialize([_dt, _cb, _qb], args=args)
Ejemplo n.º 3
0
 def setup_func(func_name):
     initializer_args = []
     available_kwargs = dict(
         log=util.configure_logging(False, log=logging.getLogger(
             'stolos.tests.%s' % func_name)),
         func_name=func_name,
     )
     for f in setup_funcs:
         tup, dct = f(func_name)
         initializer_args.extend(tup)
         available_kwargs.update(dct)
     _initialize([cb, dt, qb], args=initializer_args)
     for f in post_initialize:
         dct = smart_run(f, (), available_kwargs)
         available_kwargs.update(dct)
     return ((), available_kwargs)
Ejemplo n.º 4
0
 def setup_func(func_name):
     initializer_args = []
     available_kwargs = dict(
         log=util.configure_logging(False,
                                    log=logging.getLogger(
                                        'stolos.tests.%s' % func_name)),
         func_name=func_name,
     )
     for f in setup_funcs:
         tup, dct = f(func_name)
         initializer_args.extend(tup)
         available_kwargs.update(dct)
     _initialize([cb, dt, qb], args=initializer_args)
     for f in post_initialize:
         dct = smart_run(f, (), available_kwargs)
         available_kwargs.update(dct)
     return ((), available_kwargs)
Ejemplo n.º 5
0
def inject_into_dag(func_name, inject_dct):
    """Update (add or replace) tasks in dag with new task config.
    Assumes that the config we're using is the JSONMapping
    """
    if not all(k.startswith(makepath(func_name)) for k in inject_dct):
        raise UserWarning(
            "inject_into_dag can only inject app_names that have the"
            " correct prefix:  %s" % makepath(func_name, '{app_name}'))
    f = _create_tasks_json(func_name, inject=inject_dct)[0]
    _initialize([cb, dt, qb], args=['--tasks_json', f])

    # verify injection worked
    dg = cb.get_tasks_config().to_dict()
    for k, v in inject_dct.items():
        assert dg[k] == v, (
            "test code: inject_into_dag didn't insert the new tasks?")
    yield
    os.remove(f)
Ejemplo n.º 6
0
def inject_into_dag(func_name, inject_dct):
    """Update (add or replace) tasks in dag with new task config.
    Assumes that the config we're using is the JSONMapping
    """
    if not all(k.startswith(makepath(func_name))
               for k in inject_dct):
        raise UserWarning(
            "inject_into_dag can only inject app_names that have the"
            " correct prefix:  %s" % makepath(func_name, '{app_name}'))
    f = _create_tasks_json(func_name, inject=inject_dct)[0]
    _initialize([cb, dt, qb], args=['--tasks_json', f])

    # verify injection worked
    dg = cb.get_tasks_config().to_dict()
    for k, v in inject_dct.items():
        assert dg[k] == v, (
            "test code: inject_into_dag didn't insert the new tasks?")
    yield
    os.remove(f)