Skip to content

Commit f2c1ae3

Browse files
committed
Fix session timeout = None case
Signed-off-by: Joffrey F <[email protected]>
1 parent 2454e81 commit f2c1ae3

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

docker/api/container.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,9 +1018,10 @@ def restart(self, container, timeout=10):
10181018
"""
10191019
params = {'t': timeout}
10201020
url = self._url("/containers/{0}/restart", container)
1021-
res = self._post(
1022-
url, params=params, timeout=timeout + (self.timeout or 0)
1023-
)
1021+
conn_timeout = self.timeout
1022+
if conn_timeout is not None:
1023+
conn_timeout += timeout
1024+
res = self._post(url, params=params, timeout=conn_timeout)
10241025
self._raise_for_status(res)
10251026

10261027
@utils.check_resource('container')
@@ -1110,11 +1111,9 @@ def stop(self, container, timeout=None):
11101111
params = {'t': timeout}
11111112
url = self._url("/containers/{0}/stop", container)
11121113
conn_timeout = self.timeout
1113-
if conn_timeout:
1114-
conn_timeout = max(conn_timeout, timeout + 15)
1115-
res = self._post(
1116-
url, params=params, timeout=timeout + (self.timeout or 0)
1117-
)
1114+
if conn_timeout is not None:
1115+
conn_timeout += timeout
1116+
res = self._post(url, params=params, timeout=conn_timeout)
11181117
self._raise_for_status(res)
11191118

11201119
@utils.check_resource('container')

tests/integration/api_container_test.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,16 +1165,14 @@ def test_restart(self):
11651165
assert info2['State']['Running'] is True
11661166
self.client.kill(id)
11671167

1168-
def test_restart_with_high_timeout(self):
1168+
def test_restart_with_low_timeout(self):
11691169
container = self.client.create_container(BUSYBOX, ['sleep', '9999'])
1170-
id = container['Id']
1171-
self.client.start(id)
1170+
self.client.start(container)
11721171
self.client.timeout = 1
1173-
self.client.restart(id, timeout=3)
1172+
self.client.restart(container, timeout=3)
11741173
self.client.timeout = None
1175-
self.client.restart(id, timeout=3)
1176-
self.client.timeout = 1
1177-
self.client.stop(id, timeout=3)
1174+
self.client.restart(container, timeout=3)
1175+
self.client.kill(container)
11781176

11791177
def test_restart_with_dict_instead_of_id(self):
11801178
container = self.client.create_container(BUSYBOX, ['sleep', '9999'])

0 commit comments

Comments
 (0)