summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
Diffstat (limited to 'lcm')
-rw-r--r--lcm/lcm/nf/biz/create_subscription.py5
-rw-r--r--lcm/lcm/nf/tests/test_subscribe_notification.py12
-rw-r--r--lcm/lcm/nf/views/instantiate_vnf_view.py2
-rw-r--r--lcm/lcm/nf/views/lcm_op_occs_view.py67
-rw-r--r--lcm/lcm/nf/views/operate_vnf_view.py46
-rw-r--r--lcm/lcm/nf/views/scale_to_level_view.py57
-rw-r--r--lcm/lcm/nf/views/scale_vnf_view.py57
-rw-r--r--lcm/lcm/nf/views/subscriptions_view.py90
-rw-r--r--lcm/lcm/nf/views/terminate_vnf_view.py39
9 files changed, 141 insertions, 234 deletions
diff --git a/lcm/lcm/nf/biz/create_subscription.py b/lcm/lcm/nf/biz/create_subscription.py
index db529a73..6802c221 100644
--- a/lcm/lcm/nf/biz/create_subscription.py
+++ b/lcm/lcm/nf/biz/create_subscription.py
@@ -25,6 +25,7 @@ from rest_framework import status
from lcm.nf import const
from lcm.pub.database.models import SubscriptionModel
from lcm.pub.exceptions import NFLCMException
+from lcm.pub.exceptions import NFLCMExceptionSeeOther
from lcm.pub.utils.values import ignore_case_get
logger = logging.getLogger(__name__)
@@ -116,8 +117,8 @@ class CreateSubscription:
return True
for subscription in subscriptions:
if self.check_filter_exists(subscription):
- raise NFLCMException("Already Subscription exists with the "
- "same callbackUri and filter")
+ raise NFLCMExceptionSeeOther("Already Subscription exists with the "
+ "same callbackUri and filter")
return False
def save_db(self):
diff --git a/lcm/lcm/nf/tests/test_subscribe_notification.py b/lcm/lcm/nf/tests/test_subscribe_notification.py
index 8aeab63f..73463efa 100644
--- a/lcm/lcm/nf/tests/test_subscribe_notification.py
+++ b/lcm/lcm/nf/tests/test_subscribe_notification.py
@@ -95,7 +95,8 @@ class TestSubscription(TestCase):
mock_requests.return_value.status_code = 204
mock_requests.get.return_value.status_code = 204
expected_data = {
- 'error': 'Auth type should be BASIC'
+ 'detail': 'Auth type should be BASIC',
+ 'status': 500
}
response = self.client.post("/api/vnflcm/v1/subscriptions", data=dummy_subscription, format='json')
self.assertEqual(500, response.status_code)
@@ -118,8 +119,9 @@ class TestSubscription(TestCase):
mock_requests.return_value.status_code = 204
mock_requests.get.return_value.status_code = 204
expected_data = {
- 'error': 'If you are setting operationTypes,then ' +
- 'notificationTypes must be VnfLcmOperationOccurrenceNotification'
+ 'detail': 'If you are setting operationTypes,then ' +
+ 'notificationTypes must be VnfLcmOperationOccurrenceNotification',
+ 'status': 500
}
response = self.client.post("/api/vnflcm/v1/subscriptions", data=dummy_subscription, format='json')
self.assertEqual(500, response.status_code)
@@ -150,7 +152,3 @@ class TestSubscription(TestCase):
self.assertEqual(temp_uuid, response.data["id"])
response = self.client.post("/api/vnflcm/v1/subscriptions", data=dummy_subscription, format='json')
self.assertEqual(303, response.status_code)
- expected_data = {
- "error": "Already Subscription exists with the same callbackUri and filter"
- }
- self.assertEqual(expected_data, response.data)
diff --git a/lcm/lcm/nf/views/instantiate_vnf_view.py b/lcm/lcm/nf/views/instantiate_vnf_view.py
index 1a7905aa..b285cc8c 100644
--- a/lcm/lcm/nf/views/instantiate_vnf_view.py
+++ b/lcm/lcm/nf/views/instantiate_vnf_view.py
@@ -24,6 +24,7 @@ from lcm.nf.serializers.instantiate_vnf_request import InstantiateVnfRequestSeri
from lcm.nf.serializers.job_identifier import JobIdentifierSerializer
from lcm.pub.exceptions import NFLCMException
from lcm.pub.utils.jobutil import JobUtil
+from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
@@ -36,6 +37,7 @@ class InstantiateVnfView(APIView):
status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
}
)
+ @view_safe_call_with_log(logger=logger)
def post(self, request, instanceid):
logger.debug("InstantiateVnf--post::> %s" % request.data)
diff --git a/lcm/lcm/nf/views/lcm_op_occs_view.py b/lcm/lcm/nf/views/lcm_op_occs_view.py
index de165317..96cdecb0 100644
--- a/lcm/lcm/nf/views/lcm_op_occs_view.py
+++ b/lcm/lcm/nf/views/lcm_op_occs_view.py
@@ -13,7 +13,6 @@
# limitations under the License.
import logging
-import traceback
from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
@@ -25,6 +24,7 @@ from lcm.nf.serializers.response import ProblemDetailsSerializer
from lcm.nf.serializers.vnf_lcm_op_occ import VNFLCMOpOccSerializer
from lcm.nf.serializers.vnf_lcm_op_occs import VNFLCMOpOccsSerializer
from lcm.pub.exceptions import NFLCMException
+from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
EXCLUDE_DEFAULT = ['operationParams', 'error', 'resourceChanges', 'changedInfo', 'changedExtConnectivity']
@@ -51,36 +51,26 @@ class QueryMultiVnfLcmOpOccs(APIView):
status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
}
)
+ @view_safe_call_with_log(logger=logger)
def get(self, request):
logger.debug("QueryMultiVnfLcmOpOccs--get::> %s" % request.query_params)
- try:
- 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)
- resp_data = QueryVnfLcmOpOcc(request.query_params).query_multi_vnf_lcm_op_occ()
+ 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)
+ resp_data = QueryVnfLcmOpOcc(request.query_params).query_multi_vnf_lcm_op_occ()
- vnf_lcm_op_occs_serializer = VNFLCMOpOccsSerializer(data=resp_data)
- if not vnf_lcm_op_occs_serializer.is_valid():
- raise NFLCMException(vnf_lcm_op_occs_serializer.errors)
+ vnf_lcm_op_occs_serializer = VNFLCMOpOccsSerializer(data=resp_data)
+ if not vnf_lcm_op_occs_serializer.is_valid():
+ raise NFLCMException(vnf_lcm_op_occs_serializer.errors)
- logger.debug("QueryMultiVnfLcmOpOccs--get::> Remove default fields if exclude_default" +
- " is specified")
- # TODO(bharath): Add support for "fields", "exclude_fields" in query parameters
- if 'exclude_default' in request.query_params.keys():
- for field in EXCLUDE_DEFAULT:
- for lcm_op in vnf_lcm_op_occs_serializer.data:
- del lcm_op[field]
- return Response(data=vnf_lcm_op_occs_serializer.data, status=status.HTTP_200_OK)
- except NFLCMException as e:
- logger.error(e.message)
- problem_details_serializer = get_problem_details_serializer(status.HTTP_500_INTERNAL_SERVER_ERROR, e.message)
- return Response(data=problem_details_serializer.data, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
-
- except Exception as e:
- logger.error(e.message)
- logger.error(traceback.format_exc())
- problem_details_serializer = get_problem_details_serializer(status.HTTP_500_INTERNAL_SERVER_ERROR, e.message)
- return Response(data=problem_details_serializer.data, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ logger.debug("QueryMultiVnfLcmOpOccs--get::> Remove default fields if exclude_default" +
+ " is specified")
+ # TODO(bharath): Add support for "fields", "exclude_fields" in query parameters
+ if 'exclude_default' in request.query_params.keys():
+ for field in EXCLUDE_DEFAULT:
+ for lcm_op in vnf_lcm_op_occs_serializer.data:
+ del lcm_op[field]
+ return Response(data=vnf_lcm_op_occs_serializer.data, status=status.HTTP_200_OK)
class QuerySingleVnfLcmOpOcc(APIView):
@@ -90,22 +80,15 @@ class QuerySingleVnfLcmOpOcc(APIView):
status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
}
)
+ @view_safe_call_with_log(logger=logger)
def get(self, request, lcmopoccid):
logger.debug("QuerySingleVnfLcmOpOcc--get::> %s" % request.query_params)
- try:
- resp_data = QueryVnfLcmOpOcc(request.query_params, lcm_op_occ_id=lcmopoccid).query_single_vnf_lcm_op_occ()
- vnf_lcm_op_occ_serializer = VNFLCMOpOccSerializer(data=resp_data)
- if not vnf_lcm_op_occ_serializer.is_valid():
- raise NFLCMException(vnf_lcm_op_occ_serializer.errors)
+ resp_data = QueryVnfLcmOpOcc(request.query_params,
+ lcm_op_occ_id=lcmopoccid).query_single_vnf_lcm_op_occ()
+
+ vnf_lcm_op_occ_serializer = VNFLCMOpOccSerializer(data=resp_data)
+ if not vnf_lcm_op_occ_serializer.is_valid():
+ raise NFLCMException(vnf_lcm_op_occ_serializer.errors)
- return Response(data=vnf_lcm_op_occ_serializer.data, status=status.HTTP_200_OK)
- except NFLCMException as e:
- logger.error(e.message)
- problem_details_serializer = get_problem_details_serializer(status.HTTP_500_INTERNAL_SERVER_ERROR, e.message)
- return Response(data=problem_details_serializer.data, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- except Exception as e:
- logger.error(e.message)
- logger.error(traceback.format_exc())
- problem_details_serializer = get_problem_details_serializer(status.HTTP_500_INTERNAL_SERVER_ERROR, e.message)
- return Response(data=problem_details_serializer.data, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ return Response(data=vnf_lcm_op_occ_serializer.data, status=status.HTTP_200_OK)
diff --git a/lcm/lcm/nf/views/operate_vnf_view.py b/lcm/lcm/nf/views/operate_vnf_view.py
index ab8f905b..32218067 100644
--- a/lcm/lcm/nf/views/operate_vnf_view.py
+++ b/lcm/lcm/nf/views/operate_vnf_view.py
@@ -13,7 +13,6 @@
# limitations under the License.
import logging
-import traceback
from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
@@ -27,6 +26,7 @@ from lcm.pub.exceptions import NFLCMException, NFLCMExceptionNotFound, NFLCMExce
from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.database.models import NfInstModel
from lcm.nf.const import VNF_STATUS
+from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
@@ -41,40 +41,22 @@ class OperateVnfView(APIView):
status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
}
)
+ @view_safe_call_with_log(logger=logger)
def post(self, request, instanceid):
logger.debug("OperateVnf--post::> %s" % request.data)
- try:
- operate_vnf_request_serializer = OperateVnfRequestSerializer(data=request.data)
- if not operate_vnf_request_serializer.is_valid():
- raise NFLCMException(operate_vnf_request_serializer.errors)
- job_id = JobUtil.create_job('NF', 'OPERATE', instanceid)
- JobUtil.add_job_status(job_id, 0, "OPERATE_VNF_READY")
- self.operate_pre_check(instanceid, job_id)
- OperateVnf(operate_vnf_request_serializer.data, instanceid, job_id).start()
- response = Response(data={"jobId": job_id}, status=status.HTTP_202_ACCEPTED)
- # Location todo, it use job as the status storage
- # response["Location"] = "/api/vnflcm/v1/vnf_lcm_op_occs/%s" % lcmopoccid
- return response
- except NFLCMExceptionNotFound as e:
- probDetail = ProblemDetailsSerializer(data={"status": 404, "detail": "VNF Instance not found"})
- resp_isvalid = probDetail.is_valid()
- if not resp_isvalid:
- raise NFLCMException(probDetail.errors)
- return Response(data=probDetail.data, status=status.HTTP_404_NOT_FOUND)
- except NFLCMExceptionConflict as e:
- probDetail = ProblemDetailsSerializer(data={"status": 409, "detail": "VNF Instance not in Instantiated State"})
- resp_isvalid = probDetail.is_valid()
- if not resp_isvalid:
- raise NFLCMException(probDetail.errors)
- return Response(data=probDetail.data, status=status.HTTP_409_CONFLICT)
- except NFLCMException as e:
- logger.error(e.message)
- return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- 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)
+ operate_vnf_request_serializer = OperateVnfRequestSerializer(data=request.data)
+ if not operate_vnf_request_serializer.is_valid():
+ raise NFLCMException(operate_vnf_request_serializer.errors)
+
+ job_id = JobUtil.create_job('NF', 'OPERATE', instanceid)
+ JobUtil.add_job_status(job_id, 0, "OPERATE_VNF_READY")
+ self.operate_pre_check(instanceid, job_id)
+ OperateVnf(operate_vnf_request_serializer.data, instanceid, job_id).start()
+ response = Response(data={"jobId": job_id}, status=status.HTTP_202_ACCEPTED)
+ # Location todo, it use job as the status storage
+ # response["Location"] = "/api/vnflcm/v1/vnf_lcm_op_occs/%s" % lcmopoccid
+ return response
def operate_pre_check(self, nfInstId, jobId):
vnf_insts = NfInstModel.objects.filter(nfinstid=nfInstId)
diff --git a/lcm/lcm/nf/views/scale_to_level_view.py b/lcm/lcm/nf/views/scale_to_level_view.py
index 9ae2cd36..8d4f41cb 100644
--- a/lcm/lcm/nf/views/scale_to_level_view.py
+++ b/lcm/lcm/nf/views/scale_to_level_view.py
@@ -13,7 +13,6 @@
# limitations under the License.
import logging
-import traceback
from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
@@ -22,11 +21,14 @@ from rest_framework.views import APIView
from lcm.nf.serializers.scale_vnf_to_level_request_serializer import ScaleVnfToLevelRequestSerializer
from lcm.nf.serializers.response import ProblemDetailsSerializer
-from lcm.pub.exceptions import NFLCMException, NFLCMExceptionNotFound, NFLCMExceptionConflict
+from lcm.pub.exceptions import NFLCMException
+from lcm.pub.exceptions import NFLCMExceptionNotFound
+from lcm.pub.exceptions import NFLCMExceptionConflict
from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.database.models import NfInstModel
from lcm.nf.const import VNF_STATUS
from lcm.nf.biz.scale_vnf_to_level import ScaleVnfToLevel
+from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
@@ -41,53 +43,32 @@ class ScaleVnfToLevelView(APIView):
status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
}
)
+ @view_safe_call_with_log(logger=logger)
def post(self, request, instanceid):
logger.debug("ScaleVnfToLevel--post::> %s" % request.data)
- try:
- scale_to_level_serializer = ScaleVnfToLevelRequestSerializer(data=request.data)
- if not scale_to_level_serializer.is_valid():
- raise NFLCMException(scale_to_level_serializer.errors)
- job_id = JobUtil.create_job('NF', 'SCALE_TO_LEVEL', instanceid)
- JobUtil.add_job_status(job_id, 0, "SCALE_VNF_TO_LEVEL_READY")
- self.scale_pre_check(instanceid, job_id)
+ scale_to_level_serializer = ScaleVnfToLevelRequestSerializer(data=request.data)
+ if not scale_to_level_serializer.is_valid():
+ raise NFLCMException(scale_to_level_serializer.errors)
- ScaleVnfToLevel(scale_to_level_serializer.data, instanceid, job_id).start()
+ job_id = JobUtil.create_job('NF', 'SCALE_TO_LEVEL', instanceid)
+ JobUtil.add_job_status(job_id, 0, "SCALE_VNF_TO_LEVEL_READY")
+ self.scale_pre_check(instanceid, job_id)
- response = Response(data={"jobId": job_id},
- status=status.HTTP_202_ACCEPTED)
- return response
- except NFLCMExceptionNotFound as e:
- probDetail = ProblemDetailsSerializer(data={"status": status.HTTP_404_NOT_FOUND,
- "detail": "VNF Instance not found"})
- resp_isvalid = probDetail.is_valid()
- if not resp_isvalid:
- raise NFLCMException(probDetail.errors)
- return Response(data=probDetail.data,
- status=status.HTTP_404_NOT_FOUND)
- except NFLCMExceptionConflict as e:
- probDetail = ProblemDetailsSerializer(data={"status": status.HTTP_409_CONFLICT,
- "detail": "VNF Instance not in Instantiated State"})
- resp_isvalid = probDetail.is_valid()
- if not resp_isvalid:
- raise NFLCMException(probDetail.errors)
- return Response(data=probDetail.data,
- status=status.HTTP_409_CONFLICT)
- except NFLCMException as e:
- logger.error(e.message)
- return Response(data={'error': '%s' % e.message},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- 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)
+ ScaleVnfToLevel(scale_to_level_serializer.data, instanceid, job_id).start()
+
+ response = Response(data={"jobId": job_id},
+ status=status.HTTP_202_ACCEPTED)
+ return response
def scale_pre_check(self, nf_inst_id, job_id):
vnf_insts = NfInstModel.objects.filter(nfinstid=nf_inst_id)
if not vnf_insts.exists():
raise NFLCMExceptionNotFound("VNF nf_inst_id does not exist.")
+ if vnf_insts[0].status != 'INSTANTIATED':
+ raise NFLCMExceptionConflict("VNF instantiationState is not INSTANTIATED.")
+
vnf_insts.update(status=VNF_STATUS.SCALING)
JobUtil.add_job_status(job_id, 15, 'Nf scaling to level pre-check finish')
logger.info("Nf scaling to level pre-check finish")
diff --git a/lcm/lcm/nf/views/scale_vnf_view.py b/lcm/lcm/nf/views/scale_vnf_view.py
index 570ba74d..804ed010 100644
--- a/lcm/lcm/nf/views/scale_vnf_view.py
+++ b/lcm/lcm/nf/views/scale_vnf_view.py
@@ -13,7 +13,6 @@
# limitations under the License.
import logging
-import traceback
from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
@@ -22,11 +21,14 @@ from rest_framework.views import APIView
from lcm.nf.serializers.scale_vnf_request import ScaleVnfRequestSerializer
from lcm.nf.serializers.response import ProblemDetailsSerializer
-from lcm.pub.exceptions import NFLCMException, NFLCMExceptionNotFound, NFLCMExceptionConflict
+from lcm.pub.exceptions import NFLCMException
+from lcm.pub.exceptions import NFLCMExceptionNotFound
+from lcm.pub.exceptions import NFLCMExceptionConflict
from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.database.models import NfInstModel
from lcm.nf.const import VNF_STATUS
from lcm.nf.biz.scale_vnf import ScaleVnf
+from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
@@ -41,53 +43,32 @@ class ScaleVnfView(APIView):
status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
}
)
+ @view_safe_call_with_log(logger=logger)
def post(self, request, instanceid):
logger.debug("ScaleVnf--post::> %s" % request.data)
- try:
- scale_vnf_request_serializer = ScaleVnfRequestSerializer(data=request.data)
- if not scale_vnf_request_serializer.is_valid():
- raise NFLCMException(scale_vnf_request_serializer.errors)
- job_id = JobUtil.create_job('NF', 'SCALE', instanceid)
- JobUtil.add_job_status(job_id, 0, "SCALE_VNF_READY")
- self.scale_pre_check(instanceid, job_id)
+ scale_vnf_request_serializer = ScaleVnfRequestSerializer(data=request.data)
+ if not scale_vnf_request_serializer.is_valid():
+ raise NFLCMException(scale_vnf_request_serializer.errors)
- ScaleVnf(scale_vnf_request_serializer.data, instanceid, job_id).start()
+ job_id = JobUtil.create_job('NF', 'SCALE', instanceid)
+ JobUtil.add_job_status(job_id, 0, "SCALE_VNF_READY")
+ self.scale_pre_check(instanceid, job_id)
- response = Response(data={"jobId": job_id},
- status=status.HTTP_202_ACCEPTED)
- return response
- except NFLCMExceptionNotFound as e:
- probDetail = ProblemDetailsSerializer(data={"status": status.HTTP_404_NOT_FOUND,
- "detail": "VNF Instance not found"})
- resp_isvalid = probDetail.is_valid()
- if not resp_isvalid:
- raise NFLCMException(probDetail.errors)
- return Response(data=probDetail.data,
- status=status.HTTP_404_NOT_FOUND)
- except NFLCMExceptionConflict as e:
- probDetail = ProblemDetailsSerializer(data={"status": status.HTTP_409_CONFLICT,
- "detail": "VNF Instance not in Instantiated State"})
- resp_isvalid = probDetail.is_valid()
- if not resp_isvalid:
- raise NFLCMException(probDetail.errors)
- return Response(data=probDetail.data,
- status=status.HTTP_409_CONFLICT)
- except NFLCMException as e:
- logger.error(e.message)
- return Response(data={'error': '%s' % e.message},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- 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)
+ ScaleVnf(scale_vnf_request_serializer.data, instanceid, job_id).start()
+
+ response = Response(data={"jobId": job_id},
+ status=status.HTTP_202_ACCEPTED)
+ return response
def scale_pre_check(self, nf_inst_id, job_id):
vnf_insts = NfInstModel.objects.filter(nfinstid=nf_inst_id)
if not vnf_insts.exists():
raise NFLCMExceptionNotFound("VNF nf_inst_id does not exist.")
+ if vnf_insts[0].status != 'INSTANTIATED':
+ raise NFLCMExceptionConflict("VNF instantiationState is not INSTANTIATED.")
+
vnf_insts.update(status=VNF_STATUS.SCALING)
JobUtil.add_job_status(job_id, 15, 'Nf scaling pre-check finish')
logger.info("Nf scaling pre-check finish")
diff --git a/lcm/lcm/nf/views/subscriptions_view.py b/lcm/lcm/nf/views/subscriptions_view.py
index 4c013ee4..a9ffed9b 100644
--- a/lcm/lcm/nf/views/subscriptions_view.py
+++ b/lcm/lcm/nf/views/subscriptions_view.py
@@ -15,7 +15,6 @@
import ast
import json
import logging
-import traceback
from drf_yasg.utils import swagger_auto_schema
from lcm.nf.biz.create_subscription import CreateSubscription
@@ -29,6 +28,7 @@ from lcm.nf.serializers.lccn_subscription import LccnSubscriptionSerializer
from lcm.nf.serializers.lccn_subscriptions import LccnSubscriptionsSerializer
from lcm.nf.serializers.response import ProblemDetailsSerializer
from lcm.pub.exceptions import NFLCMException
+from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
VALID_FILTERS = ["operationTypes", "operationStates", "notificationTypes", "vnfInstanceId"]
@@ -53,39 +53,31 @@ class SubscriptionsView(APIView):
status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
}
)
+ @view_safe_call_with_log(logger=logger)
def post(self, request):
logger.debug("SubscribeNotification--post::> %s" % request.data)
- try:
- lccn_subscription_request_serializer = LccnSubscriptionRequestSerializer(data=request.data)
- if not lccn_subscription_request_serializer.is_valid():
- raise NFLCMException(lccn_subscription_request_serializer.errors)
- subscription = CreateSubscription(
- lccn_subscription_request_serializer.data).do_biz()
- lccn_notifications_filter = {
- "notificationTypes": ast.literal_eval(subscription.notification_types),
- "operationTypes": ast.literal_eval(subscription.operation_types),
- "operationStates": ast.literal_eval(subscription.operation_states),
- "vnfInstanceSubscriptionFilter": json.loads(subscription.vnf_instance_filter)
- }
- subscription_data = {
- "id": subscription.subscription_id,
- "callbackUri": subscription.callback_uri,
- "_links": json.loads(subscription.links),
- "filter": lccn_notifications_filter
- }
- sub_resp_serializer = LccnSubscriptionSerializer(data=subscription_data)
- if not sub_resp_serializer.is_valid():
- raise NFLCMException(sub_resp_serializer.errors)
- return Response(data=sub_resp_serializer.data, status=status.HTTP_201_CREATED)
- except NFLCMException as e:
- logger.error(e.message)
- if "exists" in e.message:
- return Response(data={'error': '%s' % e.message}, status=status.HTTP_303_SEE_OTHER)
- return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- except Exception as e:
- logger.error(e.message)
- logger.error(traceback.format_exc())
- return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+ lccn_subscription_request_serializer = LccnSubscriptionRequestSerializer(data=request.data)
+ if not lccn_subscription_request_serializer.is_valid():
+ raise NFLCMException(lccn_subscription_request_serializer.errors)
+ subscription = CreateSubscription(
+ lccn_subscription_request_serializer.data).do_biz()
+ lccn_notifications_filter = {
+ "notificationTypes": ast.literal_eval(subscription.notification_types),
+ "operationTypes": ast.literal_eval(subscription.operation_types),
+ "operationStates": ast.literal_eval(subscription.operation_states),
+ "vnfInstanceSubscriptionFilter": json.loads(subscription.vnf_instance_filter)
+ }
+ subscription_data = {
+ "id": subscription.subscription_id,
+ "callbackUri": subscription.callback_uri,
+ "_links": json.loads(subscription.links),
+ "filter": lccn_notifications_filter
+ }
+ sub_resp_serializer = LccnSubscriptionSerializer(data=subscription_data)
+ if not sub_resp_serializer.is_valid():
+ raise NFLCMException(sub_resp_serializer.errors)
+ return Response(data=sub_resp_serializer.data, status=status.HTTP_201_CREATED)
@swagger_auto_schema(
responses={
@@ -94,28 +86,22 @@ class SubscriptionsView(APIView):
status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
}
)
+ @view_safe_call_with_log(logger=logger)
def get(self, request):
logger.debug("SubscribeNotification--get::> %s" % request.query_params)
- try:
- 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)
- resp_data = QuerySubscription(request.query_params).query_multi_subscriptions()
- subscriptions_serializer = LccnSubscriptionsSerializer(data=resp_data)
- if not subscriptions_serializer.is_valid():
- raise NFLCMException(subscriptions_serializer.errors)
+ 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)
+ resp_data = QuerySubscription(request.query_params).query_multi_subscriptions()
- logger.debug("SubscribeNotification--get::> Remove default fields if exclude_default" +
- " is specified")
- return Response(data=subscriptions_serializer.data, status=status.HTTP_200_OK)
- except NFLCMException as e:
- logger.error(e.message)
- problem_details_serializer = get_problem_details_serializer(status.HTTP_500_INTERNAL_SERVER_ERROR, traceback.format_exc())
- return Response(data=problem_details_serializer.data, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ subscriptions_serializer = LccnSubscriptionsSerializer(data=resp_data)
+ if not subscriptions_serializer.is_valid():
+ raise NFLCMException(subscriptions_serializer.errors)
- except Exception as e:
- logger.error(e.message)
- logger.error(traceback.format_exc())
- problem_details_serializer = get_problem_details_serializer(status.HTTP_500_INTERNAL_SERVER_ERROR, traceback.format_exc())
- return Response(data=problem_details_serializer.data, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ logger.debug("SubscribeNotification--get::> Remove default fields")
+ return Response(data=subscriptions_serializer.data, status=status.HTTP_200_OK)
diff --git a/lcm/lcm/nf/views/terminate_vnf_view.py b/lcm/lcm/nf/views/terminate_vnf_view.py
index c1903b76..0530437f 100644
--- a/lcm/lcm/nf/views/terminate_vnf_view.py
+++ b/lcm/lcm/nf/views/terminate_vnf_view.py
@@ -13,7 +13,6 @@
# limitations under the License.
import logging
-import traceback
from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
@@ -25,7 +24,7 @@ from lcm.nf.serializers.terminate_vnf_req import TerminateVnfRequestSerializer
from lcm.nf.serializers.job_identifier import JobIdentifierSerializer
from lcm.pub.exceptions import NFLCMException
from lcm.pub.utils.jobutil import JobUtil
-
+from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
@@ -38,26 +37,20 @@ class TerminateVnfView(APIView):
status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
}
)
+ @view_safe_call_with_log(logger=logger)
def post(self, request, instanceid):
logger.debug("TerminateVnf--post::> %s" % request.data)
- try:
- terminate_vnf_request_serializer = TerminateVnfRequestSerializer(data=request.data)
- if not terminate_vnf_request_serializer.is_valid():
- raise NFLCMException(terminate_vnf_request_serializer.errors)
-
- job_id = JobUtil.create_job('NF', 'TERMINATE', instanceid)
- JobUtil.add_job_status(job_id, 0, "TERM_VNF_READY")
- TerminateVnf(terminate_vnf_request_serializer.data, instanceid, job_id).start()
-
- terminate_vnf_response_serializer = JobIdentifierSerializer(data={"jobId": job_id})
- if not terminate_vnf_response_serializer.is_valid():
- raise NFLCMException(terminate_vnf_response_serializer.errors)
-
- return Response(data=terminate_vnf_response_serializer.data, status=status.HTTP_202_ACCEPTED)
- except NFLCMException as e:
- logger.error(e.message)
- return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- 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)
+
+ terminate_vnf_request_serializer = TerminateVnfRequestSerializer(data=request.data)
+ if not terminate_vnf_request_serializer.is_valid():
+ raise NFLCMException(terminate_vnf_request_serializer.errors)
+
+ job_id = JobUtil.create_job('NF', 'TERMINATE', instanceid)
+ JobUtil.add_job_status(job_id, 0, "TERM_VNF_READY")
+ TerminateVnf(terminate_vnf_request_serializer.data, instanceid, job_id).start()
+
+ terminate_vnf_response_serializer = JobIdentifierSerializer(data={"jobId": job_id})
+ if not terminate_vnf_response_serializer.is_valid():
+ raise NFLCMException(terminate_vnf_response_serializer.errors)
+
+ return Response(data=terminate_vnf_response_serializer.data, status=status.HTTP_202_ACCEPTED)