From 45daac01d4a59f6bad4d36e2b5fe11788a7109a9 Mon Sep 17 00:00:00 2001 From: Philip Joseph Date: Fri, 30 Sep 2016 13:24:47 +0530 Subject: [PATCH] Fix blocking call to execute service primitive Signed-off-by: Philip Joseph --- .../python/rift/mano/config_agent/operdata.py | 20 +++++++++++++++-- common/python/rift/mano/utils/juju_api.py | 4 ++-- .../tasklets/rwconmantasklet/RiftCM_rpc.py | 22 +++++++------------ .../tasklets/rwnsmtasklet/rwnsm_conman.py | 2 +- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/common/python/rift/mano/config_agent/operdata.py b/common/python/rift/mano/config_agent/operdata.py index 551aea2d..0db3f3d9 100644 --- a/common/python/rift/mano/config_agent/operdata.py +++ b/common/python/rift/mano/config_agent/operdata.py @@ -406,9 +406,22 @@ class ConfigAgentJobMonitor(object): @asyncio.coroutine def _monitor_processes(self, registration_handle): result = 0 + errs = "" for process in self.job.tasks: - rc = yield from process - self.log.debug("Process {} returned rc: {}".format(process, rc)) + if isinstance(process, asyncio.subprocess.Process): + rc = yield from process.wait() + err = yield from process.stderr.read() + + else: + # Task instance + rc = yield from process + err = '' + + self.log.debug("Process {} returned rc: {}, err: {}". + format(process, rc, err)) + + if len(err): + errs += "{}".format(err) result |= rc if result == 0: @@ -416,6 +429,9 @@ class ConfigAgentJobMonitor(object): else: self.job.job_status = "failure" + if len(errs): + self.job.job.job_status_details = errs + registration_handle.update_element(self.job.xpath, self.job.job) def get_error_details(self): diff --git a/common/python/rift/mano/utils/juju_api.py b/common/python/rift/mano/utils/juju_api.py index 7ba53047..b452b8a5 100644 --- a/common/python/rift/mano/utils/juju_api.py +++ b/common/python/rift/mano/utils/juju_api.py @@ -360,8 +360,8 @@ class JujuApi(object): # Optimizing calls to Juju, as currently we deploy only 1 unit per # service. - if self.service == service and len(self.units): - return self.units + # if self.service == service and len(self.units): + # return self.units if env is None: env = self._get_env() diff --git a/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/RiftCM_rpc.py b/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/RiftCM_rpc.py index 91bc1ab5..5f330249 100644 --- a/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/RiftCM_rpc.py +++ b/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/RiftCM_rpc.py @@ -240,22 +240,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) 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) + 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): @@ -315,16 +313,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: diff --git a/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsm_conman.py b/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsm_conman.py index 01c0dcb2..e29f4911 100644 --- a/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsm_conman.py +++ b/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsm_conman.py @@ -62,7 +62,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, -- 2.25.1