Skip to content

Commit 6bfe200

Browse files
committed
Clear error for cancellable streams over SSH
Signed-off-by: Joffrey F <[email protected]>
1 parent 94aa9a8 commit 6bfe200

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

docker/types/daemon.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
except ImportError:
66
import urllib3
77

8+
from ..errors import DockerException
9+
810

911
class CancellableStream(object):
1012
"""
@@ -55,9 +57,17 @@ def close(self):
5557
elif hasattr(sock_raw, '_sock'):
5658
sock = sock_raw._sock
5759

60+
elif hasattr(sock_fp, 'channel'):
61+
# We're working with a paramiko (SSH) channel, which doesn't
62+
# support cancelable streams with the current implementation
63+
raise DockerException(
64+
'Cancellable streams not supported for the SSH protocol'
65+
)
5866
else:
5967
sock = sock_fp._sock
60-
if isinstance(sock, urllib3.contrib.pyopenssl.WrappedSocket):
68+
69+
if hasattr(urllib3.contrib, 'pyopenssl') and isinstance(
70+
sock, urllib3.contrib.pyopenssl.WrappedSocket):
6171
sock = sock.socket
6272

6373
sock.shutdown(socket.SHUT_RDWR)

tests/integration/api_container_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,8 @@ def test_logs_streaming_and_follow(self):
883883
assert logs == (snippet + '\n').encode(encoding='ascii')
884884

885885
@pytest.mark.timeout(5)
886+
@pytest.mark.skipif(os.environ.get('DOCKER_HOST', '').startswith('ssh://'),
887+
reason='No cancellable streams over SSH')
886888
def test_logs_streaming_and_follow_and_cancel(self):
887889
snippet = 'Flowering Nights (Sakuya Iyazoi)'
888890
container = self.client.create_container(
@@ -1255,7 +1257,8 @@ def test_attach_no_stream(self):
12551257
assert output == 'hello\n'.encode(encoding='ascii')
12561258

12571259
@pytest.mark.timeout(5)
1258-
@pytest.mark.xfail(True, reason='Cancellable events broken over SSH')
1260+
@pytest.mark.skipif(os.environ.get('DOCKER_HOST', '').startswith('ssh://'),
1261+
reason='No cancellable streams over SSH')
12591262
def test_attach_stream_and_cancel(self):
12601263
container = self.client.create_container(
12611264
BUSYBOX, 'sh -c "echo hello && sleep 60"',

tests/integration/models_containers_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import tempfile
23
import threading
34

@@ -146,6 +147,8 @@ def test_run_with_streamed_logs(self):
146147
assert logs[1] == b'world\n'
147148

148149
@pytest.mark.timeout(5)
150+
@pytest.mark.skipif(os.environ.get('DOCKER_HOST', '').startswith('ssh://'),
151+
reason='No cancellable streams over SSH')
149152
def test_run_with_streamed_logs_and_cancel(self):
150153
client = docker.from_env(version=TEST_API_VERSION)
151154
out = client.containers.run(

0 commit comments

Comments
 (0)