Module: check_mk
Branch: master
Commit: a3dc998011ed8a70ca2208362d96b4abe6501cf8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a3dc998011ed8a…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Apr 23 20:14:06 2019 +0200
Cleanup config.additional_ip_addresses
CMK-2030
Change-Id: I53f5982291420a8383975540c107bddb17fbe661
---
cmk_base/config.py | 20 ++++++++++----------
cmk_base/core_config.py | 2 +-
tests/unit/cmk_base/test_config.py | 16 ++++++++++++++++
3 files changed, 27 insertions(+), 11 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index ca28bdc..03c8710 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -726,16 +726,6 @@ def _host_is_member_of_site(config_cache, hostname, site):
return True
-def get_additional_ipaddresses_of(hostname):
- # type: (str) -> Tuple[List[str], List[str]]
- #TODO Regarding the following configuration variables from WATO
- # there's no inheritance, thus we use 'host_attributes'.
- # Better would be to use cmk_base configuration variables,
- # eg. like 'management_protocol'.
- return (host_attributes.get(hostname, {}).get("additional_ipv4addresses",
[]),
- host_attributes.get(hostname, {}).get("additional_ipv6addresses",
[]))
-
-
#
# Explicit custom variables
#
@@ -2633,6 +2623,16 @@ class HostConfig(object):
return default_value
+ @property
+ def additional_ipaddresses(self):
+ # type: () -> Tuple[List[str], List[str]]
+ #TODO Regarding the following configuration variables from WATO
+ # there's no inheritance, thus we use 'host_attributes'.
+ # Better would be to use cmk_base configuration variables,
+ # eg. like 'management_protocol'.
+ return (host_attributes.get(self.hostname,
{}).get("additional_ipv4addresses", []),
+ host_attributes.get(self.hostname,
{}).get("additional_ipv6addresses", []))
+
def exit_code_spec(self, data_source_id=None):
# type: (Optional[str]) -> Dict[str, int]
spec = {} # type: Dict[str, int]
diff --git a/cmk_base/core_config.py b/cmk_base/core_config.py
index 0bbc417..7f75278 100644
--- a/cmk_base/core_config.py
+++ b/cmk_base/core_config.py
@@ -428,7 +428,7 @@ def get_host_attributes(hostname, config_cache):
attrs["address"] = attrs["_ADDRESS_4"]
attrs["_ADDRESS_FAMILY"] = "4"
- add_ipv4addrs, add_ipv6addrs = config.get_additional_ipaddresses_of(hostname)
+ add_ipv4addrs, add_ipv6addrs = host_config.additional_ipaddresses
if add_ipv4addrs:
attrs["_ADDRESSES_4"] = " ".join(add_ipv4addrs)
for nr, ipv4_address in enumerate(add_ipv4addrs):
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index c574970..01c7b7a 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -145,6 +145,22 @@ def test_host_config_management_address(monkeypatch, attrs, result):
assert config_cache.get_host_config("hostname").management_address ==
result
+(a)pytest.mark.parametrize("attrs,result"sult", [
+ ({}, ([], [])),
+ ({
+ "additional_ipv4addresses": ["10.10.10.10"],
+ "additional_ipv6addresses": ["::3"],
+ }, (["10.10.10.10"], ["::3"])),
+])
+def test_host_config_additional_ipaddresses(monkeypatch, attrs, result):
+ ts = Scenario().add_host("hostname")
+ ts.set_option("ipaddresses", {"hostname":
"127.0.1.1"})
+ ts.set_option("host_attributes", {"hostname": attrs})
+ config_cache = ts.apply(monkeypatch)
+
+ assert config_cache.get_host_config("hostname").additional_ipaddresses ==
result
+
+
@pytest.mark.parametrize("hostname,tags,result", [
("testhost", [], True),
("testhost", ["cmk-agent"], True),