Skip to content

Commit 4bda944

Browse files
author
Andrei Neagu
committed
fixed tests and renaming endpoints
1 parent 6532ca0 commit 4bda944

File tree

15 files changed

+76
-3
lines changed

15 files changed

+76
-3
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import Final
2+
3+
from pydantic import parse_obj_as
4+
5+
from ..rabbitmq_basic_types import RPCNamespace
6+
7+
DYNAMIC_SIDECAR_RPC_NAMESPACE: Final[RPCNamespace] = parse_obj_as(
8+
RPCNamespace, "dynamic-sidecar"
9+
)

packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/dynamic_sidecar/__init__.py

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import logging
2+
3+
from models_library.api_schemas_dynamic_sidecar import DYNAMIC_SIDECAR_RPC_NAMESPACE
4+
from models_library.rabbitmq_basic_types import RPCMethodName
5+
from pydantic import parse_obj_as
6+
from servicelib.logging_utils import log_decorator
7+
from servicelib.rabbitmq import RabbitMQRPCClient
8+
from simcore_service_dynamic_sidecar.api.rpc._disk_usage import DiskUsage
9+
10+
_logger = logging.getLogger(__name__)
11+
12+
13+
@log_decorator(_logger, level=logging.DEBUG)
14+
async def update_disk_usage(
15+
rabbitmq_rpc_client: RabbitMQRPCClient, *, usage: dict[str, DiskUsage]
16+
) -> None:
17+
result = await rabbitmq_rpc_client.request(
18+
DYNAMIC_SIDECAR_RPC_NAMESPACE,
19+
parse_obj_as(RPCMethodName, "update_disk_usage"),
20+
usage=usage,
21+
)
22+
assert result is None # nosec
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from fastapi import FastAPI
2+
from models_library.api_schemas_dynamic_sidecar.telemetry import DiskUsage
3+
from servicelib.rabbitmq import RPCRouter
4+
5+
from ...modules.system_monitor import get_disk_usage_monitor
6+
7+
router = RPCRouter()
8+
9+
10+
@router.expose()
11+
async def update_disk_usage(app: FastAPI, *, usage: dict[str, DiskUsage]) -> None:
12+
await get_disk_usage_monitor(app).set_disk_usage_for_path(usage)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from fastapi import FastAPI
2+
from models_library.api_schemas_dynamic_sidecar import DYNAMIC_SIDECAR_RPC_NAMESPACE
3+
from servicelib.rabbitmq import RPCRouter
4+
5+
from ...core.rabbitmq import get_rabbitmq_rpc_server
6+
from . import _disk_usage
7+
8+
ROUTERS: list[RPCRouter] = [
9+
_disk_usage.router,
10+
]
11+
12+
13+
def setup_rpc_api_routes(app: FastAPI) -> None:
14+
async def startup() -> None:
15+
rpc_server = get_rabbitmq_rpc_server(app)
16+
for router in ROUTERS:
17+
await rpc_server.register_router(router, DYNAMIC_SIDECAR_RPC_NAMESPACE, app)
18+
19+
app.add_event_handler("startup", startup)

services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/core/application.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from .._meta import API_VERSION, API_VTAG, PROJECT_NAME, SUMMARY, __version__
1616
from ..api.rest import get_main_router
17+
from ..api.rpc.routes import setup_rpc_api_routes
1718
from ..models.schemas.application_health import ApplicationHealth
1819
from ..models.shared_store import SharedStore, setup_shared_store
1920
from ..modules.attribute_monitor import setup_attribute_monitor
@@ -171,6 +172,7 @@ def create_app():
171172
application_settings: ApplicationSettings = app.state.settings
172173

173174
setup_rabbitmq(app)
175+
setup_rpc_api_routes(app)
174176
setup_background_log_fetcher(app)
175177
setup_resource_tracking(app)
176178
setup_notifications(app)
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from ._disk_usage import get_disk_usage_monitor
12
from ._setup import setup_system_monitor
23

3-
__all__: tuple[str, ...] = ("setup_system_monitor",)
4+
__all__: tuple[str, ...] = (
5+
"get_disk_usage_monitor",
6+
"setup_system_monitor",
7+
)

services/dynamic-sidecar/tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,11 @@ def mock_core_rabbitmq(mocker: MockerFixture) -> dict[str, AsyncMock]:
328328
return_value=None,
329329
autospec=True,
330330
),
331+
"rpc.register_router": mocker.patch(
332+
"simcore_service_dynamic_sidecar.core.rabbitmq.RabbitMQRPCClient.register_router",
333+
return_value=None,
334+
autospec=True,
335+
),
331336
}
332337

333338

services/dynamic-sidecar/tests/unit/test_api_containers.py renamed to services/dynamic-sidecar/tests/unit/test_api_rest_containers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ def mock_inactive_since_command_response(
772772
activity_response: ActivityInfo,
773773
) -> None:
774774
mocker.patch(
775-
"simcore_service_dynamic_sidecar.api.containers.run_command_in_container",
775+
"simcore_service_dynamic_sidecar.api.rest.containers.run_command_in_container",
776776
return_value=activity_response.json(),
777777
)
778778

@@ -792,7 +792,7 @@ async def test_containers_activity_inactive_since(
792792
@pytest.fixture
793793
def mock_inactive_response_wrong_format(mocker: MockerFixture) -> None:
794794
mocker.patch(
795-
"simcore_service_dynamic_sidecar.api.containers.run_command_in_container",
795+
"simcore_service_dynamic_sidecar.api.rest.containers.run_command_in_container",
796796
return_value="This is an unparsable json response {}",
797797
)
798798

0 commit comments

Comments
 (0)