Files
computer-playbook/tests/unit/python/utils/networks/test_mesh_declarations.py
T
kevinveenbirkenbachandClaude Opus 5.5 05135a7cee feat(svc-net-wireguard): let a compose deployment name a hub with roaming spokes
Without a swarm manager the mesh planner only built full meshes, whose
handshake gate waits for every peer, so laptops behind NAT could not join.
An inventory may now name a hub in networks.hub: the planner builds every
declared mesh around it, the hub forwards between its spokes, a spoke marked
networks.roaming gets no endpoint in the hub's peer list and dials the hub
with PersistentKeepalive, and the hub's gate skips roaming spokes while a
roaming spoke gates only on the hub. The mesh CLI takes the hub's public
address per host (--endpoint) and a vault password per host
(--host-vault-password-file). Full meshes and the swarm manager hub plan
exactly as before; NETWORK_MESH_POOL keeps the operator's subnet.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 10:56:50 +02:00

59 lines
1.9 KiB
Python

import unittest
from utils.networks.mesh import declared_hub, is_roaming, joined_meshes
DECLARATION = {"name": "wg0", "subnet": "10.0.0.0/24", "listen_port": 51871}
def _own(**networks) -> dict:
return {"svc-net-wireguard": {"networks": networks}}
class TestDeclaredHub(unittest.TestCase):
def test_a_named_hub_is_returned(self):
self.assertEqual("galaxy", declared_hub(_own(hub="galaxy")))
def test_an_absent_hub_is_empty(self):
self.assertEqual("", declared_hub(_own(meshes=[DECLARATION])))
def test_the_shipped_empty_hub_is_empty(self):
self.assertEqual("", declared_hub(_own(hub="")))
def test_a_hub_that_is_no_hostname_is_refused(self):
with self.assertRaises(TypeError):
declared_hub(_own(hub=True))
class TestRoaming(unittest.TestCase):
def test_a_marked_host_roams(self):
self.assertTrue(is_roaming(_own(roaming=True)))
def test_an_unmarked_host_stays_put(self):
self.assertFalse(is_roaming(_own()))
def test_a_roaming_flag_that_is_no_boolean_is_refused(self):
with self.assertRaises(TypeError):
is_roaming(_own(roaming="yes"))
class TestJoinedMeshes(unittest.TestCase):
def test_a_name_in_the_own_list_joins_the_host(self):
self.assertEqual(
{"wg0": ["svc-net-wireguard"]},
joined_meshes(_own(meshes=["wg0"]), ["svc-net-wireguard"]),
)
def test_a_declaration_in_the_own_list_joins_nothing(self):
self.assertEqual(
{}, joined_meshes(_own(meshes=[DECLARATION]), ["svc-net-wireguard"])
)
def test_the_own_list_counts_only_in_the_wireguard_group(self):
self.assertEqual({}, joined_meshes(_own(meshes=["wg0"]), ["web-app-a"]))
def test_another_role_still_joins_its_hosts(self):
applications = {"web-app-a": {"networks": {"meshes": ["wg0"]}}}
self.assertEqual(
{"wg0": ["web-app-a"]}, joined_meshes(applications, ["web-app-a"])
)