|
43 | 43 | from simcore_service_director_v2.modules.dynamic_sidecar.docker_service_specs import ( |
44 | 44 | get_dynamic_sidecar_spec, |
45 | 45 | ) |
| 46 | +from simcore_service_director_v2.modules.dynamic_sidecar.scheduler._core._event_create_sidecars import ( |
| 47 | + _DYNAMIC_SIDECAR_SERVICE_EXTENDABLE_SPECS, |
| 48 | +) |
46 | 49 | from simcore_service_director_v2.utils.dict_utils import nested_update |
47 | 50 |
|
48 | 51 |
|
@@ -180,7 +183,7 @@ def expected_dynamic_sidecar_spec( |
180 | 183 | "paths_mapping": { |
181 | 184 | "inputs_path": "/tmp/inputs", # noqa: S108 |
182 | 185 | "outputs_path": "/tmp/outputs", # noqa: S108 |
183 | | - "state_exclude": ["/tmp/strip_me/*", "*.py"], # noqa: S108 |
| 186 | + "state_exclude": ["/tmp/strip_me/*"], # noqa: S108 |
184 | 187 | "state_paths": ["/tmp/save_1", "/tmp_save_2"], # noqa: S108 |
185 | 188 | }, |
186 | 189 | "callbacks_mapping": CallbacksMapping.model_config[ |
@@ -239,7 +242,7 @@ def expected_dynamic_sidecar_spec( |
239 | 242 | "DY_SIDECAR_PATH_OUTPUTS": "/tmp/outputs", # noqa: S108 |
240 | 243 | "DY_SIDECAR_PROJECT_ID": "dd1d04d9-d704-4f7e-8f0f-1ca60cc771fe", |
241 | 244 | "DY_SIDECAR_STATE_EXCLUDE": json_dumps( |
242 | | - ["*.py", "/tmp/strip_me/*"] # noqa: S108 |
| 245 | + ["/tmp/strip_me/*"] # noqa: S108 |
243 | 246 | ), |
244 | 247 | "DY_SIDECAR_STATE_PATHS": json_dumps( |
245 | 248 | ["/tmp/save_1", "/tmp_save_2"] # noqa: S108 |
@@ -614,25 +617,70 @@ async def test_merge_dynamic_sidecar_specs_with_user_specific_specs( |
614 | 617 | another_merged_dict = nested_update( |
615 | 618 | orig_dict, |
616 | 619 | 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, |
626 | 621 | ) |
627 | 622 | assert another_merged_dict |
628 | 623 |
|
629 | 624 |
|
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"}} |
633 | 628 | ) |
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, |
638 | 662 | ) |
| 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