From e9c8deab1e98f4cce04cd57e11e56e4fc4ba9d51 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Fri, 21 May 2010 14:27:04 +0100
Subject: [PATCH] ErrorLoggingAsyncNotifier

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                  |  3 ++-
 lib/asyncnotifier.py                  | 11 +++++++++++
 test/ganeti.asyncnotifier_unittest.py |  4 ++--
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/daemons/ganeti-confd b/daemons/ganeti-confd
index 958e1a133..3a685c78e 100755
--- a/daemons/ganeti-confd
+++ b/daemons/ganeti-confd
@@ -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()
diff --git a/lib/asyncnotifier.py b/lib/asyncnotifier.py
index 421e476db..286cd2fd2 100644
--- a/lib/asyncnotifier.py
+++ b/lib/asyncnotifier.py
@@ -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.
 
diff --git a/test/ganeti.asyncnotifier_unittest.py b/test/ganeti.asyncnotifier_unittest.py
index b379ba1ef..f5e7f7337 100755
--- a/test/ganeti.asyncnotifier_unittest.py
+++ b/test/ganeti.asyncnotifier_unittest.py
@@ -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()
-- 
GitLab