diff options
author | ying.yunlong <ying.yunlong@zte.com.cn> | 2017-12-07 16:44:45 +0800 |
---|---|---|
committer | ying.yunlong <ying.yunlong@zte.com.cn> | 2017-12-07 16:44:45 +0800 |
commit | a666ca97320c4f39fa0a4e463815094a9ccabcce (patch) | |
tree | 70b07fe629f141b7908eea9016f6ee76e1a73f24 /zte/vmanager | |
parent | dc916b021084214a5e351177168b53b05dcc1b28 (diff) |
Optimize vfc-ztevnfmdriver termination Code
Change-Id: Idce0afffc008bad0e336ca80ce13bea6954302d9
Issue-ID: VFC-613
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'zte/vmanager')
-rw-r--r-- | zte/vmanager/driver/interfaces/tests.py | 6 | ||||
-rw-r--r-- | zte/vmanager/driver/interfaces/views.py | 27 |
2 files changed, 12 insertions, 21 deletions
diff --git a/zte/vmanager/driver/interfaces/tests.py b/zte/vmanager/driver/interfaces/tests.py index 8832d509..d46f9a73 100644 --- a/zte/vmanager/driver/interfaces/tests.py +++ b/zte/vmanager/driver/interfaces/tests.py @@ -151,7 +151,7 @@ class InterfacesTest(TestCase): response = self.client.post("/api/ztevnfmdriver/v1/ztevnfmid/vnfs", data=json.dumps(req_data), content_type="application/json") self.assertEqual(str(status.HTTP_200_OK), response.status_code) - expect_resp_data = {"jobid": "NF-CREATE-8-b384535c-9f45-11e6-8749-fa163e91c2f9", "vnfInstanceId": "8"} + expect_resp_data = {"jobId": "NF-CREATE-8-b384535c-9f45-11e6-8749-fa163e91c2f9", "vnfInstanceId": "8"} self.assertEqual(expect_resp_data, response.data) @mock.patch.object(restcall, 'call_req') @@ -170,13 +170,13 @@ 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] response = self.client.post("/api/ztevnfmdriver/v1/ztevnfmid/vnfs/vbras_innstance_id/terminate") self.assertEqual(str(status.HTTP_200_OK), response.status_code) - expect_resp_data = {"jobid": "1", "vnfInstanceId": "1"} + expect_resp_data = {"jobId": "1", "vnfInstanceId": "1"} self.assertEqual(expect_resp_data, response.data) @mock.patch.object(restcall, 'call_req') diff --git a/zte/vmanager/driver/interfaces/views.py b/zte/vmanager/driver/interfaces/views.py index 694ce669..54c0266e 100644 --- a/zte/vmanager/driver/interfaces/views.py +++ b/zte/vmanager/driver/interfaces/views.py @@ -146,11 +146,10 @@ def instantiate_vnf(request, *args, **kwargs): if ret[0] != 0: return Response(data={'error': ret[1]}, status=ret[2]) resp = json.JSONDecoder().decode(ret[1]) - create_vnf_resp_mapping = { - "VNFInstanceID": "vnfInstanceId", - "JobId": "jobid" + resp_data = { + "vnfInstanceId": ignorcase_get(resp, "VNFInstanceID"), + "jobId": ignorcase_get(resp, "JobId") } - resp_data = mapping_conv(create_vnf_resp_mapping, resp) logger.info("[%s]resp_data=%s", fun_name(), resp_data) except Exception as e: logger.error("Error occurred when instantiating VNF") @@ -158,15 +157,6 @@ def instantiate_vnf(request, *args, **kwargs): return Response(data=resp_data, status=ret[2]) -vnf_delete_url = "v1/vnfs/%s" -vnf_delete_param_mapping = { - "terminationType": "terminationType", - "gracefulTerminationTimeout": "gracefulTerminationTimeout"} -vnf_delete_resp_mapping = { - "vnfInstanceId": "vnfInstanceId", - "JobId": "jobid"} - - @api_view(http_method_names=['POST']) def terminate_vnf(request, *args, **kwargs): try: @@ -177,20 +167,21 @@ def terminate_vnf(request, *args, **kwargs): return Response(data={'error': ret[1]}, status=ret[2]) vnfm_info = json.JSONDecoder().decode(ret[1]) logger.debug("[%s] vnfm_info=%s", fun_name(), vnfm_info) - data = {} - logger.debug("[%s]req_data=%s", fun_name(), data) ret = restcall.call_req( base_url=ignorcase_get(vnfm_info, "url"), user=ignorcase_get(vnfm_info, "userName"), passwd=ignorcase_get(vnfm_info, "password"), auth_type=restcall.rest_no_auth, - resource=vnf_delete_url % (ignorcase_get(kwargs, "vnfInstanceID")), + resource="v1/vnfs/%s" % (ignorcase_get(kwargs, "vnfInstanceID")), method='delete', - content=json.JSONEncoder().encode(data)) + content=json.JSONEncoder().encode(request.data)) if ret[0] != 0: return Response(data={'error': ret[1]}, status=ret[2]) resp = json.JSONDecoder().decode(ret[1]) - resp_data = mapping_conv(vnf_delete_resp_mapping, resp) + resp_data = { + "vnfInstanceId": ignorcase_get(resp, "VNFInstanceID"), + "jobId": ignorcase_get(resp, "JobId") + } logger.debug("[%s]resp_data=%s", fun_name(), resp_data) except Exception as e: logger.error("Error occurred when terminating VNF") |