Module: check_mk
Branch: master
Commit: c9ba7d33a2958af1d2e3424b922998576415c06b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c9ba7d33a2958a…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Apr 23 20:21:19 2019 +0200
Cleanup config.do_status_data_inventory_for
CMK-2030
Change-Id: I266a4ee44fc64f8c7ef8b6d97a341fd8bddb0fd9
---
cmk_base/config.py | 37 +++++++++++++++++++------------------
cmk_base/inventory.py | 7 +++----
tests/unit/cmk_base/test_config.py | 6 +++---
3 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 03c8710..82abafb 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -2091,24 +2091,6 @@ def _get_checkgroup_parameters(config_cache, host, checktype,
item):
raise MKGeneralException(str(e) + " (on host %s, checktype %s)" %
(host, checktype))
-def do_status_data_inventory_for(hostname):
- rules = active_checks.get('cmk_inv')
- if rules is None:
- return False
-
- # 'host_extra_conf' is already cached thus we can
- # use it after every check cycle.
- entries = get_config_cache().host_extra_conf(hostname, rules)
-
- if not entries:
- return False # No matching rule -> disable
-
- # Convert legacy rules to current dict format (just like the valuespec)
- params = {} if entries[0] is None else entries[0]
-
- return params.get('status_data_inventory', False)
-
-
def do_host_label_discovery_for(hostname):
rules = active_checks.get('cmk_inv')
if rules is None:
@@ -2658,6 +2640,25 @@ class HostConfig(object):
# Old configuration format
return spec
+ @property
+ def do_status_data_inventory(self):
+ # type: () -> bool
+ rules = active_checks.get('cmk_inv')
+ if rules is None:
+ return False
+
+ # 'host_extra_conf' is already cached thus we can
+ # use it after every check cycle.
+ entries = self._config_cache.host_extra_conf(self.hostname, rules)
+
+ if not entries:
+ return False # No matching rule -> disable
+
+ # Convert legacy rules to current dict format (just like the valuespec)
+ params = {} if entries[0] is None else entries[0]
+
+ return params.get('status_data_inventory', False)
+
#.
# .--Configuration Cache-------------------------------------------------.
diff --git a/cmk_base/inventory.py b/cmk_base/inventory.py
index 4442b82..1e9afa5 100644
--- a/cmk_base/inventory.py
+++ b/cmk_base/inventory.py
@@ -86,7 +86,7 @@ def do_inv(hostnames):
multi_host_sections=None,
host_config=host_config,
ipaddress=ipaddress,
- do_status_data_inv=config.do_status_data_inventory_for(hostname),
+ do_status_data_inv=host_config.do_status_data_inventory,
do_host_label_discovery=config.do_host_label_discovery_for(hostname),
)
except Exception as e:
@@ -123,7 +123,7 @@ def do_inv_check(hostname, options):
multi_host_sections=None,
host_config=host_config,
ipaddress=ipaddress,
- do_status_data_inv=config.do_status_data_inventory_for(hostname),
+ do_status_data_inv=host_config.do_status_data_inventory,
do_host_label_discovery=config.do_host_label_discovery_for(hostname),
)
@@ -177,8 +177,7 @@ def do_inv_check(hostname, options):
def do_inventory_actions_during_checking_for(sources, multi_host_sections, host_config,
ipaddress):
# type: (data_sources.DataSources, data_sources.MultiHostSections, config.HostConfig,
Optional[str]) -> None
hostname = host_config.hostname
- do_status_data_inventory = not host_config.is_cluster \
- and config.do_status_data_inventory_for(hostname)
+ do_status_data_inventory = not host_config.is_cluster and
host_config.do_status_data_inventory
do_host_label_discovery = config.do_host_label_discovery_for(hostname)
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index 01c7b7a..832d679 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -735,14 +735,14 @@ def test_host_ruleset_match_object_of_service(monkeypatch):
"status_data_inventory": False
}, [], config.ALL_HOSTS, {})]),
])
-def test_do_status_data_inventory_for(monkeypatch, result, ruleset):
+def test_host_config_do_status_data_inventory(monkeypatch, result, ruleset):
ts = Scenario().add_host("abc", [])
ts.set_option("active_checks", {
"cmk_inv": ruleset,
})
- ts.apply(monkeypatch)
+ config_cache = ts.apply(monkeypatch)
- assert config.do_status_data_inventory_for("abc") == result
+ assert config_cache.get_host_config("abc").do_status_data_inventory ==
result
@pytest.mark.parametrize("result,ruleset", [