Files
computer-playbook/tests/unit/python/plugins/lookup/test_deploy_domains.py
T
kevinveenbirkenbachandClaude Opus 5.5 a67dd9b372 feat(constructor): stop a deploy in a pre-flight when the host cannot carry it
The constructor now runs tasks/utils/constructor/preflight.yml before the package install and fails with a named remedy when: the running kernel has no module index on disk or the clock is not synchronised (chrony leap status, else timedatectl, outside containers); / or the docker root is fuller than SIZE_PERCENT_MAXIMUM_DISK_USAGE (90); a docker network contradicts the entity that declares it (name, compose project label, subnet outside its block, overlap with another declared subnet); a declared container lacks or a declared volume carries a foreign entity label; a docker default address pool overlaps the mesh, Tor or a declared subnet; a host process outside docker holds a public port of the deploy; or, in assert mode, a clearnet domain of the deploy does not resolve.

A volume without any label passes, since compose adopts it and installs before this change created the Synapse volume with docker run. web-app-discourse declares its launcher-started containers through networks.local.launcher, and web-app-matrix labels a new Synapse volume with its compose project.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 13:38:15 +01:00

51 lines
1.5 KiB
Python

import unittest
from unittest import mock
from ansible.errors import AnsibleError
from plugins.lookup.deploy_domains import LookupModule
from utils.preflight.context import DeployClosureContext
MODULE = "plugins.lookup.deploy_domains"
DOMAINS = {
"web-app-matomo": ["matomo.example.org", "matomo.abc.onion"],
"web-app-nextcloud": {"canonical": "cloud.example.org"},
}
def _context():
return DeployClosureContext(
roles=["svc-db-mariadb", "web-app-matomo", "web-app-nextcloud"],
applications={},
config=mock.Mock(),
lookup=lambda name, role, default: DOMAINS.get(role, default),
)
class TestDeployDomainsLookup(unittest.TestCase):
def _run(self, terms, side_effect=None):
with mock.patch(
f"{MODULE}.deploy_closure_context",
return_value=_context(),
side_effect=side_effect,
):
return LookupModule().run(terms, variables={})
def test_the_clearnet_domains_of_every_closure_role_are_listed(self):
self.assertEqual(
self._run([["web-app-matomo"]]),
[["cloud.example.org", "matomo.example.org"]],
)
def test_a_closure_error_becomes_an_ansible_error(self):
with self.assertRaises(AnsibleError):
self._run([[]], side_effect=TypeError("x"))
def test_a_wrong_term_count_is_rejected(self):
with self.assertRaises(AnsibleError):
LookupModule().run([[], []])
if __name__ == "__main__":
unittest.main()