From feac35a5ead59ff1945cdbc6db1175f893074a70 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 29 Oct 2026 11:47:41 +0100 Subject: [PATCH] fix(sys-ctl-hlth-runtime): deploy only on container hosts and drop the bare Docker Hub API literal Two CI failures on PR #1265 (run 40834164415): - Chunk 0 / SuiteCRM#2 (swarm): the post-load flush included sys-ctl-hlth-runtime on every play host, the NFS server too, which never gets sys-svc-container and therefore has no `container` CLI. The unit died with FileNotFoundError: 'container'. The role entry now runs only where a container runtime exists: in compose mode, or on swarm nodes ('svc-swarm-node' in group_names), the same role-entry host scoping that sys-ctl-hlth-csp and sys-ctl-hlth-webserver use with IS_STACK_HOST. Workers stay covered because PHP replicas can run there. - Workspace (ubuntu): tests/external/repository/test_urls_reachable.py probed the literal "https://hub.docker.com/v2" from utils/docker/image/runtime.py:20 and got HTTP 404. The constant is gone; the endpoint is written as one f-string at the call site, the way utils/update/docker.py:104 and utils/update/source.py do, which the URL test skips as a template. With the scheme now visible in the literal, ruff reported the noqa: S310 on urllib.request.Request as unused. Both test files that imported unittest twice (CodeQL) now use one `from unittest import ...` form. The run_once queue leak that spreads the stack host's post-load queue to every host is fixed separately on the updater line (70ed8a2e98); when it meets main, sys-ctl-hlth-runtime moves into sys-svc-container's queue. Co-Authored-By: Claude Opus 5.5 --- roles/sys-ctl-hlth-runtime/tasks/main.yml | 4 +++- .../lookup_plugins/test_php_hardened_services.py | 9 ++++----- .../python/utils/docker/test_image_runtime.py | 15 +++++++-------- utils/docker/image/runtime.py | 5 ++--- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/roles/sys-ctl-hlth-runtime/tasks/main.yml b/roles/sys-ctl-hlth-runtime/tasks/main.yml index 53fc6c85ca..573d6392e5 100644 --- a/roles/sys-ctl-hlth-runtime/tasks/main.yml +++ b/roles/sys-ctl-hlth-runtime/tasks/main.yml @@ -1,3 +1,5 @@ --- - include_tasks: 00_core.yml - when: run_once_sys_ctl_hlth_runtime is not defined + when: + - run_once_sys_ctl_hlth_runtime is not defined + - DEPLOYMENT_MODE == 'compose' or 'svc-swarm-node' in group_names diff --git a/tests/unit/python/roles/sys-ctl-hlth-runtime/lookup_plugins/test_php_hardened_services.py b/tests/unit/python/roles/sys-ctl-hlth-runtime/lookup_plugins/test_php_hardened_services.py index 113c602e11..6b85ad6a6a 100644 --- a/tests/unit/python/roles/sys-ctl-hlth-runtime/lookup_plugins/test_php_hardened_services.py +++ b/tests/unit/python/roles/sys-ctl-hlth-runtime/lookup_plugins/test_php_hardened_services.py @@ -2,8 +2,7 @@ from __future__ import annotations import importlib.util import sys -import unittest -from unittest import mock +from unittest import TestCase, main, mock from ansible.errors import AnsibleError @@ -37,7 +36,7 @@ HARDENING = { } -class TestHardenedServices(unittest.TestCase): +class TestHardenedServices(TestCase): def test_lists_every_mounting_service_once(self): entry = dict( HARDENING, @@ -58,7 +57,7 @@ class TestHardenedServices(unittest.TestCase): self.assertEqual(MODULE.hardened_services({"php_fpm_hardening": HARDENING}), []) -class TestLookup(unittest.TestCase): +class TestLookup(TestCase): def _run(self, volumes_by_role, **kwargs): lookup = MODULE.LookupModule() lookup._loader = mock.MagicMock() @@ -87,4 +86,4 @@ class TestLookup(unittest.TestCase): if __name__ == "__main__": - unittest.main() + main() diff --git a/tests/unit/python/utils/docker/test_image_runtime.py b/tests/unit/python/utils/docker/test_image_runtime.py index 74d9720a88..9b7c7e7489 100644 --- a/tests/unit/python/utils/docker/test_image_runtime.py +++ b/tests/unit/python/utils/docker/test_image_runtime.py @@ -3,9 +3,8 @@ from __future__ import annotations import io import json import tempfile -import unittest from pathlib import Path -from unittest import mock +from unittest import TestCase, main, mock from utils.docker.image import runtime @@ -16,7 +15,7 @@ def _php(version=None, lines=()): return runtime.PhpRuntime(version=version, lines=tuple(lines)) -class TestPhpRuntime(unittest.TestCase): +class TestPhpRuntime(TestCase): def test_reads_php_version_from_an_env_instruction(self): self.assertEqual( runtime.php_runtime( @@ -84,7 +83,7 @@ class TestPhpRuntime(unittest.TestCase): ) -class TestPhpFinding(unittest.TestCase): +class TestPhpFinding(TestCase): def test_a_version_below_its_floor_is_a_finding(self): self.assertIn( "below the security floor 8.4.27", @@ -116,7 +115,7 @@ class TestPhpFinding(unittest.TestCase): self.assertIsNone(runtime.php_finding(_php(lines=["8.3"]), FLOORS)) -class TestLoadPhpFloors(unittest.TestCase): +class TestLoadPhpFloors(TestCase): def test_reads_the_php_floors_from_the_vars_file(self): with tempfile.TemporaryDirectory() as tmp: path = Path(tmp) / "main.yml" @@ -128,7 +127,7 @@ class TestLoadPhpFloors(unittest.TestCase): self.assertEqual(runtime.load_php_floors(), {"8.4": "8.4.27"}) -class TestBuildInstructions(unittest.TestCase): +class TestBuildInstructions(TestCase): def test_a_docker_hub_tag_is_read_through_the_hub_api(self): with ( mock.patch.object( @@ -169,7 +168,7 @@ class TestBuildInstructions(unittest.TestCase): hub.assert_not_called() -class TestHubInstructions(unittest.TestCase): +class TestHubInstructions(TestCase): def _respond(self, payload): response = mock.MagicMock() response.__enter__.return_value = io.BytesIO(json.dumps(payload).encode()) @@ -212,4 +211,4 @@ class TestHubInstructions(unittest.TestCase): if __name__ == "__main__": - unittest.main() + main() diff --git a/utils/docker/image/runtime.py b/utils/docker/image/runtime.py index bb0fc8d9c3..9b564fe51a 100644 --- a/utils/docker/image/runtime.py +++ b/utils/docker/image/runtime.py @@ -17,7 +17,6 @@ from utils.roles.mapping import ROLE_FILE_VARS_MAIN FLOORS_FILE = PROJECT_ROOT / "roles" / "sys-ctl-hlth-runtime" / ROLE_FILE_VARS_MAIN FLOORS_KEY = "HEALTH_RUNTIME_FLOORS" -HUB_API = "https://hub.docker.com/v2" USER_AGENT = "infinito-nexus-runtime-report" PHP_VERSION_PATTERN = re.compile(r"\bPHP_VERSION=([0-9][^\s\"';]*)") PHP_BASE_PATTERN = re.compile(r"\bPHP_BASE=(\d+\.\d+)(?![\d.])") @@ -53,10 +52,10 @@ def _hub_instructions( repository: str, tag: str, os_name: str, architecture: str ) -> list[str] | None: url = ( - f"{HUB_API}/repositories/{quote(repository, safe='/')}" + f"https://hub.docker.com/v2/repositories/{quote(repository, safe='/')}" f"/tags/{quote(tag, safe='')}/images" ) - request = urllib.request.Request( # noqa: S310 - https request to hub.docker.com + request = urllib.request.Request( url, headers={"User-Agent": USER_AGENT, "Accept": "application/json"} ) try: