示例#1
0
def _configure(env_work_dir=None):
    """Load configuration settings.

    :returns config dict if configuration was loaded without issues.
            None or a specific exception otherwise.
    """
    assert env_work_dir, 'Working directory required.'
    assert os.path.exists(env_work_dir), \
        'working directory invalid: {}'.format(env_work_dir)

    config_manager.stop()

    def logging_config_handler(config):
        # configure logging
        logging_config = None
        if config:
            logging_config = config.get('logging', None)
        _configure_logging(logging_config)

    config_manager.register_handler(logging_config_handler)

    def timeline_config_handler(config):
        # configure pipeline timeline event log
        timeline_config = None
        if config:
            timeline_config = config.get('timeline', None)
        timeline.configure_timeline(timeline_config)

    config_manager.register_handler(timeline_config_handler)

    config_manager.load(env_work_dir)

    return config_manager.get()
示例#2
0
def test_reload():

    config_manager.CONFIG_FILE = 'test-config.1.yaml'
    _dir = os.path.dirname(os.path.abspath(__file__))
    config = {"logging": {"level": "INFO"}}
    config_file = os.path.join(_dir, config_manager.CONFIG_FILE)

    # write 1
    write_config(config_file, config)

    config1 = config_manager.load(_dir)

    assert config["logging"]["level"] == config1["logging"]["level"]

    watcher = Watch()

    config_manager.register_handler(watcher.on_change)

    config2 = {"logging": {"level": "WARN"}}

    # write 2
    config_manager.save(config2)

    # wait for polling to happen
    wait = 3
    while not watcher.changed:
        sleep(.5)
        wait -= 1
        if wait == 0:
            raise Exception("Failed to detect change")

    config3 = config_manager.get()

    assert config["logging"]["level"] == watcher.config["logging"]["level"]
    assert config["logging"]["level"] == config3["logging"]["level"]
示例#3
0
def test_handlers_mgm():
    def test1(config):
        pass

    # reset state
    config_manager.stop()
    assert len(config_manager.handlers) == 0

    config_manager.register_handler(test1)
    assert len(config_manager.handlers) == 1

    config_manager.unregister_handler(test1)
    assert len(config_manager.handlers) == 0
示例#4
0
def test_callback():

    config_manager.CONFIG_FILE = 'test-config.2.yaml'
    _dir = os.path.dirname(os.path.abspath(__file__))
    config = {"test": True}
    config_file = os.path.join(_dir, config_manager.CONFIG_FILE)

    write_config(config_file, config)
    config_manager.load(_dir)

    watcher = Watch()

    config_manager.register_handler(watcher.on_change)
    write_config(config_file, config)

    # wait for polling to happen
    wait = 3
    while not watcher.changed:
        sleep(.5)
        wait -= 1
        if wait == 0:
            raise Exception("Failed to detect change")

    assert watcher.changed