Skip to content

Commit a1a6e6d

Browse files
authored
🐛 Fix how sidecar passes the environment variables to the 'car' (#2453)
* Add a test to check if the variables acutally end up in the container created by the sidecar
1 parent 25114c5 commit a1a6e6d

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

services/sidecar/src/simcore_service_sidecar/executor.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,14 @@ async def _get_resource_limitations() -> Dict[str, int]:
304304
resource_limitations = await _get_resource_limitations()
305305

306306
nano_cpus_limit = resource_limitations["NanoCPUs"]
307-
mem_limit = resource_limitations["NanoCPUs"]
307+
mem_limit = resource_limitations["Memory"]
308308

309309
env_vars.extend(
310310
[
311-
f"{CPU_RESOURCE_LIMIT_KEY} = {str(nano_cpus_limit)}"
312-
f"{MEM_RESOURCE_LIMIT_KEY} = {str(mem_limit)}",
311+
f"{CPU_RESOURCE_LIMIT_KEY}={str(nano_cpus_limit)}",
312+
f"{MEM_RESOURCE_LIMIT_KEY}={str(mem_limit)}",
313313
]
314314
)
315-
316315
docker_container_config = {
317316
"Env": env_vars,
318317
"Cmd": "run",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
3+
print("Hello from python. I can see the following env")
4+
print(os.environ)

services/sidecar/tests/integration/test_sidecar.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from models_library.settings.celery import CeleryConfig
1616
from models_library.settings.rabbit import RabbitConfig
1717
from pytest_simcore.helpers.rawdata_fakers import random_project, random_user
18+
from servicelib.resources import CPU_RESOURCE_LIMIT_KEY, MEM_RESOURCE_LIMIT_KEY
1819
from simcore_postgres_database.storage_models import projects, users
1920
from simcore_sdk.models.pipeline_models import ComputationalPipeline, ComputationalTask
2021
from simcore_service_sidecar import config, utils
@@ -378,6 +379,22 @@ async def _create(
378379
},
379380
)
380381

382+
PYTHON_ENV_PRINTER = (
383+
"itisfoundation/osparc-python-runner",
384+
"1.0.0",
385+
{
386+
"a13d197a-bf8c-4e11-8a15-44a9894cbbe8": {
387+
"next": [],
388+
"inputs": {
389+
"input_1": {
390+
"store": SIMCORE_S3_ID,
391+
"path": "osparc_python_print_env.py",
392+
}
393+
},
394+
},
395+
},
396+
)
397+
381398

382399
# FIXME: input schema in osparc-python-executor service is wrong
383400
PYTHON_RUNNER_FACTORY_STUDY = (
@@ -410,7 +427,9 @@ async def _create(
410427
[
411428
SLEEPERS_STUDY,
412429
PYTHON_RUNNER_STUDY,
430+
PYTHON_ENV_PRINTER,
413431
],
432+
ids=["sleepers", "python-runner-study", "python-env-printer"],
414433
)
415434
async def test_run_services(
416435
loop,
@@ -452,7 +471,7 @@ async def rabbit_message_handler(message: aio_pika.IncomingMessage):
452471
await cli.run_sidecar(job_id, user_id, pipeline.project_id, node_id)
453472

454473
await asyncio.sleep(15) # wait a little bit for logs to come in
455-
await _assert_incoming_data_logs(
474+
_sidecar_logs, tasks_logs, _progress_logs = await _assert_incoming_data_logs(
456475
list(pipeline_cfg.keys()),
457476
incoming_data,
458477
user_id,
@@ -466,6 +485,12 @@ async def rabbit_message_handler(message: aio_pika.IncomingMessage):
466485
assert not list(config.SIDECAR_OUTPUT_FOLDER.glob("**/*"))
467486
assert not list(config.SIDECAR_LOG_FOLDER.glob("**/*"))
468487

488+
# The python env printer should print what he sees in the environment
489+
if pipeline_cfg == PYTHON_ENV_PRINTER[2]:
490+
logs = json.dumps(tasks_logs)
491+
assert CPU_RESOURCE_LIMIT_KEY in logs
492+
assert MEM_RESOURCE_LIMIT_KEY in logs
493+
469494

470495
def print_module_variables(module):
471496
print(module.__name__, ":")

0 commit comments

Comments
 (0)