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:
parent
867867d141
commit
285b887da6
|
@ -143,7 +143,8 @@ class HeatBaseLauncher(object):
|
||||||
p = subprocess.Popen(['mount', '-t', 'tmpfs', '-o', 'size=500M',
|
p = subprocess.Popen(['mount', '-t', 'tmpfs', '-o', 'size=500M',
|
||||||
'tmpfs', heatdir],
|
'tmpfs', heatdir],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE,
|
||||||
|
universal_newlines=True)
|
||||||
cmd_stdout, cmd_stderr = p.communicate()
|
cmd_stdout, cmd_stderr = p.communicate()
|
||||||
retval = p.returncode
|
retval = p.returncode
|
||||||
if retval != 0:
|
if retval != 0:
|
||||||
|
@ -273,7 +274,8 @@ class HeatDockerLauncher(HeatBaseLauncher):
|
||||||
'getent', 'passwd', self.user
|
'getent', 'passwd', self.user
|
||||||
]
|
]
|
||||||
log.debug(' '.join(cmd))
|
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]
|
result = p.communicate()[0]
|
||||||
if result:
|
if result:
|
||||||
return result.split(':')[2]
|
return result.split(':')[2]
|
||||||
|
@ -286,7 +288,8 @@ class HeatDockerLauncher(HeatBaseLauncher):
|
||||||
'getent', 'group', self.user
|
'getent', 'group', self.user
|
||||||
]
|
]
|
||||||
log.debug(' '.join(cmd))
|
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]
|
result = p.communicate()[0]
|
||||||
if result:
|
if result:
|
||||||
return result.split(':')[2]
|
return result.split(':')[2]
|
||||||
|
|
|
@ -1056,7 +1056,8 @@ def get_short_hostname():
|
||||||
|
|
||||||
:return string
|
: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()
|
return p.communicate()[0].rstrip()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,8 @@ def _run_live_command(args, env=None, name=None, cwd=None, wait=True):
|
||||||
name = args[0]
|
name = args[0]
|
||||||
process = subprocess.Popen(args, env=env, cwd=cwd,
|
process = subprocess.Popen(args, env=env, cwd=cwd,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT)
|
stderr=subprocess.STDOUT,
|
||||||
|
universal_newlines=True)
|
||||||
if not wait:
|
if not wait:
|
||||||
return process
|
return process
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue