Commit 4d41f315 authored by Konstantinos Togias's avatar Konstantinos Togias
Browse files

Keep unsupported adapters unadvertised and preserve typed failures in logging

parent b44c7cf2
Loading
Loading
Loading
Loading
+25 −5
Changes for src/openop_tfsdk/contract/adapters/edgecloud.py: 25 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -61,8 +61,7 @@ class I2edgeCapabilityAdapter:

    @staticmethod
    def capability_surface(capability_kind: str, config: Optional[dict] = None):
        if capability_kind == "workload":
            return list(WORKLOAD_ACTIONS), list(RUNTIME_KINDS)
        # Retained for compatibility, but unsupported in this release.
        return [], []

    def activate(self, request: CapabilityLifecycleRequest) -> CapabilityLifecycleResult:
@@ -126,14 +125,35 @@ class I2edgeCapabilityAdapter:
        try:
            return getattr(self._client, method)(*args)
        except pydantic.ValidationError as error:
            log.error("%s rejected the request: %s", method, error)
            log.error(
                "backend_request_invalid",
                method=method,
                error_code=ValidationError.error_code,
                error_type=type(error).__name__,
            )
            raise ValidationError(f"{method}: invalid request for i2edge") from error
        except I2EdgeError as error:
            log.error("%s failed: %s", method, error)
            # The client has no status code, only a message: "got 404" or "... not found ...".
            if "got 404" in str(error) or "not found" in str(error):
                log.error(
                    "backend_resource_not_found",
                    method=method,
                    error_code=ResourceNotFound.error_code,
                    error_type=type(error).__name__,
                )
                raise ResourceNotFound(f"{method}: not found") from error
            log.error(
                "backend_call_failed",
                method=method,
                error_code=DomainExecutionFailed.error_code,
                error_type=type(error).__name__,
            )
            raise DomainExecutionFailed(f"{method} failed") from error
        except Exception as error:
            log.error("%s failed: %s", method, error)
            log.error(
                "backend_call_failed",
                method=method,
                error_code=DomainExecutionFailed.error_code,
                error_type=type(error).__name__,
            )
            raise DomainExecutionFailed(f"{method} failed") from error
+4 −4
Changes for src/openop_tfsdk/contract/adapters/kubernetes.py: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ class KubernetesCapabilityAdapter:
        )

        if result.returncode != 0:
            log.error("helm install failed: %s", result.stderr)
            log.error("helm_install_failed", error_code=DomainExecutionFailed.error_code)
            raise DomainExecutionFailed("helm install failed")

        return CapabilityLifecycleResult(
@@ -106,7 +106,7 @@ class KubernetesCapabilityAdapter:
        )

        if result.returncode != 0:
            log.warning("helm status failed: %s", result.stderr)
            log.warning("helm_status_failed", error_code=DomainExecutionFailed.error_code)
            return CapabilityRuntimeState(
                external_id=release_name,
                capability_kind=request.capability_kind,
@@ -148,7 +148,7 @@ class KubernetesCapabilityAdapter:
        )

        if result.returncode != 0:
            log.error("helm uninstall failed: %s", result.stderr)
            log.error("helm_uninstall_failed", error_code=DomainExecutionFailed.error_code)
            raise DomainExecutionFailed("helm uninstall failed")

        return CapabilityLifecycleResult(
@@ -182,7 +182,7 @@ class KubernetesCapabilityAdapter:
        )

        if result.returncode != 0:
            log.error("helm upgrade failed: %s", result.stderr)
            log.error("helm_upgrade_failed", error_code=DomainExecutionFailed.error_code)
            raise DomainExecutionFailed("helm upgrade failed")

        return CapabilityLifecycleResult(
+23 −4
Changes for src/openop_tfsdk/contract/adapters/network.py: 23 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -297,7 +297,11 @@ class NetworkCapabilityAdapter:
                maxSurface=parameters.max_surface_sqm,
            )
        except pydantic.ValidationError as error:
            log.error("location_context rejected the request: %s", error)
            log.error(
                "location_context_request_invalid",
                error_code=ValidationError.error_code,
                error_type=type(error).__name__,
            )
            raise ValidationError(
                f"location_context: invalid request for {self.adapter_type}"
            ) from error
@@ -316,17 +320,32 @@ class NetworkCapabilityAdapter:
        try:
            return getattr(self._client, method)(*args)
        except (pydantic.ValidationError, OaiValidationError) as error:
            log.error("%s rejected the request: %s", method, error)
            log.error(
                "backend_request_invalid",
                method=method,
                error_code=ValidationError.error_code,
                error_type=type(error).__name__,
            )
            raise ValidationError(f"{method}: invalid request for {self.adapter_type}") from error
        except CoreHttpError as error:
            cause = error.__cause__
            if isinstance(cause, requests.HTTPError) and cause.response is not None:
                if cause.response.status_code == 404:
                    raise ResourceNotFound(f"{method}: not found") from error
            log.error("%s failed: %s", method, error)
            log.error(
                "backend_call_failed",
                method=method,
                error_code=DomainExecutionFailed.error_code,
                error_type=type(error).__name__,
            )
            raise DomainExecutionFailed(f"{method} failed") from error
        except Exception as error:
            log.error("%s failed: %s", method, error)
            log.error(
                "backend_call_failed",
                method=method,
                error_code=DomainExecutionFailed.error_code,
                error_type=type(error).__name__,
            )
            raise DomainExecutionFailed(f"{method} failed") from error


+2 −3
Changes for src/openop_tfsdk/contract/adapters/oran.py: 2 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ Deprecated: unsupported in this release (closed source, no test access).
"""
from typing import Optional

from openop_tfsdk.contract.adapters.network import QOD_ACTIONS, NetworkCapabilityAdapter
from openop_tfsdk.contract.adapters.network import NetworkCapabilityAdapter
from openop_tfsdk.contract.errors import DomainExecutionFailed, ResourceNotFound
from openop_tfsdk.oran.adapters.i2cat_ric.client import OranManager
from openop_tfsdk.oran.core.common import OranHttpError
@@ -22,8 +22,7 @@ class I2catRicCapabilityAdapter(NetworkCapabilityAdapter):

    @staticmethod
    def capability_surface(capability_kind: str, config: Optional[dict] = None):
        if capability_kind == "qod_session" and "oran-qod" in OranManager.capabilities:
            return list(QOD_ACTIONS), []
        # Retained for compatibility, but unsupported in this release.
        return [], []

    def _call(self, method: str, *args):
+4 −4
Changes for src/openop_tfsdk/edgecloud/adapters/kubernetes/client.py: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -117,7 +117,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
                request=None,
            )
        except Exception as e:
            log.error(e.args)
            log.error("edge_cloud_call_failed", error_type=type(e).__name__)
            status_code = 500
            return {
                "status": 500,
@@ -260,7 +260,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
                request=None,
            )
        except Exception as e:
            log.error(e.args)
            log.error("edge_cloud_call_failed", error_type=type(e).__name__)
            return {
                "status": 500,
                "code": "INTERNAL",
@@ -343,7 +343,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
                request=None,
            )
        except Exception as e:
            log.error(e.args)
            log.error("edge_cloud_call_failed", error_type=type(e).__name__)
            return {"status": 404, "code": "NOT_FOUND", "message": "Resource does not exist"}

    def get_edge_cloud_zones(
@@ -361,7 +361,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
            zone["edgeCloudProvider"] = self.edge_cloud_provider
            zone["edgeCloudRegion"] = node.get("location")
            zone_list.append(zone)
        log.info(zone_list)
        log.info("edge_cloud_zones_retrieved", zone_count=len(zone_list))
        return build_custom_http_response(
            status_code=200,
            content=zone_list,
Loading