Files
computer-playbook/tests/unit/python/utils/preflight/test_pools.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

57 lines
2.1 KiB
Python

import unittest
from utils.preflight.pools import address_pool_errors
RESERVED = [
("NETWORK_MESH_POOL reserves", "10.100.0.0/16"),
("NETWORK_TOR_VIRTUAL_CIDR reserves", "10.240.0.0/12"),
("web-app-matomo declares for its network 'matomo'", "192.168.31.0/24"),
]
class TestAddressPoolErrors(unittest.TestCase):
def test_the_shipped_pool_is_clear(self):
config = {"default-address-pools": [{"base": "10.208.0.0/12", "size": 24}]}
self.assertEqual(address_pool_errors(config, RESERVED), [])
def test_an_absent_file_or_key_has_nothing_to_compare(self):
self.assertEqual(address_pool_errors({}, RESERVED), [])
self.assertEqual(address_pool_errors({"dns": ["192.0.2.53"]}, RESERVED), [])
def test_a_pool_over_a_role_subnet_and_the_mesh_names_both(self):
config = {
"default-address-pools": [
{"base": "192.168.0.0/16", "size": 20},
{"base": "10.0.0.0/8", "size": 24},
]
}
self.assertEqual(
address_pool_errors(config, RESERVED),
[
(
"docker default address pool 192.168.0.0/16 overlaps 192.168.31.0/24, "
"which web-app-matomo declares for its network 'matomo'"
),
(
"docker default address pool 10.0.0.0/8 overlaps 10.100.0.0/16, "
"which NETWORK_MESH_POOL reserves"
),
(
"docker default address pool 10.0.0.0/8 overlaps 10.240.0.0/12, "
"which NETWORK_TOR_VIRTUAL_CIDR reserves"
),
],
)
def test_an_ipv6_pool_never_overlaps_an_ipv4_range(self):
config = {"default-address-pools": [{"base": "fd00::/48", "size": 64}]}
self.assertEqual(address_pool_errors(config, RESERVED), [])
def test_a_pool_without_a_base_is_rejected(self):
with self.assertRaises(ValueError):
address_pool_errors({"default-address-pools": [{"size": 24}]}, RESERVED)
if __name__ == "__main__":
unittest.main()