Module: check_mk
Branch: master
Commit: 224b0b07788d5219cd732749ef53f998f31e60e8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=224b0b07788d52…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Mar 6 10:43:29 2019 +0100
Livestatus integration tests: Reduce number of needed core changes (~90s to ~60s)
Change-Id: I4fadbf98a5bc7c9874dedde16c84022703f8c92e
---
tests/integration/livestatus/test_livestatus.py | 79 ++++++++++++-------------
1 file changed, 37 insertions(+), 42 deletions(-)
diff --git a/tests/integration/livestatus/test_livestatus.py
b/tests/integration/livestatus/test_livestatus.py
index 78c8993..844534c 100644
--- a/tests/integration/livestatus/test_livestatus.py
+++ b/tests/integration/livestatus/test_livestatus.py
@@ -1,27 +1,31 @@
#!/usr/bin/env python
# encoding: utf-8
+# pylint: disable=redefined-outer-name
+import collections
import pytest
-import itertools
-from testlib import web, create_linux_test_host
+from testlib import web, create_linux_test_host # pylint: disable=unused-import
+DefaultConfig = collections.namedtuple("DefaultConfig", ["core"])
-(a)pytest.fixture(scope="module")
+
+(a)pytest.fixture(scope="module"dule", params=["nagios", "cmc"])
def default_cfg(request, site, web):
- print "Applying default config"
+ config = DefaultConfig(core=request.param)
+ site.set_config("CORE", config.core, with_restart=True)
+
+ print "Applying default config (%s)" % config.core
create_linux_test_host(request, web, site, "livestatus-test-host")
create_linux_test_host(request, web, site, "livestatus-test-host.domain")
web.discover_services("livestatus-test-host")
web.activate_changes()
+ return config
# 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"])
-def test_tables(default_cfg, site, core):
- site.set_config("CORE", core, with_restart=True)
-
+def test_tables(default_cfg, site):
existing_tables = set([])
for row in site.live.query_table_assoc("GET columns\n"):
@@ -30,55 +34,46 @@ def test_tables(default_cfg, site, core):
assert len(existing_tables) > 5
for table in existing_tables:
- if core == "nagios" and table == "statehist":
+ if default_cfg.core == "nagios" and table == "statehist":
continue # the statehist table in nagios can not be fetched without time
filter
result = site.live.query("GET %s\n" % table)
assert isinstance(result, list)
-(a)pytest.mark.parametrize(("core")ore"), ["nagios", "cmc"])
-def test_host_table(default_cfg, site, core):
- site.set_config("CORE", core, with_restart=True)
-
+def test_host_table(default_cfg, site):
rows = site.live.query("GET hosts")
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)
-
+host_equal_queries = {
+ "nagios": {
+ "query": ("GET hosts\n"
+ "Columns: host_name\n"
+ "Filter: host_name = livestatus-test-host.domain\n"),
+ "result": [{
+ u'name': u'livestatus-test-host.domain',
+ },],
+ },
+ "cmc": {
+ "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):
+ query_and_result = host_equal_queries[default_cfg.core]
rows = site.live.query_table_assoc(query_and_result["query"])
assert rows == query_and_result["result"]
-(a)pytest.mark.parametrize(("core")ore"), ["nagios", "cmc"])
-def test_service_table(default_cfg, site, core):
- site.set_config("CORE", core, with_restart=True)
-
+def test_service_table(default_cfg, site):
rows = site.live.query("GET services\nFilter: host_name =
livestatus-test-host\n"
"Columns: description\n")
assert isinstance(rows, list)