diff options
author | Joffrey F <joffrey@docker.com> | 2018-04-25 15:12:49 -0700 |
---|---|---|
committer | Joffrey F <joffrey@docker.com> | 2018-04-25 15:12:49 -0700 |
commit | 0cef1959cde5b63282729ee9300a5869f276578f (patch) | |
tree | d331283c1196325bfc96c9c976ba262a6f1dab18 | |
parent | 705d1a6041455147640f2fa85190b1e91c3aa66a (diff) | |
download | docker-py-mnottale-stop-restart-timeout.tar.gz |
Fix session timeout = None casemnottale-stop-restart-timeout
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r-- | docker/api/container.py | 15 | ||||
-rw-r--r-- | tests/integration/api_container_test.py | 12 |
2 files changed, 12 insertions, 15 deletions
diff --git a/docker/api/container.py b/docker/api/container.py index 4a49bab..05676f1 100644 --- a/docker/api/container.py +++ b/docker/api/container.py @@ -1018,9 +1018,10 @@ class ContainerApiMixin(object): """ params = {'t': timeout} url = self._url("/containers/{0}/restart", container) - res = self._post( - url, params=params, timeout=timeout + (self.timeout or 0) - ) + conn_timeout = self.timeout + if conn_timeout is not None: + conn_timeout += timeout + res = self._post(url, params=params, timeout=conn_timeout) self._raise_for_status(res) @utils.check_resource('container') @@ -1110,11 +1111,9 @@ class ContainerApiMixin(object): params = {'t': timeout} url = self._url("/containers/{0}/stop", container) conn_timeout = self.timeout - if conn_timeout: - conn_timeout = max(conn_timeout, timeout + 15) - res = self._post( - url, params=params, timeout=timeout + (self.timeout or 0) - ) + if conn_timeout is not None: + conn_timeout += timeout + res = self._post(url, params=params, timeout=conn_timeout) self._raise_for_status(res) @utils.check_resource('container') diff --git a/tests/integration/api_container_test.py b/tests/integration/api_container_test.py index da9b3ec..afd439f 100644 --- a/tests/integration/api_container_test.py +++ b/tests/integration/api_container_test.py @@ -1165,16 +1165,14 @@ class RestartContainerTest(BaseAPIIntegrationTest): assert info2['State']['Running'] is True self.client.kill(id) - def test_restart_with_high_timeout(self): + def test_restart_with_low_timeout(self): container = self.client.create_container(BUSYBOX, ['sleep', '9999']) - id = container['Id'] - self.client.start(id) + self.client.start(container) self.client.timeout = 1 - self.client.restart(id, timeout=3) + self.client.restart(container, timeout=3) self.client.timeout = None - self.client.restart(id, timeout=3) - self.client.timeout = 1 - self.client.stop(id, timeout=3) + self.client.restart(container, timeout=3) + self.client.kill(container) def test_restart_with_dict_instead_of_id(self): container = self.client.create_container(BUSYBOX, ['sleep', '9999']) |