Module: check_mk
Branch: master
Commit: c142ca48c45583709af706ac62c9697250b1f339
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c142ca48c45583…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Mar 3 10:47:20 2016 +0100
Fixed issue with modules not being loaded correctly in some situations
Seems that it is possible that the index module is re-initialized by
mod_python. This leads to a second call of index.initialize() which
will then reinitialize the multisite modules managed by "modules"
which could lead to no modules being registered.
---
web/htdocs/modules.py | 28 +++++++++++++++++++++++-----
web/htdocs/views.py | 1 +
2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/web/htdocs/modules.py b/web/htdocs/modules.py
index 572e492..1b8e064 100644
--- a/web/htdocs/modules.py
+++ b/web/htdocs/modules.py
@@ -24,6 +24,7 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+import os
from types import ModuleType
from lib import load_web_plugins, local_web_plugins_have_changed
from mod_python.apache import import_module
@@ -44,13 +45,26 @@ pagehandlers = {}
# initialize them.
modules = []
+
# Returns a list of names of all currently imported python modules
def imports():
for name, val in globals().items():
if isinstance(val, ModuleType):
- # val.__name__ would be better, but this is not available in mod_python
- name = val.__file__.split("/")[-1][:-3]
- yield name
+ yield get_module_name(val)
+
+
+def cleanup_already_imported_modules():
+ g = globals()
+ for module in modules:
+ try:
+ del g[get_module_name(module)]
+ except KeyError:
+ pass # not loaded, it's ok
+
+
+# module name can not be get from __name__ in mod_python. use the file path to detect
it.
+def get_module_name(module):
+ return os.path.splitext(os.path.basename(module.__file__))[0]
# Loads all modules needed into memory and performs global initializations for
@@ -58,8 +72,12 @@ def imports():
# If you need more time cosuming initializations, they should be done in
# the late_init_modules() function.
def init_modules():
- global modules ; modules = []
- global pagehandlers ; pagehandlers = {}
+ global modules, pagehandlers
+
+ cleanup_already_imported_modules()
+
+ modules = []
+ pagehandlers = {}
module_names_prev = set(imports())
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index d45df63..fe9b553 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -27,6 +27,7 @@
import config, defaults, time, os, re, pprint
import weblib, traceback, forms, valuespec, inventory, visuals, metrics
import sites
+import bi
from lib import *
# Datastructures and functions needed before plugins can be loaded