From c7860536b72cc164c7ff2c6705c1f2be98211ead Mon Sep 17 00:00:00 2001 From: "Zhang Rong(Jon)" Date: Mon, 14 Nov 2022 21:07:48 +0800 Subject: [PATCH] Fix INF-354 repeat delete same subscription should return 404 Issue-ID: INF-354 Signed-off-by: Zhang Rong(Jon) Change-Id: I872ce2e274172de94372acd5cd51413d694d2bbc --- o2ims/views/alarm_view.py | 7 ++++++- o2ims/views/ocloud_view.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/o2ims/views/alarm_view.py b/o2ims/views/alarm_view.py index 58920f3..83189c1 100644 --- a/o2ims/views/alarm_view.py +++ b/o2ims/views/alarm_view.py @@ -17,7 +17,8 @@ import uuid as uuid from o2common.service import unit_of_work from o2common.views.view import gen_filter, check_filter from o2common.views.pagination_view import Pagination -from o2common.views.route_exception import BadRequestException +from o2common.views.route_exception import BadRequestException, \ + NotFoundException from o2ims.views.alarm_dto import SubscriptionDTO from o2ims.domain.alarm_obj import AlarmSubscription, AlarmEventRecord @@ -91,6 +92,10 @@ def subscription_create(subscriptionDto: SubscriptionDTO.subscription_create, def subscription_delete(subscriptionId: str, uow: unit_of_work.AbstractUnitOfWork): with uow: + first = uow.alarm_subscriptions.get(subscriptionId) + if not first: + raise NotFoundException( + "Alarm Subscription {} not found.".format(subscriptionId)) uow.alarm_subscriptions.delete(subscriptionId) uow.commit() return True diff --git a/o2ims/views/ocloud_view.py b/o2ims/views/ocloud_view.py index c685898..bc11097 100644 --- a/o2ims/views/ocloud_view.py +++ b/o2ims/views/ocloud_view.py @@ -23,7 +23,8 @@ from o2common.service import unit_of_work from o2common.config import config from o2common.views.view import gen_filter, check_filter from o2common.views.pagination_view import Pagination -from o2common.views.route_exception import BadRequestException +from o2common.views.route_exception import BadRequestException, \ + NotFoundException from o2ims.domain import ocloud from o2ims.views.ocloud_dto import SubscriptionDTO @@ -253,6 +254,10 @@ def subscription_create(subscriptionDto: SubscriptionDTO.subscription_create, def subscription_delete(subscriptionId: str, uow: unit_of_work.AbstractUnitOfWork): with uow: + first = uow.subscriptions.get(subscriptionId) + if not first: + raise NotFoundException( + "Subscription {} not found.".format(subscriptionId)) uow.subscriptions.delete(subscriptionId) uow.commit() return True -- 2.16.6