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
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)
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])
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)
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")
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
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)
class CatalogException(Exception):
pass
+
+
+class VnfPkgNotFoundException(CatalogException):
+ pass