diff options
-rw-r--r-- | lcm/ns/sfcs/urls.py | 6 | ||||
-rw-r--r-- | lcm/ns/sfcs/utils.py | 4 | ||||
-rw-r--r-- | lcm/ns/tests/vnfs/tests.py | 18 | ||||
-rw-r--r-- | lcm/ns/tests/vnfs/verify_test.py | 2 | ||||
-rw-r--r-- | lcm/ns/vnfs/create_vnfs.py | 23 | ||||
-rw-r--r-- | lcm/ns/vnfs/grant_vnfs.py | 10 | ||||
-rw-r--r-- | lcm/ns/vnfs/terminate_nfs.py | 10 | ||||
-rw-r--r-- | lcm/ns/vnfs/verify_vnfs.py | 20 | ||||
-rw-r--r-- | lcm/ns/vnfs/wait_job.py | 25 |
9 files changed, 61 insertions, 57 deletions
diff --git a/lcm/ns/sfcs/urls.py b/lcm/ns/sfcs/urls.py index 97252677..6b852567 100644 --- a/lcm/ns/sfcs/urls.py +++ b/lcm/ns/sfcs/urls.py @@ -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. diff --git a/lcm/ns/sfcs/utils.py b/lcm/ns/sfcs/utils.py index 04dd3179..61ccd0b0 100644 --- a/lcm/ns/sfcs/utils.py +++ b/lcm/ns/sfcs/utils.py @@ -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) diff --git a/lcm/ns/tests/vnfs/tests.py b/lcm/ns/tests/vnfs/tests.py index b54d92d6..b071a03f 100644 --- a/lcm/ns/tests/vnfs/tests.py +++ b/lcm/ns/tests/vnfs/tests.py @@ -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 } ] } diff --git a/lcm/ns/tests/vnfs/verify_test.py b/lcm/ns/tests/vnfs/verify_test.py index e2368fa4..532d5c1b 100644 --- a/lcm/ns/tests/vnfs/verify_test.py +++ b/lcm/ns/tests/vnfs/verify_test.py @@ -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): diff --git a/lcm/ns/vnfs/create_vnfs.py b/lcm/ns/vnfs/create_vnfs.py index 0639dc44..caaefc2d 100644 --- a/lcm/ns/vnfs/create_vnfs.py +++ b/lcm/ns/vnfs/create_vnfs.py @@ -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.') diff --git a/lcm/ns/vnfs/grant_vnfs.py b/lcm/ns/vnfs/grant_vnfs.py index bf5335fe..46041928 100644 --- a/lcm/ns/vnfs/grant_vnfs.py +++ b/lcm/ns/vnfs/grant_vnfs.py @@ -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": { diff --git a/lcm/ns/vnfs/terminate_nfs.py b/lcm/ns/vnfs/terminate_nfs.py index 14edc0f1..c88e844e 100644 --- a/lcm/ns/vnfs/terminate_nfs.py +++ b/lcm/ns/vnfs/terminate_nfs.py @@ -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.') diff --git a/lcm/ns/vnfs/verify_vnfs.py b/lcm/ns/vnfs/verify_vnfs.py index 8375acbd..2cc55a29 100644 --- a/lcm/ns/vnfs/verify_vnfs.py +++ b/lcm/ns/vnfs/verify_vnfs.py @@ -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 diff --git a/lcm/ns/vnfs/wait_job.py b/lcm/ns/vnfs/wait_job.py index 99b45076..a1788ef7 100644 --- a/lcm/ns/vnfs/wait_job.py +++ b/lcm/ns/vnfs/wait_job.py @@ -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 |