aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbiancunkang <bian.cunkang@zte.com.cn>2018-08-29 15:16:00 +0800
committerbiancunkang <bian.cunkang@zte.com.cn>2018-08-29 15:16:00 +0800
commit821361d63caac250ddc39b7db6a927d75b7527fc (patch)
treee47ed31450a7692d14f240059529d03982457c1b
parentfdc0aa401ffa1716985c1b4662b8bf2ff91f1c60 (diff)
Deal with ns descriptor
Modify problems in ns Change-Id: Id9849b4795df11c1ceb266e5391fafc9c797f680 Issue-ID: VFC-1038 Signed-off-by: biancunkang <bian.cunkang@zte.com.cn>
-rw-r--r--catalog/packages/biz/ns_descriptor.py16
-rw-r--r--catalog/packages/biz/vnf_package.py6
-rw-r--r--catalog/packages/serializers/nsd_info.py2
-rw-r--r--catalog/packages/serializers/pnfd_info.py2
-rw-r--r--catalog/packages/views/ns_descriptor_views.py16
-rw-r--r--catalog/packages/views/vnf_package_views.py10
-rw-r--r--catalog/pub/exceptions.py2
7 files changed, 31 insertions, 23 deletions
diff --git a/catalog/packages/biz/ns_descriptor.py b/catalog/packages/biz/ns_descriptor.py
index 424406c9..2d0b511b 100644
--- a/catalog/packages/biz/ns_descriptor.py
+++ b/catalog/packages/biz/ns_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, VnfPackageModel
-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
@@ -51,9 +51,6 @@ def create(data):
def query_multiple():
ns_pkgs = NSPackageModel.objects.all()
- if not ns_pkgs.exists():
- logger.error('NSDs do not exist.')
- raise CatalogException('NSDs do not exist.')
response_data = []
for ns_pkg in ns_pkgs:
data = fill_resp_data(ns_pkg)
@@ -65,7 +62,7 @@ def query_single(nsd_info_id):
ns_pkgs = NSPackageModel.objects.filter(nsPackageId=nsd_info_id)
if not ns_pkgs.exists():
logger.error('NSD(%s) does not exist.' % nsd_info_id)
- raise CatalogException('NSD(%s) does not exist.' % nsd_info_id)
+ raise ResourceNotFoundException('NSD(%s) does not exist.' % nsd_info_id)
return fill_resp_data(ns_pkgs[0])
@@ -75,17 +72,14 @@ def delete_single(nsd_info_id):
if not ns_pkgs.exists():
logger.info('NSD(%s) is deleted.' % nsd_info_id)
return
-
- if ns_pkgs[0].onboardingState == 'ONBOARDED':
- logger.error('NSD(%s) shall be non-ONBOARDED.' % nsd_info_id)
- raise CatalogException('NSD(%s) shall be non-ONBOARDED.' % nsd_info_id)
+ '''
if ns_pkgs[0].operationalState != 'DISABLED':
logger.error('NSD(%s) shall be DISABLED.' % nsd_info_id)
raise CatalogException('NSD(%s) shall be DISABLED.' % nsd_info_id)
if ns_pkgs[0].usageState != 'NOT_IN_USE':
logger.error('NSD(%s) shall be NOT_IN_USE.' % nsd_info_id)
raise CatalogException('NSD(%s) shall be NOT_IN_USE.' % nsd_info_id)
-
+ '''
ns_pkgs.delete()
ns_pkg_path = os.path.join(CATALOG_ROOT_PATH, nsd_info_id)
fileutil.delete_dirs(ns_pkg_path)
@@ -150,7 +144,7 @@ def download(nsd_info_id):
ns_pkgs = NSPackageModel.objects.filter(nsPackageId=nsd_info_id)
if not ns_pkgs.exists():
logger.error('NSD(%s) does not exist.' % nsd_info_id)
- raise CatalogException('NSD(%s) does not exist.' % nsd_info_id)
+ raise ResourceNotFoundException('NSD(%s) does not exist.' % nsd_info_id)
if ns_pkgs[0].onboardingState != 'ONBOARDED':
logger.error('NSD(%s) is not ONBOARDED.' % nsd_info_id)
raise CatalogException('NSD(%s) is not ONBOARDED.' % nsd_info_id)
diff --git a/catalog/packages/biz/vnf_package.py b/catalog/packages/biz/vnf_package.py
index 3792c44d..d1792501 100644
--- a/catalog/packages/biz/vnf_package.py
+++ b/catalog/packages/biz/vnf_package.py
@@ -25,7 +25,7 @@ from rest_framework import status
from django.http import StreamingHttpResponse
from catalog.pub.config.config import CATALOG_ROOT_PATH
from catalog.pub.database.models import VnfPackageModel
-from catalog.pub.exceptions import CatalogException, VnfPkgNotFoundException
+from catalog.pub.exceptions import CatalogException, ResourceNotFoundException
from catalog.pub.utils.values import ignore_case_get
from catalog.pub.utils import fileutil, toscaparser
@@ -66,7 +66,7 @@ def query_multiple():
def query_single(vnf_pkg_id):
nf_pkg = VnfPackageModel.objects.filter(vnfPackageId=vnf_pkg_id)
if not nf_pkg.exists():
- raise VnfPkgNotFoundException('VNF package(%s) does not exist.' % vnf_pkg_id)
+ raise ResourceNotFoundException('VNF package(%s) does not exist.' % vnf_pkg_id)
return fill_response_data(nf_pkg[0])
@@ -174,7 +174,7 @@ def fill_response_data(nf_pkg):
def fetch_vnf_pkg(request, vnf_pkg_id):
nf_pkg = VnfPackageModel.objects.filter(vnfPackageId=vnf_pkg_id)
if not nf_pkg.exists():
- raise VnfPkgNotFoundException('VNF package(%s) does not exist.' % vnf_pkg_id)
+ raise ResourceNotFoundException('VNF package(%s) does not exist.' % vnf_pkg_id)
if nf_pkg[0].onboardingState != "ONBOARDED":
raise CatalogException("VNF package (%s) is not on-boarded" % vnf_pkg_id)
file_path = nf_pkg[0].localFilePath
diff --git a/catalog/packages/serializers/nsd_info.py b/catalog/packages/serializers/nsd_info.py
index aad1fdc1..e934a1f1 100644
--- a/catalog/packages/serializers/nsd_info.py
+++ b/catalog/packages/serializers/nsd_info.py
@@ -18,7 +18,7 @@ from link import LinkSerializer
class _LinkSerializer(serializers.Serializer):
- this = LinkSerializer(
+ self = LinkSerializer(
help_text='URI of this resource.',
required=True,
allow_null=False
diff --git a/catalog/packages/serializers/pnfd_info.py b/catalog/packages/serializers/pnfd_info.py
index c86b164f..c49ce38d 100644
--- a/catalog/packages/serializers/pnfd_info.py
+++ b/catalog/packages/serializers/pnfd_info.py
@@ -18,7 +18,7 @@ from link import LinkSerializer
class _LinkSerializer(serializers.Serializer):
- this = LinkSerializer(
+ self = LinkSerializer(
help_text='URI of this resource.',
required=True,
allow_null=False
diff --git a/catalog/packages/views/ns_descriptor_views.py b/catalog/packages/views/ns_descriptor_views.py
index 19f9d1d8..653d161f 100644
--- a/catalog/packages/views/ns_descriptor_views.py
+++ b/catalog/packages/views/ns_descriptor_views.py
@@ -21,7 +21,7 @@ from catalog.packages.biz.ns_descriptor import create, delete_single, download,
from catalog.packages.serializers.create_nsd_info_request import CreateNsdInfoRequestSerializer
from catalog.packages.serializers.nsd_info import NsdInfoSerializer
from catalog.packages.serializers.nsd_infos import NsdInfosSerializer
-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: NsdInfoSerializer(),
+ status.HTTP_404_NOT_FOUND: 'NSDs do not exist.',
status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
}
)
@@ -55,6 +56,9 @@ def ns_info_rd(request, nsdInfoId): # TODO
data = query_single(nsdInfoId)
nsd_info = validate_data(data, NsdInfoSerializer)
return Response(data=nsd_info.data, status=status.HTTP_200_OK)
+ except ResourceNotFoundException as e:
+ logger.error(e.message)
+ return Response(data={'error': 'NSDs do not exist.'}, status=status.HTTP_404_NOT_FOUND)
except CatalogException as e:
logger.error(e.message)
error_msg = {'error': 'Query of a NSD failed.'}
@@ -143,6 +147,7 @@ def ns_descriptors_rc(request, *args, **kwargs):
request_body=no_body,
responses={
status.HTTP_204_NO_CONTENT: None,
+ status.HTTP_404_NOT_FOUND: 'NSD does not exist.',
status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
}
)
@@ -154,6 +159,9 @@ def nsd_content_ru(request, *args, **kwargs):
try:
upload(files[0], nsd_info_id)
return Response(data=None, status=status.HTTP_204_NO_CONTENT)
+ except CatalogException as e:
+ logger.error(e.message)
+ error_msg = {'error': 'Uploading NSD content failed.'}
except Exception as e:
logger.error(e.message)
logger.error(traceback.format_exc())
@@ -180,6 +188,12 @@ def nsd_content_ru(request, *args, **kwargs):
response['Content-Disposition'] = 'attachment; filename=%s' % file_name.encode('utf-8')
response['Content-Length'] = end - start
return response
+ except ResourceNotFoundException as e:
+ logger.error(e.message)
+ return Response(data={'error': 'NSD does not exist.'}, status=status.HTTP_404_NOT_FOUND)
+ except CatalogException as e:
+ logger.error(e.message)
+ error_msg = {'error': 'Downloading NSD content failed.'}
except Exception as e:
logger.error(e.message)
logger.error(traceback.format_exc())
diff --git a/catalog/packages/views/vnf_package_views.py b/catalog/packages/views/vnf_package_views.py
index 28399d31..b4488713 100644
--- a/catalog/packages/views/vnf_package_views.py
+++ b/catalog/packages/views/vnf_package_views.py
@@ -21,7 +21,7 @@ from drf_yasg.utils import swagger_auto_schema, no_body
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response
-from catalog.pub.exceptions import CatalogException, VnfPkgNotFoundException
+from catalog.pub.exceptions import CatalogException, ResourceNotFoundException
from catalog.packages.serializers.upload_vnf_pkg_from_uri_req import UploadVnfPackageFromUriRequestSerializer
from catalog.packages.serializers.create_vnf_pkg_info_req import CreateVnfPkgInfoRequestSerializer
from catalog.packages.serializers.vnf_pkg_info import VnfPkgInfoSerializer
@@ -127,7 +127,7 @@ def upload_vnf_pkg_content(request, vnfPkgId):
return Response(None, status=status.HTTP_202_ACCEPTED)
except CatalogException as e:
handle_upload_failed(vnfPkgId)
- logger.debug(e.message)
+ logger.error(e.message)
error_msg = {'error': 'Upload VNF package failed.'}
except Exception as e:
handle_upload_failed(vnfPkgId)
@@ -140,7 +140,7 @@ def upload_vnf_pkg_content(request, vnfPkgId):
try:
response = fetch_vnf_pkg(request, vnfPkgId)
return response
- except VnfPkgNotFoundException as e:
+ except ResourceNotFoundException as e:
logger.error(e.message)
return Response(data={'error': "VNF package does not exist"}, status=status.HTTP_404_NOT_FOUND)
except CatalogException as e:
@@ -170,7 +170,7 @@ def upload_vnf_pkg_from_uri(request, vnfPkgId):
return Response(None, status=status.HTTP_202_ACCEPTED)
except CatalogException as e:
handle_upload_failed(vnfPkgId)
- logger.debug(e.message)
+ logger.error(e.message)
error_msg = {'error': 'Upload VNF package failed.'}
except Exception as e:
handle_upload_failed(vnfPkgId)
@@ -207,7 +207,7 @@ def vnf_package_rd(request, vnfPkgId):
res = query_single(vnfPkgId)
query_serializer = validate_data(res, VnfPkgInfoSerializer)
return Response(data=query_serializer.data, status=status.HTTP_200_OK)
- except VnfPkgNotFoundException as e:
+ except ResourceNotFoundException as e:
logger.error(e.message)
return Response(data={'error': "VNF package does not exist"}, status=status.HTTP_404_NOT_FOUND)
except CatalogException as e:
diff --git a/catalog/pub/exceptions.py b/catalog/pub/exceptions.py
index 2192e113..a86775ea 100644
--- a/catalog/pub/exceptions.py
+++ b/catalog/pub/exceptions.py
@@ -17,5 +17,5 @@ class CatalogException(Exception):
pass
-class VnfPkgNotFoundException(CatalogException):
+class ResourceNotFoundException(CatalogException):
pass