Kaydet (Commit) e304f91b authored tarafından Joffrey F's avatar Joffrey F

Update detach tests to work with AF_INET as well

Signed-off-by: 's avatarJoffrey F <joffrey@docker.com>
üst dd858648
...@@ -54,7 +54,7 @@ integration-dind-py2: build ...@@ -54,7 +54,7 @@ integration-dind-py2: build
-H tcp://0.0.0.0:2375 --experimental -H tcp://0.0.0.0:2375 --experimental
docker run -t --rm --env="DOCKER_HOST=tcp://docker:2375" --env="DOCKER_TEST_API_VERSION=${TEST_API_VERSION}"\ docker run -t --rm --env="DOCKER_HOST=tcp://docker:2375" --env="DOCKER_TEST_API_VERSION=${TEST_API_VERSION}"\
--link=dpy-dind-py2:docker docker-sdk-python py.test tests/integration --link=dpy-dind-py2:docker docker-sdk-python py.test tests/integration
docker rm -vf dpy-dind-py3 docker rm -vf dpy-dind-py2
.PHONY: integration-dind-py3 .PHONY: integration-dind-py3
integration-dind-py3: build-py3 integration-dind-py3: build-py3
......
...@@ -6,8 +6,8 @@ import tarfile ...@@ -6,8 +6,8 @@ import tarfile
import tempfile import tempfile
import time import time
import re import re
import socket
import six import six
import socket
import docker import docker
import pytest import pytest
...@@ -107,16 +107,23 @@ def swarm_listen_addr(): ...@@ -107,16 +107,23 @@ def swarm_listen_addr():
return '0.0.0.0:{0}'.format(random.randrange(10000, 25000)) return '0.0.0.0:{0}'.format(random.randrange(10000, 25000))
def assert_socket_closed_with_keys(sock, inputs): def assert_cat_socket_detached_with_keys(sock, inputs):
if six.PY3: if six.PY3:
sock = sock._sock sock = sock._sock
for i in inputs: for i in inputs:
sock.send(i) sock.send(i)
time.sleep(1) time.sleep(0.5)
with pytest.raises(socket.error): # If we're using a Unix socket, the sock.send call will fail with a
# BrokenPipeError ; INET sockets will just stop receiving / sending data
# but will not raise an error
if sock.family == getattr(socket, 'AF_UNIX', -1):
with pytest.raises(socket.error):
sock.send(b'make sure the socket is closed\n')
else:
sock.send(b"make sure the socket is closed\n") sock.send(b"make sure the socket is closed\n")
assert sock.recv(32) == b''
def ctrl_with(char): def ctrl_with(char):
......
...@@ -17,7 +17,7 @@ import six ...@@ -17,7 +17,7 @@ import six
from .base import BUSYBOX, BaseAPIIntegrationTest from .base import BUSYBOX, BaseAPIIntegrationTest
from .. import helpers from .. import helpers
from ..helpers import ( from ..helpers import (
requires_api_version, ctrl_with, assert_socket_closed_with_keys requires_api_version, ctrl_with, assert_cat_socket_detached_with_keys
) )
...@@ -1227,55 +1227,54 @@ class AttachContainerTest(BaseAPIIntegrationTest): ...@@ -1227,55 +1227,54 @@ class AttachContainerTest(BaseAPIIntegrationTest):
def test_detach_with_default(self): def test_detach_with_default(self):
container = self.client.create_container( container = self.client.create_container(
BUSYBOX, '/bin/sh', BUSYBOX, 'cat',
detach=True, stdin_open=True, tty=True detach=True, stdin_open=True, tty=True
) )
id = container['Id'] self.tmp_containers.append(container)
self.tmp_containers.append(id) self.client.start(container)
self.client.start(id)
sock = self.client.attach_socket( sock = self.client.attach_socket(
container, container,
{'stdin': True, 'stream': True} {'stdin': True, 'stream': True}
) )
assert_socket_closed_with_keys(sock, [ctrl_with('p'), ctrl_with('q')]) assert_cat_socket_detached_with_keys(
sock, [ctrl_with('p'), ctrl_with('q')]
)
def test_detach_with_config_file(self): def test_detach_with_config_file(self):
self.client._general_configs['detachKeys'] = 'ctrl-p' self.client._general_configs['detachKeys'] = 'ctrl-p'
container = self.client.create_container( container = self.client.create_container(
BUSYBOX, '/bin/sh', BUSYBOX, 'cat',
detach=True, stdin_open=True, tty=True detach=True, stdin_open=True, tty=True
) )
id = container['Id'] self.tmp_containers.append(container)
self.tmp_containers.append(id) self.client.start(container)
self.client.start(id)
sock = self.client.attach_socket( sock = self.client.attach_socket(
container, container,
{'stdin': True, 'stream': True} {'stdin': True, 'stream': True}
) )
assert_socket_closed_with_keys(sock, [ctrl_with('p')]) assert_cat_socket_detached_with_keys(sock, [ctrl_with('p')])
def test_detach_with_arg(self): def test_detach_with_arg(self):
self.client._general_configs['detachKeys'] = 'ctrl-p' self.client._general_configs['detachKeys'] = 'ctrl-p'
container = self.client.create_container( container = self.client.create_container(
BUSYBOX, '/bin/sh', BUSYBOX, 'cat',
detach=True, stdin_open=True, tty=True detach=True, stdin_open=True, tty=True
) )
id = container['Id'] self.tmp_containers.append(container)
self.tmp_containers.append(id) self.client.start(container)
self.client.start(id)
sock = self.client.attach_socket( sock = self.client.attach_socket(
container, container,
{'stdin': True, 'stream': True, 'detachKeys': 'ctrl-x'} {'stdin': True, 'stream': True, 'detachKeys': 'ctrl-x'}
) )
assert_socket_closed_with_keys(sock, [ctrl_with('x')]) assert_cat_socket_detached_with_keys(sock, [ctrl_with('x')])
class PauseTest(BaseAPIIntegrationTest): class PauseTest(BaseAPIIntegrationTest):
......
...@@ -3,7 +3,7 @@ from docker.utils.socket import read_exactly ...@@ -3,7 +3,7 @@ from docker.utils.socket import read_exactly
from .base import BaseAPIIntegrationTest, BUSYBOX from .base import BaseAPIIntegrationTest, BUSYBOX
from ..helpers import ( from ..helpers import (
requires_api_version, ctrl_with, assert_socket_closed_with_keys requires_api_version, ctrl_with, assert_cat_socket_detached_with_keys
) )
...@@ -152,42 +152,54 @@ class ExecTest(BaseAPIIntegrationTest): ...@@ -152,42 +152,54 @@ class ExecTest(BaseAPIIntegrationTest):
assert exec_log == b'/var/www\n' assert exec_log == b'/var/www\n'
def test_detach_with_default(self): def test_detach_with_default(self):
container = self.client.create_container(BUSYBOX, 'cat', container = self.client.create_container(
detach=True, stdin_open=True) BUSYBOX, 'cat', detach=True, stdin_open=True
)
id = container['Id'] id = container['Id']
self.client.start(id) self.client.start(id)
self.tmp_containers.append(id) self.tmp_containers.append(id)
exec_id = self.client.exec_create(id, '/bin/sh', stdin=True, tty=True) exec_id = self.client.exec_create(
id, 'cat', stdin=True, tty=True, stdout=True
)
sock = self.client.exec_start(exec_id, tty=True, socket=True) sock = self.client.exec_start(exec_id, tty=True, socket=True)
self.addCleanup(sock.close)
assert_socket_closed_with_keys(sock, [ctrl_with('p'), ctrl_with('q')]) assert_cat_socket_detached_with_keys(
sock, [ctrl_with('p'), ctrl_with('q')]
)
def test_detach_with_config_file(self): def test_detach_with_config_file(self):
self.client._general_configs['detachKeys'] = 'ctrl-p' self.client._general_configs['detachKeys'] = 'ctrl-p'
container = self.client.create_container(BUSYBOX, 'cat', container = self.client.create_container(
detach=True, stdin_open=True) BUSYBOX, 'cat', detach=True, stdin_open=True
)
id = container['Id'] id = container['Id']
self.client.start(id) self.client.start(id)
self.tmp_containers.append(id) self.tmp_containers.append(id)
exec_id = self.client.exec_create(id, '/bin/sh', stdin=True, tty=True) exec_id = self.client.exec_create(
id, 'cat', stdin=True, tty=True, stdout=True
)
sock = self.client.exec_start(exec_id, tty=True, socket=True) sock = self.client.exec_start(exec_id, tty=True, socket=True)
self.addCleanup(sock.close)
assert_socket_closed_with_keys(sock, [ctrl_with('p')]) assert_cat_socket_detached_with_keys(sock, [ctrl_with('p')])
def test_detach_with_arg(self): def test_detach_with_arg(self):
self.client._general_configs['detachKeys'] = 'ctrl-p' self.client._general_configs['detachKeys'] = 'ctrl-p'
container = self.client.create_container(BUSYBOX, 'cat', container = self.client.create_container(
detach=True, stdin_open=True) BUSYBOX, 'cat', detach=True, stdin_open=True
)
id = container['Id'] id = container['Id']
self.client.start(id) self.client.start(id)
self.tmp_containers.append(id) self.tmp_containers.append(id)
exec_id = self.client.exec_create( exec_id = self.client.exec_create(
id, '/bin/sh', id, 'cat',
stdin=True, tty=True, detach_keys='ctrl-x' stdin=True, tty=True, detach_keys='ctrl-x', stdout=True
) )
sock = self.client.exec_start(exec_id, tty=True, socket=True) sock = self.client.exec_start(exec_id, tty=True, socket=True)
self.addCleanup(sock.close)
assert_socket_closed_with_keys(sock, [ctrl_with('x')]) assert_cat_socket_detached_with_keys(sock, [ctrl_with('x')])
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