summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2018-02-26 19:53:42 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2018-02-26 19:53:42 +0800
commit17088b6ddaadea95047edc5ea0ca6b894a3e99e2 (patch)
treee1903dd53ef3a8d7631724f27077cae991fb4686
parent55a577309d358c76b46cb37a1f9bba0d081f26c3 (diff)
Optimize vfc-ztevnfmdriver queryVnf code
Change-Id: Ib239d726c5c55bec8a106a6a1c74bb72587735cf Issue-ID: VFC-736 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r--zte/vmanager/driver/interfaces/views.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/zte/vmanager/driver/interfaces/views.py b/zte/vmanager/driver/interfaces/views.py
index 1bf6c5c9..716f83e3 100644
--- a/zte/vmanager/driver/interfaces/views.py
+++ b/zte/vmanager/driver/interfaces/views.py
@@ -237,7 +237,8 @@ class QueryVnf(APIView):
logger.debug("[%s] request.data=%s", fun_name(), request.data)
ret = get_vnfminfo_from_nslcm(vnfmid)
if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
+ raise Exception(ret[1])
+
vnfm_info = json.JSONDecoder().decode(ret[1])
logger.debug("[%s] vnfm_info=%s", fun_name(), vnfm_info)
ret = restcall.call_req(
@@ -249,15 +250,20 @@ class QueryVnf(APIView):
method='get',
content=json.JSONEncoder().encode({}))
if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
+ raise Exception(ret[1])
+
resp = json.JSONDecoder().decode(ret[1])
vnf_status = ignorcase_get(resp, "vnfinstancestatus")
resp_data = {"vnfInfo": {"vnfStatus": vnf_status}}
logger.debug("[%s]resp_data=%s", fun_name(), resp_data)
+ queryVnfResponseSerializer = QueryVnfResponseSerializer(data=resp_data)
+ if not queryVnfResponseSerializer.is_valid():
+ raise Exception(queryVnfResponseSerializer.errors)
+ return Response(data=queryVnfResponseSerializer.data, status=status.HTTP_200_OK)
except Exception as e:
- logger.error("Error occurred when querying VNF information.")
- raise e
- return Response(data=resp_data, status=ret[2])
+ logger.error("Error occurred when querying VNF information,error:%s", e.message)
+ logger.error(traceback.format_exc())
+ return Response(data={'error': 'QueryVnf expection'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class JobView(APIView):