summaryrefslogtreecommitdiffstats
path: root/zte
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2018-02-11 11:26:20 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2018-02-11 11:26:20 +0800
commit834ea30c777cbb481e24200f168128e4885fd7bd (patch)
treef12d537a90f32bcefa03699339a44b7c77e568ee /zte
parenta957cc41318c4864c87f7e9a9647e37137be1c96 (diff)
Modify vfc-ztevnfmdriver termination tests
Change-Id: Ifa18667b9cc2077d97373ac7540b2dfe47538cd6 Issue-ID: VFC-736 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'zte')
-rw-r--r--zte/vmanager/driver/interfaces/tests.py10
-rw-r--r--zte/vmanager/driver/interfaces/views.py22
2 files changed, 22 insertions, 10 deletions
diff --git a/zte/vmanager/driver/interfaces/tests.py b/zte/vmanager/driver/interfaces/tests.py
index a0f27d72..c0c062c8 100644
--- a/zte/vmanager/driver/interfaces/tests.py
+++ b/zte/vmanager/driver/interfaces/tests.py
@@ -174,12 +174,14 @@ class InterfacesTest(TestCase):
"password": "admin",
"createTime": "2016-07-06 15:33:18"}), "200"]
- r2 = [0, json.JSONEncoder().encode(
- {"vnfInstanceId": "1", "jobId": "1"}), "200"]
+ r2 = [0, json.JSONEncoder().encode({"vnfInstanceId": "1", "jobId": "1"}), "200"]
mock_call_req.side_effect = [r1, r2]
-
+ req_data = {
+ "terminationType": "GRACEFUL",
+ "gracefulTerminationTimeout": 120
+ }
response = self.client.post(
- "/api/ztevnfmdriver/v1/ztevnfmid/vnfs/vbras_innstance_id/terminate")
+ "/api/ztevnfmdriver/v1/ztevnfmid/vnfs/vbras_innstance_id/terminate", data=req_data)
self.assertEqual(status.HTTP_200_OK, response.status_code)
expect_resp_data = {"jobId": "1", "vnfInstanceId": "1"}
diff --git a/zte/vmanager/driver/interfaces/views.py b/zte/vmanager/driver/interfaces/views.py
index 8fc0379c..f19f55a6 100644
--- a/zte/vmanager/driver/interfaces/views.py
+++ b/zte/vmanager/driver/interfaces/views.py
@@ -174,9 +174,14 @@ class TerminateVnf(APIView):
def post(self, request, vnfmid, vnfInstanceId):
try:
logger.debug("[%s] request.data=%s", fun_name(), request.data)
+ terminate_vnf_request_serializer = TerminateVnfRequestSerializer(data=request.data)
+ if not terminate_vnf_request_serializer.is_valid():
+ raise Exception(terminate_vnf_request_serializer.errors)
+
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(
@@ -186,19 +191,24 @@ class TerminateVnf(APIView):
auth_type=restcall.rest_no_auth,
resource="v1/vnfs/%s" % vnfInstanceId,
method='delete',
- content=json.JSONEncoder().encode(request.data))
+ content=json.JSONEncoder().encode(terminate_vnf_request_serializer.data))
if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
+ raise Exception(ret[1])
+
resp = json.JSONDecoder().decode(ret[1])
resp_data = {
"vnfInstanceId": ignorcase_get(resp, "VNFInstanceID"),
"jobId": ignorcase_get(resp, "JobId")
}
logger.debug("[%s]resp_data=%s", fun_name(), resp_data)
- return Response(data=resp_data, status=status.HTTP_200_OK)
+ terminateRespSerializer = InstScaleHealRespSerializer(data=resp_data)
+ if not terminateRespSerializer.is_valid():
+ raise Exception(terminateRespSerializer.errors)
+ return Response(data=terminateRespSerializer.data, status=status.HTTP_200_OK)
except Exception as e:
- logger.error("Error occurred when terminating VNF")
- raise e
+ logger.error("Error occurred when terminating VNF,error: %s", e.message)
+ logger.error(traceback.format_exc())
+ return Response(data={'error': 'TerminateVnf expection'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@api_view(http_method_names=['GET'])