X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=rwlaunchpad%2Fplugins%2Frwnsm%2Frift%2Ftasklets%2Frwnsmtasklet%2Frwnsm_conman.py;h=1f5599d381b71ebad04dfbaafd7b0f1b43c1d7bc;hb=f314b4af9744068a7ed7a6a6314220c3aa857523;hp=01c0dcb2a987cf831a988a2a637b49f8faa2ce00;hpb=6f07e6f33f751ab4ffe624f6037f887b243bece2;p=osm%2FSO.git diff --git a/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsm_conman.py b/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsm_conman.py index 01c0dcb2..1f5599d3 100644 --- a/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsm_conman.py +++ b/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsm_conman.py @@ -46,6 +46,7 @@ class ROConfigManager(object): self._loop = loop self._dts = dts self.nsm = parent + self.project = parent._project self._log.debug("Initialized ROConfigManager") def is_ready(self): @@ -53,7 +54,7 @@ class ROConfigManager(object): @property def cm_state_xpath(self): - return ("/rw-conman:cm-state/rw-conman:cm-nsr") + return self.project.add_project("/rw-conman:cm-state/rw-conman:cm-nsr") @classmethod def map_config_status(cls, status): @@ -62,7 +63,7 @@ class ROConfigManager(object): 'received': nsrY.ConfigStates.CONFIGURING, 'cfg_delay': nsrY.ConfigStates.CONFIGURING, 'cfg_process': nsrY.ConfigStates.CONFIGURING, - 'cfg_process-failed': nsrY.ConfigStates.CONFIGURING, + 'cfg_process_failed': nsrY.ConfigStates.CONFIGURING, 'cfg_sched': nsrY.ConfigStates.CONFIGURING, 'connecting': nsrY.ConfigStates.CONFIGURING, 'failed_connection': nsrY.ConfigStates.CONFIGURING, @@ -73,6 +74,7 @@ class ROConfigManager(object): 'cfg_failed': nsrY.ConfigStates.FAILED, 'ready_no_cfg': nsrY.ConfigStates.CONFIG_NOT_NEEDED, 'ready': nsrY.ConfigStates.CONFIGURED, + 'terminate': nsrY.ConfigStates.TERMINATE, } return cfg_map[status] @@ -83,29 +85,39 @@ class ROConfigManager(object): return try: - nsrid = cm_nsr['id'] + nsrid = cm_nsr.id # Update the VNFRs' config status - gen = [] - if 'cm_vnfr' in cm_nsr: - gen = (vnfr for vnfr in cm_nsr['cm_vnfr'] - if vnfr['id'] in self.nsm._vnfrs) + gen = (vnfr for vnfr in cm_nsr.cm_vnfr + if vnfr.id in self.nsm._vnfrs) for vnfr in gen: - vnfrid = vnfr['id'] - new_status = ROConfigManager.map_config_status(vnfr['state']) + vnfrid = vnfr.id + new_status = ROConfigManager.map_config_status(vnfr.state) self._log.debug("Updating config status of VNFR {} " \ "in NSR {} to {}({})". format(vnfrid, nsrid, new_status, - vnfr['state'])) + vnfr.state)) yield from \ self.nsm.vnfrs[vnfrid].set_config_status(new_status) + yield from \ + self.nsm.vnfrs[vnfrid].update_config_primitives( + vnfr.vnf_configuration, + self.nsm.nsrs[nsrid]) + # Update the NSR's config status - new_status = ROConfigManager.map_config_status(cm_nsr['state']) + new_status = ROConfigManager.map_config_status(cm_nsr.state) self._log.debug("Updating config status of NSR {} to {}({})". - format(nsrid, new_status, cm_nsr['state'])) - yield from self.nsm.nsrs[nsrid].set_config_status(new_status, cm_nsr.get('state_details')) + format(nsrid, new_status, cm_nsr.state)) + + # If terminate nsr request comes when NS instantiation is in + # 'Configuring state'; self.nsm.nsrs dict is already empty when + # self.nsm.nsrs[nsrid].set_config_status gets executed. So adding a check here. + if nsrid in self.nsm.nsrs: + yield from self.nsm.nsrs[nsrid].set_config_status( + new_status, + cm_nsr.state_details) except Exception as e: self._log.error("Failed to process cm-state for nsr {}: {}". @@ -115,12 +127,11 @@ class ROConfigManager(object): @asyncio.coroutine def register(self): """ Register for cm-state changes """ - + @asyncio.coroutine def on_prepare(xact_info, query_action, ks_path, msg): """ cm-state changed """ - #print("###>>> cm-state change ({}), msg_dict = {}".format(query_action, msg_dict)) self._log.debug("Received cm-state on_prepare (%s:%s:%s)", query_action, ks_path, @@ -129,10 +140,11 @@ class ROConfigManager(object): if (query_action == rwdts.QueryAction.UPDATE or query_action == rwdts.QueryAction.CREATE): # Update Each NSR/VNFR state - msg_dict = msg.as_dict() - yield from self.update_ns_cfg_state(msg_dict) + # msg_dict = msg.as_dict() + yield from self.update_ns_cfg_state(msg) elif query_action == rwdts.QueryAction.DELETE: - self._log.debug("DELETE action in on_prepare for cm-state, ignoring") + self._log.debug("DELETE action in on_prepare for cm-state, " + "ignoring") else: raise NotImplementedError( "%s on cm-state is not supported", @@ -141,10 +153,18 @@ class ROConfigManager(object): xact_info.respond_xpath(rwdts.XactRspCode.ACK) try: - handler = rift.tasklets.DTS.RegistrationHandler(on_prepare=on_prepare) - self.dts_reg_hdl = yield from self._dts.register(self.cm_state_xpath, - flags=rwdts.Flag.SUBSCRIBER, - handler=handler) + handler = rift.tasklets.DTS.RegistrationHandler( + on_prepare=on_prepare) + self.dts_reg_hdl = yield from self._dts.register( + self.cm_state_xpath, + flags=rwdts.Flag.SUBSCRIBER, + handler=handler) + except Exception as e: self._log.error("Failed to register for cm-state changes as %s", str(e)) - + + + def deregister(self): + if self.dts_reg_hdl: + self.dts_reg_hdl.deregister() + self.dts_reg_hdl = None