Module: check_mk
Branch: master
Commit: 11feb114602b7f2262a46e72d7cfdabf9f8d8c45
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=11feb114602b7f…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Sat May 4 21:27:02 2019 +0200
Fix negated host tag transformation
Change-Id: I455602f1d63df8c3a7cb0d971bfaedd2b1413a2c
---
cmk/utils/rulesets/tuple_rulesets.py | 2 +-
tests/unit/cmk/utils/rulesets/test_rule_matcher.py | 8 ++++++++
.../cmk/utils/rulesets/test_ruleset_transformer.py | 18 ++++++++++++++++++
3 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/cmk/utils/rulesets/tuple_rulesets.py b/cmk/utils/rulesets/tuple_rulesets.py
index 2da2cc1..710ae80 100644
--- a/cmk/utils/rulesets/tuple_rulesets.py
+++ b/cmk/utils/rulesets/tuple_rulesets.py
@@ -212,7 +212,7 @@ class RulesetToDictTransformer(object):
tag_group_id = self._tag_groups[tag_id]
- conditions["host_tags." + tag_group_id] = {"ne": tag_id}
if negate else tag_id
+ conditions["host_tags." + tag_group_id] = {"$ne": tag_id}
if negate else tag_id
return conditions
diff --git a/tests/unit/cmk/utils/rulesets/test_rule_matcher.py
b/tests/unit/cmk/utils/rulesets/test_rule_matcher.py
index 1f988ce..a687b0c 100644
--- a/tests/unit/cmk/utils/rulesets/test_rule_matcher.py
+++ b/tests/unit/cmk/utils/rulesets/test_rule_matcher.py
@@ -82,6 +82,14 @@ NESTED_FIELD_MATCHES = [
"$ne": "test"
}}, [HOST_PROD]),
Case({"tags.not_existing": "test"}, []),
+ Case({
+ "tags.not_existing": {
+ "$ne": "test"
+ },
+ "tags.not_existing2": {
+ "$ne": "test"
+ },
+ }, [HOST_PROD, HOST_TEST]),
]
COMPARISON_MATCHES = [
diff --git a/tests/unit/cmk/utils/rulesets/test_ruleset_transformer.py
b/tests/unit/cmk/utils/rulesets/test_ruleset_transformer.py
index 3723d2d..739e652 100644
--- a/tests/unit/cmk/utils/rulesets/test_ruleset_transformer.py
+++ b/tests/unit/cmk/utils/rulesets/test_ruleset_transformer.py
@@ -270,6 +270,23 @@ BINARY_HOST_RULESET = [
},
},
),
+ Case(
+ ident="not_equal_tag_match",
+ is_service=False,
+ is_binary=True,
+ old=(['!TAG1', '!TAG2'], tuple_rulesets.ALL_HOSTS),
+ new={
+ "value": True,
+ "condition": {
+ 'host_tags.TG1': {
+ '$ne': 'TAG1'
+ },
+ 'host_tags.TG2': {
+ '$ne': 'TAG2'
+ },
+ },
+ },
+ ),
]
NON_BINARY_SERVICE_RULESET = [
@@ -441,6 +458,7 @@ BINARY_SERVICE_RULESET = [
TAG_TO_GROUP_MAP = {
"TAG1": "TG1",
+ "TAG2": "TG2",
"tag": "tg_group1",
"specs": "tg_group2",
}