Kaydet (Commit) 1848d2c9 authored tarafından Matthieu Nottale's avatar Matthieu Nottale Kaydeden (comit) Joffrey F

stop(), restart(): Adjust request timeout.

Signed-off-by: 's avatarMatthieu Nottale <matthieu.nottale@docker.com>
üst c0c46a3d
...@@ -1018,7 +1018,10 @@ class ContainerApiMixin(object): ...@@ -1018,7 +1018,10 @@ class ContainerApiMixin(object):
""" """
params = {'t': timeout} params = {'t': timeout}
url = self._url("/containers/{0}/restart", container) url = self._url("/containers/{0}/restart", container)
res = self._post(url, params=params) conn_timeout = self.timeout
if conn_timeout:
conn_timeout = max(conn_timeout, timeout+15)
res = self._post(url, params=params, timeout=conn_timeout)
self._raise_for_status(res) self._raise_for_status(res)
@utils.check_resource('container') @utils.check_resource('container')
...@@ -1107,9 +1110,11 @@ class ContainerApiMixin(object): ...@@ -1107,9 +1110,11 @@ class ContainerApiMixin(object):
else: else:
params = {'t': timeout} params = {'t': timeout}
url = self._url("/containers/{0}/stop", container) 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, res = self._post(url, params=params,
timeout=(timeout + (self.timeout or 0))) timeout=conn_timeout)
self._raise_for_status(res) self._raise_for_status(res)
@utils.check_resource('container') @utils.check_resource('container')
......
...@@ -1165,6 +1165,17 @@ class RestartContainerTest(BaseAPIIntegrationTest): ...@@ -1165,6 +1165,17 @@ class RestartContainerTest(BaseAPIIntegrationTest):
assert info2['State']['Running'] is True assert info2['State']['Running'] is True
self.client.kill(id) self.client.kill(id)
def test_restart_with_hight_timeout(self):
container = self.client.create_container(BUSYBOX, ['sleep', '9999'])
id = container['Id']
self.client.start(id)
self.client.timeout = 1
self.client.restart(id, timeout=3)
self.client.timeout = None
self.client.restart(id, timeout=3)
self.client.timeout = 1
self.client.stop(id, timeout=3)
def test_restart_with_dict_instead_of_id(self): def test_restart_with_dict_instead_of_id(self):
container = self.client.create_container(BUSYBOX, ['sleep', '9999']) container = self.client.create_container(BUSYBOX, ['sleep', '9999'])
assert 'Id' in container assert 'Id' in container
......
...@@ -1264,7 +1264,7 @@ class ContainerTest(BaseAPIClientTest): ...@@ -1264,7 +1264,7 @@ class ContainerTest(BaseAPIClientTest):
'POST', 'POST',
url_prefix + 'containers/3cc2351ab11b/stop', url_prefix + 'containers/3cc2351ab11b/stop',
params={'t': timeout}, params={'t': timeout},
timeout=(DEFAULT_TIMEOUT_SECONDS + timeout) timeout=(DEFAULT_TIMEOUT_SECONDS)
) )
def test_stop_container_with_dict_instead_of_id(self): def test_stop_container_with_dict_instead_of_id(self):
...@@ -1277,7 +1277,7 @@ class ContainerTest(BaseAPIClientTest): ...@@ -1277,7 +1277,7 @@ class ContainerTest(BaseAPIClientTest):
'POST', 'POST',
url_prefix + 'containers/3cc2351ab11b/stop', url_prefix + 'containers/3cc2351ab11b/stop',
params={'t': timeout}, params={'t': timeout},
timeout=(DEFAULT_TIMEOUT_SECONDS + timeout) timeout=(DEFAULT_TIMEOUT_SECONDS)
) )
def test_pause_container(self): def test_pause_container(self):
......
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