Module: check_mk
Branch: master
Commit: 21d45dbddf34fbbb0b367c1cb876826c753c690d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=21d45dbddf34fb…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu May 2 09:24:21 2019 +0200
Move config.service_groups processing to ConfigCache
CMK-2030
Change-Id: Iaafa295e80e40d089477fd3b676947d0bae2b844
---
cmk_base/config.py | 5 +++++
cmk_base/core_nagios.py | 4 ++--
cmk_base/dump_host.py | 3 +--
tests/unit/cmk_base/test_config.py | 13 +++++++++++++
4 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 76764fc..0c19a08 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -3059,6 +3059,11 @@ class ConfigCache(object):
return list(actions)
+ def servicegroups_of_service(self, hostname, description):
+ # type: (str, Text) -> List[str]
+ """Returns the list of servicegroups of this
services"""
+ return self.service_extra_conf(hostname, description, service_groups)
+
def get_explicit_service_custom_variables(self, hostname, description):
# type: (str, Text) -> Dict[str, str]
try:
diff --git a/cmk_base/core_nagios.py b/cmk_base/core_nagios.py
index 9865bc1..65ddf06 100644
--- a/cmk_base/core_nagios.py
+++ b/cmk_base/core_nagios.py
@@ -835,8 +835,8 @@ def _extra_service_conf_of(cfg, config_cache, hostname, description):
sercgr.append("check-mk-notify") # not nessary if not explicit
groups defined
service_spec["contact_groups"] = ",".join(sercgr)
- sergr = config_cache.service_extra_conf(hostname, description,
config.service_groups)
- if len(sergr) > 0:
+ sergr = config_cache.servicegroups_of_service(hostname, description)
+ if sergr:
service_spec["service_groups"] = ",".join(sergr)
if config.define_servicegroups:
cfg.servicegroups_to_define.update(sergr)
diff --git a/cmk_base/dump_host.py b/cmk_base/dump_host.py
index 1df425e..342cb69 100644
--- a/cmk_base/dump_host.py
+++ b/cmk_base/dump_host.py
@@ -127,8 +127,7 @@ def dump_host(hostname):
_evaluate_params(params),
cmk_base.utils.make_utf8(description),
cmk_base.utils.make_utf8(",".join(
- config_cache.service_extra_conf(hostname, description,
config.service_groups))),
- ",".join(deps)
+ config_cache.servicegroups_of_service(hostname, description))),
",".join(deps)
] for checktype, item, params, description, deps in check_items], " ")
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index 29f8a9d..4f6faa9 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -1068,6 +1068,19 @@ def test_config_cache_icons_and_actions(monkeypatch, hostname,
result):
{})) == sorted(result)
+(a)pytest.mark.parametrize("hostname,result"sult", [
+ ("testhost1", []),
+ ("testhost2", ["dingdong"]),
+])
+def test_config_cache_servicegroups_of_service(monkeypatch, hostname, result):
+ ts = Scenario().add_host(hostname)
+ ts.set_ruleset("service_groups", [
+ ("dingdong", [], ["testhost2"], "CPU load$", {}),
+ ])
+ config_cache = ts.apply(monkeypatch)
+ assert config_cache.servicegroups_of_service(hostname, "CPU load") ==
result
+
+
@pytest.mark.parametrize("edition_short,expected_cache_class_name,expected_host_class_name",
[
("cme", "CEEConfigCache", "CEEHostConfig"),
("cee", "CEEConfigCache", "CEEHostConfig"),