Module: check_mk
Branch: master
Commit: c1ba7533dc4559c8107e54a724e5c44f86a2c8fc
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c1ba7533dc4559…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Tue Dec 4 09:39:57 2018 +0100
Fixed unknown check plugin handling while filtering management board checks
Change-Id: I953a2c72e4f457fe078a91c6450e79ccd765419f
---
cmk_base/config.py | 8 ++++++++
tests/unit/cmk_base/test_checks.py | 27 +++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 931dae1..5ddaac4 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -2935,6 +2935,14 @@ def _get_categorized_check_plugins(check_plugin_names,
for_inventory=False):
host_only_tcp = set()
for check_plugin_name in check_plugin_names:
+ if check_plugin_name not in plugins_info:
+ msg = "Unknown plugin file %s" % check_plugin_name
+ if cmk.debug.enabled():
+ raise MKGeneralException(msg)
+ else:
+ console.verbose("%s\n" % msg)
+ continue
+
is_snmp_check_ = is_snmp_check_f(check_plugin_name)
mgmt_board = _get_management_board_precedence(check_plugin_name, plugins_info)
if mgmt_board == check_api_utils.HOST_PRECEDENCE:
diff --git a/tests/unit/cmk_base/test_checks.py b/tests/unit/cmk_base/test_checks.py
index 0673514..9c764cf 100644
--- a/tests/unit/cmk_base/test_checks.py
+++ b/tests/unit/cmk_base/test_checks.py
@@ -76,6 +76,24 @@ def _check_plugins():
"snmp_check_host_only" : "host_only",
}
+############ Unknown check plugins
+
+(a)pytest.mark.parametrize("for_discovery,result"sult", [
+ (False, []),
+ (True, []),
+])
+def test_filter_by_management_board_unknown_check_plugins(monkeypatch, for_discovery,
result):
+ monkeypatch.setattr(config, "is_snmp_host", lambda _: False)
+ monkeypatch.setattr(config, "is_tcp_host", lambda _: True)
+ monkeypatch.setattr(config, "has_management_board", lambda _: False)
+ monkeypatch.setattr(config, "_get_management_board_precedence", lambda c,
_: _check_plugins()[c])
+ monkeypatch.setattr(cmk_base.check_utils, "is_snmp_check", lambda c:
c.startswith("snmp_"))
+ found_check_plugins = [c for c in _check_plugins()]
+ monkeypatch.setattr(config, "check_info", [])
+
+ assert config.filter_by_management_board("this_host", found_check_plugins,
+ False, for_discovery=for_discovery) ==
set(result)
+
############ TCP host
@pytest.mark.parametrize("for_discovery,result", [
@@ -89,6 +107,7 @@ def
test_filter_by_management_board_TCP_host_without_mgmt_board(monkeypatch, for
monkeypatch.setattr(config, "_get_management_board_precedence", lambda c,
_: _check_plugins()[c])
monkeypatch.setattr(cmk_base.check_utils, "is_snmp_check", lambda c:
c.startswith("snmp_"))
found_check_plugins = [c for c in _check_plugins() if
c.startswith("tcp_")]
+ monkeypatch.setattr(config, "check_info", found_check_plugins)
assert config.filter_by_management_board("this_host", found_check_plugins,
False, for_discovery=for_discovery) ==
set(result)
@@ -106,6 +125,7 @@ def
test_filter_by_management_board_SNMP_host_without_mgmt_board(monkeypatch, fo
monkeypatch.setattr(config, "_get_management_board_precedence", lambda c,
_: _check_plugins()[c])
monkeypatch.setattr(cmk_base.check_utils, "is_snmp_check", lambda c:
c.startswith("snmp_"))
found_check_plugins = [c for c in _check_plugins() if
c.startswith("snmp_")]
+ monkeypatch.setattr(config, "check_info", found_check_plugins)
assert config.filter_by_management_board("this_host", found_check_plugins,
False, for_discovery=for_discovery) ==
set(result)
@@ -125,6 +145,7 @@ def
test_filter_by_management_board_dual_host_without_mgmt_board(monkeypatch, fo
monkeypatch.setattr(config, "_get_management_board_precedence", lambda c,
_: _check_plugins()[c])
monkeypatch.setattr(cmk_base.check_utils, "is_snmp_check", lambda c:
c.startswith("snmp_"))
found_check_plugins = [c for c in _check_plugins()]
+ monkeypatch.setattr(config, "check_info", found_check_plugins)
assert config.filter_by_management_board("this_host", found_check_plugins,
False, for_discovery=for_discovery) ==
set(result)
@@ -147,11 +168,13 @@ def
test_filter_by_management_board_TCP_host_with_SNMP_mgmt_board(monkeypatch,
monkeypatch.setattr(config, "_get_management_board_precedence", lambda c,
_: _check_plugins()[c])
monkeypatch.setattr(cmk_base.check_utils, "is_snmp_check", lambda c:
c.startswith("snmp_"))
found_check_plugins = [c for c in _check_plugins() if
c.startswith("tcp_")]
+ monkeypatch.setattr(config, "check_info", found_check_plugins)
assert config.filter_by_management_board("this_host", found_check_plugins,
False, for_discovery=for_discovery) ==
set(host_result)
found_check_plugins = [c for c in _check_plugins() if
c.startswith("snmp_")]
+ monkeypatch.setattr(config, "check_info", found_check_plugins)
assert config.filter_by_management_board("this_host", found_check_plugins,
True, for_discovery=for_discovery) ==
set(mgmt_board_result)
@@ -174,11 +197,13 @@ def
test_filter_by_management_board_SNMP_host_with_SNMP_mgmt_board(monkeypatch,
monkeypatch.setattr(config, "_get_management_board_precedence", lambda c,
_: _check_plugins()[c])
monkeypatch.setattr(cmk_base.check_utils, "is_snmp_check", lambda c:
c.startswith("snmp_"))
found_check_plugins = [c for c in _check_plugins() if
c.startswith("snmp_")]
+ monkeypatch.setattr(config, "check_info", found_check_plugins)
assert config.filter_by_management_board("this_host", found_check_plugins,
False, for_discovery=for_discovery) ==
set(host_result)
found_check_plugins = [c for c in _check_plugins() if
c.startswith("snmp_")]
+ monkeypatch.setattr(config, "check_info", found_check_plugins)
assert config.filter_by_management_board("this_host", found_check_plugins,
True, for_discovery=for_discovery) ==
set(mgmt_board_result)
@@ -203,11 +228,13 @@ def
test_filter_by_management_board_dual_host_with_SNMP_mgmt_board(monkeypatch,
monkeypatch.setattr(config, "_get_management_board_precedence", lambda c,
_: _check_plugins()[c])
monkeypatch.setattr(cmk_base.check_utils, "is_snmp_check", lambda c:
c.startswith("snmp_"))
found_check_plugins = [c for c in _check_plugins()]
+ monkeypatch.setattr(config, "check_info", found_check_plugins)
assert config.filter_by_management_board("this_host", found_check_plugins,
False, for_discovery=for_discovery) ==
set(host_result)
found_check_plugins = [c for c in _check_plugins() if
c.startswith("snmp_")]
+ monkeypatch.setattr(config, "check_info", found_check_plugins)
assert config.filter_by_management_board("this_host", found_check_plugins,
True, for_discovery=for_discovery) ==
set(mgmt_board_result)