mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-11 05:06:36 +00:00
The test from feature/updater renders the real daemon.json.j2, which on store-i18n also reads IS_SWARM_MODE, the NVIDIA runtime shim and the daemon MTU. Its context lacked them, so both cases died with "'IS_SWARM_MODE' is undefined". The context now carries them and derives the mode booleans from DEPLOYMENT_MODE like test_sandbox_runtime does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
70 lines
2.4 KiB
Python
70 lines
2.4 KiB
Python
import json
|
|
import unittest
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
|
|
from jinja2 import Environment, FileSystemLoader, StrictUndefined, select_autoescape
|
|
|
|
from utils import PROJECT_ROOT
|
|
|
|
TEMPLATES = Path(PROJECT_ROOT) / "roles" / "sys-svc-container" / "templates"
|
|
|
|
|
|
def _shim(exists):
|
|
return SimpleNamespace(stat=SimpleNamespace(exists=exists))
|
|
|
|
|
|
def _daemon_json(**overrides):
|
|
env = Environment(
|
|
loader=FileSystemLoader(str(TEMPLATES)),
|
|
trim_blocks=True,
|
|
undefined=StrictUndefined,
|
|
autoescape=select_autoescape(),
|
|
)
|
|
env.filters["bool"] = lambda value: value is True or str(value).lower() == "true"
|
|
env.filters["to_json"] = json.dumps
|
|
env.globals["lookup"] = lambda name, *_a, **_k: []
|
|
variables = {
|
|
"DEPLOYMENT_MODE": "compose",
|
|
"IS_STACK_HOST": True,
|
|
"DOCKER_IN_CONTAINER": False,
|
|
"DOMAIN_PRIMARY": "infinito.test",
|
|
"KATA_SHIM_BINARY": "/usr/bin/containerd-shim-kata-v2",
|
|
"RUNSC_SHIM_BINARY": "/usr/local/bin/runsc",
|
|
"NVIDIA_RUNTIME_BINARY": "/usr/bin/nvidia-container-runtime",
|
|
"SANDBOX_RUNTIME": "runsc",
|
|
"SYS_SVC_CONTAINER_DATA_ROOT": "",
|
|
"swarm": {"registry": {"host": "", "port": 5000}},
|
|
"groups": {"svc-registry-cache": []},
|
|
"ansible_facts": {"os_family": "Debian"},
|
|
"SYS_SVC_CONTAINER_DOCKER_FIREWALL_BACKEND_BY_OS_FAMILY": {
|
|
"Debian": "iptables"
|
|
},
|
|
"NETWORK_DOCKER_ADDRESS_POOLS": [{"base": "10.208.0.0/12", "size": 24}],
|
|
"SYS_DOCKER_DAEMONM_MTU": 1400,
|
|
"sys_svc_container_kvm": _shim(False),
|
|
"sys_svc_container_kata_shim": _shim(False),
|
|
"sys_svc_container_runsc_shim": _shim(False),
|
|
"sys_svc_container_nvidia_shim": _shim(False),
|
|
**overrides,
|
|
}
|
|
mode = variables["DEPLOYMENT_MODE"]
|
|
variables["IS_COMPOSE_MODE"] = mode == "compose"
|
|
variables["IS_SWARM_MODE"] = mode == "swarm"
|
|
return json.loads(env.get_template("daemon.json.j2").render(variables))
|
|
|
|
|
|
class TestUserlandProxy(unittest.TestCase):
|
|
def test_the_daemon_publishes_ports_without_the_userland_proxy(self):
|
|
self.assertIs(_daemon_json()["userland-proxy"], False)
|
|
|
|
def test_swarm_and_docker_in_docker_keep_it_off(self):
|
|
parsed = _daemon_json(
|
|
DEPLOYMENT_MODE="swarm", IS_STACK_HOST=False, DOCKER_IN_CONTAINER=True
|
|
)
|
|
self.assertIs(parsed["userland-proxy"], False)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|