- def get_script_file(script_name, nsd_name, nsd_id):
- # 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/nsd',
- nsd_id,
- nsd_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 {} initial config script {} " \
- "without execute permission: {}".
- format(nsr_id, script, perm))
- os.chmod(script, perm | stat.S_IXUSR)
- return script
-
- nsr_id = nsr_obj.nsr_id
- nsr_name = nsr_obj.nsr_name
- self._log.debug("Apply initial config for NSR {}({})".
- format(nsr_name, nsr_id))
-
- # Fetch NSR
- nsr = yield from self.cmdts_obj.get_nsr(nsr_id)
+ parameters = []
+ try:
+ parameters = conf['parameter']
+ except Exception as e:
+ self._log.debug("Parameter conf: {}, e: {}".
+ format(conf, e))
+
+ inp_file = get_input_file(parameters)
+
+ cmd = "{0} {1}".format(script, inp_file)
+ self._log.debug("Running the CMD: {}".format(cmd))
+
+ process = yield from asyncio.create_subprocess_shell(cmd,
+ 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, rc, stderr)
+ self._log.error(msg)
+ raise InitialConfigError(msg)
+
+ 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):
+ 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):
+ '''Apply the initial-config-primitives specified in NSD'''
+
+ nsr = yield from self.cmdts_obj.get_nsr(nsr_obj.nsr_id)
+ if 'initial_config_primitive' not in nsr:
+ return
+