Module: check_mk
Branch: master
Commit: 0505b2cf5bac3e1e5e2510f542be933b341c0f0f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0505b2cf5bac3e…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Fri Apr 6 10:28:51 2018 +0200
Finally nuked global variable g_status_server.
Change-Id: I650231d6357399fbe478aec34ccd22f8769bee67
---
cmk/ec/main.py | 23 +++++++++++++----------
tests/integration/cmk/ec/test_mkeventd_status.py | 18 +++++++++++-------
2 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/cmk/ec/main.py b/cmk/ec/main.py
index d75271a..8a78f25 100644
--- a/cmk/ec/main.py
+++ b/cmk/ec/main.py
@@ -269,9 +269,10 @@ class ECLock(object):
class ECServerThread(threading.Thread):
- def __init__(self, name, settings, profiling_enabled, profile_file):
+ def __init__(self, name, settings, table_events, profiling_enabled, profile_file):
super(ECServerThread, self).__init__(name=name)
self.settings = settings
+ self._table_events = table_events
self._profiling_enabled = profiling_enabled
self._profile_file = profile_file
self._terminate_event = threading.Event()
@@ -284,7 +285,7 @@ class ECServerThread(threading.Thread):
try:
with cmk.profile.Profile(enabled=self._profiling_enabled,
profile_file=str(self._profile_file)):
- self.serve(g_status_server.table_events)
+ self.serve(self._table_events)
except Exception:
self.logger.exception("Exception in %s server" % self.name)
if self._settings.options.debug:
@@ -1254,9 +1255,10 @@ class EventServer(ECServerThread):
month_names = {"Jan": 1, "Feb": 2, "Mar": 3,
"Apr": 4, "May": 5, "Jun": 6,
"Jul": 7, "Aug": 8, "Sep": 9,
"Oct": 10, "Nov": 11, "Dec": 12}
- def __init__(self, settings, perfcounters, event_status):
+ def __init__(self, settings, perfcounters, event_status, table_events):
super(EventServer, self).__init__(name="EventServer",
settings=settings,
+ table_events=table_events,
profiling_enabled=settings.options.profile_event,
profile_file=settings.paths.event_server_profile.value)
self._syslog = None
@@ -3510,16 +3512,17 @@ class StatusTableStatus(StatusTable):
# '----------------------------------------------------------------------'
class StatusServer(ECServerThread):
- def __init__(self, settings, perfcounters, event_status, event_server):
+ def __init__(self, settings, perfcounters, event_status, event_server,
table_events):
super(StatusServer, self).__init__(name="StatusServer",
settings=settings,
+ table_events=table_events,
profiling_enabled=settings.options.profile_status,
profile_file=settings.paths.status_server_profile.value)
self._socket = None
self._tcp_socket = None
self._reopen_sockets = False
- self.table_events = StatusTableEvents(event_status)
+ self.table_events = table_events
self.table_history = StatusTableHistory(settings, self.table_events)
self.table_rules = StatusTableRules(event_status)
self.table_status = StatusTableStatus(event_server)
@@ -5053,15 +5056,15 @@ def main():
settings.paths.status_file.value.parent.mkdir(parents=True, exist_ok=True)
# First do all things that might fail, before daemonizing
- global g_status_server
perfcounters = Perfcounters()
event_status = EventStatus(settings, perfcounters)
- event_server = EventServer(settings, perfcounters, event_status)
- g_status_server = StatusServer(settings, perfcounters, event_status,
event_server)
+ table_events = StatusTableEvents(event_status)
+ event_server = EventServer(settings, perfcounters, event_status, table_events)
+ status_server = StatusServer(settings, perfcounters, event_status, event_server,
table_events)
event_status.load_status(event_server)
- initialize_snmptrap_handling(settings, event_server,
g_status_server.table_events)
+ initialize_snmptrap_handling(settings, event_server, table_events)
event_server.compile_rules(g_config["rules"],
g_config["rule_packs"])
@@ -5079,7 +5082,7 @@ def main():
signal.signal(signal.SIGTERM, signal_handler)
# Now let's go...
- run_eventd(settings, perfcounters, event_status, event_server, g_status_server)
+ run_eventd(settings, perfcounters, event_status, event_server, status_server)
# We reach this point, if the server has been killed by
# a signal or hitting Ctrl-C (in foreground mode)
diff --git a/tests/integration/cmk/ec/test_mkeventd_status.py
b/tests/integration/cmk/ec/test_mkeventd_status.py
index bca73cd..d140a79 100644
--- a/tests/integration/cmk/ec/test_mkeventd_status.py
+++ b/tests/integration/cmk/ec/test_mkeventd_status.py
@@ -62,14 +62,18 @@ def event_status(settings, perfcounters):
@pytest.fixture(scope="function")
-def event_server(settings, config, perfcounters, event_status):
- return cmk.ec.main.EventServer(settings, perfcounters, event_status)
+def table_events(event_status):
+ return cmk.ec.main.StatusTableEvents(event_status)
@pytest.fixture(scope="function")
-def status_server(settings, config, perfcounters, event_status, event_server):
- cmk.ec.main.g_status_server = cmk.ec.main.StatusServer(settings, perfcounters,
event_status, event_server)
- return cmk.ec.main.g_status_server
+def event_server(settings, config, perfcounters, event_status, table_events):
+ return cmk.ec.main.EventServer(settings, perfcounters, event_status, table_events)
+
+
+(a)pytest.fixture(scope="function")
+def status_server(settings, config, perfcounters, event_status, event_server,
table_events):
+ return cmk.ec.main.StatusServer(settings, perfcounters, event_status, event_server,
table_events)
def test_handle_client(status_server):
@@ -82,9 +86,9 @@ def test_handle_client(status_server):
assert "event_id" in response[0]
-def test_mkevent_check_query_perf(config, event_status, status_server):
+def test_mkevent_check_query_perf(config, event_status, status_server, table_events):
for num in range(10000):
- event_status.new_event(status_server.table_events, CMKEventConsole.new_event({
+ event_status.new_event(table_events, CMKEventConsole.new_event({
"host": "heute-%d" % num,
"text": "%s %s BLA BLUB DINGELING ABASD AD R#@A AR@AR A@ RA@R
A@RARAR ARKNLA@RKA@LRKNA@KRLNA@RLKNA@äRLKA@RNKAL@R" \
" j:O#A@J$ KLA@J $L:A@J :AMW: RAMR@: RMA@:LRMA@ L:RMA@ :AL@R
MA:L@RM A@:LRMA@ :RLMA@ R:LA@RMM@RL:MA@R: AM@" % \