diff options
author | yunlong ying <ying.yunlong@zte.com.cn> | 2019-04-10 06:16:36 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-04-10 06:16:36 +0000 |
commit | 10f4ba74370013addc6c4bbc68527e85d90bb511 (patch) | |
tree | fd95608fd97c6a053128f2cdefd3a7d5c0951eaa | |
parent | ae9b7ddec0b15270212ea7f3509c80c886b75a4d (diff) | |
parent | 3bd58a8918d6b70cbdec37bfc96da8bf59f71d41 (diff) |
Merge "Refactor codes for ns scale"
-rw-r--r-- | lcm/ns/tests/test_sol_ns_scale_api.py | 2 | ||||
-rw-r--r-- | lcm/ns/views/sol/scale_ns_views.py | 37 |
2 files changed, 16 insertions, 23 deletions
diff --git a/lcm/ns/tests/test_sol_ns_scale_api.py b/lcm/ns/tests/test_sol_ns_scale_api.py index d11570a5..b8e17482 100644 --- a/lcm/ns/tests/test_sol_ns_scale_api.py +++ b/lcm/ns/tests/test_sol_ns_scale_api.py @@ -209,7 +209,7 @@ class TestScaleNsApi(TestCase): self.ns_inst_id, data={}) self.assertEqual( response.status_code, - status.HTTP_500_INTERNAL_SERVER_ERROR) + status.HTTP_400_BAD_REQUEST) @mock.patch.object(NSManualScaleService, 'start') def test_ns_manual_scale_when_ns_not_exist(self, mock_start): diff --git a/lcm/ns/views/sol/scale_ns_views.py b/lcm/ns/views/sol/scale_ns_views.py index 07de7d4c..708c3942 100644 --- a/lcm/ns/views/sol/scale_ns_views.py +++ b/lcm/ns/views/sol/scale_ns_views.py @@ -19,11 +19,11 @@ from rest_framework.response import Response from rest_framework.views import APIView from lcm.ns.biz.ns_manual_scale import NSManualScaleService from lcm.ns.serializers.sol.scale_ns_serializers import ScaleNsRequestSerializer -from lcm.pub.exceptions import NSLCMException from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE from lcm.ns.const import NS_OCC_BASE_URI from lcm.pub.exceptions import BadRequestException from lcm.ns.serializers.sol.pub_serializers import ProblemDetailsSerializer +from .common import view_safe_call_with_log logger = logging.getLogger(__name__) @@ -36,27 +36,20 @@ class ScaleNSView(APIView): status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer() } ) + @view_safe_call_with_log(logger=logger) def post(self, request, ns_instance_id): logger.debug("Enter ScaleNSView::post %s, %s", request.data, ns_instance_id) + + req_serializer = ScaleNsRequestSerializer(data=request.data) + if not req_serializer.is_valid(): + raise BadRequestException(req_serializer.errors) + job_id = JobUtil.create_job("NS", JOB_TYPE.MANUAL_SCALE_VNF, ns_instance_id) - try: - req_serializer = ScaleNsRequestSerializer(data=request.data) - if not req_serializer.is_valid(): - raise NSLCMException(req_serializer.errors) - nsManualScaleService = NSManualScaleService(ns_instance_id, request.data, job_id) - nsManualScaleService.start() - response = Response(data={}, status=status.HTTP_202_ACCEPTED) - logger.debug("Location: %s" % nsManualScaleService.occ_id) - response["Location"] = NS_OCC_BASE_URI % nsManualScaleService.occ_id - logger.debug("Leave ScaleNSView") - return response - except BadRequestException as e: - logger.error("Exception in ScaleNSView: %s", e.message) - JobUtil.add_job_status(job_id, 255, 'NS scale failed: %s' % e.message) - data = {'status': status.HTTP_400_BAD_REQUEST, 'detail': e.message} - return Response(data=data, status=status.HTTP_400_BAD_REQUEST) - except Exception as e: - logger.error("Exception in ScaleNSView: %s", e.message) - JobUtil.add_job_status(job_id, 255, 'NS scale failed: %s' % e.message) - data = {'status': status.HTTP_500_INTERNAL_SERVER_ERROR, 'detail': e.message} - return Response(data=data, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + nsManualScaleService = NSManualScaleService(ns_instance_id, request.data, job_id) + nsManualScaleService.start() + response = Response(data={}, status=status.HTTP_202_ACCEPTED) + logger.debug("Location: %s" % nsManualScaleService.occ_id) + response["Location"] = NS_OCC_BASE_URI % nsManualScaleService.occ_id + logger.debug("Leave ScaleNSView") + return response |