X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=o2ims%2Fviews%2Focloud_view.py;h=b529c13c0d34c32ef2d65cf7661035fb210ac129;hb=9c9fde8a0fd391b71753e51ae8b8bdd4531d79aa;hp=c685898f8ac91a0ef06004924ebe45bd7eb99c42;hpb=4dd941a359733bffe3fe6f55cdb1880eea9a30dc;p=pti%2Fo2.git diff --git a/o2ims/views/ocloud_view.py b/o2ims/views/ocloud_view.py index c685898..b529c13 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 @@ -76,11 +77,16 @@ def resource_pool_one(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork): with uow: first = uow.resource_pools.get(resourcePoolId) - return first.serialize() if first is not None else None + return first.serialize() if first else None def resources(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork, **kwargs): + with uow: + first = uow.resource_pools.get(resourcePoolId) + if first is None: + raise NotFoundException("ResourcePool {} doesn't exist".format( + resourcePoolId)) pagination = Pagination(**kwargs) # filter key should be the same with database name query_kwargs = pagination.get_pagination() @@ -112,10 +118,19 @@ def resources(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork, return pagination.get_result(ret) -def resource_one(resourceId: str, uow: unit_of_work.AbstractUnitOfWork): +def resource_one(resourceId: str, + uow: unit_of_work.AbstractUnitOfWork, resourcePoolId: str): with uow: - first = uow.resources.get(resourceId) - return first.serialize() if first is not None else None + resoucePool = uow.resource_pools.get(resourcePoolId) + if resoucePool is None: + raise NotFoundException("ResourcePool {} doesn't exist".format( + resourcePoolId)) + + first = uow.resources.get(resourceId) + if first is None: + raise NotFoundException("Resource {} doesn't exist".format( + resourceId)) + return first.serialize() def deployment_managers(uow: unit_of_work.AbstractUnitOfWork, **kwargs): @@ -253,6 +268,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