diff options
author | Oleg Mitsura <oleg.mitsura@amdocs.com> | 2019-06-21 07:44:56 -0400 |
---|---|---|
committer | Oleg Mitsura <omitsura@gmail.com> | 2019-06-25 17:35:57 +0000 |
commit | c974b0293789c2b74d73dfb19e08fd233270f407 (patch) | |
tree | b31c84989230c9681042917403643ce5e1a0efa3 /ms/command-executor/src/main/python/command_executor_handler.py | |
parent | b3eb3fc950e6cda05d85d8422863b81bd0e766dd (diff) |
python-executor will provide output line-by-line
* python-executor STDOUT contains cleaner logs
* return status has been reworked to return a list
of lines
Issue-ID: CCSDK-1404
Signed-off-by: Oleg Mitsura <oleg.mitsura@amdocs.com>
Change-Id: Ib17495e92a136ff4f950bb6e049246a9e100eb7d
Diffstat (limited to 'ms/command-executor/src/main/python/command_executor_handler.py')
-rw-r--r-- | ms/command-executor/src/main/python/command_executor_handler.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/ms/command-executor/src/main/python/command_executor_handler.py b/ms/command-executor/src/main/python/command_executor_handler.py index a5951fdb3..365c00188 100644 --- a/ms/command-executor/src/main/python/command_executor_handler.py +++ b/ms/command-executor/src/main/python/command_executor_handler.py @@ -19,6 +19,7 @@ from subprocess import CalledProcessError, PIPE import logging import os import subprocess +import sys import virtualenv import venv import utils @@ -37,10 +38,7 @@ class CommandExecutorHandler(): self.installed = self.venv_home + '/.installed' def is_installed(self): - if os.path.exists(self.installed): - return True - else: - return False + return os.path.exists(self.installed) def prepare_env(self, request, results): if not self.is_installed(): @@ -78,7 +76,16 @@ class CommandExecutorHandler(): self.logger.info("Command: {}".format(cmd)) try: - results.append(os.popen(cmd).read()) + with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + shell=True, bufsize=1, universal_newlines=True) as newProcess: + while True: + output = newProcess.stdout.readline() + if output == '' and newProcess.poll() is not None: + break + if output: + self.logger.info(output.strip()) + results.append(output.strip()) + rc = newProcess.poll() except Exception as e: self.logger.info("{} - Failed to execute command. Error: {}".format(self.blueprint_id, e)) results.append(e) |