summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog/packages/biz/pnf_descriptor.py12
-rw-r--r--catalog/packages/views/pnf_descriptor_views.py16
2 files changed, 20 insertions, 8 deletions
diff --git a/catalog/packages/biz/pnf_descriptor.py b/catalog/packages/biz/pnf_descriptor.py
index ebc965bc..463efee9 100644
--- a/catalog/packages/biz/pnf_descriptor.py
+++ b/catalog/packages/biz/pnf_descriptor.py
@@ -20,7 +20,7 @@ import uuid
from catalog.pub.config.config import CATALOG_ROOT_PATH
from catalog.pub.database.models import NSPackageModel, PnfPackageModel
-from catalog.pub.exceptions import CatalogException
+from catalog.pub.exceptions import CatalogException, ResourceNotFoundException
from catalog.pub.utils import fileutil, toscaparser
from catalog.pub.utils.values import ignore_case_get
@@ -49,9 +49,6 @@ def create(data):
def query_multiple():
pnf_pkgs = PnfPackageModel.objects.all()
- if not pnf_pkgs.exists():
- logger.error('PNFDs do not exist.')
- raise CatalogException('PNFDs do not exist.')
response_data = []
for pnf_pkg in pnf_pkgs:
data = fill_response_data(pnf_pkg)
@@ -63,7 +60,7 @@ def query_single(pnfd_info_id):
pnf_pkgs = PnfPackageModel.objects.filter(pnfPackageId=pnfd_info_id)
if not pnf_pkgs.exists():
logger.error('PNFD(%s) does not exist.' % pnfd_info_id)
- raise CatalogException('PNFD(%s) does not exist.' % pnfd_info_id)
+ raise ResourceNotFoundException('PNFD(%s) does not exist.' % pnfd_info_id)
return fill_response_data(pnf_pkgs[0])
@@ -118,7 +115,7 @@ def download(pnfd_info_id):
pnf_pkgs = PnfPackageModel.objects.filter(pnfPackageId=pnfd_info_id)
if not pnf_pkgs.exists():
logger.error('PNFD(%s) does not exist.' % pnfd_info_id)
- raise CatalogException('PNFD(%s) does not exist.' % pnfd_info_id)
+ raise ResourceNotFoundException('PNFD(%s) does not exist.' % pnfd_info_id)
if pnf_pkgs[0].onboardingState != 'ONBOARDED':
logger.error('PNFD(%s) is not ONBOARDED.' % pnfd_info_id)
raise CatalogException('PNFD(%s) is not ONBOARDED.' % pnfd_info_id)
@@ -135,10 +132,11 @@ def delete_single(pnfd_info_id):
if not pnf_pkgs.exists():
logger.info('PNFD(%s) has been deleted.' % pnfd_info_id)
return
-
+ '''
if pnf_pkgs[0].usageState != 'NOT_IN_USE':
logger.info('PNFD(%s) shall be NOT_IN_USE.' % pnfd_info_id)
raise CatalogException('PNFD(%s) shall be NOT_IN_USE.' % pnfd_info_id)
+ '''
ns_pkgs = NSPackageModel.objects.all()
for ns_pkg in ns_pkgs:
pnf_info_ids = []
diff --git a/catalog/packages/views/pnf_descriptor_views.py b/catalog/packages/views/pnf_descriptor_views.py
index c489df5f..35ed83a7 100644
--- a/catalog/packages/views/pnf_descriptor_views.py
+++ b/catalog/packages/views/pnf_descriptor_views.py
@@ -21,7 +21,7 @@ from catalog.packages.biz.pnf_descriptor import create, delete_single, download,
from catalog.packages.serializers.create_pnfd_info_request import CreatePnfdInfoRequestSerializer
from catalog.packages.serializers.pnfd_info import PnfdInfoSerializer
from catalog.packages.serializers.pnfd_infos import PnfdInfosSerializer
-from catalog.pub.exceptions import CatalogException
+from catalog.pub.exceptions import CatalogException, ResourceNotFoundException
from drf_yasg.utils import no_body, swagger_auto_schema
from rest_framework import status
from rest_framework.decorators import api_view
@@ -36,6 +36,7 @@ logger = logging.getLogger(__name__)
request_body=no_body,
responses={
status.HTTP_200_OK: PnfdInfoSerializer(),
+ status.HTTP_404_NOT_FOUND: "PNFD does not exist.",
status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
}
)
@@ -56,6 +57,9 @@ def pnfd_info_rd(request, pnfdInfoId): # TODO
data = query_single(pnfdInfoId)
pnfd_info = validate_data(data, PnfdInfoSerializer)
return Response(data=pnfd_info.data, status=status.HTTP_200_OK)
+ except ResourceNotFoundException as e:
+ logger.error(e.message)
+ return Response(data={'error': "PNFD does not exist."}, status=status.HTTP_404_NOT_FOUND)
except CatalogException as e:
logger.error(e.message)
error_msg = {'error': 'Query of a PNFD failed.'}
@@ -145,6 +149,7 @@ def pnf_descriptors_rc(request, *args, **kwargs):
request_body=no_body,
responses={
status.HTTP_204_NO_CONTENT: 'PNFD file',
+ status.HTTP_404_NOT_FOUND: "PNFD does not exist.",
status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
}
)
@@ -156,6 +161,9 @@ def pnfd_content_ru(request, *args, **kwargs):
try:
upload(files[0], pnfd_info_id)
return Response(data=None, status=status.HTTP_204_NO_CONTENT)
+ except CatalogException as e:
+ logger.error(e.message)
+ error_msg = {'error': 'Uploading PNFD content failed.'}
except Exception as e:
logger.error(e.message)
logger.error(traceback.format_exc())
@@ -169,6 +177,12 @@ def pnfd_content_ru(request, *args, **kwargs):
response['Content-Disposition'] = 'attachment; filename=%s' % file_name.encode('utf-8')
response['Content-Length'] = file_size
return response
+ except ResourceNotFoundException as e:
+ logger.error(e.message)
+ return Response(data={'error': "PNFD does not exist."}, status=status.HTTP_404_NOT_FOUND)
+ except CatalogException as e:
+ logger.error(e.message)
+ error_msg = {'error': 'Downloading PNFD content failed.'}
except Exception as e:
logger.error(e.message)
logger.error(traceback.format_exc())