Merge "Removing Popen object return from utils.run_command_and_log"
This commit is contained in:
commit
2fd3bd200c
|
@ -649,14 +649,3 @@ class TestRunCommandAndLog(TestCase):
|
|||
self.assertEqual(retcode, 0)
|
||||
self.mock_logger.debug.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.debug.assert_not_called()
|
||||
|
|
|
@ -603,8 +603,7 @@ def find_config_file(config_file_name='validation.cfg'):
|
|||
return current_path
|
||||
|
||||
|
||||
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
|
||||
|
@ -618,28 +617,23 @@ def run_command_and_log(log, cmd, cwd=None,
|
|||
|
||||
:param env: Modified environment for command run
|
||||
:type env: ``List``
|
||||
|
||||
:param retcode_only: Returns only retcode instead or proc object
|
||||
: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.debug(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.debug(line.rstrip())
|
||||
else:
|
||||
break
|
||||
proc.stdout.close()
|
||||
return proc.wait()
|
||||
|
||||
|
||||
def check_community_validations_dir(
|
||||
|
|
Loading…
Reference in New Issue