From ad7f7da32d6f90aa49873f1021d18cd54daef102 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Mon, 5 Aug 2019 14:51:14 -0700 Subject: [PATCH] py3: decode stdout from backgrounded servers Otherwise, when we go to print() it, we get a bunch of b"" strings. Change-Id: If62da0b4b34b9d1396b5838bf79ff494679f1ae3 --- swift/common/manager.py | 3 +++ test/unit/common/test_manager.py | 14 +++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/swift/common/manager.py b/swift/common/manager.py index 978e2fbb6a..47f47d03b0 100644 --- a/swift/common/manager.py +++ b/swift/common/manager.py @@ -22,6 +22,7 @@ import signal import time import subprocess import re +import six from swift import gettext_ as _ import tempfile @@ -720,6 +721,8 @@ class Server(object): else: output = proc.stdout.read() proc.stdout.close() + if not six.PY2: + output = output.decode('utf8', 'backslashreplace') if kwargs.get('once', False): # if you don't want once to wait you can send it to the diff --git a/test/unit/common/test_manager.py b/test/unit/common/test_manager.py index 0b81822260..1191bd3710 100644 --- a/test/unit/common/test_manager.py +++ b/test/unit/common/test_manager.py @@ -1288,9 +1288,9 @@ class TestServer(unittest.TestCase): # setup pipe rfd, wfd = os.pipe() # subprocess connection to read stdout - self.stdout = os.fdopen(rfd) + self.stdout = os.fdopen(rfd, 'rb') # real process connection to write stdout - self._stdout = os.fdopen(wfd, 'w') + self._stdout = os.fdopen(wfd, 'wb') self.delay = delay self.finished = False self.returncode = None @@ -1317,9 +1317,9 @@ class TestServer(unittest.TestCase): pass def fail(self): - print('mock process started', file=self._stdout) + self._stdout.write(b'mock process started\n') sleep(self.delay) # perform setup processing - print('mock process failed to start', file=self._stdout) + self._stdout.write(b'mock process failed to start\n') self.close_stdout() def poll(self): @@ -1327,12 +1327,12 @@ class TestServer(unittest.TestCase): return self.returncode or None def run(self): - print('mock process started', file=self._stdout) + self._stdout.write(b'mock process started\n') sleep(self.delay) # perform setup processing - print('setup complete!', file=self._stdout) + self._stdout.write(b'setup complete!\n') self.close_stdout() sleep(self.delay) # do some more processing - print('mock process finished', file=self._stdout) + self._stdout.write(b'mock process finished\n') self.finished = True class MockTime(object):