Module: check_mk
Branch: master
Commit: 874e0b9a6bee863d5d8edaf5b1723609909ad712
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=874e0b9a6bee86…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Thu Jun 7 08:55:21 2018 +0200
Fix dependencies of core-related modules, part 1.
We are doing two things wrong here:
First of all, we abuse modules as "normal" data structures, mixing up the
concepts of a class and its instances into a single concept (the module).
What we really want is a class definition and the explicit usage of its
instances.
This is already bad, but things get worse: In this pseudo-OO world, the
"superclass" knows its "subclasses", which violates two fundamental
design
principles:
* the Liskov substitution principle
(see
https://en.wikipedia.org/wiki/Liskov_substitution_principle)
* the open/closed principle
(see
https://en.wikipedia.org/wiki/Open/closed_principle)
In our concrete example, the more general core_config module knows about the
more concrete core_nagios and core_cmc modules. Apart from violating the
two principles above, this is the root cause of several import cycles.
As a first tiny step, this commit unified the interface for precompilation.
More to come...
Change-Id: I5f39b88afff07c29643b5cd3926874c7b2a8bc08
---
cmk_base/core_config.py | 7 +++----
cmk_base/core_nagios.py | 2 +-
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/cmk_base/core_config.py b/cmk_base/core_config.py
index 4d8d812..087a35a 100644
--- a/cmk_base/core_config.py
+++ b/cmk_base/core_config.py
@@ -284,11 +284,10 @@ def _verify_non_duplicate_hosts():
def precompile():
if config.monitoring_core == "cmc":
- import cmk_base.cee.core_cmc as core_cmc
- core_cmc.do_pack_config()
+ from cmk_base.cee.core_cmc import precompile_hook
else:
- import cmk_base.core_nagios as core_nagios
- core_nagios.do_precompile_hostchecks()
+ from cmk_base.core_nagios import precompile_hook
+ precompile_hook()
def do_update(with_precompile):
diff --git a/cmk_base/core_nagios.py b/cmk_base/core_nagios.py
index 414fab7..74f1321 100644
--- a/cmk_base/core_nagios.py
+++ b/cmk_base/core_nagios.py
@@ -865,7 +865,7 @@ def _extra_conf_of(confdict, hostname, service, exclude=None):
# '----------------------------------------------------------------------'
# TODO: Move to modes
-def do_precompile_hostchecks():
+def precompile_hook():
console.output("Precompiling host checks...")
precompile_hostchecks()
console.output(tty.ok + "\n")