[checkmk-commits] Cleanup all direct config.is_ipv4_host calls

Lars Michelsen lm at mathias-kettner.de
Tue Apr 16 15:50:27 CEST 2019


Module: check_mk
Branch: master
Commit: a6ea57cb619bfe36c849eed8b64f1c16ec253d06
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a6ea57cb619bfe36c849eed8b64f1c16ec253d06

Author: Lars Michelsen <lm at mathias-kettner.de>
Date:   Mon Apr 15 22:48:53 2019 +0200

Cleanup all direct config.is_ipv4_host calls

Change-Id: I9fec414de54a4b90be974cea7aaa288a80fbb069

---

 cmk_base/config.py                 | 5 -----
 cmk_base/core_config.py            | 4 ++--
 cmk_base/core_nagios.py            | 6 +++---
 tests/unit/cmk_base/test_config.py | 1 -
 4 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/cmk_base/config.py b/cmk_base/config.py
index 9766cb5..e46dd33 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -834,11 +834,6 @@ def parents_of(hostname):
 
 
 # TODO: Replace call sites with HostConfig access and remove this
-def is_ipv4_host(hostname):
-    return get_config_cache().get_host_config(hostname).is_ipv4_host
-
-
-# TODO: Replace call sites with HostConfig access and remove this
 def is_no_ip_host(hostname):
     return get_config_cache().get_host_config(hostname).is_no_ip_host
 
diff --git a/cmk_base/core_config.py b/cmk_base/core_config.py
index 69e3968..f41f1c9 100644
--- a/cmk_base/core_config.py
+++ b/cmk_base/core_config.py
@@ -406,7 +406,7 @@ def get_host_attributes(hostname, config_cache):
         attrs["alias"] = config.alias_of(hostname, hostname)
 
     # Now lookup configured IP addresses
-    if config.is_ipv4_host(hostname):
+    if host_config.is_ipv4_host:
         attrs["_ADDRESS_4"] = _ip_address_of(host_config, 4)
         if attrs["_ADDRESS_4"] is None:
             attrs["_ADDRESS_4"] = ""
@@ -482,7 +482,7 @@ def get_cluster_attributes(config_cache, host_config, nodes):
         "_NODENAMES": " ".join(sorted_nodes),
     }
     node_ips_4 = []
-    if config.is_ipv4_host(host_config.hostname):
+    if host_config.is_ipv4_host:
         for h in sorted_nodes:
             node_config = config_cache.get_host_config(h)
             addr = _ip_address_of(node_config, 4)
diff --git a/cmk_base/core_nagios.py b/cmk_base/core_nagios.py
index b57dfde..1ca279e 100644
--- a/cmk_base/core_nagios.py
+++ b/cmk_base/core_nagios.py
@@ -1122,14 +1122,14 @@ if '-d' in sys.argv:
     if config.is_cluster(hostname):
         for node in config.nodes_of(hostname):
             node_config = config_cache.get_host_config(node)
-            if config.is_ipv4_host(node):
+            if node_config.is_ipv4_host:
                 needed_ipaddresses[node] = ip_lookup.lookup_ipv4_address(node)
 
             if node_config.is_ipv6_host:
                 needed_ipv6addresses[node] = ip_lookup.lookup_ipv6_address(node)
 
         try:
-            if config.is_ipv4_host(hostname):
+            if host_config.is_ipv4_host:
                 needed_ipaddresses[hostname] = ip_lookup.lookup_ipv4_address(hostname)
         except:
             pass
@@ -1140,7 +1140,7 @@ if '-d' in sys.argv:
         except:
             pass
     else:
-        if config.is_ipv4_host(hostname):
+        if host_config.is_ipv4_host:
             needed_ipaddresses[hostname] = ip_lookup.lookup_ipv4_address(hostname)
 
         if host_config.is_ipv6_host:
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index d660dd3..9aac531 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -24,7 +24,6 @@ def clear_config_caches(monkeypatch):
 ])
 def test_is_ipv4_host(monkeypatch, hostname, tags, result):
     config_cache = _setup_host(monkeypatch, hostname, tags)
-    assert config.is_ipv4_host(hostname) == result
     assert config_cache.get_host_config(hostname).is_ipv4_host == result
 
 



More information about the checkmk-commits mailing list