Module: check_mk
Branch: master
Commit: 7adeaeb905ebfb83cb929d49de3fc6576d0fb351
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7adeaeb905ebfb…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Mar 11 08:02:18 2019 +0100
Fixed etc directory being created during unit tests
* Cleaned up wato_root_dir evalutation from module scope
* Mock check_mk_config_dir during unit tests
Change-Id: Ib2cc9985f76a80068feb220147faa4015a92d54b
---
cmk/gui/watolib/__init__.py | 8 ++++----
cmk/gui/watolib/activate_changes.py | 2 +-
cmk/gui/watolib/config_domains.py | 2 +-
cmk/gui/watolib/hosts_and_folders.py | 4 ++--
cmk/gui/watolib/notifications.py | 6 +++---
cmk/gui/watolib/password_store.py | 2 +-
cmk/gui/watolib/timeperiods.py | 6 +++---
cmk/gui/watolib/utils.py | 6 +++++-
tests/conftest.py | 2 ++
9 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/cmk/gui/watolib/__init__.py b/cmk/gui/watolib/__init__.py
index 347b2ab..61dae95 100644
--- a/cmk/gui/watolib/__init__.py
+++ b/cmk/gui/watolib/__init__.py
@@ -337,10 +337,10 @@ def init_wato_datastructures(with_wato_lock=False):
def _need_to_create_sample_config():
if os.path.exists(multisite_dir + "hosttags.mk") \
- or os.path.exists(wato_root_dir + "rules.mk") \
- or os.path.exists(wato_root_dir + "groups.mk") \
- or os.path.exists(wato_root_dir + "notifications.mk") \
- or os.path.exists(wato_root_dir + "global.mk"):
+ or os.path.exists(wato_root_dir() + "rules.mk") \
+ or os.path.exists(wato_root_dir() + "groups.mk") \
+ or os.path.exists(wato_root_dir() + "notifications.mk") \
+ or os.path.exists(wato_root_dir() + "global.mk"):
return False
return True
diff --git a/cmk/gui/watolib/activate_changes.py b/cmk/gui/watolib/activate_changes.py
index e00926e..5b5e775 100644
--- a/cmk/gui/watolib/activate_changes.py
+++ b/cmk/gui/watolib/activate_changes.py
@@ -96,7 +96,7 @@ def add_replication_paths(paths):
def get_replication_paths():
paths = [
- ("dir", "check_mk", cmk.gui.watolib.utils.wato_root_dir,
["sitespecific.mk"]),
+ ("dir", "check_mk", cmk.gui.watolib.utils.wato_root_dir(),
["sitespecific.mk"]),
("dir", "multisite", cmk.gui.watolib.utils.multisite_dir,
["sitespecific.mk"]),
("file", "htpasswd", cmk.utils.paths.htpasswd_file),
("file", "auth.secret", '%s/auth.secret' %
os.path.dirname(cmk.utils.paths.htpasswd_file)),
diff --git a/cmk/gui/watolib/config_domains.py b/cmk/gui/watolib/config_domains.py
index fb4195e..afb6d59 100644
--- a/cmk/gui/watolib/config_domains.py
+++ b/cmk/gui/watolib/config_domains.py
@@ -60,7 +60,7 @@ class ConfigDomainCore(ConfigDomain):
ident = "check_mk"
def config_dir(self):
- return wato_root_dir
+ return wato_root_dir()
def activate(self):
# TODO: Cleanup
diff --git a/cmk/gui/watolib/hosts_and_folders.py b/cmk/gui/watolib/hosts_and_folders.py
index 0dad5cf..be392f7 100644
--- a/cmk/gui/watolib/hosts_and_folders.py
+++ b/cmk/gui/watolib/hosts_and_folders.py
@@ -367,7 +367,7 @@ class CREFolder(BaseFolder):
@staticmethod
def folder_exists(folder_path):
- return os.path.exists(wato_root_dir + folder_path)
+ return os.path.exists(wato_root_dir() + folder_path)
@staticmethod
def root_folder():
@@ -445,7 +445,7 @@ class CREFolder(BaseFolder):
if self._root_dir:
self._root_dir = root_dir.rstrip("/") + "/" # FIXME:
ugly
else:
- self._root_dir = wato_root_dir
+ self._root_dir = wato_root_dir()
if folder_path is not None:
self._init_by_loading_existing_directory(folder_path)
diff --git a/cmk/gui/watolib/notifications.py b/cmk/gui/watolib/notifications.py
index b0e840c..6b80bd8 100644
--- a/cmk/gui/watolib/notifications.py
+++ b/cmk/gui/watolib/notifications.py
@@ -32,7 +32,7 @@ from cmk.gui.watolib.utils import wato_root_dir
def load_notification_rules(lock=False):
- filename = wato_root_dir + "notifications.mk"
+ filename = wato_root_dir() + "notifications.mk"
notification_rules = store.load_from_mk_file(filename,
"notification_rules", [], lock=lock)
# Convert to new plugin configuration format
@@ -47,9 +47,9 @@ def load_notification_rules(lock=False):
def save_notification_rules(rules):
- store.mkdir(wato_root_dir)
+ store.mkdir(wato_root_dir())
store.save_to_mk_file(
- wato_root_dir + "notifications.mk",
+ wato_root_dir() + "notifications.mk",
"notification_rules",
rules,
pprint_value=config.wato_pprint_config)
diff --git a/cmk/gui/watolib/password_store.py b/cmk/gui/watolib/password_store.py
index 7468320..08017fe 100644
--- a/cmk/gui/watolib/password_store.py
+++ b/cmk/gui/watolib/password_store.py
@@ -35,7 +35,7 @@ from cmk.gui.watolib.utils import wato_root_dir
class PasswordStore(WatoSimpleConfigFile):
def __init__(self):
super(PasswordStore, self).__init__(
- config_file_path=Path(wato_root_dir) / "passwords.mk",
+ config_file_path=Path(wato_root_dir()) / "passwords.mk",
config_variable="stored_passwords")
def filter_usable_entries(self, entries):
diff --git a/cmk/gui/watolib/timeperiods.py b/cmk/gui/watolib/timeperiods.py
index 3b54d49..4d0407a 100644
--- a/cmk/gui/watolib/timeperiods.py
+++ b/cmk/gui/watolib/timeperiods.py
@@ -48,15 +48,15 @@ def builtin_timeperiods():
def load_timeperiods():
- timeperiods = store.load_from_mk_file(wato_root_dir + "timeperiods.mk",
"timeperiods", {})
+ timeperiods = store.load_from_mk_file(wato_root_dir() + "timeperiods.mk",
"timeperiods", {})
timeperiods.update(builtin_timeperiods())
return timeperiods
def save_timeperiods(timeperiods):
- store.mkdir(wato_root_dir)
+ store.mkdir(wato_root_dir())
store.save_to_mk_file(
- wato_root_dir + "timeperiods.mk",
+ wato_root_dir() + "timeperiods.mk",
"timeperiods",
_filter_builtin_timeperiods(timeperiods),
pprint_value=config.wato_pprint_config)
diff --git a/cmk/gui/watolib/utils.py b/cmk/gui/watolib/utils.py
index 568299c..48566bf 100644
--- a/cmk/gui/watolib/utils.py
+++ b/cmk/gui/watolib/utils.py
@@ -47,7 +47,11 @@ NEGATE = '@negate'
NO_ITEM = {} # Just an arbitrary unique thing
ENTRY_NEGATE_CHAR = "!"
-wato_root_dir = cmk.utils.paths.check_mk_config_dir + "/wato/"
+
+def wato_root_dir():
+ return cmk.utils.paths.check_mk_config_dir + "/wato/"
+
+
multisite_dir = cmk.utils.paths.default_config_dir + "/multisite.d/wato/"
# TODO: Move this to CEE specific code again
liveproxyd_config_dir = cmk.utils.paths.default_config_dir +
"/liveproxyd.d/wato/"
diff --git a/tests/conftest.py b/tests/conftest.py
index d8f47e5..5240b1c 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -120,6 +120,8 @@ def fake_version_and_paths():
os.path.join(tmp_dir,
"var/check_mk/precompiled_checks"))
monkeypatch.setattr("cmk.utils.paths.include_cache_dir",
os.path.join(tmp_dir, "check_mk/check_includes"))
+ monkeypatch.setattr("cmk.utils.paths.check_mk_config_dir",
+ os.path.join(tmp_dir, "etc/check_mk/conf.d"))
# Cleanup temporary directory created above