Merge "Removing Popen object return from utils.run_command_and_log"

This commit is contained in:
Zuul 2022-08-05 19:23:58 +00:00 committed by Gerrit Code Review
commit 6e385b32c0
2 changed files with 15 additions and 31 deletions

View File

@ -561,17 +561,6 @@ class TestRunCommandAndLog(TestCase):
self.mock_logger.warning.assert_has_calls(self.log_calls,
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):
def setUp(self):

View File

@ -2141,7 +2141,7 @@ def bulk_symlink(log, src, dst, tmpd='/tmp'):
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
: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
:type cmd: List
:param cwd: current worknig directory for execution
:param cwd: current working directory for execution
:type cmd: String
:param env: modified environment for command run
:type env: List
:param retcode_only: Returns only retcode instead or proc objec
:type retcdode_only: Boolean
"""
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, shell=False,
cwd=cwd, env=env)
if retcode_only:
while True:
try:
line = proc.stdout.readline()
except StopIteration:
break
if line != b'':
if isinstance(line, bytes):
line = line.decode('utf-8')
log.warning(line.rstrip())
else:
break
proc.stdout.close()
return proc.wait()
return proc
while True:
try:
line = proc.stdout.readline()
except StopIteration:
break
if line != b'':
if isinstance(line, bytes):
line = line.decode('utf-8')
log.warning(line.rstrip())
else:
break
proc.stdout.close()
return proc.wait()
def build_prepare_env(environment_files, environment_directories):