Module: check_mk
Branch: master
Commit: 25885b3bafe9de50645b77b0620ad74268949a1c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=25885b3bafe9de…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Apr 27 19:18:30 2018 +0200
6043 FIX Fixed HW/SW inventory marking discovered services as vanished
The service discovery (e.g. WATO service discovery page) could be
confused after the execution of the HW/SW inventory check.
When opening the service discovery page for a host with SNMP services,
the page could show still existing services as vanished.
CMK-504 #close Fixed
Change-Id: I16871254bb9bb13df094568baf0bd61cef8fa917
---
.werks/6043 | 15 +++++++++++
cmk_base/data_sources/abstract.py | 8 ++++--
tests/unit/cmk_base/test_data_sources_unit.py | 36 +++++++++++++++++++++++++++
3 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/.werks/6043 b/.werks/6043
new file mode 100644
index 0000000..a961cbe
--- /dev/null
+++ b/.werks/6043
@@ -0,0 +1,15 @@
+Title: Fixed HW/SW inventory marking discovered services as vanished
+Level: 1
+Component: core
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1524849172
+
+The service discovery (e.g. WATO service discovery page) could be
+confused after the execution of the HW/SW inventory check.
+
+When opening the service discovery page for a host with SNMP services,
+the page could show still existing services as vanished.
diff --git a/cmk_base/data_sources/abstract.py b/cmk_base/data_sources/abstract.py
index c3c1e3e..c1f39cb 100644
--- a/cmk_base/data_sources/abstract.py
+++ b/cmk_base/data_sources/abstract.py
@@ -226,7 +226,7 @@ class DataSource(object):
self._logger.debug("Not using cache (Does not exist)")
return
- if self._no_cache:
+ if self.is_agent_cache_disabled():
self._logger.debug("Not using cache (Cache usage disabled)")
return
@@ -252,6 +252,10 @@ class DataSource(object):
def _write_cache_file(self, raw_data):
+ if self.is_agent_cache_disabled():
+ self._logger.debug("Not writing data to cache file (Cache usage
disabled)")
+ return
+
cachefile = self._cache_file_path()
try:
@@ -265,7 +269,7 @@ class DataSource(object):
except Exception, e:
raise MKGeneralException("Cannot create directory %r: %s" %
(os.path.dirname(cachefile), e))
- self._logger.verbose("Write data to cache file %s" % (cachefile))
+ self._logger.debug("Write data to cache file %s" % (cachefile))
try:
store.save_file(cachefile, self._to_cache_file(raw_data))
except Exception, e:
diff --git a/tests/unit/cmk_base/test_data_sources_unit.py
b/tests/unit/cmk_base/test_data_sources_unit.py
new file mode 100644
index 0000000..65503ef
--- /dev/null
+++ b/tests/unit/cmk_base/test_data_sources_unit.py
@@ -0,0 +1,36 @@
+import pytest
+
+import cmk_base.data_sources.snmp
+
+def test_data_source_cache_default():
+ source = cmk_base.data_sources.snmp.SNMPDataSource("hostname",
"ipaddress")
+ assert not source.is_agent_cache_disabled()
+
+
+def test_disable_data_source_cache():
+ source = cmk_base.data_sources.snmp.SNMPDataSource("hostname",
"ipaddress")
+ assert not source.is_agent_cache_disabled()
+ source.disable_data_source_cache()
+ assert source.is_agent_cache_disabled()
+
+
+def test_disable_data_source_cache_no_read(mocker):
+ source = cmk_base.data_sources.snmp.SNMPDataSource("hostname",
"ipaddress")
+ source.set_max_cachefile_age(999)
+ source.disable_data_source_cache()
+
+ import os
+ mocker.patch.object(os.path, "exists", return_value=True)
+
+ disabled_checker = mocker.patch.object(source, "is_agent_cache_disabled")
+ assert source._read_cache_file() is None
+ disabled_checker.assert_called_once()
+
+
+def test_disable_data_source_cache_no_write(mocker):
+ source = cmk_base.data_sources.snmp.SNMPDataSource("hostname",
"ipaddress")
+ source.disable_data_source_cache()
+
+ disabled_checker = mocker.patch.object(source, "is_agent_cache_disabled")
+ assert source._write_cache_file("X") is None
+ disabled_checker.assert_called_once()