def _find_one_config(config_filename, module_spec): full_config = ValidConfig(config_filename) sources = full_config.get("sources") if sources is None: sys.exit( f"Could not locate 'sources' configuration block in {config_filename}." ) found_configs = { k: v for k, v in sources.items() if v.get("module") == module_spec } if len(found_configs) == 0: sys.exit( f"No configuration in {config_filename} is supported by {module_spec}." ) if len(found_configs) > 1: sys.exit( f"Located more than one configuration supported by {module_spec}.\n" f"Please choose one of {list(found_configs.keys())}.") full_module_config = list(found_configs.items())[0] parameters = full_module_config[1].get("parameters") if parameters is None: sys.exit( f"Configuration for '{full_module_config[0]}' source in {config_filename}" " does not contain a 'parameters' table.") return parameters
def main(): # pragma: no cover username = pwd.getpwuid(os.getuid()).pw_name if username not in ['root', 'decisionengine']: sys.exit(f"User '{username}' is not allowed to run this script.") config_file = policies.global_config_file() global_config = ValidConfig(config_file) reaper = Reaper(global_config) reaper.reap()
def _call(relative_filename, relative_channel_config_dir=None): channel_config_dir = None if relative_channel_config_dir is None: channel_config_dir = _channel_config_dir("channels/no_config_files") else: channel_config_dir = _channel_config_dir(relative_channel_config_dir) filename = _global_config_file(relative_filename) global_config = ValidConfig(filename) handler = ChannelConfigHandler(global_config, channel_config_dir) handler.load_all_channels() return handler
def test_channel_loading(caplog): filename = _global_config_file('minimal.jsonnet') global_config = ValidConfig(filename) channel_config_dir = _channel_config_dir('channels/no_modules') handler = ChannelConfigHandler(global_config, channel_config_dir) success, result = handler.load_channel('no_modules') assert success and isinstance(result, ValidConfig) success, result = handler.load_channel('non_existent') assert not success and isinstance(result, str) assert len(handler.get_channels()) == 1 handler.load_all_channels() assert 'All channel configurations have been removed and are being reloaded.' in caplog.text
def global_config(dataspace): # noqa: F811 conf = ValidConfig(policies.global_config_file(_CONFIG_PATH)) conf["dataspace"] = dataspace.config["dataspace"] yield conf
def channel_config(channel_name): return ValidConfig( os.path.join(_CHANNEL_CONFIG_DIR, channel_name + ".jsonnet"))
def channel_config(name): return ValidConfig(os.path.join(_CHANNEL_CONFIG_DIR, name + '.jsonnet'))
import threading import os import pytest import decisionengine.framework.config.policies as policies from decisionengine.framework.config.ValidConfig import ValidConfig from decisionengine.framework.dataspace.datasources.tests.fixtures import mock_data_block # noqa: F401 from decisionengine.framework.taskmanager.TaskManager import State from decisionengine.framework.taskmanager.TaskManager import TaskManager _CWD = os.path.dirname(os.path.abspath(__file__)) _CONFIG_PATH = os.path.join(_CWD, "../../tests/etc/decisionengine") _CHANNEL_CONFIG_DIR = os.path.join(_CWD, 'channels') _global_config = ValidConfig(policies.global_config_file(_CONFIG_PATH)) def channel_config(name): return ValidConfig(os.path.join(_CHANNEL_CONFIG_DIR, name + '.jsonnet')) def task_manager_for(name): return TaskManager(name, 1, channel_config(name), _global_config) class RunChannel: def __init__(self, name): self._tm = task_manager_for(name) self._thread = threading.Thread(target=self._tm.run)