From 59bebd41eb768653f8bbccab0df46da3eac5c47c Mon Sep 17 00:00:00 2001 From: Ivan Halomi Date: Tue, 2 Jul 2024 13:52:42 +0200 Subject: [PATCH] Fix podman healtcheck when not enabled There was a bug where setting the test command for the health check to 'NONE' would throw an error in podman_worker. This was problematic since K-A uses 'NONE' as an indicator that the health check is not enabled. Closes-Bug: #2071912 Change-Id: I3140bb79eace58b23f579be3da569c502c52c38c Signed-off-by: Ivan Halomi --- ansible/module_utils/kolla_podman_worker.py | 3 ++- .../notes/bug-2071912-89d2fba8865ddf40.yaml | 6 ++++++ tests/kolla_container_tests/test_docker_worker.py | 15 +++++++++++++++ tests/kolla_container_tests/test_podman_worker.py | 12 ++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/bug-2071912-89d2fba8865ddf40.yaml diff --git a/ansible/module_utils/kolla_podman_worker.py b/ansible/module_utils/kolla_podman_worker.py index a5bd9bbcba..69a0de26e4 100644 --- a/ansible/module_utils/kolla_podman_worker.py +++ b/ansible/module_utils/kolla_podman_worker.py @@ -104,7 +104,8 @@ class PodmanWorker(ContainerWorker): if healthcheck: healthcheck = self.parse_healthcheck(healthcheck) self.params.pop('healthcheck', None) - args.update(healthcheck) + if healthcheck: + args.update(healthcheck) # getting dimensions into separate parameters dimensions = self.params.get('dimensions') diff --git a/releasenotes/notes/bug-2071912-89d2fba8865ddf40.yaml b/releasenotes/notes/bug-2071912-89d2fba8865ddf40.yaml new file mode 100644 index 0000000000..f9fae9c1e6 --- /dev/null +++ b/releasenotes/notes/bug-2071912-89d2fba8865ddf40.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixes podman failure when enable_container_healthchecks + is set to "no". + `LP#2071912 `__ diff --git a/tests/kolla_container_tests/test_docker_worker.py b/tests/kolla_container_tests/test_docker_worker.py index 021bdf7e61..e6e6f0de21 100644 --- a/tests/kolla_container_tests/test_docker_worker.py +++ b/tests/kolla_container_tests/test_docker_worker.py @@ -365,6 +365,21 @@ class TestContainer(base.BaseTestCase): self.dw.dc.create_container.assert_called_once_with( **{k: self.fake_data['params'][k] for k in expected_args}) + def test_create_container_with_None_healthcheck(self): + self.fake_data['params']['healthcheck'] = \ + {'test': ['NONE']} + self.dw = get_DockerWorker(self.fake_data['params']) + self.dw.dc.create_host_config = mock.MagicMock( + return_value=self.fake_data['params']['host_config']) + self.dw.create_container() + inject_env_when_create_container(self.fake_data['params']) + self.assertTrue(self.dw.changed) + expected_args = {'command', 'detach', 'environment', 'host_config', + 'image', 'labels', 'name', 'tty', + 'volumes'} + self.dw.dc.create_container.assert_called_once_with( + **{k: self.fake_data['params'][k] for k in expected_args}) + def test_create_container_with_tmpfs(self): self.fake_data['params']['tmpfs'] = ['/tmp'] # nosec: B108 self.dw = get_DockerWorker(self.fake_data['params']) diff --git a/tests/kolla_container_tests/test_podman_worker.py b/tests/kolla_container_tests/test_podman_worker.py index e1fd358a84..60691b1a22 100644 --- a/tests/kolla_container_tests/test_podman_worker.py +++ b/tests/kolla_container_tests/test_podman_worker.py @@ -246,6 +246,18 @@ class TestContainer(base.BaseTestCase): self.assertIsNotNone(hc_call) self.assertEqual(hc, hc_call) + def test_create_container_with_None_healthcheck(self): + hc = {'test': ['NONE']} + self.fake_data['params']['healthcheck'] = hc + self.pw = get_PodmanWorker(self.fake_data['params'].copy()) + + self.pw.create_container() + self.assertTrue(self.pw.changed) + podman_create_kwargs = self.pw.pc.containers.create.call_args.kwargs + hc_call = podman_create_kwargs.get('healthcheck', None) + self.pw.pc.containers.create.assert_called_once() + self.assertIsNone(hc_call) + @unittest.skip("Skipping because tmpfs is currently" " not supported by podman API.") def test_create_container_with_tmpfs(self):