From 5b76f88c78f26b58acb04ad5109fa588e52fa633 Mon Sep 17 00:00:00 2001 From: Khushiyant Date: Thu, 8 Feb 2024 13:42:37 +0530 Subject: [PATCH 1/2] feat: implement healthcheck start_interval #3157 Signed-off-by: Khushiyant --- docker/types/containers.py | 5 +++++ docker/types/healthcheck.py | 14 +++++++++++++- tests/integration/api_healthcheck_test.py | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/docker/types/containers.py b/docker/types/containers.py index 598188a25..c1697fa7a 100644 --- a/docker/types/containers.py +++ b/docker/types/containers.py @@ -711,6 +711,11 @@ def __init__( 'healthcheck start period was introduced in API ' 'version 1.29' ) + + if version_lt(version, '1.44') and 'StartInterval' in healthcheck: + raise errors.InvalidVersion( + 'healthcheck start interval was introduced in API version 1.44' + ) if isinstance(command, str): command = split_command(command) diff --git a/docker/types/healthcheck.py b/docker/types/healthcheck.py index dfc88a977..55b3e5fa0 100644 --- a/docker/types/healthcheck.py +++ b/docker/types/healthcheck.py @@ -26,6 +26,8 @@ class Healthcheck(DictType): start_period (int): Start period for the container to initialize before starting health-retries countdown in nanoseconds. It should be 0 or at least 1000000 (1 ms). + start_interval (int): It is interval to be used by healthchecks during the start period in + nanoseconds. It should be 0 or at least 1000000 (1 ms). """ def __init__(self, **kwargs): test = kwargs.get('test', kwargs.get('Test')) @@ -36,13 +38,15 @@ def __init__(self, **kwargs): timeout = kwargs.get('timeout', kwargs.get('Timeout')) retries = kwargs.get('retries', kwargs.get('Retries')) start_period = kwargs.get('start_period', kwargs.get('StartPeriod')) + start_interval = kwargs.get('start_interval', kwargs.get('StartInterval')) super().__init__({ 'Test': test, 'Interval': interval, 'Timeout': timeout, 'Retries': retries, - 'StartPeriod': start_period + 'StartPeriod': start_period, + 'StartInterval': start_interval }) @property @@ -86,3 +90,11 @@ def start_period(self): @start_period.setter def start_period(self, value): self['StartPeriod'] = value + + @property + def start_interval(self): + return self['StartInterval'] + + @start_interval.setter + def start_interval(self, value): + self['StartInterval'] = value diff --git a/tests/integration/api_healthcheck_test.py b/tests/integration/api_healthcheck_test.py index f00d804b4..87a4da1da 100644 --- a/tests/integration/api_healthcheck_test.py +++ b/tests/integration/api_healthcheck_test.py @@ -66,3 +66,20 @@ def test_healthcheck_start_period(self): self.tmp_containers.append(container) self.client.start(container) wait_on_health_status(self.client, container, "healthy") + + @helpers.requires_api_version('1.44') + def test_healthcheck_start_interval(self): + container = self.client.create_container( + TEST_IMG, 'top', healthcheck={ + 'test': "echo 'hello docker'", + 'interval': 1 * SECOND, + 'timeout': 1 * SECOND, + 'retries': 1, + 'start_interval': 1 * SECOND + } + ) + + self.tmp_containers.append(container) + self.client.start(container) + wait_on_health_status(self.client, container, "healthy") + \ No newline at end of file From 05040b17e260cbb330d90152e1c2a6f5d197ab80 Mon Sep 17 00:00:00 2001 From: Khushiyant Date: Thu, 8 Feb 2024 13:57:43 +0530 Subject: [PATCH 2/2] chore: ruff linter--fix Signed-off-by: Khushiyant --- docker/types/containers.py | 2 +- docker/types/healthcheck.py | 4 ++-- tests/integration/api_healthcheck_test.py | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/docker/types/containers.py b/docker/types/containers.py index c1697fa7a..6a23b30f7 100644 --- a/docker/types/containers.py +++ b/docker/types/containers.py @@ -711,7 +711,7 @@ def __init__( 'healthcheck start period was introduced in API ' 'version 1.29' ) - + if version_lt(version, '1.44') and 'StartInterval' in healthcheck: raise errors.InvalidVersion( 'healthcheck start interval was introduced in API version 1.44' diff --git a/docker/types/healthcheck.py b/docker/types/healthcheck.py index 55b3e5fa0..69c449df4 100644 --- a/docker/types/healthcheck.py +++ b/docker/types/healthcheck.py @@ -26,7 +26,7 @@ class Healthcheck(DictType): start_period (int): Start period for the container to initialize before starting health-retries countdown in nanoseconds. It should be 0 or at least 1000000 (1 ms). - start_interval (int): It is interval to be used by healthchecks during the start period in + start_interval (int): It is interval to be used by healthchecks during the start period in nanoseconds. It should be 0 or at least 1000000 (1 ms). """ def __init__(self, **kwargs): @@ -94,7 +94,7 @@ def start_period(self, value): @property def start_interval(self): return self['StartInterval'] - + @start_interval.setter def start_interval(self, value): self['StartInterval'] = value diff --git a/tests/integration/api_healthcheck_test.py b/tests/integration/api_healthcheck_test.py index 87a4da1da..5d95483e6 100644 --- a/tests/integration/api_healthcheck_test.py +++ b/tests/integration/api_healthcheck_test.py @@ -82,4 +82,3 @@ def test_healthcheck_start_interval(self): self.tmp_containers.append(container) self.client.start(container) wait_on_health_status(self.client, container, "healthy") - \ No newline at end of file