Skip to content

Commit 04d08f6

Browse files
committed
fix up dependency direction
Change-Id: Id6fe9b618329480849e3f3225c8703d210cc1899
1 parent d99e05d commit 04d08f6

8 files changed

Lines changed: 116 additions & 97 deletions

File tree

cmk/base/automations/check_mk.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@
104104
ConfigCache,
105105
EnforcedServicesTable,
106106
handle_ip_lookup_failure,
107-
LoadedConfigFragment,
108107
snmp_default_community,
109108
)
110109
from cmk.base.configlib.checkengine import CheckingConfig, DiscoveryConfig
110+
from cmk.base.configlib.loaded_config import LoadedConfigFragment
111111
from cmk.base.configlib.servicename import (
112112
FinalServiceNameConfig,
113113
PassiveServiceNameConfig,
@@ -648,7 +648,7 @@ def _get_discovery_preview(
648648
on_error: OnError,
649649
fetcher: FetcherFunction,
650650
file_cache_options: FileCacheOptions,
651-
loaded_config: config.LoadedConfigFragment,
651+
loaded_config: LoadedConfigFragment,
652652
service_name_config: PassiveServiceNameConfig,
653653
config_cache: config.ConfigCache,
654654
plugins: AgentBasedPlugins,
@@ -794,7 +794,7 @@ def compute_check_parameters_of_autocheck(
794794

795795

796796
def _execute_discovery(
797-
loaded_config: config.LoadedConfigFragment,
797+
loaded_config: LoadedConfigFragment,
798798
ruleset_matcher: RulesetMatcher,
799799
label_manager: LabelManager,
800800
host_name: HostName,
@@ -2588,7 +2588,7 @@ def _execute_silently(
25882588
ip_address_of: ip_lookup.ConfiguredIPLookup[ip_lookup.CollectFailedHosts],
25892589
ip_address_of_mgmt: ip_lookup.IPLookupOptional,
25902590
hosts_config: Hosts,
2591-
loaded_config: config.LoadedConfigFragment,
2591+
loaded_config: LoadedConfigFragment,
25922592
plugins: AgentBasedPlugins,
25932593
hosts_to_update: set[HostName] | None,
25942594
service_depends_on: Callable[[HostName, ServiceName], Sequence[ServiceName]],

cmk/base/config.py

Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from cmk.base import default_config
4646
from cmk.base.configlib.checkengine import CheckingConfig
4747
from cmk.base.configlib.labels import LabelConfig
48+
from cmk.base.configlib.loaded_config import LoadedConfigFragment
4849
from cmk.base.configlib.servicename import FinalServiceNameConfig, PassiveServiceNameConfig
4950
from cmk.base.default_config import * # noqa: F403
5051
from cmk.base.parent_scan import ScanConfig as ParentScanConfig
@@ -104,7 +105,6 @@
104105
from cmk.fetchers.config import make_persisted_section_dir
105106
from cmk.fetchers.filecache import MaxAge
106107
from cmk.piggyback import backend as piggyback_backend
107-
from cmk.rrd.config import RRDObjectConfig # pylint: disable=cmk-module-layer-violation
108108
from cmk.server_side_calls import v1 as server_side_calls_api
109109
from cmk.server_side_calls_backend import (
110110
ActiveCheck,
@@ -133,7 +133,6 @@
133133
from cmk.utils.experimental_config import load_experimental_config
134134
from cmk.utils.host_storage import (
135135
apply_hosts_file_to_object,
136-
FolderAttributesForBase,
137136
get_host_storage_loaders,
138137
)
139138
from cmk.utils.http_proxy_config import http_proxy_config_from_user_setting, HTTPProxyConfig
@@ -186,9 +185,6 @@
186185
service_service_levels: list[RuleSpec[int]] = []
187186
host_service_levels: list[RuleSpec[int]] = []
188187

189-
_AgentTargetVersion = None | str | tuple[str, str] | tuple[str, dict[str, str]]
190-
191-
ShadowHosts = dict[HostName, dict[str, Any]]
192188

193189
ObjectMacros = dict[str, AnyStr]
194190

@@ -501,7 +497,6 @@ class CheckmkCheckParameters(NamedTuple):
501497
ObjectAttributes = dict[str, Any]
502498

503499
GroupDefinitions = dict[str, str]
504-
RecurringDowntime = Mapping[str, int | str] # TODO(sk): TypedDict here
505500

506501

507502
class _NestedExitSpec(ExitSpec, total=False):
@@ -550,86 +545,6 @@ def register(name: str, default_value: Any) -> None:
550545
# '----------------------------------------------------------------------'
551546

552547

553-
@dataclasses.dataclass(frozen=True, kw_only=True)
554-
class LoadedConfigFragment:
555-
"""Return *some of* the values that have been loaded as part of the config loading process.
556-
557-
The config loading currently mostly manipulates a global state.
558-
Return an instance of this class, to indicate that the config has been loaded.
559-
560-
Someday (TM): return the actual loaded config, at which point this class will be quite big
561-
(compare cmk/base/default_config/base ...)
562-
"""
563-
564-
# TODO: get `HostAddress` VS. `str` right! Which is it at what point?!
565-
# NOTE: all of the below is wishful typing, no parsing is done yet.
566-
# for now we just copy what we find in default_config
567-
folder_attributes: Mapping[str, FolderAttributesForBase]
568-
discovery_rules: Mapping[RuleSetName, Sequence[RuleSpec]]
569-
checkgroup_parameters: Mapping[str, Sequence[RuleSpec[Mapping[str, object]]]]
570-
static_checks: Mapping[
571-
str, list[RuleSpec[list[object]]]
572-
] # a.k.a. "enforced_services". Keep the name for consistency
573-
service_rule_groups: set[str]
574-
service_descriptions: Mapping[str, str]
575-
service_description_translation: Sequence[RuleSpec[Mapping[str, object]]]
576-
use_new_descriptions_for: Container[str]
577-
monitoring_core: Literal["nagios", "cmc"]
578-
nagios_illegal_chars: str
579-
cmc_illegal_chars: str
580-
all_hosts: Sequence[str]
581-
clusters: Mapping[HostAddress, Sequence[HostAddress]]
582-
shadow_hosts: ShadowHosts
583-
service_dependencies: Sequence[tuple]
584-
fallback_agent_output_encoding: str
585-
agent_config: Mapping[str, Sequence[RuleSpec]]
586-
agent_port: int
587-
agent_ports: Sequence[RuleSpec[int]]
588-
tcp_connect_timeout: float
589-
tcp_connect_timeouts: Sequence[RuleSpec[float]]
590-
encryption_handling: Sequence[RuleSpec[Mapping[str, str]]]
591-
piggyback_translation: Sequence[RuleSpec[Mapping[str, object]]]
592-
agent_encryption: Sequence[RuleSpec[str | None]]
593-
agent_exclude_sections: Sequence[RuleSpec[dict[str, str]]]
594-
cmc_real_time_checks: RealTimeChecks | None
595-
snmp_check_interval: list[
596-
RuleSpec[
597-
tuple[list[str], tuple[Literal["cached"], float] | tuple[Literal["uncached"], None]]
598-
]
599-
]
600-
apply_bake_revision: bool
601-
bake_agents_on_restart: bool
602-
agent_bakery_logging: int | None
603-
is_wato_slave_site: bool
604-
simulation_mode: bool
605-
use_dns_cache: bool
606-
ipaddresses: Mapping[HostName, HostAddress]
607-
ipv6addresses: Mapping[HostName, HostAddress]
608-
fake_dns: str | None
609-
tag_config: cmk.utils.tags.TagConfigSpec
610-
host_tags: ruleset_matcher.TagsOfHosts
611-
cmc_log_rrdcreation: Literal["terse", "full"] | None
612-
cmc_host_rrd_config: Sequence[RuleSpec[Any]]
613-
host_recurring_downtimes: Sequence[RuleSpec[RecurringDowntime]]
614-
cmc_flap_settings: tuple[float, float, float]
615-
cmc_host_flap_settings: Sequence[RuleSpec[tuple[float, float, float]]]
616-
cmc_host_long_output_in_monitoring_history: Sequence[RuleSpec[bool]]
617-
host_state_translation: Sequence[RuleSpec[Mapping[str, object]]]
618-
cmc_smartping_settings: Sequence[RuleSpec[Mapping[str, float]]]
619-
cmc_service_rrd_config: Sequence[RuleSpec[RRDObjectConfig]]
620-
service_recurring_downtimes: Sequence[RuleSpec[Mapping[str, int | str]]]
621-
cmc_service_flap_settings: Sequence[RuleSpec[tuple[float, float, float]]]
622-
cmc_service_long_output_in_monitoring_history: Sequence[RuleSpec[bool]]
623-
service_state_translation: Sequence[RuleSpec[Mapping[str, object]]]
624-
cmc_check_timeout: int
625-
cmc_service_check_timeout: Sequence[RuleSpec[int]]
626-
cmc_graphite_host_metrics: Sequence[RuleSpec[Sequence[str]]]
627-
cmc_graphite_service_metrics: Sequence[RuleSpec[Sequence[str]]]
628-
cmc_influxdb_service_metrics: Sequence[RuleSpec[Mapping[str, object]]]
629-
cmc_log_levels: Mapping[str, int]
630-
cluster_max_cachefile_age: int
631-
632-
633548
@dataclasses.dataclass(frozen=True, kw_only=True)
634549
class LoadingResult:
635550
"""Return the result of the config loading process.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/env python3
2+
# Copyright (C) 2025 Checkmk GmbH - License: GNU General Public License v2
3+
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
4+
# conditions defined in the file COPYING, which is part of this source code package.
5+
6+
7+
import dataclasses
8+
from collections.abc import Container, Mapping, Sequence
9+
from typing import (
10+
Any,
11+
Literal,
12+
)
13+
14+
import cmk.utils
15+
import cmk.utils.tags
16+
from cmk.base.default_config.cmc import RealTimeChecks
17+
from cmk.ccc.hostaddress import HostAddress, HostName
18+
from cmk.rrd.config import RRDObjectConfig # pylint: disable=cmk-module-layer-violation
19+
from cmk.utils.host_storage import FolderAttributesForBase
20+
from cmk.utils.rulesets import ruleset_matcher, RuleSetName
21+
from cmk.utils.rulesets.ruleset_matcher import RuleSpec
22+
23+
24+
@dataclasses.dataclass(frozen=True, kw_only=True)
25+
class LoadedConfigFragment:
26+
"""Return *some of* the values that have been loaded as part of the config loading process.
27+
28+
The config loading currently mostly manipulates a global state.
29+
Return an instance of this class, to indicate that the config has been loaded.
30+
31+
Someday (TM): return the actual loaded config, at which point this class will be quite big
32+
(compare cmk/base/default_config/base ...)
33+
"""
34+
35+
# TODO: get `HostAddress` VS. `str` right! Which is it at what point?!
36+
# NOTE: all of the below is wishful typing, no parsing is done yet.
37+
# for now we just copy what we find in default_config
38+
folder_attributes: Mapping[str, FolderAttributesForBase]
39+
discovery_rules: Mapping[RuleSetName, Sequence[RuleSpec]]
40+
checkgroup_parameters: Mapping[str, Sequence[RuleSpec[Mapping[str, object]]]]
41+
static_checks: Mapping[
42+
str, list[RuleSpec[list[object]]]
43+
] # a.k.a. "enforced_services". Keep the name for consistency
44+
service_rule_groups: set[str]
45+
service_descriptions: Mapping[str, str]
46+
service_description_translation: Sequence[RuleSpec[Mapping[str, object]]]
47+
use_new_descriptions_for: Container[str]
48+
monitoring_core: Literal["nagios", "cmc"]
49+
nagios_illegal_chars: str
50+
cmc_illegal_chars: str
51+
all_hosts: Sequence[str]
52+
clusters: Mapping[HostAddress, Sequence[HostAddress]]
53+
shadow_hosts: dict[HostName, dict[str, Any]]
54+
service_dependencies: Sequence[tuple]
55+
fallback_agent_output_encoding: str
56+
agent_config: Mapping[str, Sequence[RuleSpec]]
57+
agent_port: int
58+
agent_ports: Sequence[RuleSpec[int]]
59+
tcp_connect_timeout: float
60+
tcp_connect_timeouts: Sequence[RuleSpec[float]]
61+
encryption_handling: Sequence[RuleSpec[Mapping[str, str]]]
62+
piggyback_translation: Sequence[RuleSpec[Mapping[str, object]]]
63+
agent_encryption: Sequence[RuleSpec[str | None]]
64+
agent_exclude_sections: Sequence[RuleSpec[dict[str, str]]]
65+
cmc_real_time_checks: RealTimeChecks | None
66+
snmp_check_interval: list[
67+
RuleSpec[
68+
tuple[list[str], tuple[Literal["cached"], float] | tuple[Literal["uncached"], None]]
69+
]
70+
]
71+
apply_bake_revision: bool
72+
bake_agents_on_restart: bool
73+
agent_bakery_logging: int | None
74+
is_wato_slave_site: bool
75+
simulation_mode: bool
76+
use_dns_cache: bool
77+
ipaddresses: Mapping[HostName, HostAddress]
78+
ipv6addresses: Mapping[HostName, HostAddress]
79+
fake_dns: str | None
80+
tag_config: cmk.utils.tags.TagConfigSpec
81+
host_tags: ruleset_matcher.TagsOfHosts
82+
cmc_log_rrdcreation: Literal["terse", "full"] | None
83+
cmc_host_rrd_config: Sequence[RuleSpec[Any]]
84+
host_recurring_downtimes: Sequence[RuleSpec[Mapping[str, int | str]]]
85+
86+
cmc_flap_settings: tuple[float, float, float]
87+
cmc_host_flap_settings: Sequence[RuleSpec[tuple[float, float, float]]]
88+
cmc_host_long_output_in_monitoring_history: Sequence[RuleSpec[bool]]
89+
host_state_translation: Sequence[RuleSpec[Mapping[str, object]]]
90+
cmc_smartping_settings: Sequence[RuleSpec[Mapping[str, float]]]
91+
cmc_service_rrd_config: Sequence[RuleSpec[RRDObjectConfig]]
92+
service_recurring_downtimes: Sequence[RuleSpec[Mapping[str, int | str]]]
93+
cmc_service_flap_settings: Sequence[RuleSpec[tuple[float, float, float]]]
94+
cmc_service_long_output_in_monitoring_history: Sequence[RuleSpec[bool]]
95+
service_state_translation: Sequence[RuleSpec[Mapping[str, object]]]
96+
cmc_check_timeout: int
97+
cmc_service_check_timeout: Sequence[RuleSpec[int]]
98+
cmc_graphite_host_metrics: Sequence[RuleSpec[Sequence[str]]]
99+
cmc_graphite_service_metrics: Sequence[RuleSpec[Sequence[str]]]
100+
cmc_influxdb_service_metrics: Sequence[RuleSpec[Mapping[str, object]]]
101+
cmc_log_levels: Mapping[str, int]
102+
cluster_max_cachefile_age: int

cmk/base/core_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from collections.abc import Callable, Mapping
77
from typing import assert_never
88

9-
from cmk.base.config import LoadedConfigFragment
9+
from cmk.base.configlib.loaded_config import LoadedConfigFragment
1010
from cmk.base.core_config import MonitoringCore
1111
from cmk.ccc.hostaddress import HostName
1212
from cmk.ccc.version import Edition, edition

cmk/base/diagnostics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
import cmk.ccc.version as cmk_version
3232
import cmk.utils.paths
33-
from cmk.base.config import LoadedConfigFragment
33+
from cmk.base.configlib.loaded_config import LoadedConfigFragment
3434
from cmk.ccc import site, store, tty
3535
from cmk.ccc.hostaddress import HostName
3636
from cmk.ccc.i18n import _

cmk/base/modes/check_mk.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
handle_ip_lookup_failure,
4747
)
4848
from cmk.base.configlib.checkengine import DiscoveryConfig
49+
from cmk.base.configlib.loaded_config import LoadedConfigFragment
4950
from cmk.base.core_factory import create_core, get_licensing_handler_type
5051
from cmk.base.errorhandling import CheckResultErrorHandler, create_section_crash_dump
5152
from cmk.base.modes import Mode, modes, Option
@@ -2612,7 +2613,7 @@ def mode_check(options: _CheckingOptions, args: list[str]) -> ServiceState:
26122613

26132614
# also used in precompiled host checks!
26142615
def run_checking(
2615-
loaded_config: config.LoadedConfigFragment,
2616+
loaded_config: LoadedConfigFragment,
26162617
plugins: AgentBasedPlugins,
26172618
config_cache: ConfigCache,
26182619
hosts_config: Hosts,

tests/unit/cmk/base/empty_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
44
# conditions defined in the file COPYING, which is part of this source code package.
55

6-
from cmk.base.config import LoadedConfigFragment
6+
from cmk.base.configlib.loaded_config import LoadedConfigFragment
77
from cmk.utils.labels import ABCLabelConfig, LabelManager, Labels
88
from cmk.utils.rulesets.ruleset_matcher import RulesetMatcher
99

tests/unit/cmk/base/test_config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from cmk.base.config import ConfigCache, EnforcedServicesTable
3333
from cmk.base.configlib.checkengine import CheckingConfig
3434
from cmk.base.configlib.labels import LabelConfig
35+
from cmk.base.configlib.loaded_config import LoadedConfigFragment
3536
from cmk.base.configlib.servicename import FinalServiceNameConfig, PassiveServiceNameConfig
3637
from cmk.base.default_config.base import _PeriodicDiscovery
3738
from cmk.ccc.exceptions import MKGeneralException
@@ -2564,7 +2565,7 @@ def test_host_config_add_discovery_check(
25642565

25652566

25662567
def test_get_config_file_paths_with_confd(
2567-
folder_path_test_config: config.LoadedConfigFragment,
2568+
folder_path_test_config: LoadedConfigFragment,
25682569
) -> None:
25692570
# NOTE: there are still some globals at play here, otherwise we would have to use
25702571
# the folder_path_test_config somewhere.
@@ -2585,7 +2586,7 @@ def test_get_config_file_paths_with_confd(
25852586
]
25862587

25872588

2588-
def test_load_config_folder_paths(folder_path_test_config: config.LoadedConfigFragment) -> None:
2589+
def test_load_config_folder_paths(folder_path_test_config: LoadedConfigFragment) -> None:
25892590
config_cache = config.ConfigCache(folder_path_test_config)
25902591

25912592
assert config_cache.host_path(HostName("main-host")) == "/"
@@ -2640,7 +2641,7 @@ def test_load_config_folder_paths(folder_path_test_config: config.LoadedConfigFr
26402641
@pytest.fixture(name="folder_path_test_config")
26412642
def folder_path_test_config_fixture(
26422643
monkeypatch: MonkeyPatch,
2643-
) -> Iterator[config.LoadedConfigFragment]:
2644+
) -> Iterator[LoadedConfigFragment]:
26442645
config_dir = cmk.utils.paths.check_mk_config_dir
26452646
config_dir.mkdir(parents=True, exist_ok=True)
26462647

0 commit comments

Comments
 (0)