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

@@ -107,6 +107,27 @@ class TestModuleName(unittest.TestCase):
self._module_name(GENERIC_PACKAGE, {})
class TestManagerArguments(unittest.TestCase):
def _args(self, module, facts):
action = _action({})
action._connection = mock.Mock(become=None, transport="local")
action._execute_module = mock.Mock(return_value={})
action._execute(ModuleCall(module, {"name": ["wireguard-tools"]}), {}, facts)
return action._execute_module.call_args.kwargs["module_args"]
def test_apt_installs_without_recommends(self):
args = self._args(GENERIC_PACKAGE, {"pkg_mgr": "apt"})
self.assertFalse(args["install_recommends"])
def test_other_managers_keep_their_defaults(self):
args = self._args(GENERIC_PACKAGE, {"pkg_mgr": "dnf"})
self.assertNotIn("install_recommends", args)
def test_a_concrete_module_is_left_alone(self):
args = self._args("ansible.builtin.apt", {"pkg_mgr": "apt"})
self.assertNotIn("install_recommends", args)
class TestBecomeEscalation(unittest.TestCase):
def setUp(self):
self.become = become_loader.get("sudo")
@@ -0,0 +1,56 @@
from __future__ import annotations
import unittest
from ansible.errors import AnsibleError
import plugins.lookup.mesh_address as module
def _hostvars(host: str, *interfaces: dict) -> dict:
return {
host: {
"applications": {
"svc-net-wireguard": {"networks": {"interfaces": list(interfaces)}}
}
}
}
def _run(host: str, hostvars: dict) -> str:
return module.LookupModule().run([host], variables={"hostvars": hostvars})[0]
class TestMeshAddress(unittest.TestCase):
def test_the_primary_interface_is_returned(self):
hostvars = _hostvars(
"nfs",
{
"name": "gamma",
"host": "nfs",
"address": "10.100.12.11",
"primary": False,
},
{"name": "beta", "host": "nfs", "address": "10.100.11.11", "primary": True},
)
self.assertEqual("10.100.11.11", _run("nfs", hostvars))
def test_an_entry_another_host_owns_is_ignored(self):
hostvars = _hostvars(
"wrk",
{"name": "swarm", "host": "mgr", "address": "10.100.0.1", "primary": True},
)
self.assertEqual("", _run("wrk", hostvars))
def test_a_host_off_the_mesh_has_no_address(self):
self.assertEqual("", _run("wrk", {"wrk": {}}))
self.assertEqual("", _run("absent", {}))
def test_exactly_one_hostname_is_required(self):
for terms in ([], ["a", "b"]):
with self.subTest(terms=terms), self.assertRaises(AnsibleError):
module.LookupModule().run(terms, variables={})
if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,47 @@
from __future__ import annotations
import unittest
from ansible.errors import AnsibleError
import plugins.lookup.mesh_ranges as module
POOLS = "{{ [WIREGUARD_SUBNET_POOL] }}"
class _Templar:
def __init__(self, rendered):
self.rendered = rendered
def template(self, value, **_):
return self.rendered.get(value, value) if isinstance(value, str) else value
def _run(pools, rendered=None):
lookup = module.LookupModule()
lookup._templar = _Templar(rendered or {})
return lookup.run(None, variables={"WIREGUARD_SUBNET_POOLS": pools})[0]
class TestMeshRanges(unittest.TestCase):
def test_the_declared_template_is_rendered_before_it_is_returned(self):
self.assertEqual(
_run(POOLS, {POOLS: ["10.100.0.0/16"]}),
["10.100.0.0/16"],
)
def test_a_pool_that_stays_a_template_fails_instead_of_leaking(self):
with self.assertRaises(AnsibleError) as raised:
_run(POOLS)
self.assertIn("did not render", str(raised.exception))
def test_a_literal_list_passes_through(self):
self.assertEqual(_run(["10.100.0.0/16"]), ["10.100.0.0/16"])
def test_terms_are_refused(self):
with self.assertRaises(AnsibleError):
module.LookupModule().run(["x"], variables={})
if __name__ == "__main__":
unittest.main()