Merge "Removing Popen object return from utils.run_command_and_log"
This commit is contained in:
commit
6e385b32c0
|
@ -561,17 +561,6 @@ class TestRunCommandAndLog(TestCase):
|
||||||
self.mock_logger.warning.assert_has_calls(self.log_calls,
|
self.mock_logger.warning.assert_has_calls(self.log_calls,
|
||||||
any_order=False)
|
any_order=False)
|
||||||
|
|
||||||
def test_success_no_retcode(self):
|
|
||||||
run = utils.run_command_and_log(self.mock_logger, self.cmd,
|
|
||||||
retcode_only=False)
|
|
||||||
self.mock_popen.assert_called_once_with(self.cmd,
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
stderr=subprocess.STDOUT,
|
|
||||||
shell=False,
|
|
||||||
cwd=None, env=None)
|
|
||||||
self.assertEqual(run, self.mock_process)
|
|
||||||
self.mock_logger.warning.assert_not_called()
|
|
||||||
|
|
||||||
|
|
||||||
class TestWaitForStackUtil(TestCase):
|
class TestWaitForStackUtil(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
|
@ -2141,7 +2141,7 @@ def bulk_symlink(log, src, dst, tmpd='/tmp'):
|
||||||
os.rename(tmpf, os.path.join(dst, obj))
|
os.rename(tmpf, os.path.join(dst, obj))
|
||||||
|
|
||||||
|
|
||||||
def run_command_and_log(log, cmd, cwd=None, env=None, retcode_only=True):
|
def run_command_and_log(log, cmd, cwd=None, env=None):
|
||||||
"""Run command and log output
|
"""Run command and log output
|
||||||
|
|
||||||
:param log: logger instance for logging
|
:param log: logger instance for logging
|
||||||
|
@ -2150,33 +2150,28 @@ def run_command_and_log(log, cmd, cwd=None, env=None, retcode_only=True):
|
||||||
:param cmd: command in list form
|
:param cmd: command in list form
|
||||||
:type cmd: List
|
:type cmd: List
|
||||||
|
|
||||||
:param cwd: current worknig directory for execution
|
:param cwd: current working directory for execution
|
||||||
:type cmd: String
|
:type cmd: String
|
||||||
|
|
||||||
:param env: modified environment for command run
|
:param env: modified environment for command run
|
||||||
:type env: List
|
:type env: List
|
||||||
|
|
||||||
:param retcode_only: Returns only retcode instead or proc objec
|
|
||||||
:type retcdode_only: Boolean
|
|
||||||
"""
|
"""
|
||||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT, shell=False,
|
stderr=subprocess.STDOUT, shell=False,
|
||||||
cwd=cwd, env=env)
|
cwd=cwd, env=env)
|
||||||
if retcode_only:
|
while True:
|
||||||
while True:
|
try:
|
||||||
try:
|
line = proc.stdout.readline()
|
||||||
line = proc.stdout.readline()
|
except StopIteration:
|
||||||
except StopIteration:
|
break
|
||||||
break
|
if line != b'':
|
||||||
if line != b'':
|
if isinstance(line, bytes):
|
||||||
if isinstance(line, bytes):
|
line = line.decode('utf-8')
|
||||||
line = line.decode('utf-8')
|
log.warning(line.rstrip())
|
||||||
log.warning(line.rstrip())
|
else:
|
||||||
else:
|
break
|
||||||
break
|
proc.stdout.close()
|
||||||
proc.stdout.close()
|
return proc.wait()
|
||||||
return proc.wait()
|
|
||||||
return proc
|
|
||||||
|
|
||||||
|
|
||||||
def build_prepare_env(environment_files, environment_directories):
|
def build_prepare_env(environment_files, environment_directories):
|
||||||
|
|
Loading…
Reference in New Issue