Exemplo n.º 1
0
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()
Exemplo n.º 2
0
def test_global_config_file(tmp_path, monkeypatch):
    cfg_file = tmp_path / policies.GLOBAL_CONFIG_FILENAME
    absolute_parent_path = str(cfg_file.parent.resolve())

    with pytest.raises(RuntimeError) as e:
        policies.global_config_file(absolute_parent_path)
    e.match('Global configuration file.*not found')

    # Create config file
    cfg_file.touch()

    # Explicit parent path
    global_cfg_file = policies.global_config_file(absolute_parent_path)
    assert global_cfg_file == cfg_file

    # Through global-config environment variable
    with monkeypatch.context() as m:
        m.setenv('CONFIG_PATH', absolute_parent_path)
        global_cfg_file = policies.global_config_file()
        assert global_cfg_file == cfg_file
def global_config(dataspace):  # noqa: F811
    conf = ValidConfig(policies.global_config_file(_CONFIG_PATH))
    conf["dataspace"] = dataspace.config["dataspace"]
    yield conf
Exemplo n.º 4
0
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)