Module: check_mk
Branch: master
Commit: a9381a00c7bd1182c1d61e3ca26788e3e857e69e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a9381a00c7bd11…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Apr 2 15:11:03 2019 +0200
Rename tags_of_host to tag_list_of_host
Change-Id: Idafc1f17de0d08426be24455ac7f5a5272c70a55
---
cmk_base/check_api.py | 2 +-
cmk_base/config.py | 30 +++++++++++++++---------------
cmk_base/core_config.py | 2 +-
cmk_base/data_sources/__init__.py | 2 +-
cmk_base/modes/check_mk.py | 2 +-
tests/unit/cmk_base/test_config.py | 10 +++++-----
6 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/cmk_base/check_api.py b/cmk_base/check_api.py
index 075f8dc..8c5811e 100644
--- a/cmk_base/check_api.py
+++ b/cmk_base/check_api.py
@@ -223,7 +223,7 @@ get_rule_options = _config.get_rule_options
# the future check API. It's kept here for compatibility reasons for now.
in_extraconf_hostlist = _config.in_extraconf_hostlist
hosttags_match_taglist = _config.hosttags_match_taglist
-tags_of_host = _config.tags_of_host
+tags_of_host = _config.tag_list_of_host
all_matching_hosts = _config.all_matching_hosts
nagios_illegal_chars = _config.nagios_illegal_chars
diff --git a/cmk_base/config.py b/cmk_base/config.py
index ac155ee..9411c37 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -603,8 +603,8 @@ def strip_tags(tagged_hostlist):
return result
-def tags_of_host(hostname):
- return get_config_cache().tags_of_host(hostname)
+def tag_list_of_host(hostname):
+ return get_config_cache().tag_list_of_host(hostname)
#.
@@ -776,7 +776,7 @@ def all_configured_offline_hosts():
def host_is_member_of_site(hostname, site):
- for tag in tags_of_host(hostname):
+ for tag in tag_list_of_host(hostname):
if tag.startswith("site:"):
return site == tag[5:]
# hosts without a site: tag belong to all sites
@@ -846,7 +846,7 @@ def is_agent_host(hostname):
if is_tcp_host(hostname):
return True
- tags = tags_of_host(hostname)
+ tags = tag_list_of_host(hostname)
if "piggyback" in tags:
is_piggyback_host = True
@@ -865,11 +865,11 @@ def is_dual_host(hostname):
def is_all_agents_host(hostname):
- return "all-agents" in tags_of_host(hostname)
+ return "all-agents" in tag_list_of_host(hostname)
def is_all_special_agents_host(hostname):
- return "special-agents" in tags_of_host(hostname)
+ return "special-agents" in tag_list_of_host(hostname)
#
@@ -893,19 +893,19 @@ def _primary_ip_address_family_of(hostname):
def is_ipv4v6_host(hostname):
- tags = tags_of_host(hostname)
+ tags = tag_list_of_host(hostname)
return "ip-v6" in tags and "ip-v4" in tags
def is_ipv6_host(hostname):
- return "ip-v6" in tags_of_host(hostname)
+ return "ip-v6" in tag_list_of_host(hostname)
def is_ipv4_host(hostname):
"""Whether or not the given host is configured to be monitored via
IPv4.
This is the case when it is set to be explicit IPv4 or implicit
(when host is not an IPv6 host and not a "No IP" host)"""
- tags = tags_of_host(hostname)
+ tags = tag_list_of_host(hostname)
if "ip-v4" in tags:
return True
@@ -915,7 +915,7 @@ def is_ipv4_host(hostname):
def is_no_ip_host(hostname):
"""Whether or not the given host is configured not to be monitored via
IP"""
- return "no-ip" in tags_of_host(hostname)
+ return "no-ip" in tag_list_of_host(hostname)
#
@@ -1456,7 +1456,7 @@ def service_depends_on(hostname, servicedesc):
raise MKGeneralException("Invalid entry '%r' in service
dependencies: "
"must have 3 or 4 entries" % entry)
- if hosttags_match_taglist(config_cache.tags_of_host(hostname), tags) and \
+ if hosttags_match_taglist(config_cache.tag_list_of_host(hostname), tags) and \
in_extraconf_hostlist(hostlist, hostname):
for pattern in patternlist:
matchobject = regex(pattern).search(servicedesc)
@@ -2784,7 +2784,7 @@ class HostConfig(object):
self.is_cluster = is_cluster(hostname)
self.part_of_clusters = self._config_cache.clusters_of(hostname)
- tags = self._config_cache.tags_of_host(self.hostname)
+ tags = self._config_cache.tag_list_of_host(self.hostname)
self.tags = tags
self.tag_groups = host_tags.get(hostname, {})
@@ -2931,8 +2931,8 @@ class ConfigCache(object):
parts = tagged_host.split("|")
self._hosttags[parts[0]] = set(parts[1:])
- # TODO: Rename to tag_list_of_hosts, check all call sites and remove this
- def tags_of_host(self, hostname):
+ # TODO: check all call sites and remove this
+ def tag_list_of_host(self, hostname):
"""Returns the list of all configured tags of a host. In case
a host has no tags configured or is not known, it returns an
empty list."""
@@ -3387,7 +3387,7 @@ class ConfigCache(object):
cache[cache_id] = result
else:
for entry in conf:
- actual_host_tags = self.tags_of_host(hostname)
+ actual_host_tags = self.tag_list_of_host(hostname)
entry, rule_options = get_rule_options(entry)
if rule_options.get("disabled"):
continue
diff --git a/cmk_base/core_config.py b/cmk_base/core_config.py
index 93f404c..c71f30d 100644
--- a/cmk_base/core_config.py
+++ b/cmk_base/core_config.py
@@ -391,7 +391,7 @@ def get_host_attributes(hostname, config_cache):
# Pre 1.6 legacy attribute. We have changed our whole code to use the
# livestatus column "tags" which is populated by all attributes starting
with
# "__TAG_" instead. We may deprecate this is one day.
- attrs["_TAGS"] = "
".join(sorted(config_cache.tags_of_host(hostname)))
+ attrs["_TAGS"] = "
".join(sorted(config_cache.tag_list_of_host(hostname)))
attrs.update(_get_tag_attributes(config_cache.tag_groups_of_host(hostname)))
diff --git a/cmk_base/data_sources/__init__.py b/cmk_base/data_sources/__init__.py
index 36e9e88..b991f2e 100644
--- a/cmk_base/data_sources/__init__.py
+++ b/cmk_base/data_sources/__init__.py
@@ -137,7 +137,7 @@ class DataSources(object):
source.set_main_agent_data_source()
self._add_source(source)
- if "no-piggyback" not in config.tags_of_host(self._hostname):
+ if "no-piggyback" not in config.tag_list_of_host(self._hostname):
self._add_source(PiggyBackDataSource(self._hostname, self._ipaddress))
def _initialize_snmp_data_sources(self):
diff --git a/cmk_base/modes/check_mk.py b/cmk_base/modes/check_mk.py
index 096ebf2..6bfcf57 100644
--- a/cmk_base/modes/check_mk.py
+++ b/cmk_base/modes/check_mk.py
@@ -293,7 +293,7 @@ def _list_all_hosts_with_tags(tags):
config_cache = config.get_config_cache()
for h in hostlist:
- if config.hosttags_match_taglist(config_cache.tags_of_host(h), tags):
+ if config.hosttags_match_taglist(config_cache.tag_list_of_host(h), tags):
hosts.append(h)
return hosts
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index d64c440..526fb82 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -21,7 +21,7 @@ def clear_config_caches(monkeypatch):
("testhost", ["no-ip"], False),
])
def test_is_ipv4_host(monkeypatch, hostname, tags, result):
- monkeypatch.setattr(config, "tags_of_host", lambda h: {hostname: tags}[h])
+ monkeypatch.setattr(config, "tag_list_of_host", lambda h: {hostname:
tags}[h])
assert config.is_ipv4_host(hostname) == result
@@ -33,7 +33,7 @@ def test_is_ipv4_host(monkeypatch, hostname, tags, result):
("testhost", ["no-ip"], True),
])
def test_is_no_ip_host(monkeypatch, hostname, tags, result):
- monkeypatch.setattr(config, "tags_of_host", lambda h: {hostname: tags}[h])
+ monkeypatch.setattr(config, "tag_list_of_host", lambda h: {hostname:
tags}[h])
assert config.is_no_ip_host(hostname) == result
@@ -58,7 +58,7 @@ def test_is_no_ip_host(monkeypatch, hostname, tags, result):
def test_is_ipv6_primary_host(monkeypatch, hostname, tags, result, ruleset):
monkeypatch.setattr(config, "all_hosts", ["%s|%s" % (hostname,
"|".join(tags))])
monkeypatch.setattr(config, "host_paths", {hostname: "/"})
- monkeypatch.setattr(config, "tags_of_host", lambda h: {hostname: tags}[h])
+ monkeypatch.setattr(config, "tag_list_of_host", lambda h: {hostname:
tags}[h])
monkeypatch.setattr(config, "primary_address_family", ruleset)
config.get_config_cache().initialize()
@@ -121,7 +121,7 @@ def test_is_snmp_host(monkeypatch, hostname, tags, result):
("testhost", ["cmk-agent"], False),
])
def test_is_all_agents_host(monkeypatch, hostname, tags, result):
- monkeypatch.setattr(config, "tags_of_host", lambda h: {hostname: tags}[h])
+ monkeypatch.setattr(config, "tag_list_of_host", lambda h: {hostname:
tags}[h])
assert config.is_all_agents_host(hostname) == result
@@ -133,7 +133,7 @@ def test_is_all_agents_host(monkeypatch, hostname, tags, result):
("testhost", ["cmk-agent"], False),
])
def test_is_all_special_agents_host(monkeypatch, hostname, tags, result):
- monkeypatch.setattr(config, "tags_of_host", lambda h: {hostname: tags}[h])
+ monkeypatch.setattr(config, "tag_list_of_host", lambda h: {hostname:
tags}[h])
assert config.is_all_special_agents_host(hostname) == result