Merge 28df7ba905
into 036c0dcd18
This commit is contained in:
commit
7440e45c50
|
@ -0,0 +1,2 @@
|
|||
Add support for `start_interval` option.
|
||||
Rename healthcheck flags to be consistent with Podman options.
|
|
@ -1280,7 +1280,7 @@ async def container_to_args(
|
|||
if isinstance(healthcheck_test, str):
|
||||
# podman does not add shell to handle command with whitespace
|
||||
podman_args.extend([
|
||||
"--healthcheck-command",
|
||||
"--health-cmd",
|
||||
json.dumps(["CMD-SHELL", healthcheck_test]),
|
||||
])
|
||||
elif is_list(healthcheck_test):
|
||||
|
@ -1290,11 +1290,11 @@ async def container_to_args(
|
|||
if healthcheck_type == "NONE":
|
||||
podman_args.append("--no-healthcheck")
|
||||
elif healthcheck_type == "CMD":
|
||||
podman_args.extend(["--healthcheck-command", json.dumps(healthcheck_test)])
|
||||
podman_args.extend(["--health-cmd", json.dumps(healthcheck_test)])
|
||||
elif healthcheck_type == "CMD-SHELL":
|
||||
if len(healthcheck_test) != 1:
|
||||
raise ValueError("'CMD_SHELL' takes a single string after it")
|
||||
podman_args.extend(["--healthcheck-command", json.dumps(healthcheck_test)])
|
||||
podman_args.extend(["--health-cmd", json.dumps(healthcheck_test)])
|
||||
else:
|
||||
raise ValueError(
|
||||
f"unknown healthcheck test type [{healthcheck_type}],\
|
||||
|
@ -1303,17 +1303,19 @@ async def container_to_args(
|
|||
else:
|
||||
raise ValueError("'healthcheck.test' either a string or a list")
|
||||
|
||||
# interval, timeout and start_period are specified as durations.
|
||||
# interval, timeout, start_period, and start_interval are specified as durations.
|
||||
if "interval" in healthcheck:
|
||||
podman_args.extend(["--healthcheck-interval", healthcheck["interval"]])
|
||||
podman_args.extend(["--health-interval", healthcheck["interval"]])
|
||||
if "timeout" in healthcheck:
|
||||
podman_args.extend(["--healthcheck-timeout", healthcheck["timeout"]])
|
||||
podman_args.extend(["--health-timeout", healthcheck["timeout"]])
|
||||
if "start_period" in healthcheck:
|
||||
podman_args.extend(["--healthcheck-start-period", healthcheck["start_period"]])
|
||||
podman_args.extend(["--health-start-period", healthcheck["start_period"]])
|
||||
if "start_interval" in healthcheck:
|
||||
podman_args.extend(["--health-startup-interval", healthcheck["start_interval"]])
|
||||
|
||||
# convert other parameters to string
|
||||
if "retries" in healthcheck:
|
||||
podman_args.extend(["--healthcheck-retries", str(healthcheck["retries"])])
|
||||
podman_args.extend(["--health-retries", str(healthcheck["retries"])])
|
||||
|
||||
# handle podman extension
|
||||
if 'x-podman' in cnt:
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
version: "3"
|
||||
services:
|
||||
healthcheck:
|
||||
image: nopush/podman-compose-test
|
||||
healthcheck:
|
||||
test: [ "CMD-SHELL", "curl -f http://localhost || exit 1" ]
|
||||
interval: 1m
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 10s
|
||||
start_interval: 5s
|
|
@ -0,0 +1,59 @@
|
|||
# SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
import json
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from tests.integration.test_utils import RunSubprocessMixin
|
||||
from tests.integration.test_utils import podman_compose_path
|
||||
from tests.integration.test_utils import test_path
|
||||
|
||||
|
||||
def compose_yaml_path() -> str:
|
||||
return os.path.join(os.path.join(test_path(), "healthcheck"), "docker-compose.yml")
|
||||
|
||||
|
||||
class TestHealthecheck(unittest.TestCase, RunSubprocessMixin):
|
||||
def test_healthcheck(self) -> None:
|
||||
up_cmd = [
|
||||
"coverage",
|
||||
"run",
|
||||
podman_compose_path(),
|
||||
"-f",
|
||||
os.path.join(test_path(), "healthcheck", "docker-compose.yml"),
|
||||
"up",
|
||||
"-d",
|
||||
]
|
||||
self.run_subprocess_assert_returncode(up_cmd)
|
||||
|
||||
command_container_id = [
|
||||
"podman",
|
||||
"ps",
|
||||
"-a",
|
||||
"--filter",
|
||||
"label=io.podman.compose.project=healthcheck",
|
||||
"--format",
|
||||
'"{{.ID}}"',
|
||||
]
|
||||
out, _ = self.run_subprocess_assert_returncode(command_container_id)
|
||||
self.assertNotEqual(out, b"")
|
||||
container_id = out.decode("utf-8").strip().replace('"', "")
|
||||
|
||||
command_inspect = ["podman", "container", "inspect", container_id]
|
||||
|
||||
out, _ = self.run_subprocess_assert_returncode(command_inspect)
|
||||
out_string = out.decode("utf-8")
|
||||
inspect = json.loads(out_string)
|
||||
healthcheck_obj = inspect[0]["Config"]["Healthcheck"]
|
||||
expected = {
|
||||
"Test": ["CMD-SHELL", "curl -f http://localhost || exit 1"],
|
||||
"StartPeriod": 10000000000,
|
||||
"Interval": 60000000000,
|
||||
"Timeout": 10000000000,
|
||||
"Retries": 3,
|
||||
}
|
||||
self.assertEqual(healthcheck_obj, expected)
|
||||
|
||||
# StartInterval is not available in the config object
|
||||
create_obj = inspect[0]["Config"]["CreateCommand"]
|
||||
self.assertIn("--health-startup-interval", create_obj)
|
|
@ -823,7 +823,7 @@ class TestContainerToArgs(unittest.IsolatedAsyncioTestCase):
|
|||
"--name=project_name_service_name1",
|
||||
"-d",
|
||||
"--network=bridge:alias=service_name",
|
||||
"--healthcheck-command",
|
||||
"--health-cmd",
|
||||
'["CMD-SHELL", "cmd arg1 arg2"]',
|
||||
"busybox",
|
||||
],
|
||||
|
@ -843,7 +843,7 @@ class TestContainerToArgs(unittest.IsolatedAsyncioTestCase):
|
|||
"--name=project_name_service_name1",
|
||||
"-d",
|
||||
"--network=bridge:alias=service_name",
|
||||
"--healthcheck-command",
|
||||
"--health-cmd",
|
||||
'["cmd", "arg1", "arg2"]',
|
||||
"busybox",
|
||||
],
|
||||
|
@ -863,7 +863,7 @@ class TestContainerToArgs(unittest.IsolatedAsyncioTestCase):
|
|||
"--name=project_name_service_name1",
|
||||
"-d",
|
||||
"--network=bridge:alias=service_name",
|
||||
"--healthcheck-command",
|
||||
"--health-cmd",
|
||||
'["cmd arg1 arg2"]',
|
||||
"busybox",
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue