Skip to content

Commit ae8c6d1

Browse files
authored
🐛 Fixes dynamic-sidecar settings in director-v2 (ITISFoundation#2431)
Settings introduced in PR ITISFoundation#2411 fail to initialize when deployed in master environment * Disables dynamic sidecar settings * Fixes dynamic-services vs dynamic-sidecar settings * Adds test with envdevel * disables scheduler in client fixture
1 parent 215ca26 commit ae8c6d1

File tree

7 files changed

+60
-50
lines changed

7 files changed

+60
-50
lines changed

services/director-v2/src/simcore_service_director_v2/core/application.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,24 @@ def init_app(settings: Optional[AppSettings] = None) -> FastAPI:
5757
if settings.DIRECTOR_V0.DIRECTOR_V0_ENABLED:
5858
director_v0.setup(app, settings.DIRECTOR_V0)
5959

60-
if settings.DYNAMIC_SERVICES.DIRECTOR_V2_DYNAMIC_SERVICES_ENABLED:
61-
dynamic_services.setup(app, settings.DYNAMIC_SERVICES)
62-
6360
if settings.POSTGRES.DIRECTOR_V2_POSTGRES_ENABLED:
6461
db.setup(app, settings.POSTGRES)
6562

66-
if settings.DYNAMIC_SERVICES.DIRECTOR_V2_DYNAMIC_SIDECAR_ENABLED:
67-
dynamic_sidecar.setup(app)
68-
6963
if settings.CELERY.DIRECTOR_V2_CELERY_ENABLED:
7064
celery.setup(app, settings.CELERY)
7165

7266
if settings.CELERY_SCHEDULER.DIRECTOR_V2_CELERY_SCHEDULER_ENABLED:
7367
scheduler.setup(app)
7468

69+
if settings.DYNAMIC_SERVICES.DIRECTOR_V2_DYNAMIC_SERVICES_ENABLED:
70+
dynamic_services.setup(app, settings.DYNAMIC_SERVICES)
71+
72+
if settings.DYNAMIC_SERVICES.DYNAMIC_SIDECAR and (
73+
settings.DYNAMIC_SERVICES.DYNAMIC_SCHEDULER
74+
and settings.DYNAMIC_SERVICES.DYNAMIC_SCHEDULER.DIRECTOR_V2_DYNAMIC_SCHEDULER_ENABLED
75+
):
76+
dynamic_sidecar.setup(app)
77+
7578
# setup app --
7679
app.add_event_handler("startup", on_startup)
7780
app.add_event_handler("shutdown", on_shutdown)

services/director-v2/src/simcore_service_director_v2/core/settings.py

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,17 @@ class DynamicServicesSchedulerSettings(BaseCustomSettings):
179179

180180

181181
class DynamicServicesSettings(BaseCustomSettings):
182+
# TODO: PC->ANE: refactor dynamic-sidecar settings. One settings per app module
183+
# WARNING: THIS IS NOT the same module as dynamic-sidecar
182184
DIRECTOR_V2_DYNAMIC_SERVICES_ENABLED: bool = Field(
183-
True, description="Enables/Disables connection with service"
184-
)
185-
DIRECTOR_V2_DYNAMIC_SIDECAR_ENABLED: bool = Field(
186185
True, description="Enables/Disables the dynamic_sidecar submodule"
187186
)
188187

189-
# dynamic sidecar
190-
DYNAMIC_SIDECAR: DynamicSidecarSettings
188+
# FIXME: PC -> ANE: this module was disabled since no default settings were provided and failed at startup
189+
DYNAMIC_SIDECAR: Optional[DynamicSidecarSettings] = None
191190

192-
# dynamic services scheduler
193-
DYNAMIC_SCHEDULER: DynamicServicesSchedulerSettings
191+
# FIXME: PC -> ANE: this module was disabled since no default settings were provided and failed at startup
192+
DYNAMIC_SCHEDULER: Optional[DynamicServicesSchedulerSettings] = None
194193

195194

196195
class PGSettings(PostgresSettings):
@@ -211,7 +210,8 @@ class DaskSchedulerSettings(BaseCustomSettings):
211210

212211

213212
class AppSettings(BaseCustomSettings, MixinLoggingSettings):
214-
# DOCKER
213+
214+
# docker environs
215215
SC_BOOT_MODE: Optional[BootModeEnum]
216216
SC_BOOT_TARGET: Optional[BuildTargetEnum]
217217

@@ -220,21 +220,6 @@ class AppSettings(BaseCustomSettings, MixinLoggingSettings):
220220
env=["DIRECTOR_V2_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"],
221221
)
222222

223-
# CELERY submodule
224-
CELERY: CelerySettings
225-
226-
# DIRECTOR submodule
227-
DIRECTOR_V0: DirectorV0Settings
228-
229-
# Dynamic Services submodule
230-
DYNAMIC_SERVICES: DynamicServicesSettings
231-
232-
# POSTGRES
233-
POSTGRES: PGSettings
234-
235-
# STORAGE
236-
STORAGE_ENDPOINT: str = Field("storage:8080", env="STORAGE_ENDPOINT")
237-
238223
# for passing self-signed certificate to spawned services
239224
# TODO: fix these variables once the timeout-minutes: 30 is able to start dynamic services
240225
DIRECTOR_V2_SELF_SIGNED_SSL_SECRET_ID: str = ""
@@ -246,13 +231,11 @@ class AppSettings(BaseCustomSettings, MixinLoggingSettings):
246231
PUBLISHED_HOSTS_NAME: str = Field("", env="PUBLISHED_HOSTS_NAME")
247232
SWARM_STACK_NAME: str = Field("undefined-please-check", env="SWARM_STACK_NAME")
248233

249-
#
250234
NODE_SCHEMA_LOCATION: str = Field(
251235
f"{API_ROOT}/{api_vtag}/schemas/node-meta-v0.0.1.json",
252236
description="used when in devel mode vs release mode",
253237
)
254238

255-
#
256239
SIMCORE_SERVICES_NETWORK_NAME: Optional[str] = Field(
257240
None,
258241
description="used to find the right network name",
@@ -262,9 +245,6 @@ class AppSettings(BaseCustomSettings, MixinLoggingSettings):
262245
description="useful when developing with an alternative registry namespace",
263246
)
264247

265-
# traefik
266-
TRAEFIK_SIMCORE_ZONE: str = Field("internal_simcore_stack")
267-
268248
# monitoring
269249
MONITORING_ENABLED: bool = False
270250

@@ -276,6 +256,20 @@ class AppSettings(BaseCustomSettings, MixinLoggingSettings):
276256

277257
CLIENT_REQUEST: ClientRequestSettings
278258

259+
# App modules settings ---------------------
260+
261+
CELERY: CelerySettings
262+
263+
DIRECTOR_V0: DirectorV0Settings
264+
265+
DYNAMIC_SERVICES: DynamicServicesSettings
266+
267+
POSTGRES: PGSettings
268+
269+
STORAGE_ENDPOINT: str = Field("storage:8080", env="STORAGE_ENDPOINT")
270+
271+
TRAEFIK_SIMCORE_ZONE: str = Field("internal_simcore_stack")
272+
279273
CELERY_SCHEDULER: CelerySchedulerSettings
280274

281275
DASK_SCHEDULER: DaskSchedulerSettings

services/director-v2/src/simcore_service_director_v2/modules/dynamic_services.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@
88
import httpx
99
from fastapi import FastAPI, Response
1010

11-
# Module's business logic ---------------------------------------------
1211
from ..core.settings import DynamicServicesSettings
1312
from ..utils.client_decorators import handle_errors, handle_retry
1413

1514
logger = logging.getLogger(__name__)
1615

1716

18-
# Module's setup logic ---------------------------------------------
19-
20-
2117
def setup(app: FastAPI, settings: DynamicServicesSettings):
2218
if not settings:
2319
settings = DynamicServicesSettings()

services/director-v2/tests/conftest.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import logging
88
import os
9+
from copy import deepcopy
910
from pathlib import Path
1011
from typing import Any, Dict, Iterator
1112

@@ -29,6 +30,7 @@
2930
"pytest_simcore.docker_compose",
3031
"pytest_simcore.docker_registry",
3132
"pytest_simcore.docker_swarm",
33+
"pytest_simcore.environment_configs",
3234
"pytest_simcore.postgres_service",
3335
"pytest_simcore.pydantic_models",
3436
"pytest_simcore.rabbit_service",
@@ -67,12 +69,12 @@ def project_env_devel_dict(project_slug_dir: Path) -> Dict[str, Any]:
6769

6870

6971
@pytest.fixture(scope="function")
70-
def project_env_devel_environment(project_env_devel_dict: Dict[str, Any], monkeypatch):
72+
def project_env_devel_environment(
73+
project_env_devel_dict: Dict[str, Any], monkeypatch
74+
) -> Dict[str, Any]:
7175
for key, value in project_env_devel_dict.items():
7276
monkeypatch.setenv(key, value)
73-
monkeypatch.setenv(
74-
"DYNAMIC_SIDECAR_IMAGE", "local/dynamic-sidecar:TEST_MOCKED_TAG_NOT_PRESENT"
75-
)
77+
return deepcopy(project_env_devel_dict)
7678

7779

7880
@pytest.fixture(scope="module")
@@ -83,20 +85,29 @@ def loop() -> asyncio.AbstractEventLoop:
8385

8486
@pytest.fixture(scope="function")
8587
def mock_env(monkeypatch) -> None:
88+
# TODO: PC-> ANE: Avoid using stand-alone environs setups and
89+
# use instead mock_env_devel_environment or project_env_devel_environment
90+
# which resemble real environment
91+
8692
# Works as below line in docker.compose.yml
8793
# ${DOCKER_REGISTRY:-itisfoundation}/dynamic-sidecar:${DOCKER_IMAGE_TAG:-latest}
8894

8995
registry = os.environ.get("DOCKER_REGISTRY", "local")
9096
image_tag = os.environ.get("DOCKER_IMAGE_TAG", "production")
9197

9298
image_name = f"{registry}/dynamic-sidecar:{image_tag}".strip("/")
99+
93100
logger.warning("Patching to: DYNAMIC_SIDECAR_IMAGE=%s", image_name)
94101
monkeypatch.setenv("DYNAMIC_SIDECAR_IMAGE", image_name)
95102

96103
monkeypatch.setenv("SIMCORE_SERVICES_NETWORK_NAME", "test_network_name")
97104
monkeypatch.setenv("TRAEFIK_SIMCORE_ZONE", "test_traefik_zone")
98105
monkeypatch.setenv("SWARM_STACK_NAME", "test_swarm_name")
99-
monkeypatch.setenv("DIRECTOR_V2_DYNAMIC_SIDECAR_ENABLED", "false")
106+
107+
# DISABLE dynamic-service app module
108+
monkeypatch.setenv("DIRECTOR_V2_DYNAMIC_SCHEDULER_ENABLED", "false")
109+
monkeypatch.setenv("DYNAMIC_SCHEDULER", "null")
110+
monkeypatch.setenv("DYNAMIC_SIDECAR", "null")
100111

101112
monkeypatch.setenv("SC_BOOT_MODE", "production")
102113

services/director-v2/tests/unit/conftest.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ def simcore_services_network_name() -> str:
2121
def disable_dynamic_sidecar_scheduler_in_unit_tests(
2222
monkeypatch, simcore_services_network_name: str
2323
) -> None:
24-
monkeypatch.setenv("REGISTRY_auth", "false")
25-
monkeypatch.setenv("REGISTRY_user", "test")
24+
# FIXME: PC-> ANE: please avoid autouse!!!
25+
monkeypatch.setenv("REGISTRY_AUTH", "false")
26+
monkeypatch.setenv("REGISTRY_USER", "test")
2627
monkeypatch.setenv("REGISTRY_PW", "test")
27-
monkeypatch.setenv("REGISTRY_ssl", "false")
28+
monkeypatch.setenv("REGISTRY_SSL", "false")
2829
monkeypatch.setenv("SIMCORE_SERVICES_NETWORK_NAME", simcore_services_network_name)
2930
monkeypatch.setenv("TRAEFIK_SIMCORE_ZONE", "test_traefik_zone")
3031
monkeypatch.setenv("SWARM_STACK_NAME", "test_swarm_name")

services/director-v2/tests/unit/test_core_settings.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
)
1313

1414

15-
def test_loading_env_devel_in_settings(project_env_devel_environment):
16-
15+
def test_settings_with_project_env_devel(project_env_devel_environment):
1716
# loads from environ
1817
settings = AppSettings.create_from_envs()
1918
print("captured settings: \n", settings.json(indent=2))
@@ -24,6 +23,12 @@ def test_loading_env_devel_in_settings(project_env_devel_environment):
2423
assert settings.POSTGRES.dsn == "postgresql://test:test@localhost:5432/test"
2524

2625

26+
def test_settings_with_env_devel(mock_env_devel_environment):
27+
settings = AppSettings.create_from_envs()
28+
print("captured settings: \n", settings.json(indent=2))
29+
assert settings
30+
31+
2732
@pytest.mark.parametrize(
2833
"image",
2934
[

services/director-v2/tests/unit/test_modules_celery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ def mul(x, y):
8888

8989
@pytest.mark.parametrize("runtime_requirements", ["cpu", "gpu", "mpi", "gpu:mpi"])
9090
def test_send_computation_tasks(
91-
minimal_celery_config: None,
91+
minimal_celery_config,
9292
minimal_app: FastAPI,
9393
celery_app: Celery,
94-
celery_worker_parameters: None,
94+
celery_worker_parameters,
9595
celery_worker: TestWorkController,
9696
celery_configuration: CeleryConfig,
9797
user_id: PositiveInt,

0 commit comments

Comments
 (0)