Fix session timeout = None case

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2018-04-25 15:12:49 -07:00 committed by Joffrey F
parent da028d88a2
commit ae8f77737c
2 changed files with 12 additions and 15 deletions

View File

@ -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')

View File

@ -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'])