Module: check_mk
Branch: master
Commit: 01dc7b71b2a2658854b820e866b20a6e77a14b5a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=01dc7b71b2a265…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Oct 18 18:25:14 2018 +0200
Cleaned up analyze configuration registration
* Instead of __subclass__ magic it uses the standard plugin_registry
based approach.
We assume that no one has built his own ACTests, so we don't try
to be compatible to the old approach.
* Add a test for correctly registered tests.
Change-Id: I3094230ce743f87f1d95c5e8c0073e56d48d0591
---
cmk/gui/plugins/wato/__init__.py | 1 +
cmk/gui/plugins/wato/ac_tests.py | 37 ++++++++++++++++++++++++++--------
cmk/gui/plugins/wato/utils/__init__.py | 1 +
cmk/gui/watolib.py | 19 ++++++++++++-----
tests/unit/cmk/gui/test_watolib.py | 27 +++++++++++++++++++++++++
5 files changed, 72 insertions(+), 13 deletions(-)
diff --git a/cmk/gui/plugins/wato/__init__.py b/cmk/gui/plugins/wato/__init__.py
index f42521b..9c5a8f9 100644
--- a/cmk/gui/plugins/wato/__init__.py
+++ b/cmk/gui/plugins/wato/__init__.py
@@ -45,6 +45,7 @@ from cmk.gui.plugins.wato.utils import (
ACResultWARN,
ACTest,
ACTestCategories,
+ ac_test_registry,
add_change,
add_replication_paths,
changelog_button,
diff --git a/cmk/gui/plugins/wato/ac_tests.py b/cmk/gui/plugins/wato/ac_tests.py
index 3fb7d24..073656f 100644
--- a/cmk/gui/plugins/wato/ac_tests.py
+++ b/cmk/gui/plugins/wato/ac_tests.py
@@ -37,14 +37,17 @@ from cmk.gui.i18n import _
from cmk.gui.globals import html
from cmk.gui.exceptions import MKGeneralException
-from . import \
- ACTestCategories, \
- ACTest, \
- ACResultCRIT, \
- ACResultWARN, \
- ACResultOK, \
- ConfigDomainOMD
-
+from cmk.gui.plugins.wato import (
+ ACTestCategories,
+ ACTest,
+ ac_test_registry,
+ ACResultCRIT,
+ ACResultWARN,
+ ACResultOK,
+ ConfigDomainOMD,
+)
+
+(a)ac_test_registry.register
class ACTestPersistentConnections(ACTest):
def category(self):
return ACTestCategories.performance
@@ -93,6 +96,7 @@ class ACTestPersistentConnections(ACTest):
+(a)ac_test_registry.register
class ACTestLiveproxyd(ACTest):
def category(self):
return "performance"
@@ -127,6 +131,7 @@ class ACTestLiveproxyd(ACTest):
+(a)ac_test_registry.register
class ACTestLivestatusUsage(ACTest):
def category(self):
return ACTestCategories.performance
@@ -176,6 +181,7 @@ class ACTestLivestatusUsage(ACTest):
+(a)ac_test_registry.register
class ACTestTmpfs(ACTest):
def category(self):
return ACTestCategories.performance
@@ -223,6 +229,7 @@ class ACTestTmpfs(ACTest):
+(a)ac_test_registry.register
class ACTestLDAPSecured(ACTest):
def category(self):
return ACTestCategories.security
@@ -258,6 +265,7 @@ class ACTestLDAPSecured(ACTest):
+(a)ac_test_registry.register
class ACTestNumberOfUsers(ACTest):
def category(self):
return ACTestCategories.performance
@@ -292,6 +300,7 @@ class ACTestNumberOfUsers(ACTest):
+(a)ac_test_registry.register
class ACTestHTTPSecured(ACTest):
def category(self):
return ACTestCategories.security
@@ -321,6 +330,7 @@ class ACTestHTTPSecured(ACTest):
+(a)ac_test_registry.register
class ACTestOldDefaultCredentials(ACTest):
def category(self):
return ACTestCategories.security
@@ -353,6 +363,7 @@ class ACTestOldDefaultCredentials(ACTest):
+(a)ac_test_registry.register
class ACTestBackupConfigured(ACTest):
def category(self):
return ACTestCategories.reliability
@@ -387,6 +398,7 @@ class ACTestBackupConfigured(ACTest):
+(a)ac_test_registry.register
class ACTestBackupNotEncryptedConfigured(ACTest):
def category(self):
return ACTestCategories.security
@@ -452,6 +464,7 @@ class ACApacheTest(ACTest):
+(a)ac_test_registry.register
class ACTestApacheNumberOfProcesses(ACApacheTest):
def category(self):
return ACTestCategories.performance
@@ -536,6 +549,7 @@ class ACTestApacheNumberOfProcesses(ACApacheTest):
+(a)ac_test_registry.register
class ACTestApacheProcessUsage(ACApacheTest):
def category(self):
return ACTestCategories.performance
@@ -578,6 +592,7 @@ class ACTestApacheProcessUsage(ACApacheTest):
+(a)ac_test_registry.register
class ACTestCheckMKHelperUsage(ACTest):
def category(self):
return ACTestCategories.performance
@@ -640,6 +655,7 @@ class ACTestCheckMKHelperUsage(ACTest):
+(a)ac_test_registry.register
class ACTestAlertHandlerEventTypes(ACTest):
def category(self):
return ACTestCategories.performance
@@ -668,6 +684,7 @@ class ACTestAlertHandlerEventTypes(ACTest):
+(a)ac_test_registry.register
class ACTestGenericCheckHelperUsage(ACTest):
def category(self):
return ACTestCategories.performance
@@ -722,6 +739,7 @@ class ACTestGenericCheckHelperUsage(ACTest):
+(a)ac_test_registry.register
class ACTestSizeOfExtensions(ACTest):
def category(self):
return ACTestCategories.performance
@@ -769,6 +787,8 @@ class ACTestSizeOfExtensions(ACTest):
return int(subprocess.check_output(["du", "-sb",
"%s/local" % cmk.paths.omd_root]).split()[0])
+
+(a)ac_test_registry.register
class ACTestESXDatasources(ACTest):
def category(self):
return ACTestCategories.deprecations
@@ -806,6 +826,7 @@ class ACTestESXDatasources(ACTest):
yield ACResultOK(_("No configured rules are affected"))
+(a)ac_test_registry.register
class ACTestRulebasedNotifications(ACTest):
def category(self):
return ACTestCategories.deprecations
diff --git a/cmk/gui/plugins/wato/utils/__init__.py
b/cmk/gui/plugins/wato/utils/__init__.py
index ef8461a..2be1bbd 100644
--- a/cmk/gui/plugins/wato/utils/__init__.py
+++ b/cmk/gui/plugins/wato/utils/__init__.py
@@ -92,6 +92,7 @@ from cmk.gui.watolib import (
ValueSpecAttribute,
ACTestCategories,
ACTest,
+ ac_test_registry,
ACResultCRIT,
ACResultWARN,
ACResultOK,
diff --git a/cmk/gui/watolib.py b/cmk/gui/watolib.py
index 3ebf4b4..8aaa067 100644
--- a/cmk/gui/watolib.py
+++ b/cmk/gui/watolib.py
@@ -83,6 +83,7 @@ import cmk.gui.log as log
import cmk.gui.background_job as background_job
import cmk.gui.gui_background_job as gui_background_job
import cmk.gui.weblib as weblib
+import cmk.gui.plugin_registry
from cmk.gui.i18n import _u, _
from cmk.gui.globals import html
from cmk.gui.htmllib import HTML
@@ -10226,13 +10227,21 @@ class ACTest(object):
+class ACTestRegistry(cmk.gui.plugin_registry.ClassRegistry):
+ def plugin_base_class(self):
+ return ACTest
+
+
+ def _register(self, plugin_class):
+ self._entries[plugin_class.__name__] = plugin_class
+
+
+ac_test_registry = ACTestRegistry()
+
+
def check_analyze_config():
results = []
- # TODO: I'll clean up this plugin mechanism soon
- for test_cls in ACTest.__subclasses__(): # pylint: disable=no-member
- if test_cls.__subclasses__(): # pylint: disable=no-member
- continue # Only use leaf classes
-
+ for test_cls in ac_test_registry.values():
test = test_cls()
if not test.is_relevant():
diff --git a/tests/unit/cmk/gui/test_watolib.py b/tests/unit/cmk/gui/test_watolib.py
new file mode 100644
index 0000000..58f45d2
--- /dev/null
+++ b/tests/unit/cmk/gui/test_watolib.py
@@ -0,0 +1,27 @@
+
+import cmk.gui.watolib as watolib
+
+def test_registered_ac_tests():
+ registered_plugins = sorted(watolib.ac_test_registry.keys())
+ assert registered_plugins == [
+ 'ACTestAlertHandlerEventTypes',
+ 'ACTestApacheNumberOfProcesses',
+ 'ACTestApacheProcessUsage',
+ 'ACTestBackupConfigured',
+ 'ACTestBackupNotEncryptedConfigured',
+ 'ACTestCheckMKHelperUsage',
+ 'ACTestESXDatasources',
+ 'ACTestGenericCheckHelperUsage',
+ 'ACTestHTTPSecured',
+ 'ACTestLDAPSecured',
+ 'ACTestLiveproxyd',
+ 'ACTestLivestatusUsage',
+ 'ACTestNumberOfUsers',
+ 'ACTestOldDefaultCredentials',
+ 'ACTestPersistentConnections',
+ 'ACTestRulebasedNotifications',
+ 'ACTestSecureAgentUpdaterTransport',
+ 'ACTestSecureNotificationSpoolerMessages',
+ 'ACTestSizeOfExtensions',
+ 'ACTestTmpfs'
+ ]