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: