Skip to content

Commit

Permalink
@pcrespov review: define namespace in models-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed Oct 29, 2023
1 parent 5f63703 commit e3dfbd4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import Final

from pydantic import parse_obj_as

from ..rabbitmq_basic_types import RPCNamespace

CLUSTERS_KEEPER_RPC_NAMESPACE: Final[RPCNamespace] = parse_obj_as(
RPCNamespace, "clusters-keeper"
)
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import contextlib
import logging
from typing import Final, cast
from typing import cast

from fastapi import FastAPI
from models_library.rabbitmq_messages import RabbitMessageBase
from pydantic import parse_obj_as
from servicelib.logging_utils import log_catch
from servicelib.rabbitmq import (
RabbitMQClient,
RabbitMQRPCClient,
RPCNamespace,
wait_till_rabbitmq_responsive,
)
from settings_library.rabbit import RabbitSettings
Expand All @@ -19,10 +17,6 @@

logger = logging.getLogger(__name__)

CLUSTERS_KEEPER_RPC_NAMESPACE: Final[RPCNamespace] = parse_obj_as(
RPCNamespace, "clusters-keeper"
)


def setup(app: FastAPI) -> None:
async def on_startup() -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from collections.abc import Awaitable, Callable

from fastapi import FastAPI
from models_library.api_schemas_clusters_keeper import CLUSTERS_KEEPER_RPC_NAMESPACE

from ..modules.rabbitmq import (
CLUSTERS_KEEPER_RPC_NAMESPACE,
get_rabbitmq_rpc_client,
is_rabbitmq_enabled,
)
from ..modules.rabbitmq import get_rabbitmq_rpc_client, is_rabbitmq_enabled
from .clusters import router as clusters_router
from .ec2_instances import router as ec2_instances_router

Expand Down
7 changes: 0 additions & 7 deletions services/clusters-keeper/tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
from faker import Faker
from fakeredis.aioredis import FakeRedis
from fastapi import FastAPI
from models_library.rabbitmq_basic_types import RPCNamespace
from moto.server import ThreadedMotoServer
from pydantic import parse_obj_as
from pytest_mock.plugin import MockerFixture
from pytest_simcore.helpers.utils_docker import get_localhost_ip
from pytest_simcore.helpers.utils_envs import EnvVarsDict, setenvs_from_dict
Expand Down Expand Up @@ -402,11 +400,6 @@ def clusters_keeper_docker_compose() -> dict[str, Any]:
return yaml.safe_load(data)


@pytest.fixture(scope="session")
def clusters_keeper_namespace() -> RPCNamespace:
return parse_obj_as(RPCNamespace, "clusters-keeper")


@pytest.fixture
async def clusters_keeper_rabbitmq_rpc_client(
rabbitmq_rpc_client: Callable[[str], Awaitable[RabbitMQRPCClient]]
Expand Down
8 changes: 4 additions & 4 deletions services/clusters-keeper/tests/unit/test_rpc_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
import pytest
from faker import Faker
from fastapi import FastAPI
from models_library.api_schemas_clusters_keeper import CLUSTERS_KEEPER_RPC_NAMESPACE
from models_library.api_schemas_clusters_keeper.clusters import OnDemandCluster
from models_library.users import UserID
from models_library.wallets import WalletID
from pytest_mock.plugin import MockerFixture
from servicelib.rabbitmq import RabbitMQRPCClient, RPCMethodName, RPCNamespace
from servicelib.rabbitmq import RabbitMQRPCClient, RPCMethodName
from simcore_service_clusters_keeper.utils.ec2 import HEARTBEAT_TAG_KEY
from types_aiobotocore_ec2 import EC2Client

Expand Down Expand Up @@ -96,7 +97,6 @@ def mocked_dask_ping_scheduler(mocker: MockerFixture) -> MockedDaskModule:
@pytest.mark.parametrize("use_wallet_id", [True, False])
async def test_get_or_create_cluster(
_base_configuration: None,
clusters_keeper_namespace: RPCNamespace,
clusters_keeper_rabbitmq_rpc_client: RabbitMQRPCClient,
ec2_client: EC2Client,
user_id: UserID,
Expand All @@ -106,7 +106,7 @@ async def test_get_or_create_cluster(
):
# send rabbitmq rpc to create_cluster
rpc_response = await clusters_keeper_rabbitmq_rpc_client.request(
clusters_keeper_namespace,
CLUSTERS_KEEPER_RPC_NAMESPACE,
RPCMethodName("get_or_create_cluster"),
user_id=user_id,
wallet_id=wallet_id if use_wallet_id else None,
Expand All @@ -122,7 +122,7 @@ async def test_get_or_create_cluster(

# calling it again returns the existing cluster
rpc_response = await clusters_keeper_rabbitmq_rpc_client.request(
clusters_keeper_namespace,
CLUSTERS_KEEPER_RPC_NAMESPACE,
RPCMethodName("get_or_create_cluster"),
user_id=user_id,
wallet_id=wallet_id if use_wallet_id else None,
Expand Down
9 changes: 4 additions & 5 deletions services/clusters-keeper/tests/unit/test_rpc_ec2_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

import pytest
from fastapi import FastAPI
from models_library.api_schemas_clusters_keeper import CLUSTERS_KEEPER_RPC_NAMESPACE
from models_library.api_schemas_clusters_keeper.ec2_instances import EC2InstanceType
from servicelib.rabbitmq import RabbitMQRPCClient, RPCMethodName, RPCNamespace
from servicelib.rabbitmq import RabbitMQRPCClient, RPCMethodName

pytest_simcore_core_services_selection = [
"rabbit",
Expand All @@ -30,12 +31,11 @@ def _base_configuration(

async def test_get_instance_type_details_all_options(
_base_configuration: None,
clusters_keeper_namespace: RPCNamespace,
clusters_keeper_rabbitmq_rpc_client: RabbitMQRPCClient,
):
# an empty set returns all options
rpc_response = await clusters_keeper_rabbitmq_rpc_client.request(
clusters_keeper_namespace,
CLUSTERS_KEEPER_RPC_NAMESPACE,
RPCMethodName("get_instance_type_details"),
instance_type_names=set(),
)
Expand All @@ -46,12 +46,11 @@ async def test_get_instance_type_details_all_options(

async def test_get_instance_type_details_specific_type_names(
_base_configuration: None,
clusters_keeper_namespace: RPCNamespace,
clusters_keeper_rabbitmq_rpc_client: RabbitMQRPCClient,
):
# an empty set returns all options
rpc_response = await clusters_keeper_rabbitmq_rpc_client.request(
clusters_keeper_namespace,
CLUSTERS_KEEPER_RPC_NAMESPACE,
RPCMethodName("get_instance_type_details"),
instance_type_names={"t2.micro", "g4dn.xlarge"},
)
Expand Down

0 comments on commit e3dfbd4

Please sign in to comment.