mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 06:17:25 +00:00
fix(provision): disable the services gated on a provider the row disables
A tor-only CI row disables web-svc-coturn, which no onion can serve, but the disabler switched off only service entries keyed coturn. Nextcloud's talk entry is gated on 'web-svc-coturn' in group_names and variant 0 pins it true, so Talk stayed on without a TURN server and 01_fullstack.yml's assert stopped every Nextcloud#0 tor row. When disable resolves to a provider role P, every entry whose base enabled is exactly the presence test of P is written false as well, and the reconcile releases those entries once P is no longer disabled. Negated, compound and variable gates are left alone. Across all 755 planner row states this changes one value an app sees: talk on Nextcloud#0 tor rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9e1cf40350
commit
1ed3fd11da
4 files changed
+424
-25
No files matched your search
@@ -13,6 +13,7 @@ from cli.administration.inventory.provision.services_disabler import (
|
||||
apply_services_disabled,
|
||||
apply_services_disabled_from_env,
|
||||
assert_services_disabled_inventory_consistency_from_env,
|
||||
find_presence_dependents,
|
||||
find_provider_roles,
|
||||
find_services_disabled_conflicts,
|
||||
parse_services_disabled,
|
||||
@@ -412,6 +413,175 @@ class TestApplyServicesDisabled(unittest.TestCase):
|
||||
self.assertFalse(result["applications"]["app-b"]["services"]["ldap"]["enabled"])
|
||||
|
||||
|
||||
COTURN_GATE = "{{ 'web-svc-coturn' in group_names }}"
|
||||
|
||||
|
||||
class TestPresenceDependents(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = TemporaryDirectory()
|
||||
self.addCleanup(self.tmp.cleanup)
|
||||
self.root = Path(self.tmp.name)
|
||||
self.yaml_rt = YAML(typ="rt")
|
||||
self.yaml_rt.preserve_quotes = True
|
||||
self.host_vars = self.root / "host_vars.yml"
|
||||
self.roles_dir = self.root / "roles"
|
||||
self.roles_dir.mkdir()
|
||||
self._make_role(
|
||||
"web-svc-coturn", {"coturn": {"image": "coturn", "shared": True}}
|
||||
)
|
||||
self._make_role(
|
||||
"web-app-matomo", {"matomo": {"image": "matomo", "shared": True}}
|
||||
)
|
||||
|
||||
def _make_role(self, role_name: str, services: dict) -> None:
|
||||
role_dir = self.roles_dir / role_name
|
||||
(role_dir / "meta").mkdir(parents=True)
|
||||
(role_dir / "vars").mkdir(parents=True)
|
||||
dump_yaml(role_dir / ROLE_FILE_META_SERVICES, services)
|
||||
dump_yaml(role_dir / ROLE_FILE_VARS_MAIN, {"application_id": role_name})
|
||||
|
||||
def _consumer(self, key: str, enabled: str, *, shared: bool) -> None:
|
||||
entry = {"enabled": enabled, **({"shared": enabled} if shared else {})}
|
||||
self._make_role(
|
||||
"web-app-nextcloud", {"coturn": {"enabled": COTURN_GATE}, key: entry}
|
||||
)
|
||||
pinned = {"enabled": True, **({"shared": True} if shared else {})}
|
||||
with self.host_vars.open("w") as f:
|
||||
self.yaml_rt.dump(
|
||||
{"applications": {"web-app-nextcloud": {"services": {key: pinned}}}}, f
|
||||
)
|
||||
|
||||
def _disable(self, tokens: list[str]) -> dict:
|
||||
apply_services_disabled(self.host_vars, tokens, roles_dir=self.roles_dir)
|
||||
with self.host_vars.open("r") as f:
|
||||
return dict(
|
||||
self.yaml_rt.load(f)["applications"]["web-app-nextcloud"]["services"]
|
||||
)
|
||||
|
||||
def test_an_entry_gated_on_the_disabled_provider_is_flipped(self):
|
||||
self._consumer("talk", COTURN_GATE, shared=True)
|
||||
|
||||
services = self._disable(["web-svc-coturn"])
|
||||
|
||||
self.assertEqual({"enabled": False, "shared": False}, dict(services["talk"]))
|
||||
|
||||
def test_the_service_key_of_the_provider_flips_the_gated_entry_too(self):
|
||||
self._consumer("talk", COTURN_GATE, shared=True)
|
||||
|
||||
services = self._disable(["coturn"])
|
||||
|
||||
self.assertEqual({"enabled": False, "shared": False}, dict(services["talk"]))
|
||||
|
||||
def test_double_quotes_and_tight_spacing_still_match(self):
|
||||
self._consumer("talk", '{{"web-svc-coturn" in group_names}}', shared=True)
|
||||
|
||||
services = self._disable(["web-svc-coturn"])
|
||||
|
||||
self.assertEqual({"enabled": False, "shared": False}, dict(services["talk"]))
|
||||
|
||||
def test_a_negated_gate_is_left_alone(self):
|
||||
self._consumer(
|
||||
"fallback", "{{ 'web-svc-coturn' not in group_names }}", shared=True
|
||||
)
|
||||
|
||||
services = self._disable(["web-svc-coturn"])
|
||||
|
||||
self.assertEqual({"enabled": True, "shared": True}, dict(services["fallback"]))
|
||||
|
||||
def test_a_compound_gate_is_left_alone(self):
|
||||
self._consumer(
|
||||
"talk",
|
||||
"{{ 'web-svc-coturn' in group_names and 'svc-net-tor' not in group_names }}",
|
||||
shared=True,
|
||||
)
|
||||
|
||||
services = self._disable(["web-svc-coturn"])
|
||||
|
||||
self.assertEqual({"enabled": True, "shared": True}, dict(services["talk"]))
|
||||
|
||||
def test_a_gate_on_a_variable_is_left_alone(self):
|
||||
self._consumer("talk", "{{ TURN_PROVIDER in group_names }}", shared=True)
|
||||
|
||||
services = self._disable(["web-svc-coturn"])
|
||||
|
||||
self.assertEqual({"enabled": True, "shared": True}, dict(services["talk"]))
|
||||
|
||||
def test_a_gate_on_another_provider_is_left_alone(self):
|
||||
self._consumer("talk", "{{ 'web-app-matomo' in group_names }}", shared=True)
|
||||
|
||||
services = self._disable(["web-svc-coturn"])
|
||||
|
||||
self.assertEqual({"enabled": True, "shared": True}, dict(services["talk"]))
|
||||
|
||||
def test_a_gated_entry_without_shared_does_not_get_one(self):
|
||||
self._consumer("talk", COTURN_GATE, shared=False)
|
||||
|
||||
services = self._disable(["web-svc-coturn"])
|
||||
|
||||
self.assertEqual({"enabled": False}, dict(services["talk"]))
|
||||
|
||||
def test_dependents_report_the_entry_and_its_provider(self):
|
||||
self._consumer("talk", COTURN_GATE, shared=True)
|
||||
|
||||
self.assertEqual(
|
||||
[("web-app-nextcloud", "talk", "web-svc-coturn")],
|
||||
[
|
||||
dependent
|
||||
for dependent in find_presence_dependents(
|
||||
{"web-svc-coturn"}, self.roles_dir
|
||||
)
|
||||
if dependent[1] != "coturn"
|
||||
],
|
||||
)
|
||||
|
||||
def _provision(self, disable: str) -> None:
|
||||
with unittest.mock.patch.dict(os.environ, {"disable": disable}):
|
||||
reconcile_services_disabled_from_env(self.host_vars, self.roles_dir)
|
||||
apply_services_disabled_from_env(self.host_vars, roles_dir=self.roles_dir)
|
||||
|
||||
def test_a_provider_dropped_from_disable_releases_its_gated_entry(self):
|
||||
self._make_role(
|
||||
"web-app-nextcloud",
|
||||
{"coturn": {"enabled": COTURN_GATE}, "talk": {"enabled": COTURN_GATE}},
|
||||
)
|
||||
with self.host_vars.open("w") as f:
|
||||
self.yaml_rt.dump({"applications": {}}, f)
|
||||
|
||||
self._provision("web-svc-coturn,matomo")
|
||||
self._provision("matomo")
|
||||
|
||||
with self.host_vars.open("r") as f:
|
||||
services = self.yaml_rt.load(f)["applications"]["web-app-nextcloud"][
|
||||
"services"
|
||||
]
|
||||
self.assertNotIn("talk", services)
|
||||
|
||||
def test_a_provider_another_listed_key_keeps_disabled_holds_its_gated_entry(self):
|
||||
dump_yaml(
|
||||
self.roles_dir / "web-svc-coturn" / ROLE_FILE_META_SERVICES,
|
||||
{
|
||||
"coturn": {"image": "coturn", "shared": True},
|
||||
"turn": {"enabled": True, "shared": True, "canonical": "coturn"},
|
||||
},
|
||||
)
|
||||
self._make_role(
|
||||
"web-app-nextcloud",
|
||||
{"coturn": {"enabled": COTURN_GATE}, "talk": {"enabled": COTURN_GATE}},
|
||||
)
|
||||
with self.host_vars.open("w") as f:
|
||||
self.yaml_rt.dump({"applications": {}}, f)
|
||||
self._provision("web-svc-coturn")
|
||||
|
||||
with unittest.mock.patch.dict(os.environ, {"disable": "coturn"}):
|
||||
reconcile_services_disabled_from_env(self.host_vars, self.roles_dir)
|
||||
|
||||
with self.host_vars.open("r") as f:
|
||||
services = self.yaml_rt.load(f)["applications"]["web-app-nextcloud"][
|
||||
"services"
|
||||
]
|
||||
self.assertEqual({"enabled": False}, dict(services["talk"]))
|
||||
|
||||
|
||||
class TestApplyServicesDisabledFromEnv(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = TemporaryDirectory()
|
||||
|
||||
Reference in new issue
Block a user