Skip to content

Commit d955183

Browse files
author
Andrei Neagu
committed
fixed tests
1 parent ffc5d97 commit d955183

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from models_library.services_types import RunID
2+
from pydantic import field_validator
3+
4+
5+
def _convert_str_to_run_id_object(v: RunID | str) -> RunID:
6+
if isinstance(v, str):
7+
return RunID(v)
8+
return v
9+
10+
11+
def convert_str_to_run_id_object(field: str):
12+
return field_validator(field, mode="before")(_convert_str_to_run_id_object)

services/agent/src/simcore_service_agent/core/settings.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from datetime import timedelta
22

3+
from common_library.pydantic_type_adapters import AnyHttpUrlLegacy
34
from models_library.basic_types import BootModeEnum, LogLevel
4-
from pydantic import AliasChoices, AnyHttpUrl, Field, field_validator
5+
from pydantic import AliasChoices, Field, field_validator
56
from settings_library.base import BaseCustomSettings
67
from settings_library.r_clone import S3Provider
78
from settings_library.rabbit import RabbitSettings
@@ -32,7 +33,7 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
3233
AGENT_VOLUMES_CLEANUP_TARGET_SWARM_STACK_NAME: str = Field(
3334
..., description="Exactly the same as director-v2's `SWARM_STACK_NAME` env var"
3435
)
35-
AGENT_VOLUMES_CLEANUP_S3_ENDPOINT: AnyHttpUrl
36+
AGENT_VOLUMES_CLEANUP_S3_ENDPOINT: AnyHttpUrlLegacy
3637
AGENT_VOLUMES_CLEANUP_S3_ACCESS_KEY: str
3738
AGENT_VOLUMES_CLEANUP_S3_SECRET_KEY: str
3839
AGENT_VOLUMES_CLEANUP_S3_BUCKET: str

services/agent/src/simcore_service_agent/models/volumes.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
from pathlib import Path
2+
from typing import Final
23

4+
from common_library.pydantic_validators import convert_str_to_run_id_object
35
from models_library.api_schemas_directorv2.services import (
46
CHARS_IN_VOLUME_NAME_BEFORE_DIR_NAME,
57
)
68
from models_library.projects import ProjectID
79
from models_library.projects_nodes_io import NodeID
810
from models_library.services_types import RunID
911
from models_library.users import UserID
10-
from pydantic import BaseModel, Field
12+
from pydantic import BaseModel, ConfigDict, Field, TypeAdapter
1113

1214

1315
class DynamicServiceVolumeLabels(BaseModel):
@@ -22,7 +24,16 @@ class DynamicServiceVolumeLabels(BaseModel):
2224
def directory_name(self) -> str:
2325
return self.source[CHARS_IN_VOLUME_NAME_BEFORE_DIR_NAME:][::-1].strip("_")
2426

27+
_convert_str_to_run_id_object = convert_str_to_run_id_object("run_id")
28+
29+
model_config = ConfigDict(
30+
arbitrary_types_allowed=True,
31+
)
32+
2533

2634
class VolumeDetails(BaseModel):
2735
mountpoint: Path = Field(alias="Mountpoint")
2836
labels: DynamicServiceVolumeLabels = Field(alias="Labels")
37+
38+
39+
VolumeDetailsAdapter: Final[TypeAdapter[VolumeDetails]] = TypeAdapter(VolumeDetails)

services/agent/src/simcore_service_agent/services/docker_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from simcore_service_agent.core.settings import ApplicationSettings
1616
from starlette import status
1717

18-
from ..models.volumes import VolumeDetails
18+
from ..models.volumes import VolumeDetails, VolumeDetailsAdapter
1919
from .backup import backup_volume
2020
from .instrumentation import get_instrumentation
2121

@@ -60,7 +60,7 @@ async def get_unused_dynamc_sidecar_volumes(docker: Docker) -> set[str]:
6060

6161
async def get_volume_details(docker: Docker, *, volume_name: str) -> VolumeDetails:
6262
volume_details = await DockerVolume(docker, volume_name).show()
63-
return VolumeDetails.parse_obj(volume_details)
63+
return VolumeDetailsAdapter.validate_python(volume_details)
6464

6565

6666
@contextmanager

0 commit comments

Comments
 (0)