py3: decode stdout from backgrounded servers

Otherwise, when we go to print() it, we get a bunch of b"" strings.

Change-Id: If62da0b4b34b9d1396b5838bf79ff494679f1ae3
This commit is contained in:
Tim Burke 2019-08-05 14:51:14 -07:00
parent 489a35db82
commit ad7f7da32d
2 changed files with 10 additions and 7 deletions

View File

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

View File

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