Commit c01e9bd9 authored by Zuul's avatar Zuul Committed by Gerrit Code Review

Merge "py3: decode stdout from backgrounded servers"

parents 01596bd7 ad7f7da3
...@@ -22,6 +22,7 @@ import signal ...@@ -22,6 +22,7 @@ import signal
import time import time
import subprocess import subprocess
import re import re
import six
from swift import gettext_ as _ from swift import gettext_ as _
import tempfile import tempfile
...@@ -720,6 +721,8 @@ class Server(object): ...@@ -720,6 +721,8 @@ class Server(object):
else: else:
output = proc.stdout.read() output = proc.stdout.read()
proc.stdout.close() proc.stdout.close()
if not six.PY2:
output = output.decode('utf8', 'backslashreplace')
if kwargs.get('once', False): if kwargs.get('once', False):
# if you don't want once to wait you can send it to the # if you don't want once to wait you can send it to the
......
...@@ -1288,9 +1288,9 @@ class TestServer(unittest.TestCase): ...@@ -1288,9 +1288,9 @@ class TestServer(unittest.TestCase):
# setup pipe # setup pipe
rfd, wfd = os.pipe() rfd, wfd = os.pipe()
# subprocess connection to read stdout # subprocess connection to read stdout
self.stdout = os.fdopen(rfd) self.stdout = os.fdopen(rfd, 'rb')
# real process connection to write stdout # real process connection to write stdout
self._stdout = os.fdopen(wfd, 'w') self._stdout = os.fdopen(wfd, 'wb')
self.delay = delay self.delay = delay
self.finished = False self.finished = False
self.returncode = None self.returncode = None
...@@ -1317,9 +1317,9 @@ class TestServer(unittest.TestCase): ...@@ -1317,9 +1317,9 @@ class TestServer(unittest.TestCase):
pass pass
def fail(self): def fail(self):
print('mock process started', file=self._stdout) self._stdout.write(b'mock process started\n')
sleep(self.delay) # perform setup processing 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() self.close_stdout()
def poll(self): def poll(self):
...@@ -1327,12 +1327,12 @@ class TestServer(unittest.TestCase): ...@@ -1327,12 +1327,12 @@ class TestServer(unittest.TestCase):
return self.returncode or None return self.returncode or None
def run(self): def run(self):
print('mock process started', file=self._stdout) self._stdout.write(b'mock process started\n')
sleep(self.delay) # perform setup processing sleep(self.delay) # perform setup processing
print('setup complete!', file=self._stdout) self._stdout.write(b'setup complete!\n')
self.close_stdout() self.close_stdout()
sleep(self.delay) # do some more processing 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 self.finished = True
class MockTime(object): class MockTime(object):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment