mirror of https://github.com/docker/docker-py.git
Merge pull request #1421 from shin-/add_stop_timeout
Add stop_timeout to create_container
This commit is contained in:
commit
d1b51c3967
|
@ -36,15 +36,14 @@ def buildImages = { ->
|
|||
|
||||
def getAPIVersion = { engineVersion ->
|
||||
def versionMap = ['1.12': '1.24', '1.13': '1.25']
|
||||
|
||||
engineVersion = engineVersion.substring(0, 4)
|
||||
return versionMap[engineVersion]
|
||||
return versionMap[engineVersion.substring(0, 4)]
|
||||
}
|
||||
|
||||
def runTests = { Map settings ->
|
||||
def dockerVersion = settings.get("dockerVersion", null)
|
||||
def pythonVersion = settings.get("pythonVersion", null)
|
||||
def testImage = settings.get("testImage", null)
|
||||
def apiVersion = getAPIVersion(dockerVersion)
|
||||
|
||||
if (!testImage) {
|
||||
throw new Exception("Need test image object, e.g.: `runTests(testImage: img)`")
|
||||
|
@ -62,7 +61,6 @@ def runTests = { Map settings ->
|
|||
checkout(scm)
|
||||
def dindContainerName = "dpy-dind-\$BUILD_NUMBER-\$EXECUTOR_NUMBER-${pythonVersion}-${dockerVersion}"
|
||||
def testContainerName = "dpy-tests-\$BUILD_NUMBER-\$EXECUTOR_NUMBER-${pythonVersion}-${dockerVersion}"
|
||||
def apiVersion = getAPIVersion(dockerVersion)
|
||||
try {
|
||||
sh """docker run -d --name ${dindContainerName} -v /tmp --privileged \\
|
||||
dockerswarm/dind:${dockerVersion} docker daemon -H tcp://0.0.0.0:2375
|
||||
|
|
|
@ -238,7 +238,7 @@ class ContainerApiMixin(object):
|
|||
memswap_limit=None, cpuset=None, host_config=None,
|
||||
mac_address=None, labels=None, volume_driver=None,
|
||||
stop_signal=None, networking_config=None,
|
||||
healthcheck=None):
|
||||
healthcheck=None, stop_timeout=None):
|
||||
"""
|
||||
Creates a container. Parameters are similar to those for the ``docker
|
||||
run`` command except it doesn't support the attach options (``-a``).
|
||||
|
@ -411,6 +411,8 @@ class ContainerApiMixin(object):
|
|||
volume_driver (str): The name of a volume driver/plugin.
|
||||
stop_signal (str): The stop signal to use to stop the container
|
||||
(e.g. ``SIGINT``).
|
||||
stop_timeout (int): Timeout to stop the container, in seconds.
|
||||
Default: 10
|
||||
networking_config (dict): A networking configuration generated
|
||||
by :py:meth:`create_networking_config`.
|
||||
|
||||
|
@ -437,6 +439,7 @@ class ContainerApiMixin(object):
|
|||
network_disabled, entrypoint, cpu_shares, working_dir, domainname,
|
||||
memswap_limit, cpuset, host_config, mac_address, labels,
|
||||
volume_driver, stop_signal, networking_config, healthcheck,
|
||||
stop_timeout
|
||||
)
|
||||
return self.create_container_from_config(config, name)
|
||||
|
||||
|
|
|
@ -438,6 +438,7 @@ class ContainerConfig(dict):
|
|||
working_dir=None, domainname=None, memswap_limit=None, cpuset=None,
|
||||
host_config=None, mac_address=None, labels=None, volume_driver=None,
|
||||
stop_signal=None, networking_config=None, healthcheck=None,
|
||||
stop_timeout=None
|
||||
):
|
||||
if isinstance(command, six.string_types):
|
||||
command = split_command(command)
|
||||
|
@ -466,6 +467,11 @@ class ContainerConfig(dict):
|
|||
'stop_signal was only introduced in API version 1.21'
|
||||
)
|
||||
|
||||
if stop_timeout is not None and version_lt(version, '1.25'):
|
||||
raise errors.InvalidVersion(
|
||||
'stop_timeout was only introduced in API version 1.25'
|
||||
)
|
||||
|
||||
if healthcheck is not None and version_lt(version, '1.24'):
|
||||
raise errors.InvalidVersion(
|
||||
'Health options were only introduced in API version 1.24'
|
||||
|
@ -584,4 +590,5 @@ class ContainerConfig(dict):
|
|||
'VolumeDriver': volume_driver,
|
||||
'StopSignal': stop_signal,
|
||||
'Healthcheck': healthcheck,
|
||||
'StopTimeout': stop_timeout
|
||||
})
|
||||
|
|
|
@ -43,10 +43,12 @@ def untar_file(tardata, filename):
|
|||
|
||||
|
||||
def requires_api_version(version):
|
||||
test_version = os.environ.get(
|
||||
'DOCKER_TEST_API_VERSION', docker.constants.DEFAULT_DOCKER_API_VERSION
|
||||
)
|
||||
|
||||
return pytest.mark.skipif(
|
||||
docker.utils.version_lt(
|
||||
docker.constants.DEFAULT_DOCKER_API_VERSION, version
|
||||
),
|
||||
docker.utils.version_lt(test_version, version),
|
||||
reason="API version is too low (< {0})".format(version)
|
||||
)
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import os
|
|||
import shutil
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
import six
|
||||
|
||||
from docker import errors
|
||||
|
@ -154,9 +155,11 @@ class BuildTest(BaseAPIIntegrationTest):
|
|||
self.assertEqual(info['Config']['Labels'], labels)
|
||||
|
||||
@requires_api_version('1.25')
|
||||
@pytest.mark.xfail(reason='Bad test')
|
||||
def test_build_cachefrom(self):
|
||||
script = io.BytesIO('\n'.join([
|
||||
'FROM scratch',
|
||||
'CMD sh -c "echo \'Hello, World!\'"',
|
||||
]).encode('ascii'))
|
||||
|
||||
cachefrom = ['build1']
|
||||
|
@ -169,6 +172,7 @@ class BuildTest(BaseAPIIntegrationTest):
|
|||
pass
|
||||
|
||||
info = self.client.inspect_image('cachefrom')
|
||||
# FIXME: Config.CacheFrom is not a real thing
|
||||
self.assertEqual(info['Config']['CacheFrom'], cachefrom)
|
||||
|
||||
def test_build_stderr_data(self):
|
||||
|
|
|
@ -413,6 +413,15 @@ class CreateContainerTest(BaseAPIIntegrationTest):
|
|||
config = self.client.inspect_container(container)
|
||||
assert config['HostConfig']['AutoRemove'] is True
|
||||
|
||||
@requires_api_version('1.25')
|
||||
def test_create_with_stop_timeout(self):
|
||||
container = self.client.create_container(
|
||||
BUSYBOX, ['echo', 'test'], stop_timeout=25
|
||||
)
|
||||
self.tmp_containers.append(container['Id'])
|
||||
config = self.client.inspect_container(container)
|
||||
assert config['Config']['StopTimeout'] == 25
|
||||
|
||||
|
||||
class VolumeBindTest(BaseAPIIntegrationTest):
|
||||
def setUp(self):
|
||||
|
|
Loading…
Reference in New Issue