Module: check_mk
Branch: master
Commit: c6ae82b46f8bf34f45fa3416fa922ec9c7571eae
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c6ae82b46f8bf3…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Nov 23 08:51:20 2017 +0100
Added some more tests for modes; Cleaned up some rule tests
Change-Id: I7fb9c65371a690e24d96a7f6ccbebcff66ba3851
---
tests/cmk_base/test_modes.py | 56 ++++++++++++++++++++++++++++++++++++++---
tests/cmk_base/test_rulesets.py | 23 ++++++++---------
2 files changed, 63 insertions(+), 16 deletions(-)
diff --git a/tests/cmk_base/test_modes.py b/tests/cmk_base/test_modes.py
index 3bb231b..2425fc1 100644
--- a/tests/cmk_base/test_modes.py
+++ b/tests/cmk_base/test_modes.py
@@ -366,6 +366,8 @@ def test_restore(request, test_cfg, site):
# '----------------------------------------------------------------------'
# TODO
+# TODO: --cleanup-piggyback
+
#.
# .--scan-parents--------------------------------------------------------.
@@ -663,7 +665,31 @@ def test_check_discovery(test_cfg, site):
# | \___|_| |_|\___|\___|_|\_\ |
# | |
# '----------------------------------------------------------------------'
-# TODO
+
+def test_check(test_cfg, site):
+ for opt in [ "--check", "" ]:
+ p = site.execute(["cmk", opt, "modes-test-host"],
stdout=subprocess.PIPE)
+ assert p.wait() == 0
+ output = p.stdout.read()
+ assert output.startswith("OK - Agent version")
+
+
+def test_check_verbose_perfdata(test_cfg, site):
+ p = site.execute(["cmk", "-v", "-p",
"modes-test-host"], stdout=subprocess.PIPE)
+ assert p.wait() == 0
+ output = p.stdout.read()
+ assert "Temperature Zone 0" in output
+ assert "temp=32.4;" in output
+ assert "OK - Agent version" in output
+
+
+def test_check_verbose_only_check(test_cfg, site):
+ p = site.execute(["cmk", "-v", "--checks=lnx_if",
"modes-test-host"], stdout=subprocess.PIPE)
+ assert p.wait() == 0
+ output = p.stdout.read()
+ assert "Temperature Zone 0" not in output
+ assert "Interface 2" in output
+ assert "OK - Agent version" in output
#.
# .--version-------------------------------------------------------------.
@@ -674,7 +700,15 @@ def test_check_discovery(test_cfg, site):
# | \_/ \___|_| |___/_|\___/|_| |_| |
# | |
# '----------------------------------------------------------------------'
-# TODO
+
+def test_version(test_cfg, site):
+ import cmk
+ p = site.execute(["cmk", "--version"],
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ stdout, stderr = p.communicate()
+ assert p.wait() == 0
+ assert stderr == ""
+ assert "This is Check_MK" in stdout
#.
# .--help----------------------------------------------------------------.
@@ -685,5 +719,21 @@ def test_check_discovery(test_cfg, site):
# | |_| |_|\___|_| .__/ |
# | |_| |
# '----------------------------------------------------------------------'
-# TODO
+def test_help(test_cfg, site):
+ p = site.execute(["cmk", "--help"],
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ stdout, stderr = p.communicate()
+ assert p.wait() == 0
+ assert stderr == ""
+ assert stdout.startswith("WAYS TO CALL:")
+ assert "--snmpwalk" in stdout
+
+
+def test_help_without_args(test_cfg, site):
+ p = site.execute(["cmk"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ stdout, stderr = p.communicate()
+ assert p.wait() == 0
+ assert stderr == ""
+ assert stdout.startswith("WAYS TO CALL:")
+ assert "--snmpwalk" in stdout
diff --git a/tests/cmk_base/test_rulesets.py b/tests/cmk_base/test_rulesets.py
index 4806d3e..ec0d9cd 100644
--- a/tests/cmk_base/test_rulesets.py
+++ b/tests/cmk_base/test_rulesets.py
@@ -10,6 +10,7 @@ def fake_version(monkeypatch):
monkeypatch.setattr(cmk, "omd_version", lambda: "1.4.0i1.cee")
+# Automatically refresh caches for each test
@pytest.fixture(autouse=True, scope="function")
def clear_config_caches(monkeypatch):
import cmk_base
@@ -19,12 +20,12 @@ def clear_config_caches(monkeypatch):
# TODO: Test the negations
-def test_service_extra_conf():
- # TODO: monkeypatch this!
+def test_service_extra_conf(monkeypatch):
import cmk_base.config as config
- config.all_hosts = ["host1|tag1|tag2", "host2|tag1"]
- config.clusters = {}
+ monkeypatch.setattr(config, "all_hosts", ["host1|tag1|tag2",
"host2|tag1"])
+ monkeypatch.setattr(config, "clusters", {})
config.collect_hosttags()
+
ruleset = [
("1", [], rulesets.ALL_HOSTS, rulesets.ALL_SERVICES, {}),
("2", [], rulesets.ALL_HOSTS, rulesets.ALL_SERVICES, {}),
@@ -59,17 +60,13 @@ def test_service_extra_conf():
# TODO: host_extra_conf_merged
-def test_all_matching_hosts():
- # TODO: monkeypatch this!
- import cmk_base
- #reload(cmk_base)
-
+def test_all_matching_hosts(monkeypatch):
import cmk_base.config as config
- #reload(config)
- config.distributed_wato_site = "site1"
- config.all_hosts = ["host1|tag1|tag2", "host2|tag1",
"host3|tag1|site:site2"]
- config.clusters = {}
+ monkeypatch.setattr(config, "distributed_wato_site", "site1")
+ monkeypatch.setattr(config, "all_hosts",
+ ["host1|tag1|tag2", "host2|tag1",
"host3|tag1|site:site2"])
+ monkeypatch.setattr(config, "clusters", {})
config.collect_hosttags()
assert rulesets.all_matching_hosts(["tag1"], rulesets.ALL_HOSTS,
with_foreign_hosts=False) == \