ErrorLoggingAsyncNotifier
authorGuido Trotter <ultrotter@google.com>
Fri, 21 May 2010 13:27:04 +0000 (14:27 +0100)
committerGuido Trotter <ultrotter@google.com>
Tue, 25 May 2010 10:16:55 +0000 (11:16 +0100)
This mixes AsyncNotifier with GanetiBaseAsyncoreDispatcher to provide an
AsyncNotifier which will log errors, rather than bail out.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

daemons/ganeti-confd
lib/asyncnotifier.py
test/ganeti.asyncnotifier_unittest.py

index 958e1a1..3a685c7 100755 (executable)
@@ -117,7 +117,8 @@ class ConfdConfigurationReloader(object):
     self.inotify_handler = asyncnotifier.SingleFileEventHandler(self.wm,
                                                                 self.OnInotify,
                                                                 cfg_file)
-    self.notifier = asyncnotifier.AsyncNotifier(self.wm, self.inotify_handler)
+    notifier_class = asyncnotifier.ErrorLoggingAsyncNotifier
+    self.notifier = notifier_class(self.wm, self.inotify_handler)
 
     self.timer_handle = None
     self._EnableTimer()
index 421e476..286cd2f 100644 (file)
@@ -31,6 +31,7 @@ try:
 except ImportError:
   import pyinotify
 
+from ganeti import daemon
 from ganeti import errors
 
 # We contributed the AsyncNotifier class back to python-pyinotify, and it's
@@ -65,6 +66,16 @@ class AsyncNotifier(asyncore.file_dispatcher):
     self.notifier.process_events()
 
 
+class ErrorLoggingAsyncNotifier(AsyncNotifier,
+                                daemon.GanetiBaseAsyncoreDispatcher):
+  """An asyncnotifier that can survive errors in the callbacks.
+
+  We define this as a separate class, since we don't want to make AsyncNotifier
+  diverge from what we contributed upstream.
+
+  """
+
+
 class SingleFileEventHandler(pyinotify.ProcessEvent):
   """Handle modify events for a single file.
 
index b379ba1..f5e7f73 100755 (executable)
@@ -57,8 +57,8 @@ class TestSingleFileEventHandler(testutils.GanetiTestCase):
                                                           self.cbk[i],
                                                           self.chk_files[i])
                       for i in range(len(self.NOTIFIERS))]
-    self.notifiers = [asyncnotifier.AsyncNotifier(self.wms[i],
-                                                  self.ihandler[i])
+    self.notifiers = [asyncnotifier.ErrorLoggingAsyncNotifier(self.wms[i],
+                                                              self.ihandler[i])
                        for i in range(len(self.NOTIFIERS))]
     # TERM notifier is enabled by default, as we use it to get out of the loop
     self.ihandler[self.NOTIFIER_TERM].enable()