Files
kevinveenbirkenbachandClaude Opus 5.5 f6613b78fd fix(roles): bring the role_version lookup and its image-check resolution to main
Custom roles such as web-app-cst-store pin their images to their own release,
`v{{ lookup('role_version', '<role>') }}`. Main had neither the lookup nor the
image discovery that resolves it, so core's external image tests rejected the
template as neither version nor digest and asked the registry for the literal
string (GUI CI job core / custom-role (test), red since 2026-11-11).

Ports e615f5fa22 (record the source semver in the pull marker, add the
role_version lookup) and ed9101780e (resolve role_version pins in image
checks) from the production line, without the rest of that branch. Adds
tests/unit/python/tests/external/update/docker/test_role_version_pins.py,
which runs the real pin-policy and reachability checks against a custom-role
fixture with the registry mocked; reverting the discovery change fails it at
the same lines as the GUI CI.

🎯 Fix: 94 %
💥 Break: 3 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 91
🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 %

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 17:27:08 +00:00

68 lines
2.4 KiB
Python

from __future__ import annotations
import tempfile
import unittest
from pathlib import Path
from ansible.errors import AnsibleError
from cli.administration.roles.marker import MARKER_FILE, marker_text
from plugins.lookup.role_version import LookupModule
ROLE = "web-app-cst-demo"
ORIGIN = "https://example.invalid/demo.git ansible/roles/web-app-cst-demo @ v0.4.3 (commit abc)"
class TestRoleVersion(unittest.TestCase):
def setUp(self) -> None:
tmp = tempfile.TemporaryDirectory()
self.addCleanup(tmp.cleanup)
self.root = Path(tmp.name)
self.variables = {"playbook_dir": str(self.root)}
def _place(self, directory: str, version: str) -> None:
role = self.root / "roles" / directory
role.mkdir(parents=True)
(role / MARKER_FILE).write_text(
marker_text(directory, directory, ORIGIN, version), encoding="utf-8"
)
def _lookup(self, application_id: str) -> list[str]:
return LookupModule().run([application_id], variables=self.variables)
def test_returns_the_version_the_pull_recorded(self):
self._place(ROLE, "0.4.3")
self.assertEqual(["0.4.3"], self._lookup(ROLE))
def test_a_pull_without_a_version_fails_naming_the_manifests(self):
self._place(ROLE, "")
with self.assertRaisesRegex(AnsibleError, "Cargo.toml, pyproject.toml"):
self._lookup(ROLE)
def test_a_role_the_pull_did_not_place_fails(self):
(self.root / "roles" / ROLE).mkdir(parents=True)
with self.assertRaisesRegex(AnsibleError, "was not placed by a pull"):
self._lookup(ROLE)
def test_a_marker_naming_another_directory_fails(self):
self._place("web-app-cst-other", "0.4.3")
(self.root / "roles" / "web-app-cst-other").rename(self.root / "roles" / ROLE)
with self.assertRaisesRegex(AnsibleError, "was not placed by a pull"):
self._lookup(ROLE)
def test_an_in_tree_role_is_refused(self):
with self.assertRaisesRegex(AnsibleError, "is no custom role"):
self._lookup("web-app-nextcloud")
def test_exactly_one_term_is_required(self):
with self.assertRaises(AnsibleError):
LookupModule().run([], variables=self.variables)
def test_playbook_dir_is_required(self):
with self.assertRaisesRegex(AnsibleError, "playbook_dir"):
LookupModule().run([ROLE], variables={})
if __name__ == "__main__":
unittest.main()