Module: check_mk
Branch: master
Commit: 2486783c78cd55a516d02efa42964f09ac3f5cba
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2486783c78cd55…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Feb 20 11:30:52 2018 +0100
Add more management board tests
Change-Id: Ided35be1bc222e5078210af4f0f6ddcd7a4b3de5
---
tests/cmk_base/test_mgmt_board.py | 148 +++++++++++++++++++++++++++++---------
1 file changed, 114 insertions(+), 34 deletions(-)
diff --git a/tests/cmk_base/test_mgmt_board.py b/tests/cmk_base/test_mgmt_board.py
index 06fa2a3..ee43b27 100644
--- a/tests/cmk_base/test_mgmt_board.py
+++ b/tests/cmk_base/test_mgmt_board.py
@@ -5,62 +5,142 @@ from testlib import web
import cmk_base.config as config
-(a)pytest.fixture(scope="module")
-def test_cfg(web, site):
- print "Applying default config"
- web.add_host("mgmt-host1", attributes={
+(a)pytest.fixture(autouse=True)
+def test_cfg(web):
+ import cmk.debug
+ cmk.debug.enable()
+
+ yield
+
+ #
+ # Cleanup code
+ #
+ print "Cleaning up test config"
+
+ cmk.debug.disable()
+
+ if web.host_exists("mgmt-host"):
+ web.delete_host("mgmt-host")
+
+ if web.folder_exists("folder1"):
+ web.delete_folder("folder1")
+
+ web.activate_changes()
+
+ config.load()
+
+
+def test_mgmt_explicit_settings(web):
+ web.add_host("mgmt-host", attributes={
"ipaddress": "127.0.0.1",
"management_protocol": "snmp",
"management_snmp_community": "HOST",
})
- web.add_host("mgmt-host2", attributes={
+
+ config.load()
+ assert config.has_management_board("mgmt-host")
+ assert config.management_address_of("mgmt-host") == "127.0.0.1"
+ assert config.management_protocol_of("mgmt-host") == "snmp"
+ assert config.management_credentials_of("mgmt-host") == "HOST"
+
+
+def test_mgmt_explicit_address(web):
+ web.add_host("mgmt-host", attributes={
"ipaddress": "127.0.0.1",
"management_protocol": "snmp",
"management_address": "127.0.0.2",
})
- web.add_host("mgmt-host3", attributes={
+
+ config.load()
+ assert config.has_management_board("mgmt-host")
+ assert config.management_address_of("mgmt-host") == "127.0.0.2"
+ assert config.management_protocol_of("mgmt-host") == "snmp"
+ assert config.management_credentials_of("mgmt-host") == "public"
+
+
+def test_mgmt_disabled(web):
+ web.add_host("mgmt-host", attributes={
"ipaddress": "127.0.0.1",
"management_protocol": None,
"management_address": "127.0.0.1",
"management_snmp_community": "HOST",
})
- web.activate_changes()
+ config.load()
+ assert config.has_management_board("mgmt-host") == False
+ assert config.management_address_of("mgmt-host") == "127.0.0.1"
+ assert config.management_protocol_of("mgmt-host") == None
+ assert config.management_credentials_of("mgmt-host") == "HOST"
- import cmk.debug
- cmk.debug.enable()
- import cmk_base.checks as checks
- checks.load()
+def test_mgmt_inherit_credentials_explicit_host(web):
+ web.add_folder("folder1", attributes={
+ "management_snmp_community": "FOLDER",
+ })
+
+ web.add_host("mgmt-host", folder="folder1", attributes={
+ "ipaddress": "127.0.0.1",
+ "management_protocol": "snmp",
+ "management_snmp_community": "HOST",
+ })
+
config.load()
+ assert config.has_management_board("mgmt-host")
+ assert config.management_address_of("mgmt-host") == "127.0.0.1"
+ assert config.management_protocol_of("mgmt-host") == "snmp"
+ assert config.management_credentials_of("mgmt-host") == "HOST"
- yield None
- #
- # Cleanup code
- #
- print "Cleaning up test config"
- cmk.debug.disable()
+def test_mgmt_inherit_credentials(web):
+ web.add_folder("folder1", attributes={
+ "management_snmp_community": "FOLDER",
+ })
- web.delete_host("mgmt-host1")
- web.delete_host("mgmt-host2")
- web.delete_host("mgmt-host3")
- web.activate_changes()
+ web.add_host("mgmt-host", folder="folder1", attributes={
+ "ipaddress": "127.0.0.1",
+ "management_protocol": "snmp",
+ })
+ config.load()
+ assert config.has_management_board("mgmt-host")
+ assert config.management_address_of("mgmt-host") == "127.0.0.1"
+ assert config.management_protocol_of("mgmt-host") == "snmp"
+ assert config.management_credentials_of("mgmt-host") == "FOLDER"
-def test_management_board_configc(test_cfg):
- assert config.has_management_board("mgmt-host1")
- assert config.management_address_of("mgmt-host1") == "127.0.0.1"
- assert config.management_protocol_of("mgmt-host1") == "snmp"
- assert config.management_credentials_of("mgmt-host1") == "HOST"
- assert config.has_management_board("mgmt-host2")
- assert config.management_address_of("mgmt-host2") == "127.0.0.2"
- assert config.management_protocol_of("mgmt-host2") == "snmp"
- assert config.management_credentials_of("mgmt-host2") ==
"public"
+def test_mgmt_inherit_protocol_explicit_host(web):
+ web.add_folder("folder1", attributes={
+ "management_protocol": None,
+ "management_snmp_community": "FOLDER",
+ })
- assert config.has_management_board("mgmt-host3") == False
- assert config.management_address_of("mgmt-host3") == "127.0.0.1"
- assert config.management_protocol_of("mgmt-host3") == None
- assert config.management_credentials_of("mgmt-host3") == "HOST"
+ web.add_host("mgmt-host", folder="folder1", attributes={
+ "ipaddress": "127.0.0.1",
+ "management_protocol": "snmp",
+ "management_snmp_community": "HOST",
+ })
+
+ config.load()
+ assert config.has_management_board("mgmt-host")
+ assert config.management_address_of("mgmt-host") == "127.0.0.1"
+ assert config.management_protocol_of("mgmt-host") == "snmp"
+ assert config.management_credentials_of("mgmt-host") == "HOST"
+
+
+
+def test_mgmt_inherit_protocol(web):
+ web.add_folder("folder1", attributes={
+ "management_protocol": "snmp",
+ "management_snmp_community": "FOLDER",
+ })
+
+ web.add_host("mgmt-host", folder="folder1", attributes={
+ "ipaddress": "127.0.0.1",
+ })
+
+ config.load()
+ assert config.has_management_board("mgmt-host")
+ assert config.management_address_of("mgmt-host") == "127.0.0.1"
+ assert config.management_protocol_of("mgmt-host") == "snmp"
+ assert config.management_credentials_of("mgmt-host") == "FOLDER"