diff options
author | Joffrey F <f.joffrey@gmail.com> | 2017-06-19 15:12:26 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-19 15:12:26 -0700 |
commit | ce8a6ea442cfaff4ee33eb9343de10541db6bd77 (patch) | |
tree | 0bb89b74e4c65f6f406fd291730fe8ad08f44912 | |
parent | 75e850e531027ef4f3f918a803efc1cf19d7579d (diff) | |
parent | 1ea6618b09e3a74531a0fed1d44a5d698afe2339 (diff) | |
download | docker-py-ce8a6ea442cfaff4ee33eb9343de10541db6bd77.tar.gz |
Merge pull request #1620 from docker/healthcheck-start-period
Add support for start_period in Healthcheck spec
-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 52674b1..9108421 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") |