Commit c7dfb8c4 authored by Sergio Gimenez's avatar Sergio Gimenez
Browse files

merge local zones and drop /zones

parent bd16fcbd
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -70,14 +70,23 @@ def get_federated_zones() -> List[EdgeCloudZone]:
    return []

def get_cached_zones() -> list[dict]:
    """Retrieve cached zones from storage, falling back to SRM if empty."""
    """Retrieve cached zones and merge with local SRM zones."""
    cached = []
    try:
        cached = get_zones()
        if cached:
            return cached
    except Exception as e:
        logger.warning("Failed to read cached zones: %s", e)
    return get_local_zones()

    merged = list(cached or [])
    existing_ids = {
        zone.get("edgeCloudZoneId") for zone in merged if isinstance(zone, dict)
    }
    for zone in get_local_zones():
        zone_id = zone.get("edgeCloudZoneId") if isinstance(zone, dict) else None
        if zone_id and zone_id not in existing_ids:
            merged.append(zone)
            existing_ids.add(zone_id)
    return merged

def get_all_cloud_zones() -> List[EdgeCloudZone]:
    """Get all available zones from local and federated Operator Platforms"""
@@ -144,10 +153,3 @@ def edge_cloud_zone_details(zoneId: str) -> dict:
    result = api_client.edge_cloud_zone_details(zone_id=zoneId)
    return result

def get_edge_cloud_zones_alias(x_correlator: str | None = None, region=None, status=None):
    return get_edge_cloud_zones(x_correlator=x_correlator, region=region, status=status)


def edge_cloud_zone_details_alias(zoneId: str) -> dict:
    return edge_cloud_zone_details(zoneId)
+1 −78
Original line number Diff line number Diff line
@@ -621,83 +621,6 @@ paths:
        - Edge Cloud Zones
      summary: Retrieve a list of the operators Edge Cloud Zones and
        their status
      description: |
        List of the operators Edge Cloud Zones and their
        status, ordering the results by location and filtering by
        status (active/inactive/unknown)
      operationId: edge_cloud_management_api.controllers.edge_cloud_controller.get_edge_cloud_zones_alias
      parameters:
        - $ref: "#/components/parameters/x-correlator"
        - name: region
          description: |
            Human readable name of the geographical Edge Cloud Region of
            the Edge Cloud. Defined by the Edge Cloud Provider.
          in: query
          required: false
          schema:
            $ref: "#/components/schemas/EdgeCloudRegion"
        - name: status
          description: Human readable status of the Edge Cloud Zone
          in: query
          required: false
          schema:
            $ref: "#/components/schemas/EdgeCloudZoneStatus"
      responses:
        "200":
          description: |
            Successful response, returning the
            Available Edge Cloud Zones.
          headers:
            x-correlator:
              $ref: "#/components/headers/x-correlator"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/EdgeCloudZones"
        "401":
          $ref: "#/components/responses/401"
        "403":
          $ref: "#/components/responses/403"
        "404":
          $ref: "#/components/responses/404"
        "500":
          $ref: "#/components/responses/500"
        "503":
          $ref: "#/components/responses/503"
  /edge-cloud-zones/{zoneId}:
    get:
      tags:
      - Edge Cloud Zones
      summary: Retrieve the details of an Edge Cloud Zone
      description: |
        List of the operators Edge Cloud Zones and their
        status, ordering the results by location and filtering by
        status (active/inactive/unknown)
      operationId: edge_cloud_management_api.controllers.edge_cloud_controller.edge_cloud_zone_details_alias
      parameters:
        - $ref: "#/components/parameters/x-correlator"
        - name: zoneId
          in: path
          description: |
            UID of the specific edge cloud zone
          required: true
          style: simple
          schema:
            type: string
      responses:
        "200":
          description: |
            Successful response, returning the Edge Cloud Zone details
        "404":
          $ref: "#/components/responses/404"
  /zones:
    get:
      # security:
      #   - openId:
      #       - edge-application-management:edge-cloud-zones:read
      tags:
        - Edge Cloud Zones
      summary: Retrieve a list of the operators Edge Cloud Zones and their status
      description: |
        List of the operators Edge Cloud Zones and their
        status, ordering the results by location and filtering by
@@ -741,7 +664,7 @@ paths:
          $ref: "#/components/responses/500"
        "503":
          $ref: "#/components/responses/503"
  /zones/{zoneId}:
  /edge-cloud-zones/{zoneId}:
    get:
      tags:
      - Edge Cloud Zones
+19 −0
Original line number Diff line number Diff line
@@ -87,6 +87,25 @@ def test_get_cached_zones_returns_cached(mock_zones):


@pytest.mark.unit
def test_get_cached_zones_merges_local(mock_zones):
    local_zone = {
        "edgeCloudZoneId": "local-zone",
        "edgeCloudZoneName": "local-zone",
        "edgeCloudZoneStatus": "unknown",
        "edgeCloudProvider": "local",
        "edgeCloudRegion": "local",
    }
    with patch(
        "edge_cloud_management_api.controllers.edge_cloud_controller.get_zones",
        return_value=mock_zones,
    ), patch(
        "edge_cloud_management_api.controllers.edge_cloud_controller.get_local_zones",
        return_value=[local_zone],
    ):
        result = get_cached_zones()
        assert local_zone in result


def test_get_cached_zones_fallback_to_srm(mock_zones):
    with patch(
        "edge_cloud_management_api.controllers.edge_cloud_controller.get_zones",