From 214be22e5d8c5f66e9e4761ef61515d79eaf3756 Mon Sep 17 00:00:00 2001 From: Giancarlo Romeo Date: Wed, 9 Oct 2024 15:50:18 +0200 Subject: [PATCH] fix code --- .../src/simcore_service_agent/core/application.py | 2 +- .../src/simcore_service_agent/core/settings.py | 15 ++++++++++----- services/agent/tests/conftest.py | 8 ++++---- .../tests/unit/test_modules_volumes_cleanup_s3.py | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/services/agent/src/simcore_service_agent/core/application.py b/services/agent/src/simcore_service_agent/core/application.py index 1c2211b16f3..3ac90922dc1 100644 --- a/services/agent/src/simcore_service_agent/core/application.py +++ b/services/agent/src/simcore_service_agent/core/application.py @@ -38,7 +38,7 @@ def create_app() -> FastAPI: # SETTINGS settings = ApplicationSettings.create_from_envs() _setup_logger(settings) - logger.debug(settings.json(indent=2)) + logger.debug(settings.model_dump_json(indent=2)) assert settings.SC_BOOT_MODE # nosec app = FastAPI( diff --git a/services/agent/src/simcore_service_agent/core/settings.py b/services/agent/src/simcore_service_agent/core/settings.py index 882217f9a5f..d57d8d0af5b 100644 --- a/services/agent/src/simcore_service_agent/core/settings.py +++ b/services/agent/src/simcore_service_agent/core/settings.py @@ -1,7 +1,7 @@ from typing import Final from models_library.basic_types import BootModeEnum, LogLevel -from pydantic import AnyHttpUrl, Field, NonNegativeInt, validator +from pydantic import AliasChoices, AnyHttpUrl, Field, NonNegativeInt, field_validator from settings_library.base import BaseCustomSettings from settings_library.r_clone import S3Provider from settings_library.utils_logging import MixinLoggingSettings @@ -11,16 +11,21 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings): LOGLEVEL: LogLevel = Field( - LogLevel.WARNING.value, env=["AGENT_LOGLEVEL", "LOG_LEVEL", "LOGLEVEL"] + LogLevel.WARNING.value, + validation_alias=AliasChoices( + "AGENT_LOGLEVEL", + "LOG_LEVEL", + "LOGLEVEL", + ), ) SC_BOOT_MODE: BootModeEnum | None AGENT_VOLUMES_LOG_FORMAT_LOCAL_DEV_ENABLED: bool = Field( default=False, - env=[ + validation_alias=AliasChoices( "AGENT_VOLUMES_LOG_FORMAT_LOCAL_DEV_ENABLED", "LOG_FORMAT_LOCAL_DEV_ENABLED", - ], + ), description="Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!", ) AGENT_VOLUMES_CLEANUP_TARGET_SWARM_STACK_NAME: str = Field( @@ -47,7 +52,7 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings): ) AGENT_PROMETHEUS_INSTRUMENTATION_ENABLED: bool = True - @validator("LOGLEVEL") + @field_validator("LOGLEVEL") @classmethod def valid_log_level(cls, value) -> LogLevel: return LogLevel(cls.validate_log_level(value)) diff --git a/services/agent/tests/conftest.py b/services/agent/tests/conftest.py index bd0d1a8964f..5e85be5a035 100644 --- a/services/agent/tests/conftest.py +++ b/services/agent/tests/conftest.py @@ -11,10 +11,11 @@ import pytest import simcore_service_agent from aiodocker.volumes import DockerVolume +from common_library.pydantic_networks_extension import HttpUrlLegacy from models_library.basic_types import BootModeEnum from models_library.services import RunID from moto.server import ThreadedMotoServer -from pydantic import HttpUrl, parse_obj_as +from pydantic import HttpUrl, TypeAdapter from settings_library.r_clone import S3Provider from simcore_service_agent.core.settings import ApplicationSettings @@ -187,9 +188,8 @@ def caplog_info_debug( @pytest.fixture(scope="module") -def mocked_s3_server_url(mocked_aws_server: ThreadedMotoServer) -> HttpUrl: +def mocked_s3_server_url(mocked_aws_server: ThreadedMotoServer) -> HttpUrlLegacy: # pylint: disable=protected-access - return parse_obj_as( - HttpUrl, + return TypeAdapter(HttpUrlLegacy).validate_python( f"http://{mocked_aws_server._ip_address}:{mocked_aws_server._port}", # noqa: SLF001 ) diff --git a/services/agent/tests/unit/test_modules_volumes_cleanup_s3.py b/services/agent/tests/unit/test_modules_volumes_cleanup_s3.py index 1728d0bb029..862f447fc1a 100644 --- a/services/agent/tests/unit/test_modules_volumes_cleanup_s3.py +++ b/services/agent/tests/unit/test_modules_volumes_cleanup_s3.py @@ -149,7 +149,7 @@ async def test_store_to_s3( ) await _download_files_from_bucket( - endpoint=mocked_s3_server_url, + endpoint=f"{mocked_s3_server_url}", access_key="xxx", secret_key="xxx", bucket_name=bucket,