Address python3 string issues with subprocess

This patch updates our Popen calls to enable universal newlines for
calls that we parse or consume the output for. Without
univeral_newlines=True, the output is treated as bytes under python3
which leads to issues later where we are using it as strings.

See https://docs.python.org/3/glossary.html#term-universal-newlines

Change-Id: Id0060a3abbcda8edb6124eb096cb824aaea48396
This commit is contained in:
Alex Schultz 2018-08-20 14:32:14 -06:00
parent 867867d141
commit 285b887da6
3 changed files with 10 additions and 5 deletions

View File

@ -143,7 +143,8 @@ class HeatBaseLauncher(object):
p = subprocess.Popen(['mount', '-t', 'tmpfs', '-o', 'size=500M',
'tmpfs', heatdir],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stderr=subprocess.PIPE,
universal_newlines=True)
cmd_stdout, cmd_stderr = p.communicate()
retval = p.returncode
if retval != 0:
@ -273,7 +274,8 @@ class HeatDockerLauncher(HeatBaseLauncher):
'getent', 'passwd', self.user
]
log.debug(' '.join(cmd))
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
universal_newlines=True)
result = p.communicate()[0]
if result:
return result.split(':')[2]
@ -286,7 +288,8 @@ class HeatDockerLauncher(HeatBaseLauncher):
'getent', 'group', self.user
]
log.debug(' '.join(cmd))
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
universal_newlines=True)
result = p.communicate()[0]
if result:
return result.split(':')[2]

View File

@ -1056,7 +1056,8 @@ def get_short_hostname():
:return string
"""
p = subprocess.Popen(["hostname", "-s"], stdout=subprocess.PIPE)
p = subprocess.Popen(["hostname", "-s"], stdout=subprocess.PIPE,
universal_newlines=True)
return p.communicate()[0].rstrip()

View File

@ -77,7 +77,8 @@ def _run_live_command(args, env=None, name=None, cwd=None, wait=True):
name = args[0]
process = subprocess.Popen(args, env=env, cwd=cwd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
stderr=subprocess.STDOUT,
universal_newlines=True)
if not wait:
return process