summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfujinhua <fu.jinhua@zte.com.cn>2019-06-27 16:06:32 +0800
committerfujinhua <fu.jinhua@zte.com.cn>2019-06-27 16:06:32 +0800
commit19ed1a22bfecf7e6c4f714d5ca5be422dd52c6f7 (patch)
tree8aaf626cbc5f14d2dff03e23e63372d260fba67e
parent6ee1843804237ee73147ac64ea61fc2a30c2191e (diff)
Fix resp status for term ns
Change-Id: I02dda46d4e42d4e806602d34e4badb37789ee9ba Issue-ID: VFC-1431 Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r--lcm/ns/views/deprecated/term_ns_view.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/lcm/ns/views/deprecated/term_ns_view.py b/lcm/ns/views/deprecated/term_ns_view.py
index 0aa89187..d6a94b24 100644
--- a/lcm/ns/views/deprecated/term_ns_view.py
+++ b/lcm/ns/views/deprecated/term_ns_view.py
@@ -20,9 +20,11 @@ from rest_framework.views import APIView
from lcm.ns.biz.ns_terminate import TerminateNsService
from lcm.pub.exceptions import NSLCMException
+from lcm.pub.exceptions import BadRequestException
from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.enum import JOB_TYPE
-from lcm.ns.serializers.deprecated.ns_serializers import _TerminateNsReqSerializer, _NsOperateJobSerializer
+from lcm.ns.serializers.deprecated.ns_serializers import _TerminateNsReqSerializer
+from lcm.ns.serializers.deprecated.ns_serializers import _NsOperateJobSerializer
logger = logging.getLogger(__name__)
@@ -32,6 +34,7 @@ class NSTerminateView(APIView):
request_body=_TerminateNsReqSerializer(),
responses={
status.HTTP_202_ACCEPTED: _NsOperateJobSerializer(),
+ status.HTTP_400_BAD_REQUEST: "Bad Request",
status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
}
)
@@ -40,7 +43,7 @@ class NSTerminateView(APIView):
logger.debug("Enter TerminateNSView::post %s", request.data)
req_serializer = _TerminateNsReqSerializer(data=request.data)
if not req_serializer.is_valid():
- raise NSLCMException(req_serializer.errors)
+ raise BadRequestException(req_serializer.errors)
job_id = JobUtil.create_job("NS", JOB_TYPE.TERMINATE_NS, ns_instance_id)
TerminateNsService(ns_instance_id, job_id, request.data).start()
@@ -50,6 +53,8 @@ class NSTerminateView(APIView):
raise NSLCMException(resp_serializer.errors)
logger.debug("Leave TerminateNSView::post ret=%s", resp_serializer.data)
return Response(data=resp_serializer.data, status=status.HTTP_202_ACCEPTED)
+ except BadRequestException as e:
+ return Response(data={'error': e.message}, status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
logger.error("Exception in CreateNS: %s", e.message)
return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)