Kaydet (Commit) ce8a6ea4 authored tarafından Joffrey F's avatar Joffrey F Kaydeden (comit) GitHub

Merge pull request #1620 from docker/healthcheck-start-period

Add support for start_period in Healthcheck spec
...@@ -418,6 +418,8 @@ class ContainerApiMixin(object): ...@@ -418,6 +418,8 @@ class ContainerApiMixin(object):
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`.
runtime (str): Runtime to use with this container. runtime (str): Runtime to use with this container.
healthcheck (dict): Specify a test to perform to check that the
container is healthy.
Returns: Returns:
A dictionary with an image 'Id' key and a 'Warnings' key. A dictionary with an image 'Id' key and a 'Warnings' key.
......
...@@ -516,6 +516,8 @@ class ContainerCollection(Collection): ...@@ -516,6 +516,8 @@ class ContainerCollection(Collection):
container, as a mapping of hostname to IP address. container, as a mapping of hostname to IP address.
group_add (:py:class:`list`): List of additional group names and/or group_add (:py:class:`list`): List of additional group names and/or
IDs that the container process will run as. 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. hostname (str): Optional hostname for the container.
init (bool): Run an init inside the container that forwards init (bool): Run an init inside the container that forwards
signals and reaps processes signals and reaps processes
......
...@@ -565,10 +565,17 @@ class ContainerConfig(dict): ...@@ -565,10 +565,17 @@ class ContainerConfig(dict):
'stop_timeout was only introduced in API version 1.25' '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:
raise errors.InvalidVersion( if version_lt(version, '1.24'):
'Health options were only introduced in API 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): if isinstance(command, six.string_types):
command = split_command(command) command = split_command(command)
......
...@@ -12,12 +12,14 @@ class Healthcheck(DictType): ...@@ -12,12 +12,14 @@ class Healthcheck(DictType):
interval = kwargs.get('interval', kwargs.get('Interval')) interval = kwargs.get('interval', kwargs.get('Interval'))
timeout = kwargs.get('timeout', kwargs.get('Timeout')) timeout = kwargs.get('timeout', kwargs.get('Timeout'))
retries = kwargs.get('retries', kwargs.get('Retries')) retries = kwargs.get('retries', kwargs.get('Retries'))
start_period = kwargs.get('start_period', kwargs.get('StartPeriod'))
super(Healthcheck, self).__init__({ super(Healthcheck, self).__init__({
'Test': test, 'Test': test,
'Interval': interval, 'Interval': interval,
'Timeout': timeout, 'Timeout': timeout,
'Retries': retries 'Retries': retries,
'StartPeriod': start_period
}) })
@property @property
...@@ -51,3 +53,11 @@ class Healthcheck(DictType): ...@@ -51,3 +53,11 @@ class Healthcheck(DictType):
@retries.setter @retries.setter
def retries(self, value): def retries(self, value):
self['Retries'] = value self['Retries'] = value
@property
def start_period(self):
return self['StartPeriod']
@start_period.setter
def start_period(self, value):
self['StartPeriod'] = value
...@@ -28,8 +28,8 @@ class HealthcheckTest(BaseAPIIntegrationTest): ...@@ -28,8 +28,8 @@ class HealthcheckTest(BaseAPIIntegrationTest):
container = self.client.create_container( container = self.client.create_container(
BUSYBOX, 'top', healthcheck=dict( BUSYBOX, 'top', healthcheck=dict(
test="true", test="true",
interval=1*SECOND, interval=1 * SECOND,
timeout=1*SECOND, timeout=1 * SECOND,
retries=1, retries=1,
)) ))
self.tmp_containers.append(container) self.tmp_containers.append(container)
...@@ -41,10 +41,27 @@ class HealthcheckTest(BaseAPIIntegrationTest): ...@@ -41,10 +41,27 @@ class HealthcheckTest(BaseAPIIntegrationTest):
container = self.client.create_container( container = self.client.create_container(
BUSYBOX, 'top', healthcheck=dict( BUSYBOX, 'top', healthcheck=dict(
test="false", test="false",
interval=1*SECOND, interval=1 * SECOND,
timeout=1*SECOND, timeout=1 * SECOND,
retries=1, retries=1,
)) ))
self.tmp_containers.append(container) self.tmp_containers.append(container)
self.client.start(container) self.client.start(container)
wait_on_health_status(self.client, container, "unhealthy") 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")
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