Merge branch 'main' into feature/store-i18n

This commit is contained in:
kevinveenbirkenbach committed 2026-10-19 01:54:37 +02:00
commit 15930945fe
342 files changed
+7444 -1661

No files matched your search

@@ -113,6 +113,7 @@ class TestArtifactSlug(unittest.TestCase):
entry["distro"],
entry["filesystem"],
entry["architecture"],
entry["vpn"] == "true",
),
),
)
@@ -224,7 +225,7 @@ class TestPriorityCoverage(unittest.TestCase):
def test_an_incapable_priority_variant_skips_its_onion_runs(self) -> None:
rows = [_row("web-app-a", 1, ("compose", "swarm"), priority=True)]
entries = _assign(rows, sweep=0, tor_mode="auto", variants_per_app=_VARIANTS)
self.assertEqual([e["tor"] for e in entries], ["false", "false"])
self.assertEqual({e["tor"] for e in entries}, {"false"})
class TestAssign(unittest.TestCase):
@@ -324,6 +325,29 @@ class TestAssign(unittest.TestCase):
self.assertNotIn("false", [e["tor"] for e in entries])
class TestMeshRotation(unittest.TestCase):
_ROWS = tuple(_row("web-app-b", 0, ("compose", "swarm")) for _ in range(8))
def _entries(self, sweep: int) -> list[dict[str, str]]:
return _assign(
self._ROWS, sweep=sweep, tor_mode="auto", variants_per_app=_VARIANTS
)
def test_every_sweep_lands_swarm_rows_on_both_arms(self) -> None:
for sweep in range(8):
with self.subTest(sweep=sweep):
arms = {e["vpn"] for e in self._entries(sweep) if e["mode"] == "swarm"}
self.assertEqual(arms, {"true", "false"})
def test_a_compose_row_never_carries_the_mesh(self) -> None:
for sweep in range(8):
with self.subTest(sweep=sweep):
arms = {
e["vpn"] for e in self._entries(sweep) if e["mode"] == "compose"
}
self.assertEqual(arms, {"false"})
class TestPinnedAxes(unittest.TestCase):
def _entries(self, row: dict) -> list[dict[str, str]]:
return _assign([row], sweep=0, tor_mode="auto", variants_per_app=_VARIANTS)
@@ -373,9 +397,30 @@ class TestPinnedAxes(unittest.TestCase):
priority=True,
pin_mode="swarm",
pin_tor=False,
pin_vpn=False,
)
self.assertEqual(len(self._entries(row)), 1)
def test_a_held_mesh_axis_overrides_a_priority_rows_pin(self) -> None:
row = _row(
"web-app-b", 0, ("swarm",), priority=True, pin_mode="swarm", pin_vpn=False
)
entries = _assign(
[row],
sweep=0,
tor_mode="auto",
variants_per_app=_VARIANTS,
vpn_mode="enforced",
)
self.assertNotEqual(entries, [])
self.assertEqual({e["vpn"] for e in entries}, {"true"})
def test_a_priority_rows_pin_still_narrows_a_rotating_axis(self) -> None:
row = _row(
"web-app-b", 0, ("swarm",), priority=True, pin_mode="swarm", pin_vpn=False
)
self.assertEqual({e["vpn"] for e in self._entries(row)}, {"false"})
def test_an_unoffered_mode_aborts_the_matrix(self) -> None:
row = _row("web-app-b", 0, ("compose",), pin_mode="swarm")
with self.assertRaises(SystemExit):
@@ -449,7 +494,13 @@ class TestDistroAndFilesystemAxes(unittest.TestCase):
def test_a_priority_row_spreads_its_combinations_over_the_pool(self) -> None:
rows = [_row("web-app-b", 0, ("compose", "swarm"), priority=True)]
entries = _assign(rows, sweep=0, tor_mode="auto", variants_per_app=_VARIANTS)
self.assertEqual(len({e["distro"] for e in entries}), len(entries))
self.assertEqual(
len({e["distro"] for e in entries}),
min(len(entries), len(axes.DISTROS)),
"a priority row must walk the pool, not repeat one distribution; "
"once it has more combinations than the pool has members, the "
"rotation wraps and every distribution is proven at least once",
)
def test_a_pinned_distro_replaces_the_rotation(self) -> None:
rows = [_row("web-app-b", 0, ("compose",), pin_distro="fedora")]
@@ -505,6 +556,7 @@ class TestDistroAndFilesystemAxes(unittest.TestCase):
entry["label"].startswith(
to_emoji("compose")
+ to_emoji("clearnet")
+ to_emoji("direct")
+ to_emoji("debian")
+ to_emoji("zfs")
)
@@ -0,0 +1,39 @@
import unittest
from utils.networks.mesh import dialled_peers, is_full, listens
HUB_PEER = {"host": "mgr", "address": "10.100.0.1", "is_hub": True}
SPOKE_PEER = {"host": "wrk", "address": "10.100.0.11", "is_hub": False}
OTHER_PEER = {"host": "nfs", "address": "10.100.0.12", "is_hub": False}
HUB = {"name": "swarm", "is_hub": True, "peers": [SPOKE_PEER, OTHER_PEER]}
SPOKE = {"name": "swarm", "is_hub": False, "peers": [HUB_PEER]}
FULL = {"name": "alpha", "is_hub": False, "peers": [SPOKE_PEER, OTHER_PEER]}
class TestHubAndSpoke(unittest.TestCase):
def test_only_the_hub_listens(self):
self.assertTrue(listens(HUB))
self.assertFalse(listens(SPOKE))
def test_a_spoke_dials_its_hub_alone(self):
self.assertEqual([HUB_PEER], dialled_peers(SPOKE))
def test_the_hub_dials_nobody(self):
self.assertEqual([], dialled_peers(HUB))
def test_neither_is_a_full_mesh(self):
self.assertFalse(is_full(HUB))
self.assertFalse(is_full(SPOKE))
class TestFullMesh(unittest.TestCase):
def test_a_member_listens(self):
self.assertTrue(is_full(FULL))
self.assertTrue(listens(FULL))
def test_a_member_dials_every_peer(self):
self.assertEqual([SPOKE_PEER, OTHER_PEER], dialled_peers(FULL))
def test_a_malformed_peer_list_dials_nobody(self):
self.assertEqual([], dialled_peers({"is_hub": False, "peers": "mgr"}))
@@ -1,42 +0,0 @@
import contextlib
import io
import unittest
import unittest.mock as mock
from utils.tests.swarm import matrix
class TestRunReporting(unittest.TestCase):
"""Every matrix phase must state what it cost.
A phase that only announces its start leaves the reader subtracting
timestamps by hand, and a phase that produces no output of its own becomes
invisible: the credential rotation spent 17 minutes of a budget-killed job
with nothing but the 30-second sampler in between.
"""
def _run_capturing(self, rc: int) -> tuple[int, str]:
buffer = io.StringIO()
with (
mock.patch.object(matrix, "run_watched", return_value=rc) as watched,
contextlib.redirect_stdout(buffer),
):
returned = matrix._run(["true"], env={"A": "b"}, label="demo phase")
watched.assert_called_once_with(["true"], env={"A": "b"})
return returned, buffer.getvalue()
def test_the_exit_code_passes_through(self) -> None:
returned, _ = self._run_capturing(7)
self.assertEqual(returned, 7)
def test_the_phase_announces_its_start(self) -> None:
_, output = self._run_capturing(0)
self.assertIn("=== swarm-matrix: demo phase ===", output)
def test_the_phase_reports_its_duration_and_outcome(self) -> None:
_, output = self._run_capturing(124)
self.assertRegex(output, r"demo phase took \d+s \(rc=124\)")
if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,153 @@
from __future__ import annotations
import tempfile
import unittest
import unittest.mock as mock
from pathlib import Path
from utils.cache.yaml import load_yaml_any
from utils.tests.swarm import mesh as mesh_steps
MESH = """\
applications:
svc-net-wireguard:
networks:
interfaces:
- name: swarm
host: {host}
address: {address}
"""
class TestSwitchToMeshTransport(unittest.TestCase):
def _inventory(self, td: str) -> Path:
host_vars = Path(td) / "host_vars"
host_vars.mkdir()
for host, address in (
("web-app-openbao-swarm-mgr-01", "10.100.0.1"),
("web-app-openbao-swarm-wrk-01", "10.100.0.12"),
("localhost", "10.100.0.11"),
):
(host_vars / f"{host}.yml").write_text(
MESH.format(host=host, address=address), encoding="utf-8"
)
return host_vars
def _run(self, td: str) -> int:
env = {
"INFINITO_SWARM_VPN": "true",
"INFINITO_SWARM_MESHES": "",
"KEY_PATH": str(Path(td) / "admin.key"),
}
with mock.patch.dict("os.environ", env, clear=False):
return mesh_steps.switch_to_mesh_transport(inv_dir=td)
def test_a_node_is_pointed_at_its_mesh_address(self):
with tempfile.TemporaryDirectory() as td:
host_vars = self._inventory(td)
self.assertEqual(self._run(td), 0)
doc = load_yaml_any(str(host_vars / "web-app-openbao-swarm-wrk-01.yml"))
self.assertEqual(doc["ansible_host"], "10.100.0.12")
self.assertEqual(doc["ansible_connection"], "ssh")
def test_the_controller_keeps_its_own_transport(self):
with tempfile.TemporaryDirectory() as td:
host_vars = self._inventory(td)
self.assertEqual(self._run(td), 0)
doc = load_yaml_any(str(host_vars / "localhost.yml"))
self.assertNotIn("ansible_connection", doc)
self.assertNotIn("ansible_host", doc)
EXAMPLE = "inventories/examples/wireguard-three-meshes/wireguard.yml"
class TestLayout(unittest.TestCase):
def _env(self, meshes: str):
return mock.patch.dict(
"os.environ",
{"INFINITO_SWARM_VPN": "true", "INFINITO_SWARM_MESHES": meshes},
clear=False,
)
def test_an_unset_choice_deploys_the_development_meshes(self):
with self._env(""):
self.assertEqual(mesh_steps.transport_mesh(), "swarm")
def test_an_example_moves_the_transport_onto_its_first_mesh(self):
with self._env(EXAMPLE):
self.assertEqual(mesh_steps.transport_mesh(), "alpha")
def test_the_layout_is_handed_over_as_inventory_values(self):
with self._env(EXAMPLE):
applications = mesh_steps.layout_applications()
self.assertEqual(
["alpha", "beta", "gamma"],
[
mesh["name"]
for mesh in applications["svc-net-wireguard"]["networks"]["meshes"]
],
)
self.assertEqual(
["alpha"], applications["svc-swarm-node"]["networks"]["meshes"]
)
def test_the_writer_reads_the_meshes_from_the_inventory(self):
with (
self._env(EXAMPLE),
mock.patch.object(mesh_steps, "run_step", return_value=0) as step,
):
self.assertEqual(mesh_steps.write_mesh(inv_dir="/tmp/inv"), 0)
argv = step.call_args.args[0]
self.assertNotIn("--group-vars-file", argv)
self.assertEqual(argv[argv.index("--controller-mesh") + 1], "alpha")
LINKS = """[
{"ifname": "alpha", "addr_info": [{"local": "10.100.10.11", "prefixlen": 24}]},
{"ifname": "swarm", "addr_info": [{"local": "10.100.0.11", "prefixlen": 24}]},
{"ifname": "wg0", "addr_info": [{"local": "10.8.0.2", "prefixlen": 24}]}
]"""
class TestStaleControllerInterfaces(unittest.TestCase):
def _stale(self) -> list[str]:
listed = mock.Mock(stdout=LINKS)
with (
mock.patch.dict("os.environ", {"INFINITO_SWARM_MESHES": ""}, clear=False),
mock.patch.object(mesh_steps.subprocess, "run", return_value=listed),
):
return mesh_steps.stale_controller_interfaces()
def test_a_pool_link_no_declaration_names_is_stale(self):
self.assertIn("alpha", self._stale())
def test_a_declared_mesh_is_kept(self):
self.assertNotIn("swarm", self._stale())
def test_a_link_outside_the_pool_is_not_the_harness_to_remove(self):
self.assertNotIn("wg0", self._stale())
def test_the_stale_link_goes_before_the_controller_joins(self):
calls: list[list[str]] = []
with (
tempfile.TemporaryDirectory() as td,
mock.patch.dict("os.environ", {"INFINITO_SWARM_VPN": "true"}, clear=False),
mock.patch.object(
mesh_steps, "stale_controller_interfaces", return_value=["alpha"]
),
mock.patch.object(
mesh_steps,
"run_step",
side_effect=lambda cmd, **_: calls.append(cmd) or 0,
),
):
self.assertEqual(mesh_steps.mesh_controller(inv_dir=td), 0)
self.assertEqual(calls[0][-4:], ["ip", "link", "delete", "alpha"])
self.assertEqual(calls[1][0], "ansible-playbook")
if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,52 @@
import contextlib
import io
import unittest
import unittest.mock as mock
from utils.tests.swarm import matrix, run
class TestRunReporting(unittest.TestCase):
"""Every matrix phase must state what it cost.
A phase that only announces its start leaves the reader subtracting
timestamps by hand, and a phase that produces no output of its own becomes
invisible: the credential rotation spent 17 minutes of a budget-killed job
with nothing but the 30-second sampler in between.
"""
_RUNNERS = ((matrix, "_run"), (run, "run_step"))
def _run_capturing(self, module, name: str, rc: int) -> tuple[int, str]:
buffer = io.StringIO()
with (
mock.patch.object(module, "run_watched", return_value=rc) as watched,
contextlib.redirect_stdout(buffer),
):
returned = getattr(module, name)(
["true"], env={"A": "b"}, label="demo phase"
)
watched.assert_called_once_with(["true"], env={"A": "b"})
return returned, buffer.getvalue()
def test_the_exit_code_passes_through(self) -> None:
for module, name in self._RUNNERS:
with self.subTest(runner=f"{module.__name__}.{name}"):
returned, _ = self._run_capturing(module, name, 7)
self.assertEqual(returned, 7)
def test_the_phase_announces_its_start(self) -> None:
for module, name in self._RUNNERS:
with self.subTest(runner=f"{module.__name__}.{name}"):
_, output = self._run_capturing(module, name, 0)
self.assertIn("=== swarm-matrix: demo phase ===", output)
def test_the_phase_reports_its_duration_and_outcome(self) -> None:
for module, name in self._RUNNERS:
with self.subTest(runner=f"{module.__name__}.{name}"):
_, output = self._run_capturing(module, name, 124)
self.assertRegex(output, r"demo phase took \d+s \(rc=124\)")
if __name__ == "__main__":
unittest.main()
@@ -4,9 +4,10 @@ import tempfile
import unittest
import unittest.mock as mock
from pathlib import Path
from typing import ClassVar
from utils import PROJECT_ROOT
from utils.cache.yaml import load_yaml_any
from utils.cache.yaml import dump_yaml, load_yaml_any
from utils.env.parser import parse_static_env
from utils.tests.swarm.write import extras as write_extras
@@ -40,3 +41,105 @@ class TestWriteExtrasDomainPrimary(unittest.TestCase):
with tempfile.TemporaryDirectory() as td:
extras = self._run(td, {"INFINITO_DOMAIN": "override.example"})
self.assertEqual(extras["DOMAIN_PRIMARY"], "override.example")
class TestWriteExtrasMeshAddresses(unittest.TestCase):
MESHES: ClassVar[dict[str, dict[str, tuple[str, bool]]]] = {
"swarm-mgr-01": {
"alpha": ("10.100.10.1", True),
"beta": ("10.100.11.1", False),
},
"nfs-server": {
"beta": ("10.100.11.11", True),
"gamma": ("10.100.12.11", False),
},
}
def _run(self, td: str, *, meshed: bool) -> dict:
out_path = Path(td) / "extras.yml"
host_vars = Path(td) / "host_vars"
host_vars.mkdir()
if meshed:
for host, meshes in self.MESHES.items():
dump_yaml(
str(host_vars / f"{host}.yml"),
{
"applications": {
"svc-net-wireguard": {
"networks": {
"interfaces": [
{
"name": name,
"host": host,
"address": address,
"primary": primary,
}
for name, (address, primary) in meshes.items()
]
}
}
}
},
)
env = {
"NFS_IP": "192.168.244.13",
"MGR_IP": "192.168.244.10",
"MGR": "swarm-mgr-01",
"NFS_SERVER": "nfs-server",
"OUT_PATH": str(out_path),
"KEY_PATH": str(Path(td) / "admin.key"),
"INFINITO_SWARM_BACKUP_KEY": str(Path(td) / "backup.key"),
}
with mock.patch.dict("os.environ", env, clear=False):
self.assertEqual(write_extras.main(), 0)
return load_yaml_any(str(out_path))
def test_the_manager_advertises_its_primary_mesh_address(self):
with tempfile.TemporaryDirectory() as td:
extras = self._run(td, meshed=True)
self.assertEqual(extras["swarm"]["manager"]["advertise_addr"], "10.100.10.1")
def test_the_export_is_mounted_from_the_servers_primary_mesh_address(self):
with tempfile.TemporaryDirectory() as td:
extras = self._run(td, meshed=True)
self.assertEqual(extras["storage"]["nfs"]["server"], "10.100.11.11")
def test_a_round_without_a_mesh_keeps_the_underlay(self):
with tempfile.TemporaryDirectory() as td:
extras = self._run(td, meshed=False)
self.assertEqual(extras["swarm"]["manager"]["advertise_addr"], "192.168.244.10")
self.assertEqual(extras["storage"]["nfs"]["server"], "192.168.244.13")
class TestWriteExtrasBecomePassword(unittest.TestCase):
def _run(self, td: str) -> tuple[dict, dict]:
out_path = Path(td) / "extras.yml"
env = {
"NFS_IP": "192.168.244.2",
"MGR_IP": "192.168.244.3",
"MGR": "swarm-mgr-01",
"OUT_PATH": str(out_path),
"KEY_PATH": str(Path(td) / "admin.key"),
"INFINITO_SWARM_BACKUP_KEY": str(Path(td) / "backup.key"),
}
with mock.patch.dict("os.environ", env, clear=False):
self.assertEqual(write_extras.main(), 0)
return (
load_yaml_any(str(out_path)),
load_yaml_any(str(out_path.with_suffix(".deploy.yml"))),
)
def test_become_matches_the_administrator_account(self):
with tempfile.TemporaryDirectory() as td:
extras, deploy = self._run(td)
declared = extras["users"]["administrator"]["password"]
self.assertEqual(declared, extras["ansible_become_password"])
self.assertEqual(declared, deploy["ansible_become_password"])
def test_the_deploy_twin_carries_it_although_users_are_stripped(self):
with tempfile.TemporaryDirectory() as td:
_, deploy = self._run(td)
self.assertNotIn("users", deploy)
self.assertIn("ansible_become_password", deploy)