Commit 90be0095 authored by Dimitrios Gogos's avatar Dimitrios Gogos
Browse files

fix: validate edgeCloudZones for duplicates and add tests for request handling

parent 2b1b6af5
Loading
Loading
Loading
Loading
Loading
+7 −0
Changes for src/open_exposure_gateway/application/services/edge_application_management_service.py: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -698,6 +698,9 @@ class EdgeApplicationManagementService:
        if app_registration is None:
            raise BadRequestException(message=f"App {request.appId} is not registered")

        if len(set(request.edgeCloudZones)) != len(request.edgeCloudZones):
            raise BadRequestException(message="edgeCloudZones must not contain duplicates")

        for zone_id in request.edgeCloudZones:
            if await self._app_instance_repo.exists_in_zone(
                app_registration.app_registration_id, zone_id
@@ -1118,6 +1121,8 @@ class EdgeApplicationManagementService:
                "operation_completed_for_unknown_operation", operation_id=event.operation_id
            )
            return
        if operation.operation_type not in _RECONCILABLE_OPERATION_TYPES:
            return

        if operation.status in _TERMINAL_OPERATION_STATUSES:
            logger.info(
@@ -1323,6 +1328,8 @@ class EdgeApplicationManagementService:
                "operation_status_for_unknown_operation", operation_id=event.operation_id
            )
            return
        if operation.operation_type not in _RECONCILABLE_OPERATION_TYPES:
            return

        if operation.status in _TERMINAL_OPERATION_STATUSES:
            logger.info(
+34 −0
Changes for tests/unit/test_eam_service.py: 34 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1438,6 +1438,20 @@ class TestCreateAppDeployment:
        assert app_deployment_repo.rows == {}
        assert app_instance_repo.rows == {}

    async def test_same_zone_twice_in_one_request_is_rejected(
        self,
        service: EdgeApplicationManagementService,
        publisher: AsyncMock,
        app_instance_repo: FakeAppInstanceRepository,
    ) -> None:
        request = self._make_request(zones=[self.ZONE_A, self.ZONE_A])
        with pytest.raises(BadRequestException, match="duplicates"):
            await service.create_app_deployment(
                request=request, tenant_id="tenant-1", app_provider_id="provider-1"
            )
        publisher.publish.assert_not_called()
        assert app_instance_repo.rows == {}

    def _make_request_with_subscription(
        self, with_credential: bool = False
    ) -> CreateAppDeploymentRequest:
@@ -4636,6 +4650,26 @@ class TestHandleOperationStatus:

        assert await operation_repo.get_by_id(unknown_operation_id) is None

    @pytest.mark.parametrize("state", ["accepted", "failed", "failed_before_start"])
    async def test_status_for_qod_operation_is_noop(
        self,
        service: EdgeApplicationManagementService,
        operation_repo: FakeOperationRepository,
        state: Literal["accepted", "failed", "failed_before_start"],
    ) -> None:
        await self._seed_operation(
            operation_repo,
            OperationStatus.PENDING,
            operation_type=OperationType.NETWORK_CAPABILITY,
        )

        await service.handle_operation_status(self._status_event(state))

        untouched = await operation_repo.get_by_id(self.OPERATION_ID)
        assert untouched is not None
        assert untouched.status == OperationStatus.PENDING
        assert untouched.error is None

    @pytest.mark.parametrize("failure_state", ["failed", "failed_before_start"])
    async def test_failure_state_moves_pending_deploy_operation_and_instance_to_failed(
        self,