X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=rwcm%2Fplugins%2Frwconman%2Frift%2Ftasklets%2Frwconmantasklet%2Frwconman_config.py;h=9e8b944e40aa1fdc73628976a126984b1f222831;hb=8cc7ca95395fd8e7ff7297ab020ac9dbaa6e6c6e;hp=8b47e6bd630421af51fe8d9d871137602ca902cb;hpb=4ee26c373eae89ece72d4014876aa1ab0de6f538;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 8b47e6bd..9e8b944e 100644 --- a/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/rwconman_config.py +++ b/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/rwconman_config.py @@ -30,11 +30,14 @@ from gi.repository import ( ) import rift.tasklets +import rift.package.script +import rift.package.store from . import rwconman_conagent as conagent from . import RiftCM_rpc from . import riftcm_config_plugin + if sys.version_info < (3, 4, 4): asyncio.ensure_future = asyncio.async @@ -678,10 +681,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 +695,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: @@ -722,14 +735,15 @@ class ConfigManagerConfig(object): vdu_data = [] for vdu in vnfr['vdur']: d = {} - for k in ['name','management_ip', 'vm_management_ip', 'id']: + 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'].append(vdu_data) + 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)) @@ -761,51 +775,52 @@ 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 - script = '' - # If script name starts with /, assume it is full path - if script_name[0] == '/': - # The script has full path, use as is - script = script_name - else: - script = os.path.join(os.environ['RIFT_ARTIFACTS'], - 'launchpad/packages', - d_type, - d_id, - d_name, - 'scripts', - 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) - script = os.path.join(os.environ['RIFT_INSTALL'], - 'usr/bin', - script_name) - - # Seen cases in jenkins, where the script execution fails - # with permission denied. Setting the permission on script - # 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)) - os.chmod(script, perm | stat.S_IXUSR) - return script + if d_type == "vnfd": + package_store = rift.package.store.VnfdPackageFilesystemStore(self._log) + package_store.refresh() + elif d_type == "nsd": + package_store = rift.package.store.NsdPackageFilesystemStore(self._log) + package_store.refresh() + else: + raise + script_extractor = rift.package.script.PackageScriptExtractor(self._log) + script = script_extractor.get_extracted_script_path(d_id, script_name) + + self._log.debug("Checking for script at %s", script) + if not os.path.exists(script): + self._log.warning("Did not find script %s", script) + return + + # Seen cases in jenkins, where the script execution fails + # with permission denied. Setting the permission on script + # to make sure it has execute permission + perm = os.stat(script).st_mode + if not (perm & stat.S_IXUSR): + self._log.warning("NSR/VNFR {} script {} " \ + "without execute permission: {}". + format(d_name, script, perm)) + os.chmod(script, perm | stat.S_IXUSR) + return script @asyncio.coroutine def process_ns_initial_config(self, nsr_obj): @@ -837,17 +852,17 @@ class ConfigManagerConfig(object): vnf_cfg = vnfd.vnf_configuration for conf in vnf_cfg.initial_config_primitive: - self._log.debug("VNFR {} initial config: {}". - format(vnfr_name, conf)) + self._log.debug("VNFR {} initial config: {} for vnfd id {}". + format(vnfr_name, conf, vnfd.id)) if not conf.user_defined_script: - self._log.debug("VNFR {} did not fine user defined script: {}". + self._log.debug("VNFR {} did not find user defined script: {}". format(vnfr_name, conf)) 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,