Skip to content

Commit 3e03271

Browse files
authored
Bugfix/sidecar starts as cpu (#1932)
* correctly read in the FORCE_START_CPU_MODE environ * check return value of container
1 parent 8f7de81 commit 3e03271

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

services/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ services:
162162
- REGISTRY_PW=${REGISTRY_PW}
163163
- SWARM_STACK_NAME=${SWARM_STACK_NAME:-simcore}
164164
- SIDECAR_LOGLEVEL=${LOG_LEVEL:-WARNING}
165+
- START_AS_MODE_CPU=${SIDECAR_FORCE_CPU_NODE:-0}
165166

166167
networks:
167168
- computational_services_subnet

services/sidecar/src/simcore_service_sidecar/celery_configurator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def define_celery_task(app: Celery, name: str) -> None:
6565

6666

6767
def configure_node(bootmode: BootMode) -> Celery:
68-
log.info("Initializing celery app...")
68+
log.info("Initializing celery app in %s...", bootmode)
6969
app = Celery(
7070
f"sidecar.{str(bootmode.name).lower()}.{config.SIDECAR_HOST_HOSTNAME_PATH.read_text()}",
7171
broker=config.CELERY_CONFIG.broker_url,

services/sidecar/src/simcore_service_sidecar/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import logging
22
import multiprocessing
33
import os
4+
from distutils.util import strtobool
45
from pathlib import Path
5-
from typing import Optional
66

77
from models_library.settings.celery import CeleryConfig
88

@@ -66,8 +66,8 @@
6666
logging.getLogger("sqlalchemy.pool").setLevel(SIDECAR_LOGLEVEL)
6767

6868
# sidecar celery starting mode overwrite
69-
FORCE_START_CPU_MODE: Optional[str] = os.environ.get("START_AS_MODE_CPU")
70-
FORCE_START_GPU_MODE: Optional[str] = os.environ.get("START_AS_MODE_GPU")
69+
FORCE_START_CPU_MODE: bool = strtobool(os.environ.get("START_AS_MODE_CPU", "false"))
70+
FORCE_START_GPU_MODE: bool = strtobool(os.environ.get("START_AS_MODE_GPU", "false"))
7171

7272
# if a node has this amount of CPUs it will be a candidate an MPI candidate
7373
TARGET_MPI_NODE_CPU_COUNT: int = int(os.environ.get("TARGET_MPI_NODE_CPU_COUNT", "-1"))

services/sidecar/src/simcore_service_sidecar/utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,18 @@ async def async_is_gpu_node() -> bool:
8989
"AttachStderr": False,
9090
"Tty": False,
9191
"OpenStdin": False,
92-
"HostConfig": {"Init": True, "AutoRemove": True},
92+
"HostConfig": {
93+
"Init": True,
94+
"AutoRemove": True,
95+
}, # NOTE: The Init parameter shows a weird behavior: no exception thrown when the container fails
9396
}
9497
try:
95-
await docker.containers.run(
98+
container = await docker.containers.run(
9699
config=spec_config, name=f"sidecar_{uuid.uuid4()}_test_gpu"
97100
)
98-
return True
101+
102+
container_data = await container.wait(timeout=30)
103+
return container_data["StatusCode"] == 0
99104
except aiodocker.exceptions.DockerError as err:
100105
logger.debug(
101106
"is_gpu_node DockerError while check-run %s: %s", spec_config, err

services/sidecar/tests/unit/test_celery_configurator.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ def _toggle_gpu_mock(mocker, has_gpu: bool) -> None:
1515
containers_get = mocker.patch(
1616
"aiodocker.containers.DockerContainers.run", return_value=asyncio.Future()
1717
)
18-
containers_get.return_value.set_result("")
18+
19+
class FakeContainer:
20+
async def wait(self, **kwargs):
21+
return {"StatusCode": 0 if has_gpu else 127}
22+
23+
containers_get.return_value.set_result(FakeContainer())
24+
1925
if not has_gpu:
2026
containers_get.side_effect = aiodocker.exceptions.DockerError(
2127
"MOCK Error", {"message": "this is a mocked exception"}
@@ -46,12 +52,12 @@ def mock_node_has_gpu(request, mocker) -> None:
4652

4753
@pytest.fixture
4854
def force_cpu_mode(monkeypatch):
49-
monkeypatch.setattr(config, "FORCE_START_CPU_MODE", "1", raising=True)
55+
monkeypatch.setattr(config, "FORCE_START_CPU_MODE", True, raising=True)
5056

5157

5258
@pytest.fixture
5359
def force_gpu_mode(monkeypatch):
54-
monkeypatch.setattr(config, "FORCE_START_GPU_MODE", "1", raising=True)
60+
monkeypatch.setattr(config, "FORCE_START_GPU_MODE", True, raising=True)
5561

5662

5763
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)