summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2018-10-31 17:59:26 -0700
committerJoffrey F <joffrey@docker.com>2018-11-28 11:56:08 -0800
commit6777c28dee66915dea8facca577ebf42dce1b0bf (patch)
tree329d4766e34d1fd97789bbdbee54e736e2477f74
parent8c86aa90b1353bb9aa74f2a6ff19f9913104f42b (diff)
downloaddocker-py-6777c28dee66915dea8facca577ebf42dce1b0bf.tar.gz
Clear error for cancellable streams over SSH
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r--docker/types/daemon.py12
-rw-r--r--tests/integration/api_container_test.py5
-rw-r--r--tests/integration/models_containers_test.py3
3 files changed, 18 insertions, 2 deletions
diff --git a/docker/types/daemon.py b/docker/types/daemon.py
index ee8624e..700f9a9 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 249ef7c..02f3603 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 ab41ea5..b48f6fb 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(