diff options
author | ying.yunlong <ying.yunlong@zte.com.cn> | 2017-09-12 10:13:11 +0800 |
---|---|---|
committer | ying.yunlong <ying.yunlong@zte.com.cn> | 2017-09-12 10:13:11 +0800 |
commit | 025ea76bc7db631a9a13b0cf92ca0f2b6a3e3f67 (patch) | |
tree | e8515e2e4da825062c971681b510dfc6e34d41c5 /gvnfmadapter | |
parent | 9c797acdb0aa1c0d34ddaac2c08b1033c4ede01a (diff) |
Add gvnfm-driver query vnfm from nslcm
Change-Id: I6f4739c192caeab65bcd2a97eedc7da95c142048
Issue-ID: VFC-332
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'gvnfmadapter')
-rw-r--r-- | gvnfmadapter/driver/interfaces/tests.py | 32 | ||||
-rw-r--r-- | gvnfmadapter/driver/interfaces/views.py | 28 |
2 files changed, 36 insertions, 24 deletions
diff --git a/gvnfmadapter/driver/interfaces/tests.py b/gvnfmadapter/driver/interfaces/tests.py index 48f3783..aebc5e3 100644 --- a/gvnfmadapter/driver/interfaces/tests.py +++ b/gvnfmadapter/driver/interfaces/tests.py @@ -27,9 +27,9 @@ class InterfacesTest(TestCase): def tearDown(self): pass - @mock.patch.object(restcall, 'call_req_aai') + # @mock.patch.object(restcall, 'call_req_aai') @mock.patch.object(restcall, 'call_req') - def test_instantiate_vnf(self, mock_call_req, mock_call_req_aai): + def test_instantiate_vnf(self, mock_call_req): vnfm_info = { 'userName': 'admin', 'vendor': 'ZTE', @@ -56,8 +56,8 @@ class InterfacesTest(TestCase): r1 = [0, json.JSONEncoder().encode(vnfm_info), "200"] ret = [0, json.JSONEncoder().encode(job_info), '200'] ret2 = [0, json.JSONEncoder().encode(vnflcm_info), '200'] - mock_call_req_aai.side_effect = [r1, r1] - mock_call_req.side_effect = [ret, ret2] + # mock_call_req_aai.side_effect = [r1, r1] + mock_call_req.side_effect = [r1, ret, r1, ret2] req_data = { 'vnfInstanceName': 'VFW_f88c0cb7-512a-44c4-bd09-891663f19367', 'vnfPackageId': 'd852e1be-0aac-48f1-b1a4-cd825f6cdf9a', @@ -82,9 +82,9 @@ class InterfacesTest(TestCase): self.assertEqual(job_info, response.data) - @mock.patch.object(restcall, 'call_req_aai') + # @mock.patch.object(restcall, 'call_req_aai') @mock.patch.object(restcall, 'call_req') - def test_terminate_vnf(self, mock_call_req, mock_call_req_aai): + def test_terminate_vnf(self, mock_call_req): vnfm_info = { "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee", "name": "g_vnfm", @@ -104,16 +104,16 @@ class InterfacesTest(TestCase): r1 = [0, json.JSONEncoder().encode(vnfm_info), "200"] r2 = [0, json.JSONEncoder().encode(job_info), "200"] job_ret = [0, json.JSONEncoder().encode(job_status_info), "200"] - mock_call_req_aai.side_effect = [r1, r1, r1] - mock_call_req.side_effect = [r2, job_ret, r2] + # mock_call_req_aai.side_effect = [r1, r1, r1] + mock_call_req.side_effect = [r1, r2, r1, job_ret, r1, r2] response = self.client.post("/api/gvnfmdriver/v1/ztevnfmid/vnfs/2/terminate") self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) self.assertEqual(job_info, response.data) - @mock.patch.object(restcall, 'call_req_aai') + # @mock.patch.object(restcall, 'call_req_aai') @mock.patch.object(restcall, 'call_req') - def test_query_vnf(self, mock_call_req, mock_call_req_aai): + def test_query_vnf(self, mock_call_req): vnfm_info = { "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee", "name": "g_vnfm", @@ -131,17 +131,17 @@ class InterfacesTest(TestCase): job_info = {"ResponseInfo": {"vnfInstanceId":"88","instantiationState":"INSTANTIATED","vnfSoftwareVersion":"v1.2.3"}} r1 = [0, json.JSONEncoder().encode(vnfm_info), "200"] r2 = [0, json.JSONEncoder().encode(job_info), "200"] - mock_call_req_aai.side_effect = [r1] - mock_call_req.side_effect = [r2] + # mock_call_req_aai.side_effect = [r1] + mock_call_req.side_effect = [r1, r2] response = self.client.get("/api/gvnfmdriver/v1/19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee/vnfs/88") self.assertEqual(status.HTTP_200_OK, response.status_code) expect_resp_data = {"vnfInfo": {"vnfInstanceId": "88", "vnfStatus": "ACTIVE","version":"v1.2.3"}} self.assertEqual(expect_resp_data, response.data) - @mock.patch.object(restcall, 'call_req_aai') + # @mock.patch.object(restcall, 'call_req_aai') @mock.patch.object(restcall, 'call_req') - def test_operation_status(self, mock_call_req, mock_call_req_aai): + def test_operation_status(self, mock_call_req): vnfm_info = { 'userName': 'admin', 'vendor': 'ZTE', @@ -195,8 +195,8 @@ class InterfacesTest(TestCase): } r1 = [0, json.JSONEncoder().encode(vnfm_info), '200'] r2 = [0, json.JSONEncoder().encode(resp_body), '200'] - mock_call_req_aai.side_effect = [r1] - mock_call_req.side_effect = [r2] + # mock_call_req_aai.side_effect = [r1] + mock_call_req.side_effect = [r1, r2] response = self.client.get("/api/gvnfmdriver/v1/{vnfmid}/jobs/{jobid}?responseId={responseId}". format(vnfmid=vnfm_info["vnfmId"],jobid=resp_body["ResponseInfo"]["vnfLcOpId"], responseId=resp_body["ResponseInfo"]["responseDescriptor"]["responseId"])) diff --git a/gvnfmadapter/driver/interfaces/views.py b/gvnfmadapter/driver/interfaces/views.py index 6e5a888..ac3ac27 100644 --- a/gvnfmadapter/driver/interfaces/views.py +++ b/gvnfmadapter/driver/interfaces/views.py @@ -109,6 +109,16 @@ def get_inst_levelId(vnfdId): return inst_levelId +# Query vnfm info from nslcm +def get_vnfminfo_from_nslcm(vnfm_id): + ret = req_by_msb((EXTSYS_GET_VNFM) % vnfm_id, "GET") + if ret[0] != 0: + return 255, 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) + return 0, vnfm_info + +# Query vnfm info from esr def get_vnfm_info(vnfm_id): ret = call_aai((EXTSYS_GET_VNFM) % vnfm_id, "GET") if ret[0] != 0: @@ -117,6 +127,8 @@ def get_vnfm_info(vnfm_id): logger.debug("[%s] vnfm_info=%s", fun_name(), vnfm_info) return 0, vnfm_info + + def call_vnfm_rest(vnfm_info, input_data, res_url, call_method = "post"): ret = restcall.call_req( base_url=ignorcase_get(vnfm_info, "url"), @@ -151,7 +163,7 @@ def wait4job(vnfm_id,jobId,gracefulTerminationTimeout): begin_time = time.time() try: - ret, vnfm_info = get_vnfm_info(vnfm_id) + ret, vnfm_info = get_vnfminfo_from_nslcm(vnfm_id) if ret != 0: return 255, Response(data={"error":"Fail to get VNFM!"}, status=status.HTTP_412_PRECONDITION_FAILED) @@ -180,7 +192,7 @@ def do_createvnf(request, data, vnfm_id): logger.debug("[%s] request.data=%s", fun_name(), request.data) try: - ret, vnfm_info = get_vnfm_info(vnfm_id) + ret, vnfm_info = get_vnfminfo_from_nslcm(vnfm_id) if ret != 0: return ret, vnfm_info @@ -199,7 +211,7 @@ def do_instvnf(vnfInstanceId, request, data, vnfm_id): logger.debug("[%s] request.data=%s", fun_name(), request.data) try: - ret, vnfm_info = get_vnfm_info(vnfm_id) + ret, vnfm_info = get_vnfminfo_from_nslcm(vnfm_id) if ret != 0: return ret, vnfm_info @@ -217,7 +229,7 @@ def do_instvnf(vnfInstanceId, request, data, vnfm_id): def do_terminatevnf(request, data, vnfm_id, vnfInstanceId): logger.debug("[%s] request.data=%s", fun_name(), request.data) try: - ret, vnfm_info = get_vnfm_info(vnfm_id) + ret, vnfm_info = get_vnfminfo_from_nslcm(vnfm_id) if ret != 0: return ret,vnfm_info @@ -236,7 +248,7 @@ def do_deletevnf(request, vnfm_id, vnfInstanceId): logger.debug("[%s] request.data=%s", fun_name(), request.data) input_data = set_deletevnf_params(request.data) try: - ret, vnfm_info = get_vnfm_info(vnfm_id) + ret, vnfm_info = get_vnfminfo_from_nslcm(vnfm_id) if ret != 0: return ret, vnfm_info @@ -254,7 +266,7 @@ def do_deletevnf(request, vnfm_id, vnfInstanceId): def do_queryvnf(request, vnfm_id, vnfInstanceId): logger.debug("[%s] request.data=%s", fun_name(), request.data) try: - ret, vnfm_info = get_vnfm_info(vnfm_id) + ret, vnfm_info = get_vnfminfo_from_nslcm(vnfm_id) if ret != 0: return ret, vnfm_info @@ -362,7 +374,7 @@ def operation_status(request, *args, **kwargs): jobId = ignorcase_get(kwargs, "jobId") responseId = ignorcase_get(kwargs, "responseId") - ret, vnfm_info = get_vnfm_info(vnfm_id) + ret, vnfm_info = get_vnfminfo_from_nslcm(vnfm_id) if ret != 0: return Response(data={'error': ret[1]}, status=ret[2]) logger.debug("[%s] vnfm_info=%s", fun_name(), vnfm_info) @@ -391,7 +403,7 @@ def operation_status(request, *args, **kwargs): # ================================================== -grant_vnf_url = 'api/nslcm/v1/ns/grantvnf' +grant_vnf_url = 'api/nslcm/v1/grantvnf' @api_view(http_method_names=['PUT']) def grantvnf(request, *args, **kwargs): |