Skip to content

Commit 0697ae1

Browse files
committed
Fix flaky test: automatic host removal job crashes on sites without login secret
The execute_host_removal_job cron job (running every minute in the ui-job-scheduler) builds its automation_configs dict by iterating over wato_site_ids(), which includes all remote sites with replication enabled regardless of whether they have a login secret. During composition tests, this creates a race window: between the REST API call that creates a new site connection (sites.create() writes site config to disk without a secret) and the subsequent login call (sites.login() adds the secret), the site is visible to the scheduler but has no secret. If the cron job fires in that window records a crash report. The composition tests detects this crash report in teardown and fails. The failure is flaky because whether the cron job coincides with the setup window is non-deterministic. Every other cron job that contacts remote sites (execute_sync_remote_sites, execute_host_label_sync_job) already guards against this by filtering through sites_ready_for_remote_automation(), which requires "secret" to be present. Apply the same guard to execute_host_removal_job by skipping any site that is neither local nor has a secret configured. Change-Id: Idb73bf0755eeb157a2969f438918ed7bd0bd4412
1 parent 57a1f32 commit 0697ae1

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

cmk/gui/watolib/automatic_host_removal.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818

1919
import cmk.gui.log
2020
from cmk.ccc.hostaddress import HostName
21-
from cmk.ccc.site import SiteId
21+
from cmk.ccc.site import omd_site, SiteId
2222
from cmk.gui.config import Config
2323
from cmk.gui.exceptions import MKUserError
2424
from cmk.gui.http import Request
2525
from cmk.gui.i18n import _
2626
from cmk.gui.session import SuperUserContext
27-
from cmk.gui.site_config import is_distributed_setup_remote_site, wato_site_ids
27+
from cmk.gui.site_config import (
28+
is_distributed_setup_remote_site,
29+
sites_ready_for_remote_automation,
30+
)
2831
from cmk.gui.utils.roles import UserPermissionSerializableConfig
2932
from cmk.gui.watolib.activate_changes import ActivateChangesManager
3033
from cmk.gui.watolib.automation_commands import AutomationCommand
@@ -70,7 +73,10 @@ def _folder_of_host(h: Host) -> Folder:
7073
site_id: make_automation_config(
7174
config.sites[site_id],
7275
)
73-
for site_id in wato_site_ids(config.sites)
76+
for site_id in [
77+
omd_site(),
78+
*sites_ready_for_remote_automation(config.sites),
79+
]
7480
},
7581
debug=config.debug,
7682
)

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ def default_site_config() -> SiteConfiguration:
5858
)
5959

6060

61-
@pytest.fixture(scope="function", autouse=True)
62-
def fixture_sitenames(mocker: MockerFixture) -> None:
63-
mocker.patch.object(automatic_host_removal, "wato_site_ids", lambda x: ["NO_SITE"])
64-
65-
6661
@pytest.fixture(name="activate_changes_mock")
6762
def fixture_activate_changes(mocker: MockerFixture) -> MagicMock:
6863
return mocker.patch.object(

0 commit comments

Comments
 (0)