Skip to content

Commit

Permalink
fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
giancarloromeo committed Oct 9, 2024
1 parent 0567fea commit 214be22
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 10 additions & 5 deletions services/agent/src/simcore_service_agent/core/settings.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand All @@ -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))
8 changes: 4 additions & 4 deletions services/agent/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 214be22

Please sign in to comment.