From e369f21dce451bdda7f5f52c3ad3004e7f6f0901 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Fri, 28 Aug 2009 14:57:38 +0300
Subject: [PATCH] ConfdProcessor: add disabled state

This is a state the processor will get in, if it fails to load the
config.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 daemons/ganeti-confd |  5 +++++
 lib/confd/server.py  | 19 ++++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/daemons/ganeti-confd b/daemons/ganeti-confd
index 734eb55d1..88e454bcc 100755
--- a/daemons/ganeti-confd
+++ b/daemons/ganeti-confd
@@ -322,6 +322,11 @@ def ExecConfd(options, args):
 
   # Asyncronous confd UDP server
   processor = ConfdProcessor()
+  try:
+    processor.Enable()
+  except errors.ConfigurationError:
+    # If enabling the processor has failed, we can still go on, but confd will be disabled
+    pass
   server = ConfdAsyncUDPServer(options.bind_address, options.port, processor)
 
   # Configuration reloader
diff --git a/lib/confd/server.py b/lib/confd/server.py
index 7937dfd09..601b95759 100644
--- a/lib/confd/server.py
+++ b/lib/confd/server.py
@@ -43,6 +43,7 @@ class ConfdProcessor(object):
   """A processor for confd requests.
 
   @ivar reader: confd SimpleConfigReader
+  @ivar disabled: whether confd serving is disabled
 
   """
   DISPATCH_TABLE = {
@@ -56,12 +57,25 @@ class ConfdProcessor(object):
     """Constructor for ConfdProcessor
 
     """
-    self.reader = ssconf.SimpleConfigReader()
+    self.disabled = True
     self.hmac_key = utils.ReadFile(constants.HMAC_CLUSTER_KEY)
+    self.reader = None
     assert \
       not constants.CONFD_REQS.symmetric_difference(self.DISPATCH_TABLE), \
       "DISPATCH_TABLE is unaligned with CONFD_REQS"
 
+  def Enable(self):
+    try:
+      self.reader = ssconf.SimpleConfigReader()
+      self.disabled = False
+    except errors.ConfigurationError:
+      self.disabled = True
+      raise
+
+  def Disable(self):
+    self.disabled = True
+    self.reader = None
+
   def ExecQuery(self, payload_in, ip, port):
     """Process a single UDP request from a client.
 
@@ -73,6 +87,9 @@ class ConfdProcessor(object):
     @type port: source port
 
     """
+    if self.disabled:
+      logging.debug('Confd is disabled. Ignoring query.')
+      return
     try:
       request = self.ExtractRequest(payload_in)
       reply, rsalt = self.ProcessRequest(request)
-- 
GitLab