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

Confd client library: enable optional logging

If a logger is passed in, we log some debugging messages that might help
someone who's debugging a confd client to understand what's going on.
Signed-off-by: default avatarGuido Trotter <>
Reviewed-by: default avatarMichael Hanselmann <>
parent 7d20c647
......@@ -65,7 +65,7 @@ class ConfdClient:
through asyncore or with your own handling.
def __init__(self, hmac_key, peers, callback, port=None):
def __init__(self, hmac_key, peers, callback, port=None, logger=None):
"""Constructor for ConfdClient
@type hmac_key: string
......@@ -76,6 +76,8 @@ class ConfdClient:
@param callback: function to call when getting answers
@type port: integer
@keyword port: confd port (default: use GetDaemonPort)
@type logger: L{logging.Logger}
@keyword logger: optional logger for internal conditions
if not isinstance(peers, list):
......@@ -88,6 +90,7 @@ class ConfdClient:
self._socket = ConfdAsyncUDPClient(self)
self._callback = callback
self._confd_port = port
self._logger = logger
self._requests = {}
self._expire_requests = []
......@@ -184,14 +187,16 @@ class ConfdClient:
answer, salt = self._UnpackReply(payload)
except (errors.SignatureError, errors.ConfdMagicError):
except (errors.SignatureError, errors.ConfdMagicError), err:
if self._logger:
self._logger.debug("Discarding broken package: %s" % err)
(request, args) = self._requests[salt]
except KeyError:
# If the salt is unkown the answer is probably a replay of an old
# expired query. Ignoring it.
if self._logger:
self._logger.debug("Discarding unknown (expired?) reply: %s" % err)
client_reply = ConfdUpcallPayload(salt=salt,
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