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 0e2a477d..29763180 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)
@@ -133,10 +130,11 @@ def delete_single(pnfd_info_id):
if not pnf_pkgs.exists():
logger.info('PNFD(%s) is 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 bf7f1cd2..d264e7c4 100644
--- a/catalog/packages/views/pnf_descriptor_views.py
+++ b/catalog/packages/views/pnf_descriptor_views.py
@@ -22,7 +22,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
@@ -37,6 +37,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"
}
)
@@ -57,6 +58,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.'}
@@ -146,6 +150,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"
}
)
@@ -157,6 +162,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())
@@ -172,6 +180,12 @@ def pnfd_content_ru(request, *args, **kwargs):
response['Content-Disposition'] = 'attachment; filename=%s' % file_name.encode('utf-8')
response['Content-Length'] = os.path.getsize(file_path)
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())