Module: check_mk
Branch: master
Commit: ffff545c9e9b1045d669107023b9c3fca0e8776b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ffff545c9e9b10…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Sep 27 07:19:16 2017 +0200
EC: Removed odd VerboseLock() and lock debugging
When we need that lock debugging again, we extend the regular
locking with logging functionality.
Change-Id: Id97c87a8a558a72beacf7c459beadb8acaaeab56
---
bin/mkeventd | 38 ++++++----------------------------
tests/mkeventd/test_mkeventd_status.py | 21 +++++++++++++++++++
2 files changed, 27 insertions(+), 32 deletions(-)
diff --git a/bin/mkeventd b/bin/mkeventd
index 05776d0..abcfcbe 100755
--- a/bin/mkeventd
+++ b/bin/mkeventd
@@ -75,7 +75,6 @@ logger = cmk.log.get_logger("mkeventd")
# Defaults for command line modifiable options (TODO: Encapsulate this somehow)
opt_verbose = 0
opt_debug = False
-opt_debug_locking = False
opt_foreground = False
opt_profile = {}
opt_syslog = False
@@ -405,24 +404,6 @@ def replace_groups(text, origtext, groups):
return text
-# Class for debugging locking. Beware: This does not really
-# implement a true locking! It's just for detecting deadlocks!
-class VerboseLock(object):
- def __init__(self, name):
- self._depth = 0
- self._name = name
- self.logger = logger.getChild("VerboseLock(%s)" % name)
-
- def __enter__(self):
- self._depth += 1
- self.logger.debug("%d -> %d" % (self._depth-1, self._depth))
- return self
-
- def __exit__(self, type, value, tb):
- self._depth -= 1
- self.logger.debug("%d -> %d" % (self._depth+1, self._depth))
-
-
class MKSignalException(Exception):
def __init__(self, signum):
Exception.__init__(self, "Got signal %d" % signum)
@@ -4810,12 +4791,17 @@ The following paths are used by the Event Console:
# | Main entry and option parsing |
# '----------------------------------------------------------------------'
+# Create locks for global data structures
+lock_eventstatus = thread.allocate_lock()
+lock_configuration = thread.allocate_lock()
+lock_logging = thread.allocate_lock()
+
if __name__ == "__main__":
os.unsetenv("LANG")
short_options = "hvVg"
long_options = [ "help", "version", "verbose",
"debug", "foreground",
- "profile-status", "profile-event",
"debug-locking",
+ "profile-status", "profile-event",
"syslog", "syslog-fd=", "syslog-tcp",
"syslog-tcp-fd=", "snmptrap", "snmptrap-fd=" ]
try:
@@ -4827,8 +4813,6 @@ if __name__ == "__main__":
opt_verbose += 1
elif o in [ '-d', '--debug' ]:
opt_debug = True
- elif o in [ '--debug-locking' ]:
- opt_debug_locking = True
elif o in [ '-g', '--foreground' ]:
opt_foreground = True
elif o == '--syslog':
@@ -4900,16 +4884,6 @@ if __name__ == "__main__":
make_parentdirs(g_logfile_path)
make_parentdirs(g_state_dir + "/state")
- # Create locks for global data structures
- if opt_debug_locking:
- lock_eventstatus = VerboseLock("eventstatus")
- lock_configuration = VerboseLock("configuration")
- lock_logging = VerboseLock("logging")
- else:
- lock_eventstatus = thread.allocate_lock()
- lock_configuration = thread.allocate_lock()
- lock_logging = thread.allocate_lock()
-
# First do all things that might fail, before daemonizing
g_perfcounters = Perfcounters()
g_event_status = EventStatus()
diff --git a/tests/mkeventd/test_mkeventd_status.py
b/tests/mkeventd/test_mkeventd_status.py
index 1be1766..1d0fff5 100644
--- a/tests/mkeventd/test_mkeventd_status.py
+++ b/tests/mkeventd/test_mkeventd_status.py
@@ -16,6 +16,27 @@ def test_mkeventd_unit():
assert mkeventd
+def test_handle_client(monkeypatch):
+ class FakeSocket(object):
+ def __init__(self, sock):
+ pass
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ return ["GET events"]
+
+ def close(self):
+ pass
+
+ monkeypatch.setattr(mkeventd, "Queries", FakeSocket)
+ monkeypatch.setattr(mkeventd.StatusServer, "open_sockets", lambda x: None)
+ status = mkeventd.StatusServer()
+
+ print status.handle_client(None, True, "127.0.0.1")
+
+
#
# INTEGRATION TESTS
#