X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=lcm%2Flcm%2Fnf%2Fbiz%2Finstantiate_vnf.py;h=13b29ead61823c2adfd9475865882f6513b1ebb1;hb=0457e5473e7eb27a21e7ec811ea38b23f2fba690;hp=3f4e9a3bc2747909e42ca96d338ad36937870a12;hpb=0f4bfe2b55a7af210652e43e729c400fbfd6be4f;p=vfc%2Fgvnfm%2Fvnflcm.git diff --git a/lcm/lcm/nf/biz/instantiate_vnf.py b/lcm/lcm/nf/biz/instantiate_vnf.py index 3f4e9a3b..13b29ead 100644 --- a/lcm/lcm/nf/biz/instantiate_vnf.py +++ b/lcm/lcm/nf/biz/instantiate_vnf.py @@ -19,6 +19,7 @@ from threading import Thread from lcm.pub.database.models import NfInstModel from lcm.pub.exceptions import NFLCMException +from lcm.pub.exceptions import NFLCMExceptionConflict from lcm.pub.msapi.gvnfmdriver import prepare_notification_data from lcm.pub.msapi.gvnfmdriver import notify_lcm_to_nfvo from lcm.pub.msapi.sdc_run_catalog import query_vnfpackage_by_id @@ -31,6 +32,7 @@ from lcm.nf.biz.grant_vnf import grant_resource from lcm.nf.const import CHANGE_TYPE, GRANT_TYPE, OPERATION_TYPE from lcm.nf.const import OPERATION_TASK from lcm.nf.const import OPERATION_STATE_TYPE +from lcm.nf.const import SUB_OPERATION_TASK from lcm.nf.biz import common from .operate_vnf_lcm_op_occ import VnfLcmOpOcc @@ -43,7 +45,13 @@ class InstantiateVnf(Thread): self.data = data self.nf_inst_id = nf_inst_id self.job_id = job_id - self.vim_id = ignore_case_get(ignore_case_get(self.data, "additionalParams"), "vimId") + self.vim_id = ignore_case_get( + ignore_case_get( + self.data, + "additionalParams" + ), + "vimId" + ) self.grant_type = GRANT_TYPE.INSTANTIATE self.lcm_op_occ = VnfLcmOpOcc( vnf_inst_id=nf_inst_id, @@ -51,23 +59,48 @@ class InstantiateVnf(Thread): operation=OPERATION_TYPE.INSTANTIATE, task=OPERATION_TASK.INSTANTIATE ) + self.pre_deal() def run(self): try: self.inst_pre() self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.STARTING) self.apply_grant() + self.lcm_op_occ.upd( + sub_operation=SUB_OPERATION_TASK.GRANTED, + operation_state=OPERATION_STATE_TYPE.PROCESSING + ) self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.PROCESSING) self.create_res() self.lcm_notify() - JobUtil.add_job_status(self.job_id, 100, "Instantiate Vnf success.") + JobUtil.add_job_status( + self.job_id, + 100, + "Instantiate Vnf success." + ) + self.lcm_op_occ.upd( + sub_operation=SUB_OPERATION_TASK.SUCCESS, + operation_state=OPERATION_STATE_TYPE.COMPLETED + ) except NFLCMException as e: - self.vnf_inst_failed_handle(e.message) + self.vnf_inst_failed_handle(e.args[0]) + except NFLCMExceptionConflict as e: + self.vnf_inst_failed_handle(e.args[0]) except Exception as e: - logger.error(e.message) + logger.error(str(e)) logger.error(traceback.format_exc()) self.vnf_inst_failed_handle('unexpected exception') + def pre_deal(self): + logger.debug("Start pre deal for VNF instantiate_vnf task") + + vnf_is_in_processing, vnf_op = self.lcm_op_occ.is_in_processing() + if vnf_is_in_processing: + raise NFLCMExceptionConflict('VNF(%s) %s in processing.' % ( + self.nf_inst_id, vnf_op + )) + self.lcm_op_occ.add() + def inst_pre(self): vnf_insts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id) if not vnf_insts.exists(): @@ -82,9 +115,9 @@ class InstantiateVnf(Thread): input_parameters = [] inputs = ignore_case_get(self.data, "additionalParams") if inputs: - if isinstance(inputs, (str, unicode)): + if isinstance(inputs, str): inputs = json.loads(inputs) - for key, val in inputs.items(): + for key, val in list(inputs.items()): input_parameters.append({"key": key, "value": val}) vnf_package = query_vnfpackage_by_id(self.vnfd_id) pkg_info = ignore_case_get(vnf_package, "packageInfo") @@ -167,7 +200,7 @@ class InstantiateVnf(Thread): resp = notify_lcm_to_nfvo(json.dumps(notification_content)) logger.info('Lcm notify end, response %s' % resp) except Exception as e: - logger.error("Lcm instantiate notify failed: %s", e.message) + logger.error("Lcm instantiate notify failed: %s", e.args[0]) NotificationsUtil().send_notification(notification_content) def vnf_inst_failed_handle(self, error_msg): @@ -178,6 +211,14 @@ class InstantiateVnf(Thread): ) self.lcm_op_occ.notify_lcm(OPERATION_STATE_TYPE.FAILED, error_msg) JobUtil.add_job_status(self.job_id, 255, error_msg) + self.lcm_op_occ.upd( + sub_operation=SUB_OPERATION_TASK.ERROR, + operation_state=OPERATION_STATE_TYPE.FAILED, + error={ + "status": 500, + "detail": error_msg + } + ) def do_notify(self, res_type, ret): logger.info('Creating [%s] resource' % res_type)