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
changes/03/593903/3
Alex Schultz 4 years ago
parent 867867d141
commit 285b887da6
  1. 9
      tripleoclient/heat_launcher.py
  2. 3
      tripleoclient/utils.py
  3. 3
      tripleoclient/v1/undercloud_preflight.py

@ -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]

@ -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()

@ -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

Loading…
Cancel
Save