Fix vfc-vnflcm unittests 19/27619/1
authorying.yunlong <ying.yunlong@zte.com.cn>
Mon, 8 Jan 2018 07:17:56 +0000 (15:17 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Mon, 8 Jan 2018 07:17:56 +0000 (15:17 +0800)
Change-Id: I46725c86d0f0a857cf8acc14daf3d29a684f751f
Issue-ID: VFC-630
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
lcm/lcm/nf/vnfs/const.py
lcm/lcm/nf/vnfs/tests/test_vnf_create.py
lcm/lcm/nf/vnfs/views.py
lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py
lcm/lcm/nf/vnfs/vnf_query/query_vnf.py

index 1a0cb67..02edce7 100644 (file)
@@ -18,7 +18,6 @@ VNF_STATUS = enum(NULL='null', INSTANTIATING="instantiating", INACTIVE='inactive
                   FAILED="failed", TERMINATING="terminating", SCALING="scaling", OPERATING="operating",
                   UPDATING="updating", HEALING="healing")
 
-# inst_req_data
 inst_req_data = {
     "flavourId": "flavour_1",
     "instantiationLevelId": "instantiationLevel_1",
@@ -91,7 +90,6 @@ inst_req_data = {
     }
 }
 
-# vnfd_model_dict
 vnfd_model_dict = {
     'metadata': {
         'vendor': u'zte',
index 6613706..3d3e9ad 100644 (file)
@@ -33,6 +33,14 @@ from lcm.pub.vimapi import api
 class TestNFInstantiate(TestCase):
     def setUp(self):
         self.client = Client()
+        self.grant_result = {
+            "vim": {
+                "vimid": 'vimid_1',
+                "accessinfo": {
+                    "tenant": 'tenantname_1'
+                }
+            }
+        }
 
     def tearDown(self):
         pass
@@ -111,16 +119,8 @@ class TestNFInstantiate(TestCase):
                                    vnfdid='111',
                                    create_time=now_time())
         r1_get_vnfpackage_by_vnfdid = [0, json.JSONEncoder().encode(vnfpackage_info), '200']
-        r3_apply_grant_result = [1, json.JSONEncoder().encode(
-            {
-                "vim": {
-                    "vimid": 'vimid_1',
-                    "accessinfo": {
-                        "tenant": 'tenantname_1'
-                    }
-                }
-            }), '200']
-        mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid, r3_apply_grant_result]
+        r2_apply_grant_result = [1, json.JSONEncoder().encode(self.grant_result), '200']
+        mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid, r2_apply_grant_result]
         self.nf_inst_id = '1111'
         self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
         JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY")
@@ -143,16 +143,8 @@ class TestNFInstantiate(TestCase):
                                    vnfdid='111',
                                    create_time=now_time())
         r1_get_vnfpackage_by_vnfdid = [0, json.JSONEncoder().encode(vnfpackage_info), '200']
-        r3_apply_grant_result = [0, json.JSONEncoder().encode(
-            {
-                "vim": {
-                    "vimid": 'vimid_1',
-                    "accessinfo": {
-                        "tenant": 'tenantname_1'
-                    }
-                }
-            }), '200']
-        mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid, r3_apply_grant_result]
+        r2_apply_grant_result = [0, json.JSONEncoder().encode(self.grant_result), '200']
+        mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid, r2_apply_grant_result]
         mock_call.side_effect = [c1_data_get_tenant_id, c2_data_create_volume, c3_data_get_volume]
         self.nf_inst_id = '1111'
         self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
@@ -176,17 +168,9 @@ class TestNFInstantiate(TestCase):
                                    vnfdid='111',
                                    create_time=now_time())
         r1_get_vnfpackage_by_vnfdid = [0, json.JSONEncoder().encode(vnfpackage_info), '200']
-        r3_apply_grant_result = [0, json.JSONEncoder().encode(
-            {
-                "vim": {
-                    "vimid": 'vimid_1',
-                    "accessinfo": {
-                        "tenant": 'tenantname_1'
-                    }
-                }
-            }), '200']
-        r4_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']
-        mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid, r3_apply_grant_result, r4_lcm_notify_result]
+        r2_apply_grant_result = [0, json.JSONEncoder().encode(self.grant_result), '200']
+        r3_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']
+        mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid, r2_apply_grant_result, r3_lcm_notify_result]
         mock_call.side_effect = [c1_data_get_tenant_id, c2_data_create_volume, c3_data_get_volume,
                                  c4_data_create_network, c5_data_create_subnet, c6_data_create_port,
                                  c7_data_create_flavor, c8_data_list_image, c9_data_create_vm, c10_data_get_vm]
index 2330fa2..495e782 100644 (file)
@@ -32,7 +32,7 @@ logger = logging.getLogger(__name__)
 
 class CreateVnfAndQueryVnfs(APIView):
     def get(self, request):
-        logger.debug("QuerySingleVnf--get::> %s" % request.data)
+        logger.debug("QueryMultiVnf--get::> %s" % request.data)
         try:
             resp_data = QueryVnf(request.data).query_multi_vnf()
         except NFLCMException as e:
@@ -54,7 +54,9 @@ class CreateVnfAndQueryVnfs(APIView):
         except Exception:
             logger.error(traceback.format_exc())
             return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
-        rsp = {"vnfInstanceId": nf_inst_id}
+        rsp = {
+            "vnfInstanceId": nf_inst_id
+        }
         return Response(data=rsp, status=status.HTTP_201_CREATED)
 
 
@@ -71,7 +73,9 @@ class InstantiateVnf(APIView):
         except Exception:
             logger.error(traceback.format_exc())
             return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
-        rsp = {"jobId": job_id}
+        rsp = {
+            "jobId": job_id
+        }
         return Response(data=rsp, status=status.HTTP_202_ACCEPTED)
 
 
@@ -115,5 +119,7 @@ class TerminateVnf(APIView):
         except Exception:
             logger.error(traceback.format_exc())
             return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
-        rsp = {"jobId": job_id}
+        rsp = {
+            "jobId": job_id
+        }
         return Response(data=rsp, status=status.HTTP_202_ACCEPTED)
index c8c85d2..12df170 100644 (file)
@@ -40,13 +40,14 @@ class TermVnf(Thread):
         self.gracefulTerminationTimeout = ignore_case_get(self.data, "gracefulTerminationTimeout")
         self.apply_result = None
         self.notify_data = None
-        self.inst_resource = {'volumn': [],
-                              'network': [],
-                              'subnet': [],
-                              'port': [],
-                              'flavor': [],
-                              'vm': [],
-                              }
+        self.inst_resource = {
+            'volumn': [],
+            'network': [],
+            'subnet': [],
+            'port': [],
+            'flavor': [],
+            'vm': [],
+        }
 
     def run(self):
         try:
index 80e0d9b..70727b1 100644 (file)
@@ -11,6 +11,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
 import logging
 
 from lcm.pub.database.models import NfInstModel, StorageInstModel, VLInstModel, NetworkInstModel, VNFCInstModel, \
@@ -24,7 +25,6 @@ class QueryVnf:
     def __init__(self, data, instanceid=''):
         self.vnf_inst_id = instanceid
         self.data = data
-        pass
 
     def query_single_vnf(self):
         vnf_inst = NfInstModel.objects.filter(nfinstid=self.vnf_inst_id)
@@ -120,15 +120,9 @@ class QueryVnf:
         resp_data = {
             "vnfInstanceId": vnf.nfinstid,
             "vnfInstanceName": vnf.nf_name,
-            # "vnfInstanceDescription": vnf.nf_desc,
             "onboardedVnfPkgInfoId": vnf.package_id,
-            # "vnfdId": vnf.vnfdid,
             "vnfdVersion": vnf.version,
-            # "vnfSoftwareVersion": vnf.vnfSoftwareVersion,
             "vnfProvider": vnf.vendor,
-            # "vnfProductName": vnf.producttype,
-            # "vnfConfigurableProperties": {vnf.vnfConfigurableProperties},
-            # "instantiationState": vnf.status,
             "instantiatedVnfInfo": {
                 "flavourId": vnf.flavour_id,
                 "vnfState": vnf.status,
@@ -136,13 +130,10 @@ class QueryVnf:
                 "extCpInfo": [],
                 "extVirtualLink": [],
                 "monitoringParameters": {},
-                # "localizationLanguage": vnf.localizationLanguage,
                 "vimInfo": vm_arr,
                 "vnfcResourceInfo": vnfc_arr,
                 "virtualLinkResourceInfo": vl_arr,
                 "virtualStorageResourceInfo": arr
-            },
-            # "metadata": vnf.input_params,
-            # "extensions": vnf.extension
+            }
         }
         return resp_data