Module: check_mk
Branch: master
Commit: 8413b81af4766eaee2907d4802e6e27259a517cc
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8413b81af4766e…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Apr 27 10:30:55 2018 +0200
6037 FIX Fixed broken "Primary IP address family" rule set
When using the rule set "Primary IP address family" to change the
IP address family of dual stack hosts to IPv6, this rule was not
effective.
Change-Id: I364757474544262f8686b84a14b6c5eb827f923b
---
.werks/6037 | 13 +++++++++++++
cmk_base/config.py | 9 ++++++++-
tests/unit/cmk_base/test_config.py | 22 ++++++++++++++++++++++
3 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/.werks/6037 b/.werks/6037
new file mode 100644
index 0000000..ed5fe78
--- /dev/null
+++ b/.werks/6037
@@ -0,0 +1,13 @@
+Title: Fixed broken "Primary IP address family" rule set
+Level: 1
+Component: core
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1524817782
+
+When using the rule set "Primary IP address family" to change the
+IP address family of dual stack hosts to IPv6, this rule was not
+effective.
diff --git a/cmk_base/config.py b/cmk_base/config.py
index e964cdb..5b297c4 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -666,7 +666,14 @@ def is_ipv6_primary(hostname):
primarily via IPv6."""
dual_stack_host = is_ipv4v6_host(hostname)
return (not dual_stack_host and is_ipv6_host(hostname)) \
- or (dual_stack_host and rulesets.host_extra_conf(hostname,
primary_address_family) == "ipv6")
+ or (dual_stack_host and _primary_ip_address_family_of(hostname) ==
"ipv6")
+
+
+def _primary_ip_address_family_of(hostname):
+ rules = rulesets.host_extra_conf(hostname, primary_address_family)
+ if rules:
+ return rules[0]
+ return "ipv4"
def is_ipv4v6_host(hostname):
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index a0e0e23..6727434 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -1,6 +1,7 @@
import pytest
import cmk_base.config as config
+import cmk_base.rulesets as rulesets
@pytest.mark.parametrize("hostname,tags,result", [
("testhost", [], True),
@@ -24,3 +25,24 @@ def test_is_ipv4_host(monkeypatch, hostname, tags, result):
def test_is_no_ip_host(monkeypatch, hostname, tags, result):
monkeypatch.setattr(config, "tags_of_host", lambda h: {hostname: tags}[h])
assert config.is_no_ip_host(hostname) == result
+
+
+(a)pytest.mark.parametrize("hostname,tags,result,ruleset"eset", [
+ ("testhost", [], False, []),
+ ("testhost", ["ip-v4"], False,
+ [ ( 'ipv6', [], rulesets.ALL_HOSTS, {} ), ]),
+ ("testhost", ["ip-v4", "ip-v6"], False, []),
+ ("testhost", ["ip-v4", "ip-v6"], True,
+ [ ( 'ipv6', [], rulesets.ALL_HOSTS, {} ), ]),
+ ("testhost", ["ip-v6"], True, []),
+ ("testhost", ["ip-v6"], True,
+ [ ( 'ipv4', [], rulesets.ALL_HOSTS, {} ), ]),
+ ("testhost", ["ip-v6"], True,
+ [ ( 'ipv6', [], rulesets.ALL_HOSTS, {} ), ]),
+ ("testhost", ["no-ip"], False, []),
+])
+def test_is_ipv6_primary_host(monkeypatch, hostname, tags, result, ruleset):
+ monkeypatch.setattr(config, "all_hosts", ["%s|%s" % (hostname,
"|".join(tags))])
+ monkeypatch.setattr(config, "tags_of_host", lambda h: {hostname: tags}[h])
+ monkeypatch.setattr(config, "primary_address_family", ruleset)
+ assert config.is_ipv6_primary(hostname) == result