Module: check_mk
Branch: master
Commit: 2a52f8ccd66096e5af1d43885ee7708e89b0e2db
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2a52f8ccd66096…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Fri May 18 09:49:11 2018 +0200
Encapsulated lock/MongoDB in History object where they belong.
Note that we use a plain threading.Lock() now, ECLock doesn't really serve a
purpose and is even a bit harmful: Adding logging to locking may change the
threading behavior, serializing things more than usual when logging is on.
This gives a false sense of security...
Change-Id: I2c4b023ac6c27120452be0dcfce5f0a1c54990cb
---
cmk/ec/history.py | 7 ++++---
cmk/ec/main.py | 4 +---
tests/integration/cmk/ec/test_mkeventd_status.py | 16 +++-------------
3 files changed, 8 insertions(+), 19 deletions(-)
diff --git a/cmk/ec/history.py b/cmk/ec/history.py
index 43f3167..2630440 100644
--- a/cmk/ec/history.py
+++ b/cmk/ec/history.py
@@ -27,6 +27,7 @@
import os
import string
import subprocess
+import threading
import time
import cmk.ec.actions
@@ -36,13 +37,13 @@ import cmk.render
# TODO: As one can see clearly below, we should really have a class hierarchy here...
class History(object):
- def __init__(self, settings, config, logger, lock_history, mongodb):
+ def __init__(self, settings, config, logger):
super(History, self).__init__()
self._settings = settings
self._config = config
self._logger = logger
- self._lock_history = lock_history
- self._mongodb = mongodb
+ self._lock_history = threading.Lock()
+ self._mongodb = MongoDB()
reload_configuration(self, self._config)
diff --git a/cmk/ec/main.py b/cmk/ec/main.py
index 4ec3253..184a663 100644
--- a/cmk/ec/main.py
+++ b/cmk/ec/main.py
@@ -3948,9 +3948,7 @@ def main():
slave_status = default_slave_status_master()
config = load_configuration(settings, logger, slave_status)
- lock_history = ECLock(logger.getChild("lock.history"))
- mongodb = cmk.ec.history.MongoDB()
- history = cmk.ec.history.History(settings, config, logger, lock_history,
mongodb)
+ history = cmk.ec.history.History(settings, config, logger)
pid_path = settings.paths.pid_file.value
if pid_path.exists():
diff --git a/tests/integration/cmk/ec/test_mkeventd_status.py
b/tests/integration/cmk/ec/test_mkeventd_status.py
index 13e4cdc..f4944e0 100644
--- a/tests/integration/cmk/ec/test_mkeventd_status.py
+++ b/tests/integration/cmk/ec/test_mkeventd_status.py
@@ -58,28 +58,18 @@ def lock_configuration():
@pytest.fixture(scope="function")
-def lock_history():
- return cmk.ec.main.ECLock(logging.getLogger("cmk.mkeventd.history"))
-
-
-(a)pytest.fixture(scope="function")
def slave_status():
return cmk.ec.main.default_slave_status_master()
@pytest.fixture(scope="function")
-def mongodb():
- return cmk.ec.history.MongoDB()
-
-
-(a)pytest.fixture(scope="function")
-def config(settings, lock_history, mongodb, slave_status):
+def config(settings, slave_status):
return cmk.ec.main.load_configuration(settings,
logging.getLogger("cmk.mkeventd"), slave_status)
@pytest.fixture(scope="function")
-def history(settings, lock_history, mongodb, slave_status):
- return cmk.ec.history.History(settings, conf,
logging.getLogger("cmk.mkeventd"), lock_history, mongodb)
+def history(settings, config):
+ return cmk.ec.history.History(settings, config,
logging.getLogger("cmk.mkeventd"))
@pytest.fixture(scope="function")