Ema has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371123 )

Change subject: coordinator: exit if exceptions are raised importing monitors
......................................................................

coordinator: exit if exceptions are raised importing monitors

If importing a configured pybal.monitor results in an exception, we want
PyBal to stop immediately. This is to be explicit with the admin who
might think that everything is fine while in fact none of the checks
that should have been performed by the failing monitor are being run.

Also, use importlib instead of __import__.

Change-Id: I5a0733310d0c8277e755e4cd1e3f1a61bc716a54
---
M pybal/coordinator.py
1 file changed, 13 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/debs/pybal 
refs/changes/23/371123/1

diff --git a/pybal/coordinator.py b/pybal/coordinator.py
index 26905ef..c828ca3 100755
--- a/pybal/coordinator.py
+++ b/pybal/coordinator.py
@@ -6,10 +6,11 @@
 
 LVS Squid balancer/monitor for managing the Wikimedia Squid servers using LVS
 """
+import importlib
 import random
 import socket
 
-from twisted.internet import defer
+from twisted.internet import defer, reactor
 from twisted.names import client, dns
 from twisted.python import failure
 
@@ -193,9 +194,18 @@
         else:
             for monitorname in monitorlist:
                 try:
-                    monitormodule = getattr(__import__('pybal.monitors', 
fromlist=[monitorname.lower()], level=0), monitorname.lower())
-                except AttributeError:
+                    monitormodule = importlib.import_module(
+                        "pybal.monitors.{}".format(monitorname.lower()))
+                except ImportError:
                     log.err("Monitor {} does not exist".format(monitorname))
+                except Exception:
+                    log.critical("Cannot import 
pybal.monitors.{}".format(monitorname))
+                    # An exception was raised importing the given monitor
+                    # module. Instead of just logging the problem, stop PyBal
+                    # as the admin might think everything is fine and all
+                    # checks are green, while in fact no check is being
+                    # performed.
+                    reactor.stop()
                 else:
                     monitorclass = getattr(monitormodule, monitorname + 
'MonitoringProtocol')
                     monitor = monitorclass(coordinator, self, 
lvsservice.configuration)

-- 
To view, visit https://gerrit.wikimedia.org/r/371123
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5a0733310d0c8277e755e4cd1e3f1a61bc716a54
Gerrit-PatchSet: 1
Gerrit-Project: operations/debs/pybal
Gerrit-Branch: master
Gerrit-Owner: Ema <e...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to