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