Merge remote-tracking branch 'upstream/main' into feature/svc-net-wireguard

This commit is contained in:
evangelostsak committed 2026-10-17 22:19:57 +02:00
commit 0c9ad653f7
14 files changed
+169 -15

No files matched your search

Whitespace-only changes.
Whitespace-only changes.
@@ -0,0 +1,80 @@
import os
import subprocess
import tempfile
import unittest
from pathlib import Path
from utils import PROJECT_ROOT
SCRIPT = PROJECT_ROOT / "roles/web-app-openproject/files/shell/await_migrations.sh"
BUNDLE_STUB = """#!/usr/bin/env bash
printf '%s\\n' "$*" >>"${STUB_DIR}/calls"
cat "${STUB_DIR}/status"
exit "${STUB_RC}"
"""
HEADER = (
"\ndatabase: openproject\n\n"
" Status Migration ID Migration Name\n" + "-" * 50 + "\n"
)
ALL_UP = HEADER + " up 1000016 Aggregated migrations\n"
ONE_DOWN = ALL_UP + " down 20261001000000 Add announcement flags\n"
class TestAwaitMigrations(unittest.TestCase):
def run_gate(self, status, rc=0):
"""Run the gate against a stubbed `bundle` with a 2 s deadline.
Args:
status: what the stubbed `rails db:migrate:status` prints.
rc: exit code of the stubbed `bundle`.
Returns:
Tuple of the gate's stdout plus stderr and the recorded `bundle` calls.
"""
with tempfile.TemporaryDirectory() as tmp:
stub_dir = Path(tmp)
bundle = stub_dir / "bundle"
bundle.write_text(BUNDLE_STUB)
bundle.chmod(0o755)
(stub_dir / "status").write_text(status)
env = dict(os.environ)
env["PATH"] = f"{stub_dir}{os.pathsep}{env['PATH']}"
env["STUB_DIR"] = tmp
env["STUB_RC"] = str(rc)
done = subprocess.run(
["bash", str(SCRIPT), "2", "1", "echo", "ENTRYPOINT"],
env=env,
capture_output=True,
text=True,
check=False,
)
calls = (
stub_dir / "calls"
).read_text() # nocheck: cache-read tempdir fixture
return done.stdout + done.stderr, calls
def test_a_current_schema_starts_the_entrypoint_at_once(self):
output, calls = self.run_gate(ALL_UP)
self.assertIn("schema is current", output)
self.assertIn("ENTRYPOINT", output)
self.assertEqual(calls.splitlines(), ["exec rails db:migrate:status"])
def test_a_pending_migration_keeps_the_gate_waiting(self):
output, calls = self.run_gate(ONE_DOWN)
self.assertIn("deadline of 2s reached", output)
self.assertGreaterEqual(len(calls.splitlines()), 1)
def test_a_failing_probe_keeps_the_gate_waiting(self):
output, _ = self.run_gate("", rc=1)
self.assertIn("deadline of 2s reached", output)
def test_the_probe_never_builds_a_migrator(self):
_, calls = self.run_gate(ONE_DOWN)
self.assertNotIn("abort_if_pending_migrations", calls)
self.assertEqual(set(calls.splitlines()), {"exec rails db:migrate:status"})
if __name__ == "__main__":
unittest.main()
+55
View File
@@ -16,6 +16,7 @@ import tempfile
import textwrap
import unittest
from pathlib import Path
from unittest import mock
from utils.cache import _reset_cache_for_tests
from utils.cache import applications as cache_apps
@@ -422,6 +423,60 @@ class TestGetMergedApplicationsCarrierFact(unittest.TestCase):
)
class TestNestedLookupsReuseTheUnrenderedView(unittest.TestCase):
def setUp(self) -> None:
_reset_cache_for_tests()
def test_nested_calls_during_one_render_build_the_defaults_once(self):
with tempfile.TemporaryDirectory() as tmp:
roles = _seed_minimal_roles(Path(tmp))
_write(
roles / "web-app-foo" / ROLE_FILE_META_SERVICES,
"""
foo:
image: "pre-{{ nested }}"
version: "v-{{ nested }}"
""",
)
variables = {
"applications": {
"web-app-foo": {"volumes": {"data": {"type": "volume"}}}
}
}
nested_views = []
class _NestingTemplar:
def __init__(self) -> None:
self.available_variables: dict = {}
def template(self, value, **_kwargs):
nested_views.append(
cache_apps.get_merged_applications(
variables=self.available_variables,
roles_dir=roles,
templar=self,
)
)
return "rendered"
with mock.patch.object(
cache_apps,
"get_application_defaults",
wraps=cache_apps.get_application_defaults,
) as defaults:
rendered = cache_apps.get_merged_applications(
variables=variables, roles_dir=roles, templar=_NestingTemplar()
)
self.assertEqual(defaults.call_count, 1)
self.assertGreaterEqual(len(nested_views), 2)
self.assertTrue(all(view is nested_views[0] for view in nested_views))
self.assertIn("volumes", nested_views[0]["web-app-foo"])
self.assertEqual(
rendered["web-app-foo"]["services"]["foo"]["image"], "rendered"
)
class TestRecursiveMetaWalk(unittest.TestCase):
"""`_build_role_base_config` walks the whole `meta/` tree: every
`meta/**/*.yml` lands at the matching nested path under