Fix vfc-lcm/pub/scaleaspect pep8 issue 71/15771/1
authorying.yunlong <ying.yunlong@zte.com.cn>
Wed, 27 Sep 2017 02:25:17 +0000 (10:25 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Wed, 27 Sep 2017 02:25:17 +0000 (10:25 +0800)
Change-Id: I0b88058e230b51ae58aa807b208b7dc797299843
Issue-ID: VFC-456
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
lcm/pub/utils/scaleaspect.py
lcm/workflows/auto_deploy.py
lcm/workflows/build_in.py
lcm/workflows/tests.py
lcm/workflows/views.py

index dda1797..0cd9216 100644 (file)
 # limitations under the License.
 
 import json
-import os
 import logging
-from lcm.pub.exceptions import NSLCMException
-from rest_framework import status
-from rest_framework.response import Response
-from rest_framework.views import APIView
-from rest_framework import status
-from rest_framework.response import Response
+import os
 
 logger = logging.getLogger(__name__)
 SCALE_TYPE = ("SCALE_NS", "SCALE_VNF")
 
 scale_vnf_data_mapping = {
-    "vnfInstanceId":"",
-    "scaleByStepData":[
+    "vnfInstanceId": "",
+    "scaleByStepData": [
         {
-            "type":"",
-            "aspectId":"",
-            "numberOfSteps":""
+            "type": "",
+            "aspectId": "",
+            "numberOfSteps": ""
         }
     ]
 }
 
+
 def ignorcase_get(args, key):
     if not key:
         return ""
@@ -48,6 +43,7 @@ def ignorcase_get(args, key):
             return args[old_key]
     return ""
 
+
 def mapping_conv(keyword_map, rest_return):
     resp_data = {}
     for param in keyword_map:
@@ -58,6 +54,7 @@ def mapping_conv(keyword_map, rest_return):
                 resp_data[param] = ignorcase_get(rest_return, param)
     return resp_data
 
+
 def get_vnf_scale_info(filename, ns_instanceId, aspect, step):
     json_data = get_json_data(filename)
     scale_options = ignorcase_get(json_data, "scale_options")
@@ -73,6 +70,7 @@ def get_vnf_scale_info(filename, ns_instanceId, aspect, step):
 
     return None
 
+
 def get_json_data(filename):
     f = open(filename)
     json_str = f.read()
@@ -80,13 +78,17 @@ def get_json_data(filename):
     f.close()
     return data
 
+
 def check_scale_list(vnf_scale_list, ns_instanceId, aspect, step):
     if vnf_scale_list is None:
-        logger.debug("The scaling option[ns=%s, aspect=%s, step=%s] does not exist. Pls check the config file." %(ns_instanceId, aspect, step))
-        raise Exception("The scaling option[ns=%s, aspect=%s, step=%s] does not exist. Pls check the config file." %(ns_instanceId, aspect, step))
+        logger.debug("The scaling option[ns=%s, aspect=%s, step=%s] does not exist. Pls check the config file."
+                     % (ns_instanceId, aspect, step))
+        raise Exception("The scaling option[ns=%s, aspect=%s, step=%s] does not exist. Pls check the config file."
+                        % (ns_instanceId, aspect, step))
     else:
         return vnf_scale_list
 
+
 def set_scaleVnfData_type(vnf_scale_list, scale_type):
     logger.debug("vnf_scale_list = %s, type = %s" % (vnf_scale_list, scale_type))
     scaleVnfDataList = []
@@ -101,40 +103,44 @@ def set_scaleVnfData_type(vnf_scale_list, scale_type):
     logger.debug("scaleVnfDataList = %s" % scaleVnfDataList)
     return scaleVnfDataList
 
+
 def get_vnfInstanceIdByName(name):
     return name
 
+
 def get_vnf_data(filename, ns_instanceId, aspect, step, scale_type):
 
     vnf_scale_list = get_vnf_scale_info(filename, ns_instanceId, aspect, step)
     check_scale_list(vnf_scale_list, ns_instanceId, aspect, step)
-    scaleVnfDataList = set_scaleVnfData_type(vnf_scale_list,scale_type)
+    scaleVnfDataList = set_scaleVnfData_type(vnf_scale_list, scale_type)
     logger.debug("scaleVnfDataList = %s" % scaleVnfDataList)
     return scaleVnfDataList
 
-    #return Response(data={'error': e.message},status=status.HTTP_204_NO_CONTENT)
-    #return Response(data={'success': 'success'},status=status.HTTP_200_OK)
+    # return Response(data={'error': e.message},status=status.HTTP_204_NO_CONTENT)
+    # return Response(data={'success': 'success'},status=status.HTTP_200_OK)
+
 
 def get_and_check_params(scaleNsData, ns_InstanceId):
 
     if scaleNsData is None:
         pass
-        #raise NSLCMException("Error! scaleNsData in the request is Empty!")
+        # raise NSLCMException("Error! scaleNsData in the request is Empty!")
 
     scaleNsByStepsData = scaleNsData[0]["scaleNsByStepsData"]
     if scaleNsByStepsData is None:
         pass
-        #raise NSLCMException("Error! scaleNsByStepsData in the request is Empty!")
+        # raise NSLCMException("Error! scaleNsByStepsData in the request is Empty!")
 
     aspect = scaleNsByStepsData[0]["aspectId"]
     numberOfSteps = scaleNsByStepsData[0]["numberOfSteps"]
     scale_type = scaleNsByStepsData[0]["scalingDirection"]
 
-    return ns_InstanceId,aspect,numberOfSteps,scale_type
+    return ns_InstanceId, aspect, numberOfSteps, scale_type
+
 
 def get_scale_vnf_data(scaleNsData, ns_InstanceId):
     curdir_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
     filename = curdir_path + "/ns/data/scalemapping.json"
     logger.debug("filename = %s" % filename)
-    ns_InstanceId,aspect,numberOfSteps,scale_type = get_and_check_params(scaleNsData, ns_InstanceId)
-    return get_vnf_data(filename, ns_InstanceId,aspect,numberOfSteps,scale_type)
+    ns_InstanceId, aspect, numberOfSteps, scale_type = get_and_check_params(scaleNsData, ns_InstanceId)
+    return get_vnf_data(filename, ns_InstanceId, aspect, numberOfSteps, scale_type)
index 4f19d80..913d42b 100644 (file)
@@ -28,8 +28,8 @@ def deploy_workflow_on_startup():
         file_path = "TODO:"
         deploy_info = activiti.deploy_workflow(file_path)
         WFPlanModel(
-            deployed_id=deploy_info["deployedId"], 
-            process_id=deploy_info["processId"], 
+            deployed_id=deploy_info["deployedId"],
+            process_id=deploy_info["processId"],
             status=deploy_info["status"],
             message=deploy_info["message"],
             plan_name="ns_instantiate").save()
index cbc2185..e1e3cdd 100644 (file)
@@ -32,14 +32,14 @@ g_jobs_status = {}
 """
 format of input_data
 {
-    "jobId": uuid of job, 
+    "jobId": uuid of job,
     "nsInstanceId": id of ns instance,
     "object_context": json format of nsd,
     "object_additionalParamForNs": json format of additional parameters for ns,
     "object_additionalParamForVnf": json format of additional parameters for vnf,
     "vlCount": int type of VL count,
     "vnfCount: int type of VNF count,
-    "sfcCount": int type of SFC count, 
+    "sfcCount": int type of SFC count,
     "sdnControllerId": uuid of SDN controller
 }
 """
@@ -64,14 +64,14 @@ def run_ns_instantiate(input_data):
             create_vl(ns_inst_id, i + 1, nsd_json, ns_param_json)
 
         update_job(job_id, 30, "0", "Start to create VNF")
-        jobs = [create_vnf(ns_inst_id, i + 1, vnf_param_json) for i in range(vnf_count)] 
+        jobs = [create_vnf(ns_inst_id, i + 1, vnf_param_json) for i in range(vnf_count)]
         wait_until_jobs_done(job_id, jobs)
 
         [confirm_vnf_status(inst_id) for inst_id, _, _ in jobs]
 
         update_job(job_id, 70, "0", "Start to create SFC")
         g_jobs_status[job_id] = [1 for i in range(sfc_count)]
-        jobs = [create_sfc(ns_inst_id, i + 1, nsd_json, sdnc_id) for i in range(sfc_count)] 
+        jobs = [create_sfc(ns_inst_id, i + 1, nsd_json, sdnc_id) for i in range(sfc_count)]
         wait_until_jobs_done(job_id, jobs)
 
         [confirm_sfc_status(inst_id) for inst_id, _, _ in jobs]
@@ -161,7 +161,7 @@ def create_sfc(ns_inst_id, fp_index, nsd_json, sdnc_id):
 
 
 def post_deal(ns_inst_id, status):
-    uri = "api/nslcm/v1/ns/{nsInstanceId}/postdeal".format(nsInstanceId=ns_inst_id) 
+    uri = "api/nslcm/v1/ns/{nsInstanceId}/postdeal".format(nsInstanceId=ns_inst_id)
     data = json.JSONEncoder().encode({
         "status": status
     })
@@ -179,12 +179,12 @@ def update_job(job_id, progress, errcode, desc):
         "errcode": errcode,
         "desc": desc
     })
-    restcall.req_by_msb(uri, "POST", data)  
+    restcall.req_by_msb(uri, "POST", data)
 
 
 class JobWaitThread(Thread):
     """
-    Job Wait 
+    Job Wait
     """
     def __init__(self, inst_id, job_id, ns_job_id, index):
         Thread.__init__(self)
index c74f44d..5a91db3 100644 (file)
@@ -42,8 +42,8 @@ class WorkflowViewTest(unittest.TestCase):
             "processId": "4"
         }
         mock_upload_by_msb.return_value = [0, json.JSONEncoder().encode(res_data), '202']
-        response = self.client.post("/api/nslcm/v1/workflow", 
-            {"filePath": os.path.abspath(__file__)}, format='json')
+        response = self.client.post("/api/nslcm/v1/workflow",
+                                    {"filePath": os.path.abspath(__file__)}, format='json')
         self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
         self.assertEqual(1, len(WFPlanModel.objects.filter(deployed_id="3")))
 
@@ -61,16 +61,16 @@ class WorkflowViewTest(unittest.TestCase):
             "processId": "5"
         }), '202']
         WFPlanModel(deployed_id="1", process_id="2", status="3", message="4").save()
-        response = self.client.post("/api/nslcm/v1/workflow", 
-            {"filePath": os.path.abspath(__file__), "forceDeploy": "True"}, format='json')
+        response = self.client.post("/api/nslcm/v1/workflow",
+                                    {"filePath": os.path.abspath(__file__), "forceDeploy": "True"}, format='json')
         self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
         self.assertEqual(0, len(WFPlanModel.objects.filter(deployed_id="1")))
         self.assertEqual(1, len(WFPlanModel.objects.filter(deployed_id="4")))
 
     def test_deploy_workflow_when_already_deployed(self):
         WFPlanModel(deployed_id="1", process_id="2", status="3", message="4").save()
-        response = self.client.post("/api/nslcm/v1/workflow", 
-            {"filePath": os.path.abspath(__file__)}, format='json')
+        response = self.client.post("/api/nslcm/v1/workflow",
+                                    {"filePath": os.path.abspath(__file__)}, format='json')
         self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
         self.assertEqual({'msg': 'Already deployed.'}, json.loads(response.content))
 
@@ -126,9 +126,9 @@ class WorkflowViewTest(unittest.TestCase):
                     "progress": 100,
                     "statusDescription": "ok"
                 }}), '200'],
-            "api/nslcm/v1/jobs/{jobId}".format(jobId=job_id): 
+            "api/nslcm/v1/jobs/{jobId}".format(jobId=job_id):
                 [0, '{}', '201'],
-            "api/nslcm/v1/ns/{nsInstanceId}/postdeal".format(nsInstanceId=ns_inst_id): 
+            "api/nslcm/v1/ns/{nsInstanceId}/postdeal".format(nsInstanceId=ns_inst_id):
                 [0, '{}', '201']
         }
 
index 8e48acb..26b6fd4 100644 (file)
@@ -47,8 +47,8 @@ def deploy_workflow(request, *args, **kwargs):
                 return Response(data={'msg': 'Already deployed.'}, status=status.HTTP_202_ACCEPTED)
         deploy_info = activiti.deploy_workflow(file_path)
         WFPlanModel(
-            deployed_id=deploy_info["deployedId"], 
-            process_id=deploy_info["processId"], 
+            deployed_id=deploy_info["deployedId"],
+            process_id=deploy_info["processId"],
             status=deploy_info["status"],
             message=deploy_info["message"],
             plan_name="ns_instantiate").save()