From: ying.yunlong Date: Tue, 19 Sep 2017 06:57:33 +0000 (+0800) Subject: Fix vfc-gvnfm-vnflcm unit tests X-Git-Tag: v1.0.0~18 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=vfc%2Fgvnfm%2Fvnflcm.git;a=commitdiff_plain;h=330326a951816eb215847bfff677c4872fa2094b Fix vfc-gvnfm-vnflcm unit tests Change-Id: Iab689aa92b8c5be00b5b44b322e5ac0c62512d21 Issue-ID: VFC-382 Signed-off-by: ying.yunlong --- diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py b/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py index c3e4b38c..4d5748cc 100644 --- a/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py +++ b/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py @@ -82,21 +82,18 @@ class TestNFTerminate(TestCase): vnfminstid='11111', apiurl='1') - def tearDown(self): VmInstModel.objects.all().delete() NetworkInstModel.objects.all().delete() SubNetworkInstModel.objects.all().delete() PortInstModel.objects.all().delete() - def assert_job_result(self, job_id, job_progress, job_detail): jobs = JobStatusModel.objects.filter(jobid=job_id, progress=job_progress, descp=job_detail) self.assertEqual(1, len(jobs)) - @mock.patch.object(restcall, 'call_req') def test_delete_vnf_identifier(self, mock_call_req): NfInstModel.objects.create(nfinstid='1111', @@ -113,25 +110,31 @@ class TestNFTerminate(TestCase): vnfConfigurableProperties='todo', localizationLanguage='EN_US', create_time=now_time()) - r1_create_vnf_to_aai = [0, json.JSONEncoder().encode({}), '200'] - mock_call_req.side_effect = [r1_create_vnf_to_aai] + vnf_info = { + "vnf-id": "vnf-id-test111", + "vnf-name": "vnf-name-test111", + "vnf-type": "vnf-type-test111", + "in-maint": True, + "is-closed-loop-disabled": False, + "resource-version": "1505465356262" + } + r1_query_vnf_to_aai = [0, json.JSONEncoder().encode(vnf_info), '200'] + r1_delete_vnf_to_aai = [0, json.JSONEncoder().encode({}), '200'] + mock_call_req.side_effect = [r1_query_vnf_to_aai, r1_delete_vnf_to_aai] response = self.client.delete("/api/vnflcm/v1/vnf_instances/1111") self.failUnlessEqual(status.HTTP_204_NO_CONTENT, response.status_code) self.assertEqual(None, response.data) - def test_delete_vnf_identifier_when_vnf_not_exist(self): response = self.client.delete("/api/vnflcm/v1/vnf_instances/1111") self.failUnlessEqual(status.HTTP_204_NO_CONTENT, response.status_code) - @mock.patch.object(TermVnf, 'run') def test_terminate_vnf(self, mock_run): mock_run.re.return_value = None response = self.client.post("/api/vnflcm/v1/vnf_instances/12/terminate", data={}, format='json') self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code) - def test_terminate_vnf_when_inst_id_not_exist(self): data = { "terminationType": "GRACEFUL", @@ -143,7 +146,6 @@ class TestNFTerminate(TestCase): TermVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run() self.assert_job_result(self.job_id, 100, "Terminate Vnf success.") - @mock.patch.object(restcall, 'call_req') @mock.patch.object(api, 'call') def test_terminate_vnf_success(self, mock_call, mock_call_req): diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py index 6669fafe..3260c2db 100644 --- a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py +++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. - import json import uuid diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_query.py b/lcm/lcm/nf/vnfs/tests/test_vnf_query.py index acaa5e84..991583e7 100644 --- a/lcm/lcm/nf/vnfs/tests/test_vnf_query.py +++ b/lcm/lcm/nf/vnfs/tests/test_vnf_query.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. - from django.test import TestCase, Client from rest_framework import status diff --git a/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py b/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py index 3ae64458..3442afa2 100644 --- a/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py +++ b/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py @@ -30,9 +30,9 @@ class DeleteVnf: def do_biz(self): try: self.check_parameter() - self.delete_info_from_db() if REPORT_TO_AAI: self.delete_vnf_in_aai() + self.delete_info_from_db() except NFLCMException as e: logger.debug('Delete VNF instance[%s] from AAI failed' % self.nf_inst_id) except: diff --git a/lcm/lcm/pub/config/config.py b/lcm/lcm/pub/config/config.py index 1b95acc0..c47d7637 100644 --- a/lcm/lcm/pub/config/config.py +++ b/lcm/lcm/pub/config/config.py @@ -22,7 +22,7 @@ MSB_SERVICE_PORT = '80' AAI_BASE_URL = "https://127.0.0.1:8443/aai/v11" AAI_USER = "AAI" AAI_PASSWORD = "AAI" -REPORT_TO_AAI = False +REPORT_TO_AAI = True # [REDIS] diff --git a/lcm/lcm/pub/msapi/aai.py b/lcm/lcm/pub/msapi/aai.py index a7fc8f00..945eacda 100644 --- a/lcm/lcm/pub/msapi/aai.py +++ b/lcm/lcm/pub/msapi/aai.py @@ -87,7 +87,7 @@ def delete_vnf_aai(vnf_id, resource_version=""): if ret[0] != 0: logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) raise NFLCMException("Vnf instance delete exception in AAI") - return json.JSONDecoder().decode(ret[1]) + return json.JSONDecoder().decode(ret[1]), ret[2] def query_vnf_aai(vnf_id): resource = "/network/generic-vnfs/generic-vnf/%s?depth=all" % vnf_id