Module: check_mk
Branch: master
Commit: 6bf830c9d5dd0e1a4db8667dba1c8c72c4062f59
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6bf830c9d5dd0e…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Sat May 4 20:28:08 2019 +0200
Cleanup GUI config file loading a bit
* Cleaned up loading code a bit
* multisite.mk is now optional
Change-Id: I4ade430545f48a0337588221aea0f5e9d9f2ca31
---
cmk/gui/config.py | 22 ++++++++++------------
tests/unit/cmk/gui/conftest.py | 6 ------
2 files changed, 10 insertions(+), 18 deletions(-)
diff --git a/cmk/gui/config.py b/cmk/gui/config.py
index d8f2be5..5c06cb3 100644
--- a/cmk/gui/config.py
+++ b/cmk/gui/config.py
@@ -153,18 +153,16 @@ def initialize():
cmk.gui.i18n.set_user_localizations(user_localizations)
-# Read in a multisite.d/*.mk file
-def include(filename):
- if not filename.startswith("/"):
- filename = cmk.utils.paths.default_config_dir + "/" + filename
-
- # Config file is obligatory. An empty example is installed
- # during setup.sh. Better signal an error then simply ignore
- # Absence.
+def _load_config_file(path):
+ # type: (str) -> None
+ """Load the given GUI configuration file"""
try:
- execfile(filename, globals(), globals())
+ execfile(path, globals(), globals())
+ except IOError as e:
+ if e.errno != errno.ENOENT: # No such file or directory
+ raise
except Exception as e:
- raise MKConfigError(_("Cannot read configuration file %s: %s:") %
(filename, e))
+ raise MKConfigError(_("Cannot read configuration file %s: %s:") %
(path, e))
# Load multisite.mk and all files in multisite.d/. This will happen
@@ -184,7 +182,7 @@ def load_config():
sites = default_single_site_configuration()
# First load main file
- include("multisite.mk")
+ _load_config_file(cmk.utils.paths.default_config_dir + "/multisite.mk")
# Load also recursively all files below multisite.d
conf_dir = cmk.utils.paths.default_config_dir + "/multisite.d"
@@ -197,7 +195,7 @@ def load_config():
filelist.sort()
for p in filelist:
- include(p)
+ _load_config_file(p)
if sites:
sites = migrate_old_site_config(sites)
diff --git a/tests/unit/cmk/gui/conftest.py b/tests/unit/cmk/gui/conftest.py
index 2fa1b29..6ec0d94 100644
--- a/tests/unit/cmk/gui/conftest.py
+++ b/tests/unit/cmk/gui/conftest.py
@@ -34,14 +34,8 @@ def register_builtin_html():
@pytest.fixture()
def load_config(register_builtin_html):
old_root_log_level = cmk.utils.log.logger.getEffectiveLevel()
-
- multisite_mk = Path(cmk.utils.paths.default_config_dir) / "multisite.mk"
- multisite_mk.parent.mkdir(parents=True, exist_ok=True) # pylint: disable=no-member
- multisite_mk.touch() # pylint: disable=no-member
config.initialize()
-
yield
-
cmk.utils.log.logger.setLevel(old_root_log_level)