Skip to content

Commit 2b2456f

Browse files
committed
test: verify execute_host_removal_job skips remote sites without login secret
Add a unit test that exercises the guard introduced in the previous commit: a remote site with replication enabled but no secret Change-Id: Ib6ca0b9ccb1b84e103e89e436bc47ef618c20f07
1 parent 0697ae1 commit 2b2456f

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

tests/unit/cmk/gui/watolib/test_automatic_host_removal.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,35 @@ def test_execute_host_removal_job(
273273
]
274274
mock_delete_hosts_automation.assert_called_once()
275275
activate_changes_mock.assert_called_once()
276+
277+
278+
@pytest.mark.usefixtures(
279+
"setup_rules"
280+
) # needed to pass the early-exit guard in execute_host_removal_job
281+
@pytest.mark.usefixtures("with_admin_login")
282+
def test_execute_host_removal_job_skips_remote_site_without_secret(
283+
mocker: MockerFixture, request_context: None
284+
) -> None:
285+
"""A remote site with replication enabled but no login secret must not appear in
286+
automation_configs. Covers the race window between sites.create() (no secret yet)
287+
and sites.login() (secret added).
288+
"""
289+
mock_hosts_to_be_removed = mocker.patch.object(
290+
automatic_host_removal,
291+
"_hosts_to_be_removed",
292+
return_value=[], # I don't care about actually removing hosts in this test
293+
)
294+
295+
config = Config()
296+
config.sites[SiteId("NO_SITE")] = default_site_config()
297+
remote_without_secret = default_site_config()
298+
remote_without_secret["id"] = SiteId("remote_no_secret")
299+
remote_without_secret["replication"] = "slave" # replication enabled — but no "secret"
300+
config.sites[SiteId("remote_no_secret")] = remote_without_secret
301+
302+
automatic_host_removal.execute_host_removal_job(config)
303+
304+
mock_hosts_to_be_removed.assert_called_once()
305+
automation_configs = mock_hosts_to_be_removed.call_args.kwargs["automation_configs"]
306+
assert SiteId("remote_no_secret") not in automation_configs
307+
assert SiteId("NO_SITE") in automation_configs

0 commit comments

Comments
 (0)