mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 14:30:52 +00:00
fix(web-app-stalwart): write the 1.x store guard in store-i18n's conventions
updater's Stalwart v1 port (store_guard.yml, migrate.env.j2) arrived in the merge (c9e7f950d9) with three constructs store-i18n's lints reject: - `DEPLOYMENT_MODE == 'swarm'` in store_guard.yml and migrate.env.j2 (test_deployment_mode_booleans): now IS_SWARM_MODE; - `get_entity_name` in the store-engine fail_msg, a filter store-i18n renamed to entity_name (a05071fe78), so TestAllUsedFiltersAreDefined failed: now entity_name; - two pairs of sibling tasks repeating the same `when` (test_no_repeated_when_runs): the shared-database and dedicated-volume lookups now sit in one block gated on `not (stalwart_store_marked | bool)`, the migrate include and the pre-1.0 assert in one block gated on `stalwart_store_layout is not skipped`; each task keeps its own remaining condition. Ansible evaluates a block's `when` per task, so the assert still sees the layout migrate.yml registers again. updater's test_store_guard.py walked only the top-level tasks and failed with KeyError: 'register' on the block wrappers. It now walks block/rescue/always (utils.roles.invocations.NESTED_KEYS), hands a block's `when` down to its children and checks the block condition before the task's own, as Ansible does; the assertions are unchanged. With either block's `when` removed from a copy of store_guard.yml, two respectively four of its tests fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
dfa33edaf7
commit
699e5d8d83
3 files changed
+73
-55
No files matched your search
@@ -11,16 +11,21 @@ from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import unittest
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from ansible.parsing.dataloader import DataLoader
|
||||
from ansible.template import Templar
|
||||
|
||||
from utils.cache.yaml import load_yaml_any
|
||||
from utils.roles.invocations import NESTED_KEYS
|
||||
from utils.roles.mapping import ROLE_FILE_VARS_MAIN
|
||||
from utils.templating.ansible import _trust_as_template
|
||||
|
||||
from . import PROJECT_ROOT
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Iterator
|
||||
|
||||
ROLE = PROJECT_ROOT / "roles" / "web-app-stalwart"
|
||||
GUARD = ROLE / "tasks" / "store_guard.yml"
|
||||
MANAGER_OPS = ROLE / "tasks" / "manager_ops.yml"
|
||||
@@ -50,6 +55,23 @@ def _module(task: dict, name: str) -> dict | None:
|
||||
return task.get(f"ansible.builtin.{name}") or task.get(name)
|
||||
|
||||
|
||||
def _conditions(task: dict) -> list[str]:
|
||||
if "when" not in task:
|
||||
return []
|
||||
when = task["when"]
|
||||
return when if isinstance(when, list) else [when]
|
||||
|
||||
|
||||
def _walk(tasks: list[dict], gates: list[str]) -> Iterator[tuple[dict, list[str]]]:
|
||||
for task in tasks:
|
||||
conditions = gates + _conditions(task)
|
||||
nested = [key for key in NESTED_KEYS if key in task]
|
||||
if not nested:
|
||||
yield task, conditions
|
||||
for key in nested:
|
||||
yield from _walk(task[key], conditions)
|
||||
|
||||
|
||||
def _layout_version() -> str:
|
||||
return load_yaml_any(str(VARS), default_if_missing={})[
|
||||
"STALWART_STORE_LAYOUT_VERSION"
|
||||
@@ -83,11 +105,8 @@ def _guard(results: dict[str, dict], *, shared: bool) -> str:
|
||||
"STALWART_DATABASE_SHARED": shared,
|
||||
"STALWART_STORE_LAYOUT_VERSION": _layout_version(),
|
||||
}
|
||||
for task in load_yaml_any(str(GUARD), default_if_missing=[]):
|
||||
when = task.get("when", [])
|
||||
if not all(
|
||||
_holds(c, facts) for c in (when if isinstance(when, list) else [when])
|
||||
):
|
||||
for task, conditions in _walk(load_yaml_any(str(GUARD), default_if_missing=[]), []):
|
||||
if not all(_holds(c, facts) for c in conditions):
|
||||
if "register" in task:
|
||||
facts[task["register"]] = SKIPPED
|
||||
continue
|
||||
|
||||
Reference in new issue
Block a user