Skip to content

Commit cc46b6b

Browse files
authored
🐛 Fix/backwards compatibility on service annotation labels (ITISFoundation#3041)
1 parent d942ea4 commit cc46b6b

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ class SimcoreServiceSettingLabelEntry(BaseModel):
4747
_destination_container: str = PrivateAttr()
4848
name: str = Field(..., description="The name of the service setting")
4949
setting_type: Literal[
50-
"string", "int", "integer", "number", "object", "ContainerSpec", "Resources"
50+
"string",
51+
"int",
52+
"integer",
53+
"number",
54+
"object",
55+
"ContainerSpec",
56+
"Resources",
5157
] = Field(
5258
...,
5359
description="The type of the service setting (follows Docker REST API naming scheme)",
@@ -58,6 +64,14 @@ class SimcoreServiceSettingLabelEntry(BaseModel):
5864
description="The value of the service setting (shall follow Docker REST API scheme for services",
5965
)
6066

67+
@validator("setting_type", pre=True)
68+
@classmethod
69+
def ensure_backwards_compatible_setting_type(cls, v):
70+
if v == "resources":
71+
# renamed in the latest version as
72+
return "Resources"
73+
return v
74+
6175
class Config(_BaseConfig):
6276
schema_extra = {
6377
"examples": [
@@ -73,7 +87,7 @@ class Config(_BaseConfig):
7387
"type": "ContainerSpec",
7488
"value": {"Command": ["run"]},
7589
},
76-
# SEE service_resources.py::ResourceValue
90+
# SEE services_resources.py::ResourceValue
7791
{
7892
"name": "Resources",
7993
"type": "Resources",
@@ -103,6 +117,20 @@ class Config(_BaseConfig):
103117
},
104118
# environments
105119
{"name": "env", "type": "string", "value": ["DISPLAY=:0"]},
120+
# SEE 'simcore.service.settings' label annotations for simcore/services/dynamic/jupyter-octave-python-math:1.6.5
121+
{"name": "ports", "type": "int", "value": 8888},
122+
{
123+
"name": "constraints",
124+
"type": "string",
125+
"value": ["node.platform.os == linux"],
126+
},
127+
{
128+
"name": "resources",
129+
"type": "resources",
130+
"value": {
131+
"Limits": {"NanoCPUs": 4000000000, "MemoryBytes": 8589934592}
132+
},
133+
},
106134
]
107135
}
108136

packages/service-integration/tests/test_osparc_config.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
import json
66
from pathlib import Path
77
from pprint import pformat
8-
from typing import Any, Type
8+
from typing import Any
99

1010
import pytest
1111
import yaml
1212
from models_library.service_settings_labels import SimcoreServiceSettingLabelEntry
13-
from pydantic import BaseModel
1413
from service_integration.osparc_config import MetaConfig, RuntimeConfig, SettingsItem
1514

1615

@@ -66,12 +65,24 @@ def test_load_from_labels(
6665

6766

6867
@pytest.mark.parametrize(
69-
"model_cls",
70-
(SimcoreServiceSettingLabelEntry,),
68+
"example_data", SimcoreServiceSettingLabelEntry.Config.schema_extra["examples"]
7169
)
7270
def test_settings_item_in_sync_with_service_settings_label(
73-
model_cls: Type[BaseModel], model_cls_examples: dict[str, dict[str, Any]]
71+
example_data: dict[str, Any]
7472
):
75-
for name, example in model_cls_examples.items():
76-
print(name, ":", pformat(example))
77-
SettingsItem.parse_obj(example)
73+
74+
print(pformat(example_data))
75+
76+
# First we parse with SimcoreServiceSettingLabelEntry since it also supports backwards compatibility
77+
# and will upgrade old version
78+
example_model = SimcoreServiceSettingLabelEntry.parse_obj(example_data)
79+
80+
# SettingsItem is exclusively for NEW labels, so it should not support backwards compatibility
81+
new_model = SettingsItem(
82+
name=example_model.name,
83+
type=example_model.setting_type,
84+
value=example_model.value,
85+
)
86+
87+
# check back
88+
SimcoreServiceSettingLabelEntry.parse_obj(new_model.dict(by_alias=True))

requirements/tools/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ RUN apt-get update \
2222

2323
# SEE bug with pip==22.1 https://github.com/jazzband/pip-tools/issues/1617
2424
RUN pip --no-cache-dir install --upgrade \
25-
pip~=22.0.1 \
25+
pip~=22.0 \
2626
wheel \
2727
setuptools
2828

0 commit comments

Comments
 (0)