X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=lcm%2Fns%2Fbiz%2Fns_heal.py;h=8ca033fcee288ef594917fd4eb94749e93fc08dd;hb=f0c32021572945e00a30570d2323babb03401d16;hp=be069cbd0a31ff4fe4fd245344e02e302be3976a;hpb=90662f422e118d17cbe8714a32747532514922da;p=vfc%2Fnfvo%2Flcm.git diff --git a/lcm/ns/biz/ns_heal.py b/lcm/ns/biz/ns_heal.py index be069cbd..8ca033fc 100644 --- a/lcm/ns/biz/ns_heal.py +++ b/lcm/ns/biz/ns_heal.py @@ -21,12 +21,12 @@ import traceback from lcm.ns.enum import NS_INST_STATUS from lcm.pub.database.models import JobModel, NSInstModel, NfInstModel, VNFCInstModel, VmInstModel from lcm.pub.exceptions import NSLCMException -from lcm.pub.utils.jobutil import JobUtil, JOB_MODEL_STATUS +from lcm.pub.utils.jobutil import JobUtil +from lcm.pub.enum import JOB_MODEL_STATUS, JOB_PROGRESS from lcm.pub.utils.values import ignore_case_get from lcm.ns_vnfs.biz.heal_vnfs import NFHealService from lcm.ns.biz.ns_lcm_op_occ import NsLcmOpOcc -JOB_ERROR = 255 logger = logging.getLogger(__name__) @@ -44,12 +44,12 @@ class NSHealService(threading.Thread): try: self.do_biz() except NSLCMException as e: - JobUtil.add_job_status(self.job_id, JOB_ERROR, e.message) - NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.message) + JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, e.args[0]) + NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.args[0]) except Exception as e: logger.error(traceback.format_exc()) - JobUtil.add_job_status(self.job_id, JOB_ERROR, 'ns heal fail') - NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.message) + JobUtil.add_job_status(self.job_id, JOB_PROGRESS.ERROR, 'ns heal fail') + NsLcmOpOcc.update(self.occ_id, operationState="FAILED", error=e.args[0]) def do_biz(self): self.update_job(1, desc='ns heal start') @@ -64,7 +64,6 @@ class NSHealService(threading.Thread): ns_info = NSInstModel.objects.filter(id=self.ns_instance_id) if not ns_info: errmsg = 'NS [id=%s] does not exist' % self.ns_instance_id - logger.error(errmsg) raise NSLCMException(errmsg) self.heal_ns_data = ignore_case_get(self.request_data, 'healNsData') @@ -77,7 +76,6 @@ class NSHealService(threading.Thread): if not self.heal_ns_data and not self.heal_vnf_data: errmsg = 'healNsData and healVnfData parameters does not exist or value is incorrect.' - logger.error(errmsg) raise NSLCMException(errmsg) def do_heal(self): @@ -85,23 +83,18 @@ class NSHealService(threading.Thread): vnf_heal_params = self.prepare_vnf_heal_params(self.heal_vnf_data) status = self.do_vnf_or_ns_heal(vnf_heal_params, 15) if status is JOB_MODEL_STATUS.FINISHED: - logger.info('nf[%s] heal handle end' % - vnf_heal_params.get('vnfInstanceId')) - self.update_job(90, - desc='nf[%s] heal handle end' % vnf_heal_params.get('vnfInstanceId')) + logger.info('nf[%s] heal handle end' % vnf_heal_params.get('vnfInstanceId')) + self.update_job(90, desc='nf[%s] heal handle end' % vnf_heal_params.get('vnfInstanceId')) else: errmsg = 'nf heal failed' - logger.error(errmsg) raise NSLCMException(errmsg) else: ns_heal_params = self.prepare_ns_heal_params(self.heal_ns_data) for ns_heal_param in ns_heal_params: status = self.do_vnf_or_ns_heal(ns_heal_param, 15) if status is JOB_MODEL_STATUS.FINISHED: - logger.info('nf[%s] heal handle end' % - ns_heal_param.get('vnfInstanceId')) - self.update_job(90, - desc='nf[%s] heal handle end' % ns_heal_param.get('vnfInstanceId')) + logger.info('nf[%s] heal handle end' % ns_heal_param.get('vnfInstanceId')) + self.update_job(90, desc='nf[%s] heal handle end' % ns_heal_param.get('vnfInstanceId')) else: errmsg = 'nf heal failed' logger.error(errmsg) @@ -123,37 +116,31 @@ class NSHealService(threading.Thread): logger.error(errmsg) raise NSLCMException(errmsg) ns_instance_id = self.ns_instance_id - cause = '' - action = ignore_case_get(ns_data, 'actionsHealing') + cause = 'vm is down' + # action = ignore_case_get(ns_data, 'actionsHealing') if degree_healing == "HEAL_RESTORE": - ns_inst_infos = NfInstModel.objects.filter( - ns_inst_id=self.ns_instance_id) + ns_inst_infos = NfInstModel.objects.filter(ns_inst_id=self.ns_instance_id) if not ns_inst_infos.exists(): - raise NSLCMException( - 'NSInsts(%s) does not exist' % self.ns_instance_id) - + raise NSLCMException('NSInsts(%s) does not exist' % self.ns_instance_id) result_arr = [] for ns_inst_info in ns_inst_infos: - vnfc_insts = VNFCInstModel.objects.filter( - nfinstid=ns_inst_info.nfinstid) + vnfc_insts = VNFCInstModel.objects.filter(nfinstid=ns_inst_info.nfinstid) # If a condition is not met, will it all terminate? if not vnfc_insts.exists(): - raise NSLCMException( - 'vnfcinsts(%s) does not exist' % ns_inst_info.nfinstid) + raise NSLCMException('vnfcinsts(%s) does not exist' % ns_inst_info.nfinstid) for vnfc_inst in vnfc_insts: vm_id = vnfc_inst.vmid vdu_id = vnfc_inst.vduid vm_inst_info = VmInstModel.objects.filter(vmid=vm_id) if not vm_inst_info.exists(): - raise NSLCMException( - 'vminstinfo(%s) does not exist' % vm_id) + raise NSLCMException('vminstinfo(%s) does not exist' % vm_id) vm_name = vm_inst_info[0].vmname result = { "vnfInstanceId": ns_instance_id, "cause": cause, "additionalParams": { - "action": action, + "action": "restartvm", "actionvminfo": { "vmid": vm_id, "vduid": vdu_id, @@ -204,9 +191,9 @@ class NSHealService(threading.Thread): job_result = JobModel.objects.get(jobid=sub_job_id) time.sleep(query_interval) end_time = datetime.datetime.now() - if job_result.progress == 100: + if job_result.progress == JOB_PROGRESS.FINISHED: return JOB_MODEL_STATUS.FINISHED - elif job_result.progress > 100: + elif job_result.progress > JOB_PROGRESS.FINISHED: return JOB_MODEL_STATUS.ERROR else: continue