Commit e369f21d authored by Guido Trotter's avatar Guido Trotter
Browse files

ConfdProcessor: add disabled state



This is a state the processor will get in, if it fails to load the
config.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 05f1ebf3
......@@ -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
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment