Fix vfc-gvnfm-vnflcm unit tests 09/13409/1
authorying.yunlong <ying.yunlong@zte.com.cn>
Tue, 19 Sep 2017 06:57:33 +0000 (14:57 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Tue, 19 Sep 2017 06:57:33 +0000 (14:57 +0800)
Change-Id: Iab689aa92b8c5be00b5b44b322e5ac0c62512d21
Issue-ID: VFC-382
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py
lcm/lcm/nf/vnfs/tests/test_vnf_create.py
lcm/lcm/nf/vnfs/tests/test_vnf_query.py
lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py
lcm/lcm/pub/config/config.py
lcm/lcm/pub/msapi/aai.py

index c3e4b38..4d5748c 100644 (file)
@@ -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):
index 6669faf..3260c2d 100644 (file)
@@ -12,7 +12,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-
 import json
 import uuid
 
index acaa5e8..991583e 100644 (file)
@@ -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
 
index 3ae6445..3442afa 100644 (file)
@@ -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:
index 1b95acc..c47d763 100644 (file)
@@ -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]
index a7fc8f0..945eacd 100644 (file)
@@ -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