Fix vfc-lcm/ns/vnfs pep8 issue 37/16237/1
authorying.yunlong <ying.yunlong@zte.com.cn>
Thu, 28 Sep 2017 06:30:03 +0000 (14:30 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Thu, 28 Sep 2017 06:30:03 +0000 (14:30 +0800)
Change-Id: Ifbfd3af32a41ef58261383cbaafa08aa87394bf1
Issue-ID: VFC-456
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
lcm/ns/sfcs/urls.py
lcm/ns/sfcs/utils.py
lcm/ns/tests/vnfs/tests.py
lcm/ns/tests/vnfs/verify_test.py
lcm/ns/vnfs/create_vnfs.py
lcm/ns/vnfs/grant_vnfs.py
lcm/ns/vnfs/terminate_nfs.py
lcm/ns/vnfs/verify_vnfs.py
lcm/ns/vnfs/wait_job.py

index 9725267..6b85256 100644 (file)
@@ -1,11 +1,11 @@
 # Copyright 2016 ZTE Corporation.
-# 
+#
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
-# 
+#
 #         http://www.apache.org/licenses/LICENSE-2.0
-# 
+#
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
index 04dd317..61ccd0b 100644 (file)
@@ -41,12 +41,12 @@ def ignor_dot(str):
     return str[0:index]
 
 
-def get_fp_id(fpindex,ns_model):
+def get_fp_id(fpindex, ns_model):
     index = int(int(float(fpindex)) - 1)
     return ns_model['fps'][index].get("fp_id")
 
 
-def update_fp_status(fp_inst_id,status_info):
+def update_fp_status(fp_inst_id, status_info):
     FPInstModel.objects.filter(fpinstid=fp_inst_id).update(status=status_info)
 
 
index b54d92d..b071a03 100644 (file)
@@ -340,23 +340,23 @@ class TestScaleVnfViews(TestCase):
                 "properties": {
                     "name": "elementGroup1",
                 },
-                "members": ["gsu_vm","pfu_vm"]
+                "members": ["gsu_vm", "pfu_vm"]
             }]
         }
 
         req_data = {
             "scaleVnfData": [
                 {
-                    "type":"SCALE_OUT",
-                    "aspectId":"demo_aspect1",
-                    "numberOfSteps":1,
-                    "additionalParam":vnfd_info
+                    "type": "SCALE_OUT",
+                    "aspectId": "demo_aspect1",
+                    "numberOfSteps": 1,
+                    "additionalParam": vnfd_info
                 },
                 {
-                    "type":"SCALE_OUT",
-                    "aspectId":"demo_aspect2",
-                    "numberOfSteps":1,
-                    "additionalParam":vnfd_info
+                    "type": "SCALE_OUT",
+                    "aspectId": "demo_aspect2",
+                    "numberOfSteps": 1,
+                    "additionalParam": vnfd_info
                 }
             ]
         }
index e2368fa..532d5c1 100644 (file)
@@ -19,7 +19,7 @@ from rest_framework import status
 class TestGetVnfViews(TestCase):
     def setUp(self):
         self.client = Client()
-        self.data = {"PackageID":"1223334"}
+        self.data = {"PackageID": "1223334"}
         pass
 
     def tearDown(self):
index 0639dc4..caaefc2 100644 (file)
@@ -139,15 +139,15 @@ class CreateVnfs(Thread):
                 continue
             for network_info in vnf_info['networks']:
                 vl_instance = VLInstModel.objects.get(
-                    vldid=network_info['vl_id'], 
+                    vldid=network_info['vl_id'],
                     ownertype=OWNER_TYPE.NS,
                     ownerid=self.ns_inst_id)
                 vl_instance_id = vl_instance.vlinstanceid
                 network_name, subnet_name = self.get_network_info_of_vl(network_info['vl_id'])
                 virtual_link_list.append({
-                    'network_name': network_name, 
+                    'network_name': network_name,
                     'key_name': network_info['key_name'],
-                    'subnetwork_name': subnet_name, 
+                    'subnetwork_name': subnet_name,
                     'vl_instance_id': vl_instance_id
                 })
                 ext_virtual_link.append({
@@ -176,13 +176,16 @@ class CreateVnfs(Thread):
     def send_nf_init_request_to_vnfm(self):
         virtual_link_list, ext_virtual_link = self.get_virtual_link_info(self.vnf_id)
         req_param = json.JSONEncoder().encode({
-            'vnfInstanceName': self.vnf_inst_name, 
+            'vnfInstanceName': self.vnf_inst_name,
             'vnfPackageId': ignore_case_get(self.nf_package_info, "vnfPackageId"),
             'vnfDescriptorId': self.vnfd_id,
             'extVirtualLink': ext_virtual_link,
-            'additionalParam': {"inputs": self.inputs, 
+            'additionalParam': {
+                "inputs": self.inputs,
                 "vimId": self.vim_id,
-                "extVirtualLinks": virtual_link_list}})
+                "extVirtualLinks": virtual_link_list
+            }
+        })
         rsp = send_nf_init_request(self.vnfm_inst_id, req_param)
         self.vnfm_job_id = ignore_case_get(rsp, 'jobId')
         self.vnfm_nf_inst_id = ignore_case_get(rsp, 'vnfInstanceId')
@@ -225,9 +228,11 @@ class CreateVnfs(Thread):
         create_vnf(data)
 
     def wait_vnfm_job_finish(self):
-        ret = wait_job_finish(vnfm_id=self.vnfm_inst_id, vnfo_job_id=self.job_id, 
-            vnfm_job_id=self.vnfm_job_id, progress_range=[10, 90],
-            timeout=NFVO_VNF_INST_TIMEOUT_SECOND)
+        ret = wait_job_finish(vnfm_id=self.vnfm_inst_id,
+                              vnfo_job_id=self.job_id,
+                              vnfm_job_id=self.vnfm_job_id,
+                              progress_range=[10, 90],
+                              timeout=NFVO_VNF_INST_TIMEOUT_SECOND)
 
         if ret != JOB_MODEL_STATUS.FINISHED:
             logger.error('VNF instantiation failed on VNFM side.')
index bf5335f..4604192 100644 (file)
@@ -61,7 +61,7 @@ class GrantVnfs(object):
             if not vnfinsts:
                 raise NSLCMException("Vnfinst(%s) is not found in vnfm(%s)" % (
                     m_vnf_inst_id, vnfm_inst_id))
-                
+
             vnf_pkg_id = vnfinsts[0].package_id
             # vnf_pkgs = NfPackageModel.objects.filter(nfpackageid=vnf_pkg_id)
             nfpackage_info = query_vnfpackage_by_id(vnf_pkg_id)
@@ -72,8 +72,8 @@ class GrantVnfs(object):
             vnfd = json.JSONDecoder().decode(vnf_pkgs[0].vnfdmodel)
 
             req_param = {
-                "vnfInstanceId": m_vnf_inst_id, 
-                "vimId": vim_id, 
+                "vnfInstanceId": m_vnf_inst_id,
+                "vimId": vim_id,
                 "additionalParam": additional_param,
                 grant_type: []
             }
@@ -81,7 +81,7 @@ class GrantVnfs(object):
                 vdu_name = ignore_case_get(res, "vdu")
                 grant_res = {
                     "resourceDefinitionId": ignore_case_get(res, "resourceDefinitionId"),
-                    "type": ignore_case_get(res,"type"),
+                    "type": ignore_case_get(res, "type"),
                     "vdu": vdu_name
                 }
                 for vdu in vnfd["vdus"]:
@@ -102,7 +102,7 @@ class GrantVnfs(object):
                     "numVirtualCpu": int(vdu["nfv_compute"]["num_cpus"])
                 },
                 "virtualMemory": {
-                    "virtualMemSize": int(vdu["nfv_compute"]["mem_size"]) 
+                    "virtualMemSize": int(vdu["nfv_compute"]["mem_size"])
                 }
             },
             "virtualStorageDescriptor": {
index 14edc0f..c88e844 100644 (file)
@@ -106,7 +106,7 @@ class TerminateVnfs(threading.Thread):
 
     def send_nf_terminate_to_vnfmDriver(self):
         req_param = json.JSONEncoder().encode({
-            'terminationType': self.terminationType, 
+            'terminationType': self.terminationType,
             'gracefulTerminationTimeout': self.gracefulTerminationTimeout})
         rsp = send_nf_terminate_request(self.vnfm_inst_id, self.vnf_uuid, req_param)
         self.vnfm_job_id = ignore_case_get(rsp, 'jobId')
@@ -118,9 +118,11 @@ class TerminateVnfs(threading.Thread):
         if not self.vnfm_job_id:
             logger.warn("No Job, need not wait")
             return
-        ret = wait_job_finish(vnfm_id=self.vnfm_inst_id, vnfo_job_id=self.job_id, 
-            vnfm_job_id=self.vnfm_job_id, progress_range=[10, 90],
-            timeout=NFVO_VNF_INST_TIMEOUT_SECOND)
+        ret = wait_job_finish(vnfm_id=self.vnfm_inst_id,
+                              vnfo_job_id=self.job_id,
+                              vnfm_job_id=self.vnfm_job_id,
+                              progress_range=[10, 90],
+                              timeout=NFVO_VNF_INST_TIMEOUT_SECOND)
 
         if ret != JOB_MODEL_STATUS.FINISHED:
             logger.error('VNF terminate failed on VNFM side.')
index 8375acb..2cc55a2 100644 (file)
@@ -58,8 +58,8 @@ class VerifyVnfs(threading.Thread):
     def do_on_boarding(self):
         self.update_job(10, "Start vnf on boarding.")
         onboarding_data = {
-            "csarId":self.data["PackageID"],
-            "labVimId":ignore_case_get(self.verify_config, "labVimId")
+            "csarId": self.data["PackageID"],
+            "labVimId": ignore_case_get(self.verify_config, "labVimId")
         }
         ret = req_by_msb("/api/nslcm/v1/vnfpackage", "POST", json.JSONEncoder().encode(onboarding_data))
         if ret[0] != 0:
@@ -68,7 +68,7 @@ class VerifyVnfs(threading.Thread):
         if not self.wait_until_job_done(rsp_data["jobId"], 15):
             raise NSLCMException("Vnf onboarding failed")
         self.update_job(20, "Vnf on boarding success.")
-        
+
     def do_inst_vnf(self):
         self.update_job(30, "Start inst vnf.")
         vnf_param = ignore_case_get(self.verify_config, "additionalParamForVnf")
@@ -87,10 +87,10 @@ class VerifyVnfs(threading.Thread):
         if not self.wait_until_job_done(rsp_data["jobId"], 40):
             raise NSLCMException("Vnf(%s) inst failed" % self.vnf_inst_id)
         self.update_job(50, "Inst vnf success.")
-        
+
     def do_func_test(self):
         self.update_job(60, "Start vnf function test.")
-        func_data = {"PackageID":self.data["PackageID"]}
+        func_data = {"PackageID": self.data["PackageID"]}
         ret = req_by_msb("/openapi/vnfsdk/v1/functest/taskmanager/testtasks", "POST", json.JSONEncoder().encode(func_data))
         if ret[0] != 0:
             raise NSLCMException("Failed to call func test: %s" % ret[1])
@@ -106,7 +106,7 @@ class VerifyVnfs(threading.Thread):
         rsp_result_data = json.JSONDecoder().decode(ret[1])
         logger.info("Func test(%s) result: %s", rsp_result_data)
         self.update_job(80, "Vnf function test success.")
-        
+
     def do_term_vnf(self):
         if not self.vnf_inst_id:
             return
@@ -125,10 +125,10 @@ class VerifyVnfs(threading.Thread):
             logger.error("Vnf(%s) term failed", self.vnf_inst_id)
             end_progress = JOB_ERROR
         self.update_job(end_progress, "Term vnf end.")
-        
+
     def update_job(self, progress, desc=''):
         JobUtil.add_job_status(self.job_id, progress, desc)
-        
+
     def wait_until_job_done(self, job_id, global_progress, retry_count=60, interval_second=3):
         count = 0
         response_id, new_response_id = 0, 0
@@ -176,8 +176,8 @@ class VerifyVnfs(threading.Thread):
         while count < retry_count:
             count = count + 1
             time.sleep(interval_second)
-            ret = req_by_msb("/openapi/vnfsdk/v1/functest/taskmanager/testtasks/%s?responseId=%s" %
-                (job_id, response_id), "GET")
+            ret = req_by_msb("/openapi/vnfsdk/v1/functest/taskmanager/testtasks/%s?responseId=%s"
+                             % (job_id, response_id), "GET")
             if ret[0] != 0:
                 logger.error("Failed to query job: %s:%s", ret[2], ret[1])
                 continue
index 99b4507..a1788ef 100644 (file)
@@ -36,18 +36,16 @@ def calc_progress(vnfm_progress, target_range=None):
 
 def default_callback(vnfo_job_id, vnfm_job_id, job_status, jobs, progress_range, **kwargs):
     for job in jobs:
-        progress = calc_progress(
-            ignore_case_get(job, 'progress'), 
-            progress_range)
-        JobUtil.add_job_status(vnfo_job_id, progress, 
-            ignore_case_get(job, 'statusdescription'), 
-            ignore_case_get(job, 'errorcode'))
-    latest_progress = calc_progress(
-        ignore_case_get(job_status, 'progress'), 
-        progress_range)
-    JobUtil.add_job_status(vnfo_job_id, latest_progress, 
-        ignore_case_get(job_status, 'statusdescription'),
-        ignore_case_get(job_status, 'errorcode'))
+        progress = calc_progress(ignore_case_get(job, 'progress'),
+                                 progress_range)
+        JobUtil.add_job_status(vnfo_job_id, progress,
+                               ignore_case_get(job, 'statusdescription'),
+                               ignore_case_get(job, 'errorcode'))
+    latest_progress = calc_progress(ignore_case_get(job_status, 'progress'),
+                                    progress_range)
+    JobUtil.add_job_status(vnfo_job_id, latest_progress,
+                           ignore_case_get(job_status, 'statusdescription'),
+                           ignore_case_get(job_status, 'errorcode'))
     jobstatus = ignore_case_get(job_status, 'status')
     if jobstatus in (JOB_MODEL_STATUS.ERROR, JOB_MODEL_STATUS.FINISHED):
         return True, jobstatus
@@ -73,8 +71,7 @@ def wait_job_finish(vnfm_id, vnfo_job_id, vnfm_job_id, progress_range=None, time
         jobs = ignore_case_get(job_status, 'responsehistorylist', [])
         if jobs:
             jobs.reverse()
-        is_end, status = job_callback(vnfo_job_id, vnfm_job_id, job_status, 
-            jobs, progress_range, **kwargs)
+        is_end, status = job_callback(vnfo_job_id, vnfm_job_id, job_status, jobs, progress_range, **kwargs)
         if is_end:
             return status
     return JOB_MODEL_STATUS.TIMEOUT