aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog/packages/views/common.py7
-rw-r--r--catalog/packages/views/pnf_descriptor_views.py21
-rwxr-xr-xcatalog/packages/views/vnf_package_subscription_views.py24
-rw-r--r--catalog/packages/views/vnf_package_views.py21
-rw-r--r--catalog/pub/exceptions.py4
5 files changed, 41 insertions, 36 deletions
diff --git a/catalog/packages/views/common.py b/catalog/packages/views/common.py
index 43455c5c..d336ec1a 100644
--- a/catalog/packages/views/common.py
+++ b/catalog/packages/views/common.py
@@ -19,6 +19,7 @@ from rest_framework import status
from rest_framework.response import Response
from catalog.pub.exceptions import CatalogException
+from catalog.pub.exceptions import BadRequestException
from catalog.pub.exceptions import NsdmBadRequestException
from catalog.pub.exceptions import PackageNotFoundException
from catalog.pub.exceptions import ResourceNotFoundException
@@ -87,6 +88,12 @@ def view_safe_call_with_log(logger):
detail=e.message,
status=status.HTTP_404_NOT_FOUND
)
+ except BadRequestException as e:
+ logger.error(e.message)
+ return make_error_resp(
+ detail=e.message,
+ status=status.HTTP_400_BAD_REQUEST
+ )
except NsdmBadRequestException as e:
logger.error(e.message)
return make_error_resp(
diff --git a/catalog/packages/views/pnf_descriptor_views.py b/catalog/packages/views/pnf_descriptor_views.py
index 897644d5..2b99fd93 100644
--- a/catalog/packages/views/pnf_descriptor_views.py
+++ b/catalog/packages/views/pnf_descriptor_views.py
@@ -25,10 +25,10 @@ from catalog.packages.serializers.create_pnfd_info_request import CreatePnfdInfo
from catalog.packages.serializers.pnfd_info import PnfdInfoSerializer
from catalog.packages.serializers.pnfd_infos import PnfdInfosSerializer
from catalog.packages.views.common import validate_data
-from catalog.pub.exceptions import CatalogException
from catalog.packages.serializers.catalog_serializers import ParseModelRequestSerializer
from catalog.packages.serializers.catalog_serializers import ParseModelResponseSerializer
from catalog.packages.serializers.catalog_serializers import InternalErrorRequestSerializer
+from catalog.packages.serializers.response import ProblemDetailsSerializer
from catalog.pub.utils.syscomm import fun_name
from catalog.pub.utils.values import ignore_case_get
from .common import view_safe_call_with_log
@@ -42,8 +42,8 @@ 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"
+ status.HTTP_404_NOT_FOUND: ProblemDetailsSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
}
)
@swagger_auto_schema(
@@ -52,7 +52,7 @@ logger = logging.getLogger(__name__)
request_body=no_body,
responses={
status.HTTP_204_NO_CONTENT: "No content",
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
}
)
@api_view(http_method_names=['GET', 'DELETE'])
@@ -77,7 +77,7 @@ def pnfd_info_rd(request, **kwargs): # TODO
request_body=CreatePnfdInfoRequestSerializer(),
responses={
status.HTTP_201_CREATED: PnfdInfoSerializer(),
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
}
)
@swagger_auto_schema(
@@ -86,7 +86,7 @@ def pnfd_info_rd(request, **kwargs): # TODO
request_body=no_body,
responses={
status.HTTP_200_OK: PnfdInfosSerializer(),
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
}
)
@api_view(http_method_names=['POST', 'GET'])
@@ -114,7 +114,7 @@ def pnf_descriptors_rc(request):
request_body=no_body,
responses={
status.HTTP_204_NO_CONTENT: "No content",
- status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
}
)
@swagger_auto_schema(
@@ -123,8 +123,8 @@ def pnf_descriptors_rc(request):
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"
+ status.HTTP_404_NOT_FOUND: ProblemDetailsSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
}
)
@api_view(http_method_names=['PUT', 'GET'])
@@ -137,9 +137,6 @@ def pnfd_content_ru(request, **kwargs):
local_file_name = PnfDescriptor().upload(files[0], pnfd_info_id)
PnfDescriptor().parse_pnfd_and_save(pnfd_info_id, local_file_name)
return Response(data=None, status=status.HTTP_204_NO_CONTENT)
- except CatalogException as e:
- PnfDescriptor().handle_upload_failed(pnfd_info_id)
- raise e
except Exception as e:
PnfDescriptor().handle_upload_failed(pnfd_info_id)
raise e
diff --git a/catalog/packages/views/vnf_package_subscription_views.py b/catalog/packages/views/vnf_package_subscription_views.py
index 303f0d40..32904e32 100755
--- a/catalog/packages/views/vnf_package_subscription_views.py
+++ b/catalog/packages/views/vnf_package_subscription_views.py
@@ -28,20 +28,19 @@ from catalog.packages.biz.vnf_pkg_subscription import QuerySubscription
from catalog.packages.biz.vnf_pkg_subscription import TerminateSubscription
from catalog.packages.views.common import validate_data
from catalog.pub.exceptions import VnfPkgSubscriptionException
+from catalog.pub.exceptions import BadRequestException
from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
-VALID_FILTERS = ["callbackUri", "notificationTypes", "vnfdId", "vnfPkgId", "operationalState", "usageState"]
-
-def get_problem_details_serializer(status_code, error_message):
- problem_details = {
- "status": status_code,
- "detail": error_message
- }
- problem_details_serializer = ProblemDetailsSerializer(data=problem_details)
- problem_details_serializer.is_valid()
- return problem_details_serializer
+VALID_FILTERS = [
+ "callbackUri",
+ "notificationTypes",
+ "vnfdId",
+ "vnfPkgId",
+ "operationalState",
+ "usageState"
+]
class CreateQuerySubscriptionView(APIView):
@@ -74,9 +73,8 @@ class CreateQuerySubscriptionView(APIView):
logger.debug("SubscribeNotification--get::> %s" % request.query_params)
if request.query_params and not set(request.query_params).issubset(set(VALID_FILTERS)):
- problem_details_serializer = get_problem_details_serializer(status.HTTP_400_BAD_REQUEST,
- "Not a valid filter")
- return Response(data=problem_details_serializer.data, status=status.HTTP_400_BAD_REQUEST)
+ raise BadRequestException("Not a valid filter")
+
resp_data = QuerySubscription().query_multi_subscriptions(request.query_params)
subscriptions_serializer = PkgmSubscriptionsSerializer(data=resp_data)
diff --git a/catalog/packages/views/vnf_package_views.py b/catalog/packages/views/vnf_package_views.py
index b3d84dbe..094b6f59 100644
--- a/catalog/packages/views/vnf_package_views.py
+++ b/catalog/packages/views/vnf_package_views.py
@@ -19,13 +19,16 @@ 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.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
from catalog.packages.serializers.vnf_pkg_infos import VnfPkgInfosSerializer
-from catalog.packages.biz.vnf_package import VnfPackage, VnfPkgUploadThread, parse_vnfd_and_save, handle_upload_failed
-from catalog.packages.views.common import validate_data
+from catalog.packages.biz.vnf_package import VnfPackage
+from catalog.packages.biz.vnf_package import VnfPkgUploadThread
+from catalog.packages.biz.vnf_package import parse_vnfd_and_save
+from catalog.packages.biz.vnf_package import handle_upload_failed
+from .common import validate_data
from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
@@ -60,7 +63,8 @@ def vnf_packages_rc(request):
if request.method == 'POST':
logger.debug("Create VNF package> %s" % request.data)
- create_vnf_pkg_info_request = validate_data(request.data, CreateVnfPkgInfoRequestSerializer)
+ create_vnf_pkg_info_request = validate_data(request.data,
+ CreateVnfPkgInfoRequestSerializer)
data = VnfPackage().create_vnf_pkg(create_vnf_pkg_info_request.data)
vnf_pkg_info = validate_data(data, VnfPkgInfoSerializer)
return Response(data=vnf_pkg_info.data, status=status.HTTP_201_CREATED)
@@ -96,9 +100,6 @@ def package_content_ru(request, **kwargs):
local_file_name = VnfPackage().upload(vnf_pkg_id, files[0])
parse_vnfd_and_save(vnf_pkg_id, local_file_name)
return Response(None, status=status.HTTP_202_ACCEPTED)
- except CatalogException as e:
- handle_upload_failed(vnf_pkg_id)
- raise e
except Exception as e:
handle_upload_failed(vnf_pkg_id)
raise e
@@ -123,12 +124,10 @@ def package_content_ru(request, **kwargs):
def upload_from_uri_c(request, **kwargs):
vnf_pkg_id = kwargs.get("vnfPkgId")
try:
- upload_vnf_from_uri_request = validate_data(request.data, UploadVnfPackageFromUriRequestSerializer)
+ upload_vnf_from_uri_request = validate_data(request.data,
+ UploadVnfPackageFromUriRequestSerializer)
VnfPkgUploadThread(upload_vnf_from_uri_request.data, vnf_pkg_id).start()
return Response(None, status=status.HTTP_202_ACCEPTED)
- except CatalogException as e:
- handle_upload_failed(vnf_pkg_id)
- raise e
except Exception as e:
handle_upload_failed(vnf_pkg_id)
raise e
diff --git a/catalog/pub/exceptions.py b/catalog/pub/exceptions.py
index a9354204..e0dac0e4 100644
--- a/catalog/pub/exceptions.py
+++ b/catalog/pub/exceptions.py
@@ -17,6 +17,10 @@ class CatalogException(Exception):
pass
+class BadRequestException(CatalogException):
+ pass
+
+
class ResourceNotFoundException(CatalogException):
pass