diff options
author | Joffrey F <joffrey@docker.com> | 2017-05-17 18:12:26 -0700 |
---|---|---|
committer | Joffrey F <joffrey@docker.com> | 2017-06-16 17:02:59 -0700 |
commit | 1ea6618b09e3a74531a0fed1d44a5d698afe2339 (patch) | |
tree | 201b69c54d324bebac1588e5560d0289fa450f33 | |
parent | 8645d1d41b69763b7dfb4dd0cbe3a3ab2d7f5321 (diff) | |
download | docker-py-healthcheck-start-period.tar.gz |
Add support for start_period in Healthcheck spechealthcheck-start-period
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r-- | docker/api/container.py | 2 | ||||
-rw-r--r-- | docker/models/containers.py | 2 | ||||
-rw-r--r-- | docker/types/containers.py | 15 | ||||
-rw-r--r-- | docker/types/healthcheck.py | 12 | ||||
-rw-r--r-- | tests/integration/api_healthcheck_test.py | 25 |
5 files changed, 47 insertions, 9 deletions
diff --git a/docker/api/container.py b/docker/api/container.py index 97a39b6..5668b43 100644 --- a/docker/api/container.py +++ b/docker/api/container.py @@ -418,6 +418,8 @@ class ContainerApiMixin(object): networking_config (dict): A networking configuration generated by :py:meth:`create_networking_config`. runtime (str): Runtime to use with this container. + healthcheck (dict): Specify a test to perform to check that the + container is healthy. Returns: A dictionary with an image 'Id' key and a 'Warnings' key. diff --git a/docker/models/containers.py b/docker/models/containers.py index 300c5a9..cf01b27 100644 --- a/docker/models/containers.py +++ b/docker/models/containers.py @@ -516,6 +516,8 @@ class ContainerCollection(Collection): container, as a mapping of hostname to IP address. group_add (:py:class:`list`): List of additional group names and/or IDs that the container process will run as. + healthcheck (dict): Specify a test to perform to check that the + container is healthy. hostname (str): Optional hostname for the container. init (bool): Run an init inside the container that forwards signals and reaps processes diff --git a/docker/types/containers.py b/docker/types/containers.py index 6bbb57a..030e292 100644 --- a/docker/types/containers.py +++ b/docker/types/containers.py @@ -565,10 +565,17 @@ class ContainerConfig(dict): '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' - ) + if healthcheck is not None: + if version_lt(version, '1.24'): + raise errors.InvalidVersion( + 'Health options were only introduced in API version 1.24' + ) + + if version_lt(version, '1.29') and 'StartPeriod' in healthcheck: + raise errors.InvalidVersion( + 'healthcheck start period was introduced in API ' + 'version 1.29' + ) if isinstance(command, six.string_types): command = split_command(command) diff --git a/docker/types/healthcheck.py b/docker/types/healthcheck.py index ba63d21..8ea9a35 100644 --- a/docker/types/healthcheck.py +++ b/docker/types/healthcheck.py @@ -12,12 +12,14 @@ class Healthcheck(DictType): interval = kwargs.get('interval', kwargs.get('Interval')) timeout = kwargs.get('timeout', kwargs.get('Timeout')) retries = kwargs.get('retries', kwargs.get('Retries')) + start_period = kwargs.get('start_period', kwargs.get('StartPeriod')) super(Healthcheck, self).__init__({ 'Test': test, 'Interval': interval, 'Timeout': timeout, - 'Retries': retries + 'Retries': retries, + 'StartPeriod': start_period }) @property @@ -51,3 +53,11 @@ class Healthcheck(DictType): @retries.setter def retries(self, value): self['Retries'] = value + + @property + def start_period(self): + return self['StartPeriod'] + + @start_period.setter + def start_period(self, value): + self['StartPeriod'] = value diff --git a/tests/integration/api_healthcheck_test.py b/tests/integration/api_healthcheck_test.py index afe1dea..211042d 100644 --- a/tests/integration/api_healthcheck_test.py +++ b/tests/integration/api_healthcheck_test.py @@ -28,8 +28,8 @@ class HealthcheckTest(BaseAPIIntegrationTest): container = self.client.create_container( BUSYBOX, 'top', healthcheck=dict( test="true", - interval=1*SECOND, - timeout=1*SECOND, + interval=1 * SECOND, + timeout=1 * SECOND, retries=1, )) self.tmp_containers.append(container) @@ -41,10 +41,27 @@ class HealthcheckTest(BaseAPIIntegrationTest): container = self.client.create_container( BUSYBOX, 'top', healthcheck=dict( test="false", - interval=1*SECOND, - timeout=1*SECOND, + interval=1 * SECOND, + timeout=1 * SECOND, retries=1, )) self.tmp_containers.append(container) self.client.start(container) wait_on_health_status(self.client, container, "unhealthy") + + @helpers.requires_api_version('1.29') + def test_healthcheck_start_period(self): + container = self.client.create_container( + BUSYBOX, 'top', healthcheck=dict( + test="echo 'x' >> /counter.txt && " + "test `cat /counter.txt | wc -l` -ge 3", + interval=1 * SECOND, + timeout=1 * SECOND, + retries=1, + start_period=3 * SECOND + ) + ) + + self.tmp_containers.append(container) + self.client.start(container) + wait_on_health_status(self.client, container, "healthy") |