Skip to content

Commit b88faf3

Browse files
committed
Fix get-configuration automation not returning defaults
While porting the get-configuration automation to run on the automation helper, the loading of the non-confd configuration was removed. This however broke the only callsite of this automation which was to get the factory settings of our configuration. We restore the old behavior of the automation by forcing it to run outside the automation helper. To still have some performance improvements for the global settings page, we cache the output of this automation call in the apache process. Slightly risky :) co-authored-by: [email protected] CMK-21350 Change-Id: Ia0d8144f77ea53ef9bddcbd151dd15f41bcbe916
1 parent e07af43 commit b88faf3

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

Diff for: cmk/base/automations/check_mk.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,7 @@ def _execute_silently(
19251925

19261926

19271927
class AutomationGetConfiguration(Automation):
1928+
# Automation call to get the default configuration
19281929
cmd = "get-configuration"
19291930
needs_config = False
19301931
# This needed the checks in the past. This was necessary to get the
@@ -1943,21 +1944,25 @@ def execute(
19431944
args: list[str],
19441945
called_from_automation_helper: bool,
19451946
) -> GetConfigurationResult:
1947+
if called_from_automation_helper:
1948+
raise RuntimeError(
1949+
"This automation call should never be called from the automation helper "
1950+
"as it can only return the active config and we want the default config."
1951+
)
19461952
# We read the list of variable names from stdin since
19471953
# that could be too much for the command line
19481954
variable_names = ast.literal_eval(sys.stdin.read())
19491955

1950-
if not called_from_automation_helper:
1951-
config.load(with_conf_d=False)
1956+
config.load(with_conf_d=False)
19521957

1953-
missing_variables = [v for v in variable_names if not hasattr(config, v)]
1958+
missing_variables = [v for v in variable_names if not hasattr(config, v)]
19541959

1955-
if missing_variables:
1956-
config.load_all_plugins(
1957-
local_checks_dir=local_checks_dir,
1958-
checks_dir=checks_dir,
1959-
)
1960-
config.load(with_conf_d=False)
1960+
if missing_variables:
1961+
config.load_all_plugins(
1962+
local_checks_dir=local_checks_dir,
1963+
checks_dir=checks_dir,
1964+
)
1965+
config.load(with_conf_d=False)
19611966

19621967
result = {}
19631968
for varname in variable_names:

Diff for: cmk/gui/watolib/check_mk_automations.py

+3
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ def get_configuration(*config_var_names: str) -> results.GetConfigurationResult:
362362
_automation_serialized(
363363
"get-configuration",
364364
indata=list(config_var_names),
365+
# We must not call this through the automation helper,
366+
# see automation call execution.
367+
force_cli_interface=True,
365368
),
366369
results.GetConfigurationResult,
367370
)

Diff for: cmk/gui/watolib/config_domains.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from collections.abc import Iterable, Mapping, Sequence
1414
from dataclasses import dataclass, field
1515
from datetime import datetime
16+
from functools import lru_cache
1617
from pathlib import Path
1718
from typing import Any, NewType
1819

@@ -88,6 +89,14 @@ def __post_init__(self) -> None:
8889
self.validate()
8990

9091

92+
@lru_cache
93+
def _core_config_default_globals(*config_var_names: str) -> Mapping[str, object]:
94+
# Import cycle
95+
from cmk.gui.watolib.check_mk_automations import get_configuration
96+
97+
return get_configuration(*config_var_names).result
98+
99+
91100
class ConfigDomainCore(ABCConfigDomain):
92101
@classmethod
93102
def ident(cls) -> ConfigDomainName:
@@ -113,10 +122,7 @@ def _parse_settings(
113122
return ConfigDomainCoreSettings(**activate_settings)
114123

115124
def default_globals(self) -> Mapping[str, Any]:
116-
# Import cycle
117-
from cmk.gui.watolib.check_mk_automations import get_configuration
118-
119-
return get_configuration(*self._get_global_config_var_names()).result
125+
return _core_config_default_globals(*self._get_global_config_var_names())
120126

121127
@classmethod
122128
def get_domain_request(cls, settings: list[SerializedSettings]) -> DomainRequest:

0 commit comments

Comments
 (0)