Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -322,6 +322,11 @@ def ExecConfd(options, args): ...@@ -322,6 +322,11 @@ def ExecConfd(options, args):
# Asyncronous confd UDP server # Asyncronous confd UDP server
processor = ConfdProcessor() 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) server = ConfdAsyncUDPServer(options.bind_address, options.port, processor)
# Configuration reloader # Configuration reloader
......
...@@ -43,6 +43,7 @@ class ConfdProcessor(object): ...@@ -43,6 +43,7 @@ class ConfdProcessor(object):
"""A processor for confd requests. """A processor for confd requests.
@ivar reader: confd SimpleConfigReader @ivar reader: confd SimpleConfigReader
@ivar disabled: whether confd serving is disabled
""" """
DISPATCH_TABLE = { DISPATCH_TABLE = {
...@@ -56,12 +57,25 @@ class ConfdProcessor(object): ...@@ -56,12 +57,25 @@ class ConfdProcessor(object):
"""Constructor for ConfdProcessor """Constructor for ConfdProcessor
""" """
self.reader = ssconf.SimpleConfigReader() self.disabled = True
self.hmac_key = utils.ReadFile(constants.HMAC_CLUSTER_KEY) self.hmac_key = utils.ReadFile(constants.HMAC_CLUSTER_KEY)
self.reader = None
assert \ assert \
not constants.CONFD_REQS.symmetric_difference(self.DISPATCH_TABLE), \ not constants.CONFD_REQS.symmetric_difference(self.DISPATCH_TABLE), \
"DISPATCH_TABLE is unaligned with CONFD_REQS" "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): def ExecQuery(self, payload_in, ip, port):
"""Process a single UDP request from a client. """Process a single UDP request from a client.
...@@ -73,6 +87,9 @@ class ConfdProcessor(object): ...@@ -73,6 +87,9 @@ class ConfdProcessor(object):
@type port: source port @type port: source port
""" """
if self.disabled:
logging.debug('Confd is disabled. Ignoring query.')
return
try: try:
request = self.ExtractRequest(payload_in) request = self.ExtractRequest(payload_in)
reply, rsalt = self.ProcessRequest(request) reply, rsalt = self.ProcessRequest(request)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment