diff --git a/roles/sys-stk-backend/tasks/main.yml b/roles/sys-stk-backend/tasks/main.yml index afac268cae..4b7ad305d7 100644 --- a/roles/sys-stk-backend/tasks/main.yml +++ b/roles/sys-stk-backend/tasks/main.yml @@ -18,13 +18,6 @@ - "sso_proxy_enabled={{ lookup('sso', application_id, 'is_proxy_gated') }}" when: MODE_DEBUG | bool -- name: "🧩 For '{{ application_id }}': Load sys-svc-compose" - include_role: - name: sys-svc-compose - vars: - compose_handlers_flush: false - database_consumer_id: "{{ _sys_stk_backend_database_consumer_id }}" - - name: "🧩 For '{{ application_id }}': Load central RDBMS" include_role: name: sys-svc-rdbms @@ -51,6 +44,13 @@ vars: engine_consumer_id: "{{ application_id }}" +- name: "🧩 For '{{ application_id }}': Load sys-svc-compose" + include_role: + name: sys-svc-compose + vars: + compose_handlers_flush: false + database_consumer_id: "{{ _sys_stk_backend_database_consumer_id }}" + - block: - name: "🔧 set sso_proxy_application_id (needed due to lazy-loading issue)" set_fact: diff --git a/roles/sys-svc-rdbms/tasks/dedicated.yml b/roles/sys-svc-rdbms/tasks/dedicated.yml index 80c1b17a0a..9d9b87a6d0 100644 --- a/roles/sys-svc-rdbms/tasks/dedicated.yml +++ b/roles/sys-svc-rdbms/tasks/dedicated.yml @@ -5,6 +5,12 @@ tasks_from: none.yml handlers_from: main +- name: "🥾 For '{{ application_id }}': bootstrap the compose host once" + ansible.builtin.include_role: + name: sys-svc-compose + tasks_from: 00_core.yml + when: run_once_sys_svc_compose is not defined + - name: "✅ Ensure env dir exists: {{ _container_env_dir }}" ansible.builtin.file: path: "{{ _container_env_dir }}" diff --git a/tests/unit/python/roles/sys-stk-backend/test_handler_registration_order.py b/tests/unit/python/roles/sys-stk-backend/test_handler_registration_order.py index 6aa013c713..8bcb729bd0 100644 --- a/tests/unit/python/roles/sys-stk-backend/test_handler_registration_order.py +++ b/tests/unit/python/roles/sys-stk-backend/test_handler_registration_order.py @@ -23,20 +23,28 @@ def _role_include(task: dict) -> dict: return {} -def _included_roles(tasks: list) -> list[str]: - names = [] +def _role_includes(tasks: list) -> list[dict]: + includes = [] for task in tasks: include = _role_include(task) if include.get("name"): - names.append(include["name"]) - return names + includes.append(include) + return includes class TestHandlerRegistrationOrder(unittest.TestCase): - def test_the_backend_loads_the_handler_owner_before_any_other_role(self) -> None: - order = _included_roles(load_yaml_str(read_text(str(BACKEND)))) + def test_the_backend_renders_the_stack_after_every_foreign_provider(self) -> None: + includes = _role_includes(load_yaml_str(read_text(str(BACKEND)))) + order = [include["name"] for include in includes] self.assertIn(COMPOSE_OWNER, order) - self.assertEqual(order[0], COMPOSE_OWNER) + render = next( + index + for index, include in enumerate(includes) + if include["name"] == COMPOSE_OWNER and not include.get("tasks_from") + ) + for provider in ("sys-svc-rdbms", "sys-svc-objstore", "sys-svc-engine"): + with self.subTest(provider=provider): + self.assertLess(order.index(provider), render) def test_the_owner_is_reloaded_directly_before_the_flush(self) -> None: tasks = load_yaml_str(read_text(str(BACKEND))) @@ -56,6 +64,19 @@ class TestHandlerRegistrationOrder(unittest.TestCase): self.assertEqual(loader.get("name"), COMPOSE_OWNER) self.assertEqual(loader.get("handlers_from"), "main") + def test_the_notifier_bootstraps_the_compose_host_before_its_first_notify(self) -> None: + tasks = load_yaml_str(read_text(str(RDBMS_DEDICATED))) + bootstrap = next( + index + for index, task in enumerate(tasks) + if _role_include(task).get("tasks_from") == "00_core.yml" + ) + notify = next(index for index, task in enumerate(tasks) if task.get("notify")) + self.assertLess(bootstrap, notify) + self.assertIn( + "run_once_sys_svc_compose is not defined", str(tasks[bootstrap].get("when")) + ) + def test_the_owner_still_holds_every_compose_topic_that_is_notified(self) -> None: owner = "" for path, content in iter_project_files_with_content(