Skip to content

Commit 7b3b83d

Browse files
committed
fix exec api inconsistency
Signed-off-by: Corentin Henry <[email protected]>
1 parent 41c0eb7 commit 7b3b83d

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

docker/utils/socket.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,21 @@ def consume_socket_output(frames, demux=False):
138138

139139
# If the streams are demultiplexed, the generator yields tuples
140140
# (stdout, stderr)
141-
out = [six.binary_type(), six.binary_type()]
141+
out = [None, None]
142142
for frame in frames:
143143
# It is guaranteed that for each frame, one and only one stream
144144
# is not None.
145145
assert frame != (None, None)
146146
if frame[0] is not None:
147-
out[0] += frame[0]
147+
if out[0] is None:
148+
out[0] = frame[0]
149+
else:
150+
out[0] += frame[0]
148151
else:
149-
out[1] += frame[1]
152+
if out[1] is None:
153+
out[1] = frame[1]
154+
else:
155+
out[1] += frame[1]
150156
return tuple(out)
151157

152158

tests/integration/api_exec_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def test_exec_command_demux(self):
134134
# tty=True, stream=False, demux=True
135135
res = self.client.exec_create(id, cmd, tty=True)
136136
exec_log = self.client.exec_start(res, demux=True)
137-
assert exec_log == (b'hello out\r\nhello err\r\n', b'')
137+
assert exec_log == (b'hello out\r\nhello err\r\n', None)
138138

139139
# tty=True, stream=True, demux=True
140140
res = self.client.exec_create(id, cmd, tty=True)

tests/unit/api_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ def test_read_from_socket_5(self):
574574

575575
def test_read_from_socket_6(self):
576576
res = self.request(stream=False, tty=True, demux=True)
577-
assert res == (self.stdout_data + self.stderr_data, b'')
577+
assert res == (self.stdout_data + self.stderr_data, None)
578578

579579
def test_read_from_socket_7(self):
580580
res = self.request(stream=False, tty=False, demux=False)

0 commit comments

Comments
 (0)