Commit 813cec91 authored by Sergio Gimenez's avatar Sergio Gimenez
Browse files

fix(eam): read the instance name from SRM's ref

SRM keeps the name an App Provider asks for as the service instance's
ref, and its instance listing has no "name" field. SRMServiceInstance
read "name", always got None, and the CAMARA AppInstanceInfo fell back
to the instance id, for local and partner-hosted instances alike. The
unit fakes built instances with name=, so no test saw it.

Accept ref, keeping name as an alias so the fakes still work, and add a
test that parses SRM's real response shape.

Co-Authored-By: default avatarClaude Opus 5.5 <noreply@anthropic.com>
parent 8b1048c8
Loading
Loading
Loading
Loading
Loading
+3 −2
Changes for src/open_exposure_gateway/domain/edge_application_management.py: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ from enum import StrEnum
from typing import Any, Literal
from uuid import UUID

from pydantic import BaseModel, Field, model_validator
from pydantic import AliasChoices, BaseModel, Field, model_validator


class Subject(StrEnum):
@@ -349,7 +349,8 @@ class SRMServiceInstance(BaseModel):
    state: str
    app_provider_id: str
    zone_id: str | None = None
    name: str | None = None
    # SRM keeps the requested instance name as the instance's ref
    name: str | None = Field(default=None, validation_alias=AliasChoices("ref", "name"))
    capability_instances: list[SRMCapabilityInstanceSummary] = []


+18 −0
Changes for tests/unit/test_srm_client.py: 18 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -289,6 +289,24 @@ async def test_get_app_instances_sends_app_provider_id_query_param(
    assert captured["params"] == {"app_provider_id": "provider-1"}


async def test_app_instance_name_is_read_from_srms_ref(monkeypatch: pytest.MonkeyPatch) -> None:
    srm_instance = {
        "service_instance_id": "0e2f6c1a-5b7d-4c8e-9f10-2a3b4c5d6e7f",
        "service_specification_id": "7d1e2f3a-4b5c-4d6e-8f90-1a2b3c4d5e6f",
        "zone_id": "3c4d5e6f-7a8b-4c9d-8e0f-1a2b3c4d5e6f",
        "state": "active",
        "ref": "podinfo_bcn_01",
        "app_provider_id": "provider-1",
        "metadata": {},
        "capability_instances": [],
    }
    client = _client(monkeypatch, lambda request: httpx.Response(200, json=[srm_instance]))

    [instance] = await client.get_app_instances(app_provider_id="provider-1")

    assert instance.name == "podinfo_bcn_01"


@pytest.mark.parametrize(
    "body",
    [