test(swarm-test): extras bind swarm and NFS to the primary mesh

This commit is contained in:
evangelostsak committed 2026-10-14 11:23:23 +02:00
1 parent af74e70ac0
commit 2f96b52580
1 file changed
+69 -1
@@ -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
@@ -42,6 +43,73 @@ class TestWriteExtrasDomainPrimary(unittest.TestCase):
self.assertEqual(extras["DOMAIN_PRIMARY"], "override.example")
class TestWriteExtrasMeshAddresses(unittest.TestCase):
"""Swarm and NFS bind to the primary mesh, whatever the deployment named it."""
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": {
"meshes": {
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"