Commit c3350080 authored by Cesar Cajas's avatar Cesar Cajas
Browse files

feature/add-gsma-schemas-to-edgecloud-adapters: fix patch method

parent 2ab09603
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ from .common import (
    I2EdgeError,
    i2edge_delete,
    i2edge_get,
    i2edge_patch,
    i2edge_post,
    i2edge_post_multiform_data,
)
@@ -1026,7 +1027,30 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
        :param request_body: Payload with updated onboarding info.
        :return: Response with update confirmation.
        """
        pass
        url = f"{self.base_url}/application/onboarding/{app_id}"
        params = {}
        response = i2edge_get(url, params, expected_status=200)
        response_json = response.json()
        app_component_specs = request_body.get("appComponents")
        app_qos_profile = request_body.get("appUpdQoSProfile")
        response_json["profile_data"]["appQoSProfile"] = app_qos_profile
        response_json["profile_data"]["appComponentSpecs"] = app_component_specs
        data = response_json.get("profile_data")
        try:
            payload = i2edge_schemas.ApplicationOnboardingRequest(profile_data=data)
            url = "{}/application/onboarding/{}".format(self.base_url, app_id)
            response = i2edge_patch(url, payload, expected_status=200)
            return build_custom_http_response(
                status_code=200,
                content={"response": "Application update successful"},
                headers={"Content-Type": self.content_type_gsma},
                encoding=self.encoding_gsma,
                url=response.url,
                request=response.request,
            )
        except I2EdgeError as e:
            log.error(f"Failed to patch onboarded app: {e}")
            raise

    def delete_onboarded_app_gsma(self, app_id: str) -> Response:
        """
+12 −5
Original line number Diff line number Diff line
@@ -66,16 +66,23 @@ def i2edge_post(url: str, model_payload: BaseModel, expected_status: int = 201)
        raise I2EdgeError(err_msg)


def i2edge_put(url: str, model_payload: BaseModel) -> dict:
def i2edge_patch(url: str, model_payload: BaseModel, expected_status: int = 200) -> dict:
    headers = {
        "Content-Type": "application/json",
        "accept": "application/json",
    }
    json_payload = json.dumps(model_payload.model_dump(mode="json"))
    json_payload = json.dumps(model_payload.model_dump(exclude_unset=True, mode="json"))
    try:
        response = requests.put(url, data=json_payload, headers=headers)
        response.raise_for_status()
        response = requests.patch(url, data=json_payload, headers=headers)
        if response.status_code == expected_status:
            return response
        else:
            i2edge_err_msg = get_error_message_from(response)
            err_msg = "Failed to patch: Expected status {}, got {}. Detail: {}".format(
                expected_status, response.status_code, i2edge_err_msg
            )
            log.error(err_msg)
            raise I2EdgeError(err_msg)
    except requests.exceptions.HTTPError as e:
        i2edge_err_msg = get_error_message_from(response)
        err_msg = "Failed to patch: {}. Detail: {}".format(i2edge_err_msg, e)
+1 −0
Original line number Diff line number Diff line
@@ -122,6 +122,7 @@ class AppQoSProfile(BaseModel):
    appProvisioning: bool = Field(default=True)
    bandwidthRequired: int = Field(default=1)
    latencyConstraints: str = Field(default="NONE")
    mobilitySupport: Optional[bool] = None
    multiUserClients: str = Field(default="APP_TYPE_SINGLE_USER")
    noOfUsersPerAppInst: int = Field(default=1)