mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 14:30:52 +00:00
perf(packages): install every role's packages per host in one run at deploy start
A constructor task after the update role and the swarm auto-placement installs, in one package-manager call, every package id of every role the host's groups may run: meta dependencies, service edges and every role invocation readable from tasks and handlers, conditions ignored. Ids that must stay with their role (a conditional install, a repository added first, a need before update) carry batch: false in meta/packages.yml and keep their task; roles reference shared root ids with shared: true. 42 per-role install tasks go, and a lint keeps the split: no batched id in a role task, none in a role run ahead of the batch. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
3be77f1aa9
commit
18ea75049e
82 files changed
+1415
-189
No files matched your search
@@ -2,10 +2,12 @@ import unittest
|
||||
import unittest.mock as mock
|
||||
|
||||
from ansible.errors import AnsibleActionFail
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.plugins.loader import become_loader, shell_loader
|
||||
|
||||
from plugins.action.package_install import ActionModule
|
||||
from utils.packages.calls import GENERIC_PACKAGE, ModuleCall, RetryPolicy
|
||||
from utils.packages.schema import PackageSpec
|
||||
|
||||
|
||||
def _action(args) -> ActionModule:
|
||||
@@ -238,6 +240,47 @@ class TestTargetFacts(unittest.TestCase):
|
||||
self.assertIn("localhost", str(caught.exception))
|
||||
|
||||
|
||||
class TestRunMergesPlainPlans(unittest.TestCase):
|
||||
FACTS = {"distribution": "Debian", "os_family": "Debian", "pkg_mgr": "apt"}
|
||||
|
||||
def _run(self, package_ids, specs):
|
||||
action = _action({"id": package_ids})
|
||||
action._task._role = None
|
||||
action._task.delegate_to = None
|
||||
action._connection = mock.Mock(become=None, transport="local")
|
||||
action._execute_module = mock.Mock(return_value={"changed": False})
|
||||
registry = {
|
||||
package_id: mock.Mock(package_id=package_id, role=None, shared=True)
|
||||
for package_id in package_ids
|
||||
}
|
||||
with (
|
||||
mock.patch.object(ActionBase, "run", return_value={}),
|
||||
mock.patch(
|
||||
"plugins.action.package_install.build_registry", return_value=registry
|
||||
),
|
||||
mock.patch(
|
||||
"plugins.action.package_install.resolve",
|
||||
side_effect=lambda declaration, *_: specs[declaration.package_id],
|
||||
),
|
||||
):
|
||||
result = action.run(task_vars={"ansible_facts": self.FACTS})
|
||||
return action._execute_module, result
|
||||
|
||||
def test_two_repository_ids_cost_one_package_manager_call(self):
|
||||
execute, _result = self._run(
|
||||
["git", "curl"],
|
||||
{"git": PackageSpec(("git",)), "curl": PackageSpec(("curl",))},
|
||||
)
|
||||
execute.assert_called_once()
|
||||
self.assertEqual(execute.call_args.kwargs["module_args"]["name"], ["git", "curl"])
|
||||
|
||||
def test_an_id_without_names_is_reported_skipped(self):
|
||||
_execute, result = self._run(
|
||||
["git", "mhwd"], {"git": PackageSpec(("git",)), "mhwd": PackageSpec(())}
|
||||
)
|
||||
self.assertEqual(result["skipped_ids"], ["mhwd"])
|
||||
|
||||
|
||||
class TestAttempt(unittest.TestCase):
|
||||
def _action_with(self, results):
|
||||
action = _action({})
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
|
||||
from plugins.lookup.package_batch import LookupModule
|
||||
from utils.packages.schema import PackagesShapeError
|
||||
|
||||
MODULE = "plugins.lookup.package_batch"
|
||||
|
||||
|
||||
class TestPackageBatchLookup(unittest.TestCase):
|
||||
def _run(self, terms, group_names, closure=None, side_effect=None):
|
||||
applications = mock.Mock()
|
||||
applications.run.return_value = [{"web-app-x": {}}]
|
||||
with (
|
||||
mock.patch(f"{MODULE}.lookup_loader.get", return_value=applications),
|
||||
mock.patch(f"{MODULE}.types_from_group_names", return_value=["server"]),
|
||||
mock.patch(
|
||||
f"{MODULE}.deploy_closure",
|
||||
return_value=closure or {"web-app-x"},
|
||||
side_effect=side_effect,
|
||||
) as closure_mock,
|
||||
mock.patch(f"{MODULE}.batch_ids", return_value=["git"]) as ids_mock,
|
||||
):
|
||||
lookup = LookupModule()
|
||||
result = lookup.run(terms, variables={"group_names": group_names})
|
||||
return result, closure_mock, ids_mock
|
||||
|
||||
def test_returns_the_batch_ids_of_the_closure(self):
|
||||
result, _closure, ids = self._run([["web-app-x"]], ["web-app-x"])
|
||||
self.assertEqual(result, [["git"]])
|
||||
self.assertEqual(ids.call_args.args[0], {"web-app-x"})
|
||||
|
||||
def test_nested_and_scalar_terms_become_one_seed_list(self):
|
||||
_result, closure, _ids = self._run([["web-app-x"], "role-b"], ["web-app-x"])
|
||||
self.assertEqual(closure.call_args.args[1], ["web-app-x", "role-b"])
|
||||
|
||||
def test_the_host_groups_select_types_and_gates(self):
|
||||
_result, closure, _ids = self._run([["web-app-x"]], ["web-app-x", "servers"])
|
||||
self.assertEqual(closure.call_args.kwargs["host_types"], ["server"])
|
||||
self.assertEqual(
|
||||
closure.call_args.kwargs["group_names"], ["web-app-x", "servers"]
|
||||
)
|
||||
|
||||
def test_a_registry_error_becomes_an_ansible_error(self):
|
||||
with self.assertRaises(AnsibleError):
|
||||
self._run([["web-app-x"]], [], side_effect=PackagesShapeError("broken"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,76 @@
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from utils.cache.yaml import dump_yaml
|
||||
from utils.packages.batch import batch_ids, batch_ids_by_role
|
||||
|
||||
|
||||
def _write(root: Path, relative: str, payload) -> None:
|
||||
path = root / relative
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
dump_yaml(str(path), payload)
|
||||
|
||||
|
||||
class TestBatchIds(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self._tmp = tempfile.TemporaryDirectory()
|
||||
self.root = Path(self._tmp.name)
|
||||
self.addCleanup(self._tmp.cleanup)
|
||||
_write(
|
||||
self.root,
|
||||
"meta/packages.yml",
|
||||
{
|
||||
"git": {"Debian": ["git"]},
|
||||
"postfix": {"Debian": ["postfix"], "batch": False},
|
||||
},
|
||||
)
|
||||
|
||||
def test_a_role_batches_its_own_ids(self):
|
||||
_write(self.root, "roles/role-a/meta/packages.yml", {"jq": {"Debian": ["jq"]}})
|
||||
self.assertEqual(batch_ids(["role-a"], self.root), ["jq"])
|
||||
|
||||
def test_an_unbatched_own_id_is_left_to_the_role(self):
|
||||
_write(
|
||||
self.root,
|
||||
"roles/role-a/meta/packages.yml",
|
||||
{"jq": {"Debian": ["jq"], "batch": False}},
|
||||
)
|
||||
self.assertEqual(batch_ids(["role-a"], self.root), [])
|
||||
|
||||
def test_a_referenced_shared_id_is_batched_with_the_role(self):
|
||||
_write(self.root, "roles/role-a/meta/packages.yml", {"git": {"shared": True}})
|
||||
self.assertEqual(batch_ids(["role-a"], self.root), ["git"])
|
||||
|
||||
def test_a_referenced_unbatched_shared_id_stays_out(self):
|
||||
_write(
|
||||
self.root, "roles/role-a/meta/packages.yml", {"postfix": {"shared": True}}
|
||||
)
|
||||
self.assertEqual(batch_ids(["role-a"], self.root), [])
|
||||
|
||||
def test_shared_ids_nobody_references_stay_out(self):
|
||||
self.assertEqual(batch_ids(["role-a"], self.root), [])
|
||||
|
||||
def test_roles_outside_the_deploy_contribute_nothing(self):
|
||||
_write(self.root, "roles/role-a/meta/packages.yml", {"jq": {"Debian": ["jq"]}})
|
||||
_write(
|
||||
self.root, "roles/role-b/meta/packages.yml", {"curl": {"Debian": ["curl"]}}
|
||||
)
|
||||
self.assertEqual(batch_ids(["role-a"], self.root), ["jq"])
|
||||
|
||||
def test_ids_are_sorted_and_unique(self):
|
||||
_write(
|
||||
self.root,
|
||||
"roles/role-a/meta/packages.yml",
|
||||
{"jq": {"Debian": ["jq"]}, "git": {"shared": True}},
|
||||
)
|
||||
_write(self.root, "roles/role-b/meta/packages.yml", {"git": {"shared": True}})
|
||||
self.assertEqual(batch_ids(["role-b", "role-a"], self.root), ["git", "jq"])
|
||||
|
||||
def test_ids_are_grouped_by_role(self):
|
||||
_write(self.root, "roles/role-a/meta/packages.yml", {"jq": {"Debian": ["jq"]}})
|
||||
self.assertEqual(batch_ids_by_role(self.root), {"role-a": {"jq"}})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -2,7 +2,7 @@ import re
|
||||
import unittest
|
||||
|
||||
from utils.packages.calls import STATE_ABSENT, STATE_PRESENT
|
||||
from utils.packages.plan import build_plan
|
||||
from utils.packages.plan import build_plan, merge_plans
|
||||
from utils.packages.schema import SOURCE_AUR, SOURCE_BUILD, SOURCE_COPR, PackageSpec
|
||||
from utils.packages.sources import AUR_BUILDER_USER, PACMAN_CONF
|
||||
|
||||
@@ -189,5 +189,53 @@ class TestBuildPlan(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
def _plan(*names, **spec):
|
||||
return build_plan(PackageSpec(tuple(names), **spec), STATE_PRESENT)
|
||||
|
||||
|
||||
def _names(call):
|
||||
return call.args["name"]
|
||||
|
||||
|
||||
class TestMergePlans(unittest.TestCase):
|
||||
def test_plain_plans_share_one_call(self):
|
||||
merged = merge_plans([_plan("git"), _plan("curl", "jq")])
|
||||
self.assertEqual(len(merged), 1)
|
||||
self.assertEqual([_names(call) for call in merged[0]], [["git", "curl", "jq"]])
|
||||
|
||||
def test_a_name_requested_twice_is_installed_once(self):
|
||||
merged = merge_plans([_plan("git"), _plan("git")])
|
||||
self.assertEqual(_names(merged[0][0]), ["git"])
|
||||
|
||||
def test_bootstrap_packages_install_before_every_name(self):
|
||||
epel = {"repo": {"bootstrap_package": "epel-release"}}
|
||||
merged = merge_plans([_plan("git"), _plan("micro", **epel), _plan("jq", **epel)])
|
||||
self.assertEqual(
|
||||
[_names(call) for call in merged[0]],
|
||||
[["epel-release"], ["git", "micro", "jq"]],
|
||||
)
|
||||
|
||||
def test_a_plan_with_other_modules_runs_unchanged_after_the_merged_one(self):
|
||||
aur = _plan("caffeine", source=SOURCE_AUR)
|
||||
merged = merge_plans([aur, _plan("git")])
|
||||
self.assertEqual([_names(call) for call in merged[0]], [["git"]])
|
||||
self.assertEqual(merged[1], aur)
|
||||
|
||||
def test_plans_of_different_states_never_merge(self):
|
||||
absent = build_plan(PackageSpec(("postfix",)), STATE_ABSENT)
|
||||
merged = merge_plans([_plan("git"), absent])
|
||||
self.assertEqual(
|
||||
[(call.args["state"], _names(call)) for plan in merged for call in plan],
|
||||
[(STATE_PRESENT, ["git"]), (STATE_ABSENT, ["postfix"])],
|
||||
)
|
||||
|
||||
def test_no_plans_merge_to_nothing(self):
|
||||
self.assertEqual(merge_plans([]), [])
|
||||
|
||||
def test_the_merged_call_keeps_the_retry_policy(self):
|
||||
merged = merge_plans([_plan("git"), _plan("curl")])
|
||||
self.assertIsNotNone(merged[0][0].retry)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -7,6 +7,7 @@ from utils.packages.registry import (
|
||||
build_registry,
|
||||
iter_inventory_package_lists,
|
||||
load_declarations,
|
||||
load_references,
|
||||
resolve,
|
||||
)
|
||||
from utils.packages.schema import (
|
||||
@@ -223,6 +224,44 @@ class TestRegistry(unittest.TestCase):
|
||||
with self.assertRaises(PackagesShapeError):
|
||||
list(iter_inventory_package_lists(self.root))
|
||||
|
||||
def test_an_unflagged_id_is_batched(self):
|
||||
_write_role(self.root, "role-a", {"git": {"Debian": ["git"]}})
|
||||
self.assertTrue(self._declaration("git").batch)
|
||||
|
||||
def test_batch_false_keeps_the_id_out_of_the_batch(self):
|
||||
_write_role(
|
||||
self.root, "role-a", {"git": {"Debian": ["git"], "batch": False}}
|
||||
)
|
||||
self.assertFalse(self._declaration("git").batch)
|
||||
|
||||
def test_the_batch_flag_is_no_distro_key(self):
|
||||
_write_role(
|
||||
self.root, "role-a", {"git": {"Debian": ["git"], "batch": False}}
|
||||
)
|
||||
self.assertIsNone(resolve(self._declaration("git"), "arch"))
|
||||
|
||||
def test_non_boolean_batch_raises(self):
|
||||
_write_role(self.root, "role-a", {"git": {"Debian": ["git"], "batch": "no"}})
|
||||
with self.assertRaises(PackagesShapeError):
|
||||
load_declarations(self.root)
|
||||
|
||||
def test_a_shared_reference_is_no_declaration(self):
|
||||
_write_shared(self.root, {"git": {"Debian": ["git"]}})
|
||||
_write_role(self.root, "role-a", {"git": {"shared": True}})
|
||||
declaration = self._declaration("git")
|
||||
self.assertTrue(declaration.shared)
|
||||
|
||||
def test_shared_references_are_collected_per_role(self):
|
||||
_write_shared(self.root, {"git": {"Debian": ["git"]}})
|
||||
_write_role(self.root, "role-a", {"git": {"shared": True}})
|
||||
_write_role(self.root, "role-b", {"curl": {"Debian": ["curl"]}})
|
||||
self.assertEqual(load_references(self.root), {"role-a": {"git"}})
|
||||
|
||||
def test_shared_flag_in_the_root_file_is_no_reference(self):
|
||||
_write_shared(self.root, {"git": {"shared": True}})
|
||||
self.assertEqual(load_references(self.root), {})
|
||||
self.assertIn("git", build_registry(self.root))
|
||||
|
||||
def test_default_matrix_covers_five_distros(self):
|
||||
self.assertEqual(
|
||||
sorted(DISTRO_FAMILY), ["arch", "centos", "debian", "fedora", "ubuntu"]
|
||||
|
||||
@@ -0,0 +1,245 @@
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from utils.cache.yaml import dump_yaml
|
||||
from utils.roles.invocations import (
|
||||
deploy_closure,
|
||||
expand_roles,
|
||||
role_invocations,
|
||||
stage_files,
|
||||
stage_invocations,
|
||||
)
|
||||
from utils.roles.mapping import (
|
||||
ROLE_FILE_HANDLERS_MAIN,
|
||||
ROLE_FILE_META_MAIN,
|
||||
ROLE_FILE_TASKS_MAIN,
|
||||
ROLE_FILE_VARS_MAIN,
|
||||
)
|
||||
|
||||
ROLES = ("role-a", "role-b", "role-c", "sys-ctl-hlth-x", "sys-ctl-hlth-y")
|
||||
|
||||
|
||||
def _role_file(role: str, role_file: str) -> str:
|
||||
return f"roles/{role}/{role_file}"
|
||||
|
||||
|
||||
class _TreeMixin:
|
||||
def setUp(self) -> None:
|
||||
self._tmp = tempfile.TemporaryDirectory()
|
||||
self.root = Path(self._tmp.name)
|
||||
self.addCleanup(self._tmp.cleanup)
|
||||
for role in ROLES:
|
||||
(self.root / "roles" / role / "tasks").mkdir(parents=True)
|
||||
|
||||
def _write(self, relative: str, payload) -> Path:
|
||||
path = self.root / relative
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
dump_yaml(str(path), payload)
|
||||
return path
|
||||
|
||||
def _invoked(self, tasks, role: str = "role-a") -> frozenset[str]:
|
||||
self._write(_role_file(role, ROLE_FILE_TASKS_MAIN), tasks)
|
||||
return role_invocations(str(self.root / "roles"), role)
|
||||
|
||||
|
||||
class TestRoleInvocations(_TreeMixin, unittest.TestCase):
|
||||
def test_a_literal_include_role_is_an_edge(self):
|
||||
self.assertEqual(
|
||||
self._invoked([{"include_role": {"name": "role-b"}}]), {"role-b"}
|
||||
)
|
||||
|
||||
def test_an_import_role_is_an_edge(self):
|
||||
self.assertEqual(
|
||||
self._invoked([{"ansible.builtin.import_role": {"name": "role-b"}}]),
|
||||
{"role-b"},
|
||||
)
|
||||
|
||||
def test_a_literal_loop_names_every_item(self):
|
||||
tasks = [
|
||||
{
|
||||
"include_role": {"name": "{{ dep }}"},
|
||||
"loop": ["role-b", "role-c"],
|
||||
"loop_control": {"loop_var": "dep"},
|
||||
}
|
||||
]
|
||||
self.assertEqual(self._invoked(tasks), {"role-b", "role-c"})
|
||||
|
||||
def test_a_template_with_a_literal_part_matches_a_glob(self):
|
||||
tasks = [{"include_role": {"name": "sys-ctl-hlth-{{ kind }}"}}]
|
||||
self.assertEqual(self._invoked(tasks), {"sys-ctl-hlth-x", "sys-ctl-hlth-y"})
|
||||
|
||||
def test_a_role_name_handed_over_as_a_var_is_an_edge(self):
|
||||
tasks = [
|
||||
{
|
||||
"include_tasks": "utils/load/app.yml",
|
||||
"vars": {"load_app_id": "role-b"},
|
||||
}
|
||||
]
|
||||
self.assertEqual(self._invoked(tasks), {"role-b"})
|
||||
|
||||
def test_including_a_task_file_of_another_role_is_an_edge(self):
|
||||
tasks = [
|
||||
{
|
||||
"include_tasks": "{{ lookup('path_absolute', 'roles/role-c/tasks/x.yml') }}"
|
||||
}
|
||||
]
|
||||
self.assertEqual(self._invoked(tasks), {"role-c"})
|
||||
|
||||
def test_includes_nested_in_blocks_count(self):
|
||||
tasks = [
|
||||
{
|
||||
"block": [{"include_role": {"name": "role-b"}}],
|
||||
"rescue": [{"include_role": {"name": "role-c"}}],
|
||||
}
|
||||
]
|
||||
self.assertEqual(self._invoked(tasks), {"role-b", "role-c"})
|
||||
|
||||
def test_conditions_do_not_hide_an_edge(self):
|
||||
tasks = [{"include_role": {"name": "role-b"}, "when": "false"}]
|
||||
self.assertEqual(self._invoked(tasks), {"role-b"})
|
||||
|
||||
def test_a_bare_template_falls_back_to_quoted_role_names_in_vars(self):
|
||||
self._write(
|
||||
_role_file("role-a", ROLE_FILE_VARS_MAIN),
|
||||
{"DEPS": "{{ ['role-b'] + (['role-c'] if flag else []) }}"},
|
||||
)
|
||||
tasks = [
|
||||
{
|
||||
"include_role": {"name": "{{ dep }}"},
|
||||
"loop": "{{ DEPS }}",
|
||||
"loop_control": {"loop_var": "dep"},
|
||||
}
|
||||
]
|
||||
self.assertEqual(self._invoked(tasks), {"role-b", "role-c"})
|
||||
|
||||
def test_quoted_names_are_ignored_while_every_include_resolves(self):
|
||||
self._write(_role_file("role-a", ROLE_FILE_VARS_MAIN), {"OTHER": "{{ 'role-c' }}"})
|
||||
self.assertEqual(
|
||||
self._invoked([{"include_role": {"name": "role-b"}}]), {"role-b"}
|
||||
)
|
||||
|
||||
def test_unknown_role_names_are_dropped(self):
|
||||
self.assertEqual(
|
||||
self._invoked([{"include_role": {"name": "role-missing"}}]), frozenset()
|
||||
)
|
||||
|
||||
def test_a_role_does_not_invoke_itself(self):
|
||||
self.assertEqual(
|
||||
self._invoked([{"include_role": {"name": "role-a"}}]), frozenset()
|
||||
)
|
||||
|
||||
def test_handlers_count(self):
|
||||
self._write(
|
||||
_role_file("role-a", ROLE_FILE_HANDLERS_MAIN),
|
||||
[{"include_role": {"name": "role-c"}}],
|
||||
)
|
||||
self.assertEqual(
|
||||
self._invoked([{"include_role": {"name": "role-b"}}]), {"role-b", "role-c"}
|
||||
)
|
||||
|
||||
|
||||
class TestStageInvocations(_TreeMixin, unittest.TestCase):
|
||||
def _stage(self, tasks):
|
||||
return self._write("tasks/stages/01_constructor.yml", tasks)
|
||||
|
||||
def test_a_group_membership_gate_closes_for_a_non_member(self):
|
||||
path = self._stage(
|
||||
[{"include_role": {"name": "role-b"}, "when": "'role-b' in group_names"}]
|
||||
)
|
||||
self.assertEqual(
|
||||
stage_invocations(path, frozenset(ROLES), seeds=[], group_names=[]), set()
|
||||
)
|
||||
|
||||
def test_a_group_membership_gate_opens_for_a_member(self):
|
||||
path = self._stage(
|
||||
[{"include_role": {"name": "role-b"}, "when": "'role-b' in group_names"}]
|
||||
)
|
||||
self.assertEqual(
|
||||
stage_invocations(
|
||||
path, frozenset(ROLES), seeds=[], group_names=["role-b"]
|
||||
),
|
||||
{"role-b"},
|
||||
)
|
||||
|
||||
def test_an_application_allowed_gate_decides_on_the_seeds(self):
|
||||
path = self._stage(
|
||||
[
|
||||
{
|
||||
"when": "'role-b' | application_allowed(group_names, whitelist)",
|
||||
"block": [{"include_role": {"name": "role-b"}}],
|
||||
}
|
||||
]
|
||||
)
|
||||
self.assertEqual(
|
||||
stage_invocations(
|
||||
path, frozenset(ROLES), seeds=[], group_names=["role-b"]
|
||||
),
|
||||
set(),
|
||||
)
|
||||
self.assertEqual(
|
||||
stage_invocations(
|
||||
path, frozenset(ROLES), seeds=["role-b"], group_names=[]
|
||||
),
|
||||
{"role-b"},
|
||||
)
|
||||
|
||||
def test_any_other_condition_keeps_the_include(self):
|
||||
path = self._stage(
|
||||
[{"include_role": {"name": "role-c"}, "when": ["MODE_CLEANUP | bool"]}]
|
||||
)
|
||||
self.assertEqual(
|
||||
stage_invocations(path, frozenset(ROLES), seeds=[], group_names=[]),
|
||||
{"role-c"},
|
||||
)
|
||||
|
||||
def test_stage_files_follow_the_host_types(self):
|
||||
for name in ("01_constructor", "02_server", "02_workstation", "03_destructor"):
|
||||
self._write(f"tasks/stages/{name}.yml", [])
|
||||
self.assertEqual(
|
||||
[path.name for path in stage_files(self.root, ["server"])],
|
||||
["01_constructor.yml", "02_server.yml", "03_destructor.yml"],
|
||||
)
|
||||
|
||||
|
||||
class TestClosure(_TreeMixin, unittest.TestCase):
|
||||
def test_invocations_are_followed_transitively(self):
|
||||
self._write(
|
||||
_role_file("role-b", ROLE_FILE_TASKS_MAIN),
|
||||
[{"include_role": {"name": "role-c"}}],
|
||||
)
|
||||
self._write(
|
||||
_role_file("role-a", ROLE_FILE_TASKS_MAIN),
|
||||
[{"include_role": {"name": "role-b"}}],
|
||||
)
|
||||
self.assertEqual(
|
||||
expand_roles({}, ["role-a"], project_root=self.root),
|
||||
{"role-a", "role-b", "role-c"},
|
||||
)
|
||||
|
||||
def test_meta_dependencies_are_followed(self):
|
||||
self._write(
|
||||
_role_file("role-a", ROLE_FILE_META_MAIN), {"dependencies": ["role-c"]}
|
||||
)
|
||||
self.assertEqual(
|
||||
expand_roles({}, ["role-a"], project_root=self.root), {"role-a", "role-c"}
|
||||
)
|
||||
|
||||
def test_the_deploy_closure_adds_the_stage_roles(self):
|
||||
self._write(
|
||||
"tasks/stages/01_constructor.yml", [{"include_role": {"name": "role-c"}}]
|
||||
)
|
||||
self.assertEqual(
|
||||
deploy_closure(
|
||||
{},
|
||||
["role-a"],
|
||||
project_root=self.root,
|
||||
host_types=[],
|
||||
group_names=["role-a"],
|
||||
),
|
||||
{"role-a", "role-c"},
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user