Module: check_mk
Branch: master
Commit: 4083a4f4055259a56e202b382becacdffd58ecd9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4083a4f4055259…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon May 6 09:40:32 2019 +0200
Move host ruleset match object computation to ConfigCache for the moment
Change-Id: I0264b8d3f36874e9f57bb8c7ecc269108d8ab3ef
---
cmk_base/config.py | 25 ++++++++++++-------------
tests/unit/cmk_base/test_config.py | 14 +++++++-------
2 files changed, 19 insertions(+), 20 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index f95aa99..cca5a82 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -2215,7 +2215,6 @@ class HostConfig(object):
self.tag_groups = self._config_cache.tags_of_host(hostname)
self.labels = self._get_host_labels()
self.label_sources = self._get_host_label_sources()
- self.ruleset_match_object = self._get_ruleset_match_object()
# Basic types
self.is_tcp_host = self._config_cache.in_binary_hostlist(hostname, tcp_hosts)
@@ -2258,14 +2257,6 @@ class HostConfig(object):
self.is_ipv6_primary = (not self.is_ipv4v6_host and self.is_ipv6_host) \
or (self.is_ipv4v6_host and
self._primary_ip_address_family_of() == "ipv6")
- def _get_ruleset_match_object(self):
- # type: () -> RulesetMatchObject
- """Construct the dictionary object that is needed to match this
host to rulesets"""
- return RulesetMatchObject(
- host_name=self.hostname,
- host_tags=self.tag_groups,
- )
-
@property
def has_piggyback_data(self):
if piggyback.has_piggyback_raw_data(piggyback_max_cachefile_age, self.hostname):
@@ -3091,6 +3082,17 @@ class ConfigCache(object):
except KeyError:
return {}
+ # TODO: Move to HostConfig? Is currently not possible to have this in HostConfig
because
+ # the constructor executes rule matching functions. Moved the computation to this
place
+ # to prevent dependency issues for the moment.
+ def ruleset_match_object_of_host(self, hostname):
+ # type: (str) -> RulesetMatchObject
+ """Construct the dictionary object that is needed to match this
host to rulesets"""
+ return RulesetMatchObject(
+ host_name=hostname,
+ host_tags=self.tags_of_host(hostname),
+ )
+
def ruleset_match_object_of_service(self, hostname, svc_desc):
# type: (str, Text) -> RulesetMatchObject
"""Construct the dictionary object that is needed to match this
service to rulesets
@@ -3098,11 +3100,8 @@ class ConfigCache(object):
This is done by loading the host match object and extending it with the
information of this service.
"""
- host_config = self.get_host_config(hostname)
- match_object = host_config.ruleset_match_object.copy()
-
+ match_object = self.ruleset_match_object_of_host(hostname)
match_object.service_description = svc_desc
-
return match_object
def set_all_processed_hosts(self, all_processed_hosts):
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index ec443da..13fba5c 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -1248,7 +1248,7 @@ def test_config_cache_get_host_config(monkeypatch, edition_short,
expected_cache
assert host_config is cache.get_host_config("xyz")
-def test_host_ruleset_match_object_of_host(monkeypatch):
+def test_config_cache_ruleset_match_object_of_host(monkeypatch):
ts = Scenario()
ts.set_option("host_tags", {
"test-host": {
@@ -1258,16 +1258,16 @@ def test_host_ruleset_match_object_of_host(monkeypatch):
ts.add_host("test-host", ["abc"])
config_cache = ts.apply(monkeypatch)
- cfg = config_cache.get_host_config("xyz")
- assert isinstance(cfg.ruleset_match_object, RulesetMatchObject)
- assert cfg.ruleset_match_object.to_dict() == {
+ ruleset_match_object = config_cache.ruleset_match_object_of_host("xyz")
+ assert isinstance(ruleset_match_object, RulesetMatchObject)
+ assert ruleset_match_object.to_dict() == {
"host_tags": {},
"host_name": "xyz",
}
- cfg = config_cache.get_host_config("test-host")
- assert isinstance(cfg.ruleset_match_object, RulesetMatchObject)
- assert cfg.ruleset_match_object.to_dict() == {
+ ruleset_match_object =
config_cache.ruleset_match_object_of_host("test-host")
+ assert isinstance(ruleset_match_object, RulesetMatchObject)
+ assert ruleset_match_object.to_dict() == {
"host_name": "test-host",
"host_tags": {
"tag_group": "abc",