diff --git a/docker/types/daemon.py b/docker/types/daemon.py index ee8624e8..700f9a90 100644 --- a/docker/types/daemon.py +++ b/docker/types/daemon.py @@ -5,6 +5,8 @@ try: except ImportError: import urllib3 +from ..errors import DockerException + class CancellableStream(object): """ @@ -55,9 +57,17 @@ class CancellableStream(object): elif hasattr(sock_raw, '_sock'): sock = sock_raw._sock + elif hasattr(sock_fp, 'channel'): + # We're working with a paramiko (SSH) channel, which doesn't + # support cancelable streams with the current implementation + raise DockerException( + 'Cancellable streams not supported for the SSH protocol' + ) else: sock = sock_fp._sock - if isinstance(sock, urllib3.contrib.pyopenssl.WrappedSocket): + + if hasattr(urllib3.contrib, 'pyopenssl') and isinstance( + sock, urllib3.contrib.pyopenssl.WrappedSocket): sock = sock.socket sock.shutdown(socket.SHUT_RDWR) diff --git a/tests/integration/api_container_test.py b/tests/integration/api_container_test.py index 249ef7cf..02f36033 100644 --- a/tests/integration/api_container_test.py +++ b/tests/integration/api_container_test.py @@ -883,6 +883,8 @@ Line2''' assert logs == (snippet + '\n').encode(encoding='ascii') @pytest.mark.timeout(5) + @pytest.mark.skipif(os.environ.get('DOCKER_HOST', '').startswith('ssh://'), + reason='No cancellable streams over SSH') def test_logs_streaming_and_follow_and_cancel(self): snippet = 'Flowering Nights (Sakuya Iyazoi)' container = self.client.create_container( @@ -1255,7 +1257,8 @@ class AttachContainerTest(BaseAPIIntegrationTest): assert output == 'hello\n'.encode(encoding='ascii') @pytest.mark.timeout(5) - @pytest.mark.xfail(True, reason='Cancellable events broken over SSH') + @pytest.mark.skipif(os.environ.get('DOCKER_HOST', '').startswith('ssh://'), + reason='No cancellable streams over SSH') def test_attach_stream_and_cancel(self): container = self.client.create_container( BUSYBOX, 'sh -c "echo hello && sleep 60"', diff --git a/tests/integration/models_containers_test.py b/tests/integration/models_containers_test.py index ab41ea57..b48f6fb6 100644 --- a/tests/integration/models_containers_test.py +++ b/tests/integration/models_containers_test.py @@ -1,3 +1,4 @@ +import os import tempfile import threading @@ -146,6 +147,8 @@ class ContainerCollectionTest(BaseIntegrationTest): assert logs[1] == b'world\n' @pytest.mark.timeout(5) + @pytest.mark.skipif(os.environ.get('DOCKER_HOST', '').startswith('ssh://'), + reason='No cancellable streams over SSH') def test_run_with_streamed_logs_and_cancel(self): client = docker.from_env(version=TEST_API_VERSION) out = client.containers.run(