diff options
author | Fu Jinhua <fu.jinhua@zte.com.cn> | 2018-08-29 05:43:40 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-08-29 05:43:40 +0000 |
commit | c5c48f85bbccf2d8baa73cf9c43deb60c694d953 (patch) | |
tree | 7bed7a586c0d336ff9e82c79c78ee8d291632b3b | |
parent | 5f53ec675ea9ba441c2047e2ab1e918fb5147c9e (diff) | |
parent | 2e3f2063bf4ed5fc736182d378e9b626c0dd590f (diff) |
Merge "Deal with nfPackage"
-rw-r--r-- | catalog/packages/biz/vnf_package.py | 10 | ||||
-rw-r--r-- | catalog/packages/tests/test_vnf_package.py | 5 | ||||
-rw-r--r-- | catalog/packages/views/vnf_package_views.py | 18 | ||||
-rw-r--r-- | catalog/pub/exceptions.py | 4 |
4 files changed, 24 insertions, 13 deletions
diff --git a/catalog/packages/biz/vnf_package.py b/catalog/packages/biz/vnf_package.py index 7f3511d8..661597df 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 +from catalog.pub.exceptions import CatalogException, VnfPkgNotFoundException from catalog.pub.utils.values import ignore_case_get from catalog.pub.utils import fileutil, toscaparser @@ -57,8 +57,6 @@ def create_vnf_pkg(data): def query_multiple(): pkgs_info = [] nf_pkgs = VnfPackageModel.objects.filter() - if not nf_pkgs.exists(): - raise CatalogException('VNF packages do not exist.') for nf_pkg in nf_pkgs: ret = fill_response_data(nf_pkg) pkgs_info.append(ret) @@ -68,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 CatalogException('VNF package(%s) does not exist.' % vnf_pkg_id) + raise VnfPkgNotFoundException('VNF package(%s) does not exist.' % vnf_pkg_id) return fill_response_data(nf_pkg[0]) @@ -77,12 +75,12 @@ def delete_vnf_pkg(vnf_pkg_id): if not vnf_pkg.exists(): logger.debug('VNF package(%s) is deleted.' % vnf_pkg_id) return - if vnf_pkg[0].onboardingState != "CREATED": - raise CatalogException("The VNF package (%s) is not on-boarded" % vnf_pkg_id) + ''' if vnf_pkg[0].operationalState != "DISABLED": raise CatalogException("The VNF package (%s) is not disabled" % vnf_pkg_id) if vnf_pkg[0].usageState != "NOT_IN_USE": raise CatalogException("The VNF package (%s) is in use" % vnf_pkg_id) + ''' vnf_pkg.delete() vnf_pkg_path = os.path.join(CATALOG_ROOT_PATH, vnf_pkg_id) fileutil.delete_dirs(vnf_pkg_path) diff --git a/catalog/packages/tests/test_vnf_package.py b/catalog/packages/tests/test_vnf_package.py index fb3a5dee..10527cc2 100644 --- a/catalog/packages/tests/test_vnf_package.py +++ b/catalog/packages/tests/test_vnf_package.py @@ -410,6 +410,11 @@ class TestVnfPackage(TestCase): self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertEqual(response.data, None) + def test_delete_when_vnf_pkg_not_exist(self): + response = self.client.delete("/api/vnfpkgm/v1/vnf_packages/222") + self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) + self.assertEqual(response.data, None) + def test_fetch_vnf_pkg(self): with open("vnfPackage.csar", "wb") as fp: fp.writelines("AAAABBBBCCCCDDDD") diff --git a/catalog/packages/views/vnf_package_views.py b/catalog/packages/views/vnf_package_views.py index 26244dd9..3782ea5c 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 +from catalog.pub.exceptions import CatalogException, VnfPkgNotFoundException 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 @@ -206,16 +206,20 @@ def vnf_package_rd(request, vnfPkgId): res = query_single(vnfPkgId) query_serializer = VnfPkgInfoSerializer(data=res) if not query_serializer.is_valid(): - raise CatalogException + logger.debug("Data validation failed.") + raise CatalogException(query_serializer.error) return Response(data=query_serializer.data, status=status.HTTP_200_OK) - except CatalogException: - logger.error(traceback.format_exc()) - return Response(data={'error': 'Query an individual VNF package failed.'}, - status=status.HTTP_500_INTERNAL_SERVER_ERROR) + except VnfPkgNotFoundException as e: + logger.error(e.message) + return Response(data={'error': 'Query an individual VNF package failed.'}, status=status.HTTP_404_NOT_FOUND) + except CatalogException as e: + logger.error(e.message) + error_msg = {'error': 'Query an individual VNF package failed.'} except Exception as e: logger.error(e.message) logger.error(traceback.format_exc()) - return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + error_msg = {'error': 'unexpected exception'} + return Response(data=error_msg, status=status.HTTP_500_INTERNAL_SERVER_ERROR) if request.method == 'DELETE': logger.debug("Delete an individual VNF package> %s" % request.data) diff --git a/catalog/pub/exceptions.py b/catalog/pub/exceptions.py index c994b46e..2192e113 100644 --- a/catalog/pub/exceptions.py +++ b/catalog/pub/exceptions.py @@ -15,3 +15,7 @@ class CatalogException(Exception): pass + + +class VnfPkgNotFoundException(CatalogException): + pass |