Module: check_mk
Branch: master
Commit: eef087ccf9d24c591285063a2ce68beaa66ebac3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=eef087ccf9d24c…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Mar 1 20:58:05 2019 +0100
Tests: Wait for livestatus being ready after core restart
Change-Id: Ifdaa0020c1545cb62ea3323841c509efebb4c406
---
.../cmk_base/test_services_prediction.py | 3 +-
tests/testlib/__init__.py | 53 +++++++++++++---------
2 files changed, 34 insertions(+), 22 deletions(-)
diff --git a/tests/integration/cmk_base/test_services_prediction.py
b/tests/integration/cmk_base/test_services_prediction.py
index 0146868..126051a 100644
--- a/tests/integration/cmk_base/test_services_prediction.py
+++ b/tests/integration/cmk_base/test_services_prediction.py
@@ -27,7 +27,8 @@ def cfg_setup(request, web, site):
site.write_file(
"var/check_mk/rrd/test-prediction/CPU_load.info",
file("%s/tests/integration/cmk_base/test-files/CPU_load.info" %
repo_path()).read())
- site.omd("restart", "cmc")
+
+ site.restart_core()
create_linux_test_host(request, web, site, "test-prediction")
diff --git a/tests/testlib/__init__.py b/tests/testlib/__init__.py
index 633f318..b98d3d2 100644
--- a/tests/testlib/__init__.py
+++ b/tests/testlib/__init__.py
@@ -304,6 +304,37 @@ class Site(object):
live.set_timeout(2)
return live
+ def wait_for_core_reloaded(self, after):
+ # Activating changes can involve an asynchronous(!) monitoring
+ # core restart/reload, so e.g. querying a Livestatus table immediately
+ # might not reflect the changes yet. Ask the core for a successful reload.
+ def config_reloaded():
+ import livestatus
+ try:
+ new_t = self.live.query_value("GET status\nColumns:
program_start\n")
+ except livestatus.MKLivestatusException:
+ # Seems like the socket may vanish for a short time. Keep waiting in
case
+ # of livestatus (connection) issues...
+ return False
+
+ return new_t > after
+
+ reload_time, timeout = time.time(), 10
+ while not config_reloaded():
+ if time.time() > reload_time + timeout:
+ raise Exception("Config did not update within %d seconds" %
timeout)
+ time.sleep(0.2)
+
+ assert config_reloaded()
+
+ def restart_core(self):
+ # Remember the time for the core reload check and wait a second because the
program_start
+ # is reported as integer and wait_for_core_reloaded() compares with
">".
+ before_restart = time.time()
+ time.sleep(1)
+ self.omd("restart", "core")
+ self.wait_for_core_reloaded(before_restart)
+
def send_host_check_result(self, hostname, state, output, expected_state=None):
if expected_state is None:
expected_state = state
@@ -1632,27 +1663,7 @@ class CMKWebSession(WebSession):
"Failed to activate %s: %r" % (site_id, status)
assert status["_time_ended"] > time_started
- # Activating changes can involve an asynchronous(!) monitoring
- # core restart/reload, so e.g. querying a Livestatus table immediately
- # might not reflect the changes yet. Ask the core for a successful reload.
- def config_reloaded():
- import livestatus
- try:
- new_t = self.site.live.query_value("GET status\nColumns:
program_start\n")
- except livestatus.MKLivestatusException:
- # Seems like the socket may vanish for a short time. Keep waiting in
case
- # of livestatus (connection) issues...
- return False
-
- return new_t > old_t
-
- reload_time, timeout = time.time(), 10
- while not config_reloaded():
- if time.time() > reload_time + timeout:
- raise Exception("Config did not update within %d seconds" %
timeout)
- time.sleep(0.2)
-
- assert config_reloaded()
+ self.site.wait_for_core_reloaded(old_t)
def get_regular_graph(self, hostname, service_description, graph_index,
expect_error=False):
result = self._api_request(