async def test_runtime_apps_config(monkeypatch, runtime_apps_response):
    app_config = config('apps/examples/simple-example/config/app-config.json')
    monkeypatch.setattr(runtime, "server", MockServer(app_config))

    plugin_config = config(
        'plugins/ops/config-manager/config/plugin-config.json')
    result = await execute_event(app_config=plugin_config,
                                 event_name="runtime-apps-config",
                                 payload=None)

    assert result == runtime_apps_response
Ejemplo n.º 2
0
def mock_runtime(monkeypatch, effective_events):
    setattr(apps, "_expire", 0.0)
    monkeypatch.setattr(server_config.os, 'getenv', mock_getenv)
    app_config = config('apps/examples/simple-example/config/app-config.json')
    basic_auth_config = config(
        'plugins/auth/basic-auth/config/plugin-config.json')
    client_app_config = config(
        'apps/examples/client-example/config/app-config.json')
    server = MockServer(basic_auth_config, app_config, client_app_config)
    for app_key, app_effective_events in effective_events.items():
        server.app_engines[app_key].effective_events = Payload.from_obj(
            app_effective_events, datatype=dict, item_datatype=EventDescriptor)
    monkeypatch.setattr(runtime, "server", server)
Ejemplo n.º 3
0
async def test_runtime_apps_config(monkeypatch, runtime_apps_response):
    app_config = config('apps/examples/simple-example/config/app-config.json')
    basic_auth_config = config(
        'plugins/auth/basic-auth/config/plugin-config.json')
    monkeypatch.setattr(runtime, "server",
                        MockServer(app_config, basic_auth_config))

    plugin_config = config(
        'plugins/ops/config-manager/config/plugin-config.json')
    result = await execute_event(app_config=plugin_config,
                                 event_name="runtime_apps_config",
                                 payload=None)

    import json
    print(json.dumps(result.to_dict()))
    assert result == runtime_apps_response
Ejemplo n.º 4
0
def test_config(mock_app_config):  # noqa: F811
    file_name = Path('/tmp') / (str(uuid.uuid4()) + '.json')
    expected = mock_app_config
    with open(file_name, 'w') as f:
        f.write(expected.to_json())
    result = config(file_name)
    os.remove(file_name)
    assert result.app == expected.app
    assert result.engine == expected.engine
    assert result.events == expected.events
    assert result.server == server_config()
Ejemplo n.º 5
0
def client_app_config(monkeypatch):
    def mock_getenv(var: str) -> Any:
        if var == "HOPEIT_SIMPLE_EXAMPLE_HOSTS":
            return "test-host"
        if var == "HOPEIT_APPS_API_VERSION":
            return version.APPS_API_VERSION
        if var == "HOPEIT_APPS_ROUTE_VERSION":
            return version.APPS_ROUTE_VERSION
        raise NotImplementedError(var)

    monkeypatch.setattr(server_config.os, "getenv", mock_getenv)
    return config('apps/examples/client-example/config/app-config.json')
Ejemplo n.º 6
0
def plugin_config(monkeypatch):
    def getenv(var_name):
        if var_name == "HOPEIT_APPS_VISUALIZER_HOSTS":
            return "in-process"
        elif var_name == "HOPEIT_APPS_API_VERSION":
            return APPS_API_VERSION
        elif var_name == "HOPEIT_APPS_ROUTE_VERSION":
            return APPS_ROUTE_VERSION
        raise NotImplementedError(var_name)

    monkeypatch.setattr(server_config.os, 'getenv', getenv)
    return config('plugins/ops/apps-visualizer/config/plugin-config.json')
Ejemplo n.º 7
0
def runtime_apps(monkeypatch):
    app_config = config('apps/examples/simple-example/config/app-config.json')
    monkeypatch.setattr(runtime, "server", MockServer(app_config))
    return RuntimeApps(apps={
        app_config.app_key():
        RuntimeAppInfo(servers=[
            ServerInfo(host_name=socket.gethostname(),
                       pid=str(os.getpid()),
                       url="in-process")
        ],
                       app_config=app_config)
    },
                       server_status={"in-process": ServerStatus.ALIVE})
async def test_cluster_apps_config(monkeypatch, cluster_apps_response,
                                   server1_apps_response, server2_apps_response):

    def apply_mock_client(module, context):
        mock_client(module.client, monkeypatch, server1_apps_response, server2_apps_response)

    plugin_config = config('plugins/ops/config-manager/config/plugin-config.json')
    result = await execute_event(
        app_config=plugin_config, event_name="cluster_apps_config", payload=None,
        mocks=[apply_mock_client], hosts="http://test-server1,http://test-server2"
    )

    assert result == cluster_apps_response
Ejemplo n.º 9
0
async def test_runtime_apps_config_expand_events(monkeypatch,
                                                 effective_events_example):
    app_config = config('apps/examples/simple-example/config/app-config.json')
    basic_auth_config = config(
        'plugins/auth/basic-auth/config/plugin-config.json')
    server = MockServer(app_config, basic_auth_config)
    server.set_effective_events(app_config.app_key(), effective_events_example)
    monkeypatch.setattr(runtime, "server", server)

    plugin_config = config(
        'plugins/ops/config-manager/config/plugin-config.json')
    result = await execute_event(app_config=plugin_config,
                                 event_name="runtime_apps_config",
                                 payload=None,
                                 expand_events=True)

    app_prefix = app_config.app_key()
    for k, v in result.apps[app_config.app_key()].effective_events.items():
        assert k[0:len(app_prefix)] == app_prefix
        if v.plug_mode == EventPlugMode.ON_APP:
            app_plugin_prefx = f"{app_prefix}.{basic_auth_config.app_key()}"
            assert k[0:len(app_plugin_prefx)] == app_plugin_prefx
        event_name = k.split('.')[-1]
        assert v == effective_events_example[event_name]
async def test_cluster_apps_config_expand_events(
    monkeypatch, effective_events_example,
    server1_apps_response, server2_apps_response
):

    def apply_mock_client(module, context):
        mock_client(
            module.client, monkeypatch,
            server1_apps_response, server2_apps_response,
            effective_events_example
        )

    plugin_config = config('plugins/ops/config-manager/config/plugin-config.json')
    result = await execute_event(
        app_config=plugin_config, event_name="cluster_apps_config", payload=None,
        mocks=[apply_mock_client], hosts="http://test-server1,http://test-server2",
        expand_events=True
    )

    for _, v in result.apps.items():
        assert v.effective_events == effective_events_example
Ejemplo n.º 11
0
async def _process_log_entries(raw: LogRawBatch) -> LogBatch:
    plugin_config = config(
        'plugins/ops/log-streamer/config/plugin-config.json')
    return await execute_event(plugin_config, "log_reader",
                               payload=raw)  # type: ignore
Ejemplo n.º 12
0
def plugin_config(monkeypatch):
    monkeypatch.setattr(server_config.os, 'getenv', mock_getenv)
    return config('plugins/ops/apps-visualizer/config/plugin-config.json')
Ejemplo n.º 13
0
def app_config():
    return config('apps/examples/simple-example/config/app-config.json')
Ejemplo n.º 14
0
async def test_log_reader(raw_log_entries, expected_log_entries):
    app_config = config('plugins/ops/log-streamer/config/plugin-config.json')
    result = await execute_event(app_config, "log_reader", raw_log_entries)
    assert result == expected_log_entries
Ejemplo n.º 15
0
def context():
    app_config = config('plugins/ops/log-streamer/config/plugin-config.json')
    return create_test_context(app_config, "log_reader")
Ejemplo n.º 16
0
def app_config():
    cfg = config("plugins/storage/fs/test/integration/app_config.json")
    # Set unique folder for each test run
    cfg.settings["test_stream_batch_storage"][
        "path"] += f"/{str(uuid.uuid4())}"
    return cfg