Module: check_mk
Branch: master
Commit: 1938e207d9b598b8188bfd119ba08f27628debf8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1938e207d9b598…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Nov 29 13:24:05 2018 +0100
Add integration test based regression test for CMK-1381
Change-Id: Ia7b3b9e2148f94a06db3b76856389b63a1d4b9fe
---
tests/integration/livestatus/test_livestatus.py | 64 ++++++++++++++++++++-----
1 file changed, 51 insertions(+), 13 deletions(-)
diff --git a/tests/integration/livestatus/test_livestatus.py
b/tests/integration/livestatus/test_livestatus.py
index 5526cb7..187532e 100644
--- a/tests/integration/livestatus/test_livestatus.py
+++ b/tests/integration/livestatus/test_livestatus.py
@@ -2,14 +2,22 @@
# encoding: utf-8
import pytest
+import itertools
+
from testlib import web
+
@pytest.fixture(scope="module")
def default_cfg(web):
print "Applying default config"
- web.add_host("livestatus-test-host", attributes={
- "ipaddress": "127.0.0.1",
- })
+ web.add_host(
+ "livestatus-test-host", attributes={
+ "ipaddress": "127.0.0.1",
+ })
+ web.add_host(
+ "livestatus-test-host.domain", attributes={
+ "ipaddress": "127.0.0.1",
+ })
web.discover_services("livestatus-test-host")
@@ -22,11 +30,12 @@ def default_cfg(web):
print "Cleaning up default config"
web.delete_host("livestatus-test-host")
+ web.delete_host("livestatus-test-host.domain")
# Simply detects all tables by querying the columns table and then
# queries each of those tables without any columns and filters
-(a)pytest.mark.parametrize(("core")ore"), [ "nagios", "cmc" ])
+(a)pytest.mark.parametrize(("core")ore"), ["nagios", "cmc"])
def test_tables(default_cfg, site, core):
site.set_config("CORE", core, with_restart=True)
@@ -39,31 +48,60 @@ def test_tables(default_cfg, site, core):
for table in existing_tables:
if core == "nagios" and table == "statehist":
- continue # the statehist table in nagios can not be fetched without time
filter
+ continue # the statehist table in nagios can not be fetched without time
filter
result = site.live.query("GET %s\n" % table)
- assert type(result) == list
+ assert isinstance(result, list)
-(a)pytest.mark.parametrize(("core")ore"), [ "nagios", "cmc" ])
+(a)pytest.mark.parametrize(("core")ore"), ["nagios", "cmc"])
def test_host_table(default_cfg, site, core):
site.set_config("CORE", core, with_restart=True)
rows = site.live.query("GET hosts")
- assert type(rows) == list
- assert len(rows) >= 2 # header + min 1 host
+ assert isinstance(rows, list)
+ assert len(rows) >= 2 # header + min 1 host
+
+
+(a)pytest.mark.parametrize("core,query_and_result"sult",
+ itertools.product([
+ "nagios",
+ "cmc",
+ ], [
+ {
+ "query": ("GET hosts\n"
+ "Columns: host_name\n"
+ "Filter: host_name =
livestatus-test-host.domain\n"),
+ "result": [{
+ u'name':
u'livestatus-test-host.domain',
+ },],
+ },
+ {
+ "query": ("GET hosts\n"
+ "Columns: host_name\n"
+ "Filter: host_name =
livestatus-test-host\n"),
+ "result": [{
+ u'name': u'livestatus-test-host',
+ },],
+ },
+ ]))
+def test_host_table_host_equal_filter(default_cfg, site, core, query_and_result):
+ site.set_config("CORE", core, with_restart=True)
+
+ rows = site.live.query_table_assoc(query_and_result["query"])
+ assert rows == query_and_result["result"]
-(a)pytest.mark.parametrize(("core")ore"), [ "nagios", "cmc" ])
+(a)pytest.mark.parametrize(("core")ore"), ["nagios", "cmc"])
def test_service_table(default_cfg, site, core):
site.set_config("CORE", core, with_restart=True)
rows = site.live.query("GET services\nFilter: host_name =
livestatus-test-host\n"
"Columns: description\n")
- assert type(rows) == list
- assert len(rows) >= 20 # header + min 1 service
+ assert isinstance(rows, list)
+ assert len(rows) >= 20 # header + min 1 service
- descriptions = [ r[0] for r in rows ]
+ descriptions = [r[0] for r in rows]
assert "Check_MK" in descriptions
assert "Check_MK Discovery" in descriptions