diff options
author | ying.yunlong <ying.yunlong@zte.com.cn> | 2017-09-01 16:25:06 +0800 |
---|---|---|
committer | ying.yunlong <ying.yunlong@zte.com.cn> | 2017-09-01 16:25:06 +0800 |
commit | e157d63aa568a1c87b900dcd8547c52752bc6ae9 (patch) | |
tree | d5479c2f63205859c69167f056beb38181b80c6d /gvnfmadapter | |
parent | d4fbe2f11e4e7c10bd811335942dcf391669ddf1 (diff) |
Update gvnfm driver unit tests
Change-Id: I26f448548f03ec79e3f8c869291b4e298640cf91
Issue-ID: VFC-228
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'gvnfmadapter')
-rw-r--r-- | gvnfmadapter/driver/interfaces/tests.py | 30 | ||||
-rw-r--r-- | gvnfmadapter/driver/interfaces/views.py | 4 |
2 files changed, 21 insertions, 13 deletions
diff --git a/gvnfmadapter/driver/interfaces/tests.py b/gvnfmadapter/driver/interfaces/tests.py index f20d7ac..48f3783 100644 --- a/gvnfmadapter/driver/interfaces/tests.py +++ b/gvnfmadapter/driver/interfaces/tests.py @@ -27,8 +27,9 @@ class InterfacesTest(TestCase): def tearDown(self): pass + @mock.patch.object(restcall, 'call_req_aai') @mock.patch.object(restcall, 'call_req') - def test_instantiate_vnf(self, mock_call_req): + def test_instantiate_vnf(self, mock_call_req, mock_call_req_aai): vnfm_info = { 'userName': 'admin', 'vendor': 'ZTE', @@ -55,7 +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.side_effect = [r1, ret, r1, ret2] + mock_call_req_aai.side_effect = [r1, r1] + mock_call_req.side_effect = [ret, ret2] req_data = { 'vnfInstanceName': 'VFW_f88c0cb7-512a-44c4-bd09-891663f19367', 'vnfPackageId': 'd852e1be-0aac-48f1-b1a4-cd825f6cdf9a', @@ -80,8 +82,9 @@ class InterfacesTest(TestCase): self.assertEqual(job_info, response.data) + @mock.patch.object(restcall, 'call_req_aai') @mock.patch.object(restcall, 'call_req') - def test_terminate_vnf(self, mock_call_req): + def test_terminate_vnf(self, mock_call_req, mock_call_req_aai): vnfm_info = { "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee", "name": "g_vnfm", @@ -101,14 +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.side_effect = [r1, r2, r1, job_ret, r1, r2] + mock_call_req_aai.side_effect = [r1, r1, r1] + mock_call_req.side_effect = [r2, job_ret, 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') - def test_query_vnf(self, mock_call_req): + def test_query_vnf(self, mock_call_req, mock_call_req_aai): vnfm_info = { "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee", "name": "g_vnfm", @@ -126,15 +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.side_effect = [r1, r2] + mock_call_req_aai.side_effect = [r1] + mock_call_req.side_effect = [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') - def test_operation_status(self, mock_call_req): + def test_operation_status(self, mock_call_req, mock_call_req_aai): vnfm_info = { 'userName': 'admin', 'vendor': 'ZTE', @@ -188,7 +195,8 @@ class InterfacesTest(TestCase): } r1 = [0, json.JSONEncoder().encode(vnfm_info), '200'] r2 = [0, json.JSONEncoder().encode(resp_body), '200'] - mock_call_req.side_effect = [r1, r2] + mock_call_req_aai.side_effect = [r1] + mock_call_req.side_effect = [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"])) @@ -284,7 +292,7 @@ class InterfacesTest(TestCase): self.assertEqual(str(status.HTTP_200_OK), response.status_code) expect_resp_data = None self.assertEqual(expect_resp_data, response.data) - + @mock.patch.object(restcall, 'call_req') def test_get_vnfpkgs(self, mock_call_req): mock_call_req.return_value = [0, json.JSONEncoder().encode({ diff --git a/gvnfmadapter/driver/interfaces/views.py b/gvnfmadapter/driver/interfaces/views.py index 86b2400..7316654 100644 --- a/gvnfmadapter/driver/interfaces/views.py +++ b/gvnfmadapter/driver/interfaces/views.py @@ -22,7 +22,7 @@ from rest_framework.decorators import api_view from rest_framework.response import Response from driver.pub.utils import restcall -from driver.pub.utils.restcall import req_by_msb +from driver.pub.utils.restcall import req_by_msb, call_aai # ================================================== vnf_create_url = "api/vnflcm/v1/vnf_instances" @@ -110,7 +110,7 @@ def get_inst_levelId(vnfdId): return inst_levelId def get_vnfm_info(vnfm_id): - ret = req_by_msb((EXTSYS_GET_VNFM) % vnfm_id, "GET") + ret = call_aai((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]) |