X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=rwcm%2Fplugins%2Frwconman%2Frift%2Ftasklets%2Frwconmantasklet%2FRiftCM_rpc.py;h=f622d5fbd3ec22a095bd7977d24ec37d9a858004;hb=f49375710db1acf3cd74c8651d098b7a08e8d0b2;hp=03756d87578ef6326bc27e136555df83aef176cd;hpb=1ada8dbd934164c007c5b81ea4273b4438350545;p=osm%2FSO.git diff --git a/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/RiftCM_rpc.py b/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/RiftCM_rpc.py index 03756d87..f622d5fb 100644 --- a/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/RiftCM_rpc.py +++ b/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/RiftCM_rpc.py @@ -42,17 +42,19 @@ class RiftCMRPCHandler(object): GET_NS_CONF_XPATH = "I,/nsr:get-ns-service-primitive-values" GET_NS_CONF_O_XPATH = "O,/nsr:get-ns-service-primitive-values" - def __init__(self, dts, log, loop, nsm): + def __init__(self, dts, log, loop, project, nsm): self._dts = dts self._log = log self._loop = loop + self._project = project self._nsm = nsm self._ns_regh = None self._vnf_regh = None self._get_ns_conf_regh = None - self.job_manager = rift.mano.config_agent.ConfigAgentJobManager(dts, log, loop, nsm) + self.job_manager = rift.mano.config_agent.ConfigAgentJobManager(dts, log, loop, + project, nsm) self._rift_install_dir = os.environ['RIFT_INSTALL'] self._rift_artif_dir = os.environ['RIFT_ARTIFACTS'] @@ -67,6 +69,16 @@ class RiftCMRPCHandler(object): """ Return the NS manager instance """ return self._nsm + def deregister(self): + self._log.debug("De-register conman rpc handlers for project {}". + format(self._project)) + for reg in self.reghs: + if reg: + reg.deregister() + reg = None + + self.job_manager.deregister() + def prepare_meta(self, rpc_ip): try: @@ -146,7 +158,7 @@ class RiftCMRPCHandler(object): for vnfr_id in agent_nsr.vnfr_ids: vnfr = agent_vnfrs[vnfr_id] - self._log.debug("CA_RPC: VNFR metadata: {}".format(vnfr)) + self._log.debug("CA-RPC: VNFR metadata: {}".format(vnfr)) # index->vnfr ref vnfr_index_map[vnfr.member_vnf_index] = vnfr_id @@ -189,8 +201,12 @@ class RiftCMRPCHandler(object): for primitive in vnfr.vnf_configuration['initial_config_primitive']: if 'parameter' in primitive: for parameter in primitive['parameter']: - value = xlate(parameter['value'], vnfr.tags) - param_data[parameter.name] = value + try: + value = xlate(parameter['value'], vnfr.tags) + param_data[parameter['name']] = value + except KeyError as e: + self._log.warn("Unable to parse the parameter{}: {}". + format(parameter)) initial_params[vnfr_id] = param_data @@ -207,7 +223,7 @@ class RiftCMRPCHandler(object): return config_plugin.agent_data return ret - unit_names, init_data, vnfr_index_map, vnf_data_map = get_meta(agent_nsr, agent_vnfrs) + unit_names, init_data, vnfr_index_map, vnfr_data_map = get_meta(agent_nsr, agent_vnfrs) # The data consists of 4 sections # 1. Account data @@ -227,7 +243,7 @@ class RiftCMRPCHandler(object): tmp_file.write(yaml.dump(data, default_flow_style=True) .encode("UTF-8")) - self._log.debug("CA_RPC: Creating a temp file {} with input data: {}". + self._log.debug("CA-RPC: Creating a temp file {} with input data: {}". format(tmp_file.name, data)) # Get the full path to the script @@ -236,22 +252,20 @@ class RiftCMRPCHandler(object): # The script has full path, use as is script = rpc_ip.user_defined_script else: - script = os.path.join(self._rift_artif_dir, 'launchpad/libs', agent_nsr.id, 'scripts', + script = os.path.join(self._rift_artif_dir, 'launchpad/packages/nsd', + agent_nsr.id, 'scripts', rpc_ip.user_defined_script) - self.log.debug("CA_RPC: Checking for script in %s", script) + self._log.debug("CA-RPC: Checking for script in %s", script) if not os.path.exists(script): script = os.path.join(self._rift_install_dir, 'usr/bin', rpc_ip.user_defined_script) - cmd = "{} {}".format(rpc_ip.user_defined_script, tmp_file.name) - self._log.debug("CA_RPC: Running the CMD: {}".format(cmd)) + cmd = "{} {}".format(script, tmp_file.name) + self._log.debug("CA-RPC: Running the CMD: {}".format(cmd)) - coro = asyncio.create_subprocess_shell(cmd, loop=self._loop, - stderr=asyncio.subprocess.PIPE) - process = yield from coro - err = yield from process.stderr.read() - task = self._loop.create_task(process.wait()) + process = asyncio.create_subprocess_shell(cmd, loop=self._loop, + stderr=asyncio.subprocess.PIPE) - return task, err + return process @asyncio.coroutine def register(self): @@ -262,6 +276,10 @@ class RiftCMRPCHandler(object): def on_ns_config_prepare(xact_info, action, ks_path, msg): """ prepare callback from dts exec-ns-service-primitive""" assert action == rwdts.QueryAction.RPC + + if not self._project.rpc_check(msg, xact_info): + return + rpc_ip = msg rpc_op = NsrYang.YangOutput_Nsr_ExecNsServicePrimitive.from_dict({ "triggered_by": rpc_ip.triggered_by, @@ -311,16 +329,12 @@ class RiftCMRPCHandler(object): if nsd_cfg_prim_msg and nsd_cfg_prim_msg.has_field("user_defined_script"): rpc_ip.user_defined_script = nsd_cfg_prim_msg.user_defined_script - tasks = [] - task, err = yield from self._apply_ns_config( + task = yield from self._apply_ns_config( nsr, vnfrs, rpc_ip) - tasks.append(task) - if err: - rpc_op.job_status_details = err.decode() - self.job_manager.add_job(rpc_op, tasks) + self.job_manager.add_job(rpc_op, [task]) else: # Otherwise create VNF primitives. for vnf in rpc_ip.vnf_list: @@ -391,6 +405,10 @@ class RiftCMRPCHandler(object): @asyncio.coroutine def on_get_ns_config_values_prepare(xact_info, action, ks_path, msg): assert action == rwdts.QueryAction.RPC + + if not self._project.rpc_check(msg, xact_info): + return + nsr_id = msg.nsr_id_ref cfg_prim_name = msg.name try: