Skip to content

Commit aa62425

Browse files
committed
maybe the fix
1 parent 2fd7af1 commit aa62425

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,24 @@ def _backwards_compatibility(cls, values: dict[str, Any]) -> dict[str, Any]:
122122

123123
mapped_values.setdefault(
124124
f"{_SIMCORE_RUNTIME_DOCKER_LABEL_PREFIX}memory-limit",
125-
_UNDEFINED_LABEL_VALUE_INT,
125+
values.get("memory_limit", _UNDEFINED_LABEL_VALUE_INT),
126126
)
127127

128128
def _convert_nano_cpus_to_cpus(nano_cpu: str) -> str:
129129
with contextlib.suppress(ValidationError):
130-
return f"{TypeAdapter(float).validate_python(nano_cpu) / (1.0*10**9):.2f}"
130+
return f"{TypeAdapter(float).validate_python(nano_cpu) / (1.0 * 10**9):.2f}"
131131
return _UNDEFINED_LABEL_VALUE_INT
132132

133133
mapped_values.setdefault(
134134
f"{_SIMCORE_RUNTIME_DOCKER_LABEL_PREFIX}cpu-limit",
135-
_convert_nano_cpus_to_cpus(
136-
values.get("nano_cpus_limit", _UNDEFINED_LABEL_VALUE_INT)
135+
values.get(
136+
"cpu_limit",
137+
_convert_nano_cpus_to_cpus(
138+
values.get(
139+
"nano_cpus_limit",
140+
_UNDEFINED_LABEL_VALUE_INT,
141+
)
142+
),
137143
),
138144
)
139145
return mapped_values

packages/models-library/tests/test_docker.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55

66
from typing import Any
7+
from uuid import UUID
78

89
import pytest
910
from faker import Faker
@@ -13,7 +14,7 @@
1314
DockerLabelKey,
1415
StandardSimcoreDockerLabels,
1516
)
16-
from pydantic import TypeAdapter, ValidationError
17+
from pydantic import ByteSize, TypeAdapter, ValidationError
1718

1819
_faker = Faker()
1920

@@ -83,11 +84,11 @@ def test_docker_label_key(label_key: str, valid: bool):
8384
True,
8485
),
8586
(
86-
f"registry:5000/si.m--c_ore/services/1234/jupyter-smash:{'A'*128}",
87+
f"registry:5000/si.m--c_ore/services/1234/jupyter-smash:{'A' * 128}",
8788
True,
8889
),
8990
(
90-
f"registry:5000/si.m--c_ore/services/1234/jupyter-smash:{'A'*129}",
91+
f"registry:5000/si.m--c_ore/services/1234/jupyter-smash:{'A' * 129}",
9192
False,
9293
),
9394
),
@@ -122,3 +123,17 @@ def test_simcore_service_docker_label_keys(obj_data: dict[str, Any]):
122123
).validate_python(exported_dict)
123124
assert re_imported_docker_label_keys
124125
assert simcore_service_docker_label_keys == re_imported_docker_label_keys
126+
127+
128+
def test_simcore_service_docker_label_keys_construction():
129+
simcore_service_docker_label_keys = StandardSimcoreDockerLabels(
130+
user_id=8268,
131+
project_id=UUID("5ea24ce0-0e4d-4ee6-a3f1-e4799752a684"),
132+
node_id=UUID("c17c6279-23c6-412f-8826-867323a7711a"),
133+
product_name="osparc",
134+
simcore_user_agent="oePqmjQbZndJghceKRJR",
135+
swarm_stack_name="UNDEFINED_DOCKER_LABEL", # NOTE: there is currently no need for this label in the comp backend
136+
memory_limit=ByteSize(23424324),
137+
cpu_limit=1.0,
138+
)
139+
assert simcore_service_docker_label_keys.cpu_limit == 1.0

0 commit comments

Comments
 (0)