X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=rwcm%2Fplugins%2Frwconman%2Frift%2Ftasklets%2Frwconmantasklet%2Frwconman_config.py;h=4b010b6d8c869159e74b6a1a2f51ff8622ab8628;hb=e87945d31ee2d7085e025f61cc257e474c5408ff;hp=caf09b5ac1d2e0d34e7c025ea678146df322d783;hpb=df4e972f5e6581a85dd5a072ac4da8585b4c83e6;p=osm%2FSO.git diff --git a/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/rwconman_config.py b/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/rwconman_config.py index caf09b5a..4b010b6d 100644 --- a/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/rwconman_config.py +++ b/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/rwconman_config.py @@ -509,7 +509,7 @@ class ConfigManagerConfig(object): # Parse NSR if nsr is not None: - nsr_obj.set_nsr_name(nsr['nsd_name_ref']) + nsr_obj.set_nsr_name(nsr['name_ref']) nsr_dir = os.path.join(self._parent.cfg_dir, nsr_obj.nsr_name) self._log.info("Checking NS config directory: %s", nsr_dir) if not os.path.isdir(nsr_dir): @@ -678,10 +678,6 @@ class ConfigManagerConfig(object): if vnfr_name: inp['vnfr_name'] = vnfr_name - # TODO (pjoseph): Add config agents, we need to identify which all - # config agents are required from this NS and provide only those - inp['config-agent'] = {} - # Add parameters for initial config inp['parameter'] = {} for parameter in parameters: @@ -696,6 +692,20 @@ class ConfigManagerConfig(object): format(nsr_obj.nsr_name, parameter, e)) + # Add config agents specific to each VNFR + inp['config-agent'] = {} + for vnfr in nsr_obj.agent_nsr.vnfrs: + # Get the config agent for the VNFR + # If vnfr name is specified, add only CA specific to that + if (vnfr_name is None) or \ + (vnfr_name == vnfr.name): + agent = self._config_agent_mgr.get_vnfr_config_agent(vnfr.vnfr_msg) + if agent: + if agent.agent_type != riftcm_config_plugin.DEFAULT_CAP_TYPE: + inp['config-agent'][vnfr.member_vnf_index] = agent.agent_data + inp['config-agent'][vnfr.member_vnf_index] \ + ['service-name'] = agent.get_service_name(vnfr.id) + # Add vnfrs specific data inp['vnfr'] = {} for vnfr in nsr_obj.vnfrs: @@ -719,15 +729,18 @@ class ConfigManagerConfig(object): ) v['vdur'] = [] - vdu_data = [(vdu['name'], vdu['management_ip'], vdu['vm_management_ip'], vdu['id']) - for vdu in vnfr['vdur']] - - for data in vdu_data: - data = dict(zip(['name', 'management_ip', 'vm_management_ip', 'id'] , data)) - v['vdur'].append(data) + vdu_data = [] + for vdu in vnfr['vdur']: + d = {} + for k in ['name','management_ip', 'vm_management_ip', 'id', 'vdu_id_ref']: + if k in vdu: + d[k] = vdu[k] + vdu_data.append(d) + v['vdur'] = vdu_data inp['vnfr'][vnfr['member_vnf_index_ref']] = v + self._log.debug("Input data for {}: {}". format((vnfr_name if vnfr_name else nsr_obj.nsr_name), inp)) @@ -759,18 +772,24 @@ class ConfigManagerConfig(object): self._log.debug("Running the CMD: {}".format(cmd)) process = yield from asyncio.create_subprocess_shell(cmd, - loop=self._loop) - yield from process.wait() - - if process.returncode: - msg = "NSR/VNFR {} initial config using {} failed with {}". \ + loop=self._loop, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout, stderr = yield from process.communicate() + rc = yield from process.wait() + + if rc: + msg = "NSR/VNFR {} initial config using {} failed with {}: {}". \ format(vnfr_name if vnfr_name else nsr_obj.nsr_name, - script, process.returncode) + script, rc, stderr) self._log.error(msg) raise InitialConfigError(msg) - else: - # os.remove(inp_file) - pass + + try: + os.remove(inp_file) + except Exception as e: + self._log.debug("Error removing input file {}: {}". + format(inp_file, e)) def get_script_file(self, script_name, d_name, d_id, d_type): # Get the full path to the script @@ -789,7 +808,7 @@ class ConfigManagerConfig(object): script_name) self._log.debug("Checking for script at %s", script) if not os.path.exists(script): - self._log.debug("Did not find script %s", script) + self._log.warning("Did not find script %s", script) script = os.path.join(os.environ['RIFT_INSTALL'], 'usr/bin', script_name) @@ -799,9 +818,9 @@ class ConfigManagerConfig(object): # to make sure it has execute permission perm = os.stat(script).st_mode if not (perm & stat.S_IXUSR): - self._log.warn("NSR/VNFR {} initial config script {} " \ - "without execute permission: {}". - format(d_name, script, perm)) + self._log.warning("NSR/VNFR {} initial config script {} " \ + "without execute permission: {}". + format(d_name, script, perm)) os.chmod(script, perm | stat.S_IXUSR) return script @@ -831,13 +850,7 @@ class ConfigManagerConfig(object): vnfr_name = vnfr.name - vnfd = yield from self.cmdts_obj.get_vnfd(vnfr.vnfd_ref) - if vnfd is None: - msg = "VNFR {}, unable to get VNFD {}". \ - format(vnfr_name, vnfr.vnfd_ref) - self._log.error(msg) - raise InitialConfigError(msg) - + vnfd = vnfr.vnfd vnf_cfg = vnfd.vnf_configuration for conf in vnf_cfg.initial_config_primitive: @@ -850,8 +863,8 @@ class ConfigManagerConfig(object): continue script = self.get_script_file(conf.user_defined_script, - vnfd.id, vnfd.name, + vnfd.id, 'vnfd') yield from self.process_initial_config(nsr_obj,