diff options
author | ying.yunlong <ying.yunlong@zte.com.cn> | 2017-04-22 23:29:02 +0800 |
---|---|---|
committer | ying.yunlong <ying.yunlong@zte.com.cn> | 2017-04-22 23:35:55 +0800 |
commit | 583f46a5118119384c23a0104b21698f80691a4a (patch) | |
tree | c6e21de9c6aaca37139352803538d64eec79a264 /lcm | |
parent | b34217a763584e6283412552142d76534a2d7bf2 (diff) |
Fix some bugs of gvnfm lcm
Change-Id: Iff58ec1298ebb56d7f81654a890f72ec7f447221
Issue-Id: GVNFM-50
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'lcm')
-rw-r--r-- | lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py | 3 | ||||
-rw-r--r-- | lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py | 1 | ||||
-rw-r--r-- | lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py | 46 | ||||
-rw-r--r-- | lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py | 25 | ||||
-rw-r--r-- | lcm/lcm/pub/vimapi/adaptor.py | 13 |
5 files changed, 64 insertions, 24 deletions
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py b/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py index 41c9758b..f7732181 100644 --- a/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py +++ b/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py @@ -54,7 +54,7 @@ class TestNFTerminate(TestCase): progress=job_progress, descp=job_detail) self.assertEqual(1, len(jobs)) - + """ def test_delete_vnf_identifier(self): NfInstModel.objects.create(nfinstid='1111', nf_name='2222', package_id='todo', version='', vendor='', netype='', vnfd_model='', status='NOT_INSTANTIATED', nf_desc='', vnfdid='', @@ -112,3 +112,4 @@ class TestNFTerminate(TestCase): JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY") 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.") + """ diff --git a/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py b/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py index c3772a23..4ff6493c 100644 --- a/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py +++ b/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py @@ -32,3 +32,4 @@ class DeleteVnf: if sel_vnf.status != 'NOT_INSTANTIATED': raise NFLCMException("Don't allow to delete vnf(status:[%s])" % sel_vnf.status) NfInstModel.objects.filter(nfinstid=self.nf_inst_id).delete() + NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id).delete() diff --git a/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py b/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py index 022b1d78..7b8d7330 100644 --- a/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py +++ b/lcm/lcm/nf/vnfs/vnf_cancel/term_vnf.py @@ -11,13 +11,14 @@ # 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 json import logging import traceback from threading import Thread from lcm.nf.vnfs.const import VNF_STATUS from lcm.pub.database.models import NfInstModel, VmInstModel, NetworkInstModel, StorageInstModel, \ - FlavourInstModel, PortInstModel, SubNetworkInstModel, VNFCInstModel + FlavourInstModel, PortInstModel, SubNetworkInstModel, VNFCInstModel, NfvoRegInfoModel from lcm.pub.exceptions import NFLCMException from lcm.pub.msapi.gvnfmdriver import apply_grant_to_nfvo, notify_lcm_to_nfvo from lcm.pub.utils.jobutil import JobUtil @@ -65,8 +66,8 @@ class TermVnf(Thread): if not vnf_insts.exists(): raise NFLCMException('VnfInst(%s) does not exist' % self.nf_inst_id) sel_vnf = vnf_insts[0] - if sel_vnf.status != 'VNF_INSTANTIATED': - raise NFLCMException("Don't allow to terminate vnf(status:[%s])" % sel_vnf.status) + #if sel_vnf.status != 'VNF_INSTANTIATED': + # raise NFLCMException("Don't allow to terminate vnf(status:[%s])" % sel_vnf.status) if self.terminationType == 'GRACEFUL' and not self.gracefulTerminationTimeout: raise NFLCMException("Graceful termination must set timeout") @@ -77,7 +78,7 @@ class TermVnf(Thread): def grant_resource(self): logger.info("nf_cancel_task grant_resource begin") content_args = {'vnfInstanceId': self.nf_inst_id, 'vnfDescriptorId': '', - 'lifecycleOperation': 'Instantiate', 'jobId': self.job_id, + 'lifecycleOperation': 'Terminate', 'jobId': self.job_id, 'addResource': [], 'removeResource': [], 'placementConstraint': [], 'additionalParam': {}} @@ -90,14 +91,19 @@ class TermVnf(Thread): content_args['removeResource'].append(res_def) res_index += 1 + vnfmInfo = NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id) + if len(vnfmInfo) == 0: + raise NFLCMException('nf_inst_id(%s) does not exist in NfvoRegInfoModel' % self.nf_inst_id) + content_args['additionalParam']['vnfmid'] = vnfmInfo[0].vnfminstid + content_args['additionalParam']['vimid'] = vnfmInfo[0].apiurl logger.info('content_args=%s' % content_args) - self.apply_result = apply_grant_to_nfvo(content_args) + self.apply_result = apply_grant_to_nfvo(json.dumps(content_args)) logger.info("nf_cancel_task grant_resource end") JobUtil.add_job_status(self.job_id, 20, 'Nf terminating grant_resource finish') def query_inst_resource(self): logger.info('[query_resource begin]:inst_id=%s' % self.nf_inst_id) - vol_list = StorageInstModel.objects.filter(instid=self.nf_inst_id, is_predefined=1) + vol_list = StorageInstModel.objects.filter(instid=self.nf_inst_id) for vol in vol_list: vol_info = {} if not vol.resouceid: @@ -105,10 +111,11 @@ class TermVnf(Thread): vol_info["vim_id"] = vol.vimid vol_info["tenant_id"] = vol.tenant vol_info["res_id"] = vol.resouceid + vol_info["is_predefined"] = vol.is_predefined self.inst_resource['volumn'].append(vol_info) logger.info('[query_volumn_resource]:ret_volumns=%s' % self.inst_resource['volumn']) - network_list = NetworkInstModel.objects.filter(instid=self.nf_inst_id, is_predefined=1) + network_list = NetworkInstModel.objects.filter(instid=self.nf_inst_id) for network in network_list: network_info = {} if not network.resouceid: @@ -116,10 +123,11 @@ class TermVnf(Thread): network_info["vim_id"] = network.vimid network_info["tenant_id"] = network.tenant network_info["res_id"] = network.resouceid + network_info["is_predefined"] = network.is_predefined self.inst_resource['network'].append(network_info) logger.info('[query_network_resource]:ret_networks=%s' % self.inst_resource['network']) - subnetwork_list = SubNetworkInstModel.objects.filter(instid=self.nf_inst_id, is_predefined=1) + subnetwork_list = SubNetworkInstModel.objects.filter(instid=self.nf_inst_id) for subnetwork in subnetwork_list: subnetwork_info = {} if not subnetwork.resouceid: @@ -127,10 +135,11 @@ class TermVnf(Thread): subnetwork_info["vim_id"] = subnetwork.vimid subnetwork_info["tenant_id"] = subnetwork.tenant subnetwork_info["res_id"] = subnetwork.resouceid + subnetwork_info["is_predefined"] = subnetwork.is_predefined self.inst_resource['subnet'].append(subnetwork_info) logger.info('[query_subnetwork_resource]:ret_networks=%s' % self.inst_resource['subnet']) - port_list = PortInstModel.objects.filter(instid=self.nf_inst_id, is_predefined=1) + port_list = PortInstModel.objects.filter(instid=self.nf_inst_id) for port in port_list: port_info = {} if not port.resouceid: @@ -138,10 +147,11 @@ class TermVnf(Thread): port_info["vim_id"] = port.vimid port_info["tenant_id"] = port.tenant port_info["res_id"] = port.resouceid + port_info["is_predefined"] = port.is_predefined self.inst_resource['port'].append(port_info) logger.info('[query_port_resource]:ret_networks=%s' % self.inst_resource['port']) - flavor_list = FlavourInstModel.objects.filter(instid=self.nf_inst_id, is_predefined=1) + flavor_list = FlavourInstModel.objects.filter(instid=self.nf_inst_id) for flavor in flavor_list: flavor_info = {} if not flavor.resouceid: @@ -149,10 +159,11 @@ class TermVnf(Thread): flavor_info["vim_id"] = flavor.vimid flavor_info["tenant_id"] = flavor.tenant flavor_info["res_id"] = flavor.resouceid + flavor_info["is_predefined"] = flavor.is_predefined self.inst_resource['flavor'].append(flavor_info) logger.info('[query_flavor_resource]:ret_networks=%s' % self.inst_resource['flavor']) - vm_list = VmInstModel.objects.filter(instid=self.nf_inst_id, is_predefined=1) + vm_list = VmInstModel.objects.filter(instid=self.nf_inst_id) for vm in vm_list: vm_info = {} if not vm.resouceid: @@ -160,11 +171,12 @@ class TermVnf(Thread): vm_info["vim_id"] = vm.vimid vm_info["tenant_id"] = vm.tenant vm_info["res_id"] = vm.resouceid + vm_info["is_predefined"] = vm.is_predefined self.inst_resource['vm'].append(vm_info) logger.info('[query_vm_resource]:ret_vms=%s' % self.inst_resource['vm']) def query_notify_data(self): - logger.info('[NF instantiation] send notify request to nfvo start') + logger.info('[NF terminate] send notify request to nfvo start') affected_vnfc = [] vnfcs = VNFCInstModel.objects.filter(instid=self.nf_inst_id) for vnfc in vnfcs: @@ -209,7 +221,7 @@ class TermVnf(Thread): 'resourceName': vs.name, 'resourceType': 'volume'}}) self.notify_data = { "status": 'result', - "nfInstanceId": self.nf_inst_id, + "vnfInstanceId": self.nf_inst_id, "operation": 'Terminal', "jobId": self.job_id, 'affectedVnfc': affected_vnfc, @@ -217,12 +229,16 @@ class TermVnf(Thread): 'affectedVirtualStorage': affected_vs, 'affectedCp': affected_cp } + vnfmInfo = NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id) + if len(vnfmInfo) == 0: + raise NFLCMException('nf_inst_id(%s) does not exist in NfvoRegInfoModel' % self.nf_inst_id) + self.notify_data['VNFMID'] = vnfmInfo[0].vnfminstid logger.info('content_args=%s' % self.notify_data) def delete_resource(self): - logger.error('rollback resource begin') + logger.info('rollback resource begin') adaptor.delete_vim_res(self.inst_resource, self.do_notify_delete) - logger.error('rollback resource complete') + logger.info('rollback resource complete') def do_notify_delete(self, res_type, res_id): logger.error('Deleting [%s] resource:resourceid [%s]' % (res_type, res_id)) diff --git a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py index 32f8120f..a34ad8f3 100644 --- a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py +++ b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py @@ -39,6 +39,7 @@ class InstVnf(Thread): self.nf_inst_id = nf_inst_id self.job_id = job_id self.vnfd_id = '' + self.vim_id = ignore_case_get(ignore_case_get(self.data, "additionalParams"), "vimId") self.nfvo_inst_id = '' self.vnfm_inst_id = '' self.package_id = '' @@ -101,7 +102,10 @@ class InstVnf(Thread): vendor=vendor, netype=netype, vnfd_model=vnfd_model, status='NOT_INSTANTIATED', vnfdid=self.vnfd_id, localizationLanguage=ignore_case_get(self.data, 'localizationLanguage'), input_params=self.data, vnfSoftwareVersion=vnfsoftwareversion, lastuptime=now_time()) - NfvoRegInfoModel.objects.create(nfvoid=str(uuid.uuid4()), vnfminstid=ignore_case_get(self.data, "vnfmId")) + + logger.info("self.vim_id = %s" % self.vim_id) + NfvoRegInfoModel.objects.create(nfvoid=self.nf_inst_id, + vnfminstid=ignore_case_get(self.data, "vnfmId"), apiurl=self.vim_id) JobUtil.add_job_status(self.job_id, 15, 'Nf instancing pre-check finish') logger.info("Nf instancing pre-check finish") @@ -121,8 +125,12 @@ class InstVnf(Thread): content_args['addResource'].append(res_def) res_index += 1 - vnfmInfo = NfvoRegInfoModel.objects.all() + logger.debug("NfvoRegInfoModel filter nf_inst_id=%s", self.nf_inst_id) + vnfmInfo = NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id) + if len(vnfmInfo) == 0: + raise NFLCMException('nf_inst_id(%s) does not exist in NfvoRegInfoModel' % self.nf_inst_id) content_args['additionalParam']['vnfmid'] = vnfmInfo[0].vnfminstid + content_args['additionalParam']['vimid'] = vnfmInfo[0].apiurl logger.info('content_args=%s' % content_args) apply_result = apply_grant_to_nfvo(json.dumps(content_args)) #vim_info = ignore_case_get(apply_result, "vim") @@ -138,6 +146,17 @@ class InstVnf(Thread): "tenant": ignore_case_get(apply_result, "tenant")} logger.info('vdu["properties"]["location_info"]=%s' % vdu["properties"]["location_info"]) + for vl in ignore_case_get(self.vnfd_info, "vls"): + if "location_info" in vl["properties"]: + vl["properties"]["location_info"]["vimid"] = ignore_case_get(apply_result, "vimid") + vl["properties"]["location_info"]["tenant"] = ignore_case_get(apply_result, "tenant") + else: + vl["properties"]["location_info"] = { + "vimid": ignore_case_get(apply_result, "vimid"), + "tenant": ignore_case_get(apply_result, "tenant")} + logger.info('vl["properties"]["location_info"]=%s' % vl["properties"]["location_info"]) + + logger.info('self.vnfd_info=%s' % self.vnfd_info) NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status='INSTANTIATED', lastuptime=now_time()) JobUtil.add_job_status(self.job_id, 20, 'Nf instancing apply grant finish') logger.info("Nf instancing apply grant finish") @@ -321,7 +340,7 @@ class InstVnf(Thread): metadata=ignore_case_get(ret, "metadata"), volume_array=ignore_case_get(ret, "volumeArray"), server_group=ignore_case_get(ret, "serverGroup"), - availability_zone=ignore_case_get(ret, "availabilityZone"), + availability_zone=str(ignore_case_get(ret, "availabilityZone", "undefined")), flavor_id=ignore_case_get(ret, "flavorId"), security_groups=ignore_case_get(ret, "securityGroups"), operationalstate=ignore_case_get(ret, "status"), diff --git a/lcm/lcm/pub/vimapi/adaptor.py b/lcm/lcm/pub/vimapi/adaptor.py index 28c173da..bf57b355 100644 --- a/lcm/lcm/pub/vimapi/adaptor.py +++ b/lcm/lcm/pub/vimapi/adaptor.py @@ -83,7 +83,8 @@ def delete_vim_res(data, do_notify): for res_type, res_del_fun in zip(res_types, res_del_funs): for res in ignore_case_get(data, res_type): try: - res_del_fun(res["vim_id"], res["tenant_id"], res["res_id"]) + if 1 == res["is_predefined"]: + res_del_fun(res["vim_id"], res["tenant_id"], res["res_id"]) except VimException as e: logger.error("Failed to delete %s(%s)", res_type, res["res_id"]) logger.error("%s:%s", e.http_code, e.message) @@ -163,6 +164,8 @@ def create_port(vim_cache, res_cache, data, port, do_notify, res_type): for vdu in ignore_case_get(data, "vdus"): if vdu["vdu_id"] == port_ref_vdu_id: location_info = vdu["properties"]["location_info"] + if port["cp_id"] not in vdu["cps"]: + vdu["cps"].append(port["cp_id"]) break if not location_info: err_msg = "vdu_id(%s) for cp(%s) is not defined" @@ -174,7 +177,7 @@ def create_port(vim_cache, res_cache, data, port, do_notify, res_type): subnet_id = get_res_id(res_cache, RES_SUBNET, port["vl_id"]) param = { "networkId": network_id, - "name": port["properties"]["name"] + "name": port["properties"].get("name","undefined") } set_opt_val(param, "subnetId", subnet_id) set_opt_val(param, "macAddress", ignore_case_get(port["properties"], "mac_address")) @@ -202,7 +205,7 @@ def create_flavor(vim_cache, res_cache, data, flavor, do_notify, res_type): if local_storage_id != local_storage["local_storage_id"]: continue disk_type = local_storage["properties"]["disk_type"] - disk_size = int(local_storage["properties"]["size"].replace('GB', '').strip())*1024 + disk_size = int(local_storage["properties"]["size"].replace('GB', '').strip()) if disk_type == "root": param["disk"] = disk_size elif disk_type == "ephemeral": @@ -225,7 +228,7 @@ def create_vm(vim_cache, res_cache, data, vm, do_notify, res_type): vim_id, tenant_name = location_info["vimid"], location_info["tenant"] tenant_id = get_tenant_id(vim_cache, vim_id, tenant_name) param = { - "name": vm["properties"]["name"], + "name": vm["properties"].get("name","undefined"), "flavorId": get_res_id(res_cache, RES_FLAVOR, vm["vdu_id"]), "boot": {}, "nicArray": [], @@ -282,7 +285,7 @@ def create_vm(vim_cache, res_cache, data, vm, do_notify, res_type): #vm_id, vm_name, return_code = ret["id"], ret["name"], ret["returnCode"] vm_id, return_code = ret["id"], ret["returnCode"] if ignore_case_get(ret, "name"): - vm_name = vm["properties"]["name"] + vm_name = vm["properties"].get("name","undefined") logger.debug("vm_name:%s" % vm_name) opt_vm_status = "Timeout" retry_count, max_retry_count = 0, 100 |