Skip to content

Commit cc87c99

Browse files
author
Andrei Neagu
committed
fixed tests with parsing of the specs
1 parent 7a9e81b commit cc87c99

File tree

4 files changed

+78
-28
lines changed

4 files changed

+78
-28
lines changed

packages/models-library/src/models_library/service_settings_labels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def validate_volume_limits(cls, v, info: ValidationInfo) -> str | None:
226226
"outputs_path": "/tmp/outputs", # noqa: S108 nosec
227227
"inputs_path": "/tmp/inputs", # noqa: S108 nosec
228228
"state_paths": ["/tmp/save_1", "/tmp_save_2"], # noqa: S108 nosec
229-
"state_exclude": ["/tmp/strip_me/*", "*.py"], # noqa: S108 nosec
229+
"state_exclude": ["/tmp/strip_me/*"], # noqa: S108 nosec
230230
},
231231
{
232232
"outputs_path": "/t_out",

packages/models-library/tests/test_service_settings_labels.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ def test_container_outgoing_permit_list_and_container_allow_internet_without_com
291291
)
292292
},
293293
):
294-
assert TypeAdapter(DynamicSidecarServiceLabels).validate_json(json.dumps(dict_data))
294+
assert TypeAdapter(DynamicSidecarServiceLabels).validate_json(
295+
json.dumps(dict_data)
296+
)
295297

296298

297299
def test_container_allow_internet_no_compose_spec_not_ok():
@@ -414,7 +416,7 @@ def service_labels() -> dict[str, str]:
414416
"inputs_path": "/tmp/inputs", # noqa: S108
415417
"outputs_path": "/tmp/outputs", # noqa: S108
416418
"state_paths": ["/tmp/save_1", "/tmp_save_2"], # noqa: S108
417-
"state_exclude": ["/tmp/strip_me/*", "*.py"], # noqa: S108
419+
"state_exclude": ["/tmp/strip_me/*"], # noqa: S108
418420
}
419421
),
420422
"simcore.service.compose-spec": json.dumps(

services/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/scheduler/_core/_event_create_sidecars.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@
5757
_logger = logging.getLogger(__name__)
5858

5959
_DYNAMIC_SIDECAR_SERVICE_EXTENDABLE_SPECS: Final[tuple[list[str], ...]] = (
60-
["Labels"],
61-
["TaskTemplate", "Resources", "Limits"],
62-
["TaskTemplate", "Resources", "Reservation", "MemoryBytes"],
63-
["TaskTemplate", "Resources", "Reservation", "NanoCPUs"],
64-
["TaskTemplate", "Placement", "Constraints"],
65-
["TaskTemplate", "ContainerSpec", "Env"],
66-
["TaskTemplate", "Resources", "Reservation", "GenericResources"],
60+
["labels"],
61+
["task_template", "container_spec", "env"],
62+
["task_template", "placement", "constraints"],
63+
["task_template", "resources", "reservation", "generic_resources"],
64+
["task_template", "resources", "limits"],
65+
["task_template", "resources", "reservation", "memory_bytes"],
66+
["task_template", "resources", "reservation", "nano_cp_us"],
6767
)
6868

6969

services/director-v2/tests/unit/with_dbs/test_modules_dynamic_sidecar_docker_service_specs.py

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
from simcore_service_director_v2.modules.dynamic_sidecar.docker_service_specs import (
4444
get_dynamic_sidecar_spec,
4545
)
46+
from simcore_service_director_v2.modules.dynamic_sidecar.scheduler._core._event_create_sidecars import (
47+
_DYNAMIC_SIDECAR_SERVICE_EXTENDABLE_SPECS,
48+
)
4649
from simcore_service_director_v2.utils.dict_utils import nested_update
4750

4851

@@ -180,7 +183,7 @@ def expected_dynamic_sidecar_spec(
180183
"paths_mapping": {
181184
"inputs_path": "/tmp/inputs", # noqa: S108
182185
"outputs_path": "/tmp/outputs", # noqa: S108
183-
"state_exclude": ["/tmp/strip_me/*", "*.py"], # noqa: S108
186+
"state_exclude": ["/tmp/strip_me/*"], # noqa: S108
184187
"state_paths": ["/tmp/save_1", "/tmp_save_2"], # noqa: S108
185188
},
186189
"callbacks_mapping": CallbacksMapping.model_config[
@@ -239,7 +242,7 @@ def expected_dynamic_sidecar_spec(
239242
"DY_SIDECAR_PATH_OUTPUTS": "/tmp/outputs", # noqa: S108
240243
"DY_SIDECAR_PROJECT_ID": "dd1d04d9-d704-4f7e-8f0f-1ca60cc771fe",
241244
"DY_SIDECAR_STATE_EXCLUDE": json_dumps(
242-
["*.py", "/tmp/strip_me/*"] # noqa: S108
245+
["/tmp/strip_me/*"] # noqa: S108
243246
),
244247
"DY_SIDECAR_STATE_PATHS": json_dumps(
245248
["/tmp/save_1", "/tmp_save_2"] # noqa: S108
@@ -614,25 +617,70 @@ async def test_merge_dynamic_sidecar_specs_with_user_specific_specs(
614617
another_merged_dict = nested_update(
615618
orig_dict,
616619
user_dict,
617-
include=(
618-
["labels"],
619-
["task_template", "Resources", "Limits"],
620-
["task_template", "Resources", "Reservation", "MemoryBytes"],
621-
["task_template", "Resources", "Reservation", "NanoCPUs"],
622-
["task_template", "Placement", "Constraints"],
623-
["task_template", "ContainerSpec", "Env"],
624-
["task_template", "Resources", "Reservation", "GenericResources"],
625-
),
620+
include=_DYNAMIC_SIDECAR_SERVICE_EXTENDABLE_SPECS,
626621
)
627622
assert another_merged_dict
628623

629624

630-
def test_regression_aio_docker_service_spec_serialization():
631-
raw_json = json.loads(
632-
'{"sidecar":{"Name":null,"Labels":{"io.simcore.scalable-service":"true"},"TaskTemplate":{"PluginSpec":null,"ContainerSpec":null,"NetworkAttachmentSpec":null,"Resources":null,"RestartPolicy":null,"Placement":{"Constraints":["node.labels.io.simcore.autoscaled-node==true","node.labels.io.simcore.osparc-services-ready==true"],"Preferences":null,"MaxReplicas":0,"Platforms":null},"ForceUpdate":null,"Runtime":null,"Networks":null,"LogDriver":null},"Mode":null,"UpdateConfig":null,"RollbackConfig":null,"Networks":null,"EndpointSpec":null},"service":null}'
625+
def test_regression_nested_update():
626+
mock_service_spec = AioDockerServiceSpec.model_validate(
627+
{"Labels": {"l1": "false", "l0": "a"}}
633628
)
634-
to_validate = raw_json["sidecar"]
635-
result = AioDockerServiceSpec.model_validate(to_validate)
636-
assert (
637-
result.model_dump(mode="json", exclude_unset=True, by_alias=True) == to_validate
629+
mock_catalog_constraints = AioDockerServiceSpec.model_validate(
630+
{
631+
"Labels": {"l1": "true", "l2": "a"},
632+
"TaskTemplate": {
633+
"Placement": {
634+
"Constraints": [
635+
"c1==true",
636+
"c2==true",
637+
],
638+
},
639+
"Resources": {
640+
"Limits": {"MemoryBytes": 1, "NanoCPUs": 1},
641+
"Reservations": {
642+
"GenericResources": [
643+
{"DiscreteResourceSpec": {"Kind": "VRAM", "Value": 1}}
644+
],
645+
"MemoryBytes": 2,
646+
"NanoCPUs": 2,
647+
},
648+
},
649+
"ContainerSpec": {
650+
"Env": [
651+
"key-1=value-1",
652+
"key2-value2=a",
653+
]
654+
},
655+
},
656+
}
657+
)
658+
result = nested_update(
659+
jsonable_encoder(mock_service_spec, exclude_unset=True, by_alias=False),
660+
jsonable_encoder(mock_catalog_constraints, exclude_unset=True, by_alias=False),
661+
include=_DYNAMIC_SIDECAR_SERVICE_EXTENDABLE_SPECS,
638662
)
663+
assert AioDockerServiceSpec.model_validate(result).model_dump(
664+
by_alias=True, exclude_unset=True
665+
) == {
666+
"Labels": {"l1": "true", "l2": "a", "l0": "a"},
667+
"TaskTemplate": {
668+
"Placement": {
669+
"Constraints": [
670+
"c1==true",
671+
"c2==true",
672+
],
673+
},
674+
"Resources": {
675+
"Limits": {"MemoryBytes": 1, "NanoCPUs": 1},
676+
"Reservations": {
677+
"GenericResources": [
678+
{"DiscreteResourceSpec": {"Kind": "VRAM", "Value": 1}}
679+
],
680+
"MemoryBytes": 2,
681+
"NanoCPUs": 2,
682+
},
683+
},
684+
"ContainerSpec": {"Env": {"key-1": "value-1", "key2-value2": "a"}},
685+
},
686+
}

0 commit comments

Comments
 (0)