Commit 07b8a2b5 authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix use of the logging functions



The logging functions expand the arguments themselves, thus it's safer
to let them do it rather than manual string formatting.

Also re-wraps one comment.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarOlivier Tharan <olive@google.com>
parent d984846d
...@@ -67,7 +67,7 @@ class ConfdAsyncUDPServer(daemon.AsyncUDPSocket): ...@@ -67,7 +67,7 @@ class ConfdAsyncUDPServer(daemon.AsyncUDPSocket):
self.port = port self.port = port
self.processor = processor self.processor = processor
self.bind((bind_address, port)) self.bind((bind_address, port))
logging.debug("listening on ('%s':%d)" % (bind_address, port)) logging.debug("listening on ('%s':%d)", bind_address, port)
# this method is overriding a daemon.AsyncUDPSocket method # this method is overriding a daemon.AsyncUDPSocket method
def handle_datagram(self, payload_in, ip, port): def handle_datagram(self, payload_in, ip, port):
...@@ -134,7 +134,7 @@ class ConfdInotifyEventHandler(pyinotify.ProcessEvent): ...@@ -134,7 +134,7 @@ class ConfdInotifyEventHandler(pyinotify.ProcessEvent):
# IN_IGNORED event from inotify, because of the file removal (which is # IN_IGNORED event from inotify, because of the file removal (which is
# contextual with the replacement). In such a case we need to create # contextual with the replacement). In such a case we need to create
# another watcher for the "new" file. # another watcher for the "new" file.
logging.debug("Received 'ignored' inotify event for %s" % event.path) logging.debug("Received 'ignored' inotify event for %s", event.path)
self.watch_handle = None self.watch_handle = None
try: try:
...@@ -144,7 +144,7 @@ class ConfdInotifyEventHandler(pyinotify.ProcessEvent): ...@@ -144,7 +144,7 @@ class ConfdInotifyEventHandler(pyinotify.ProcessEvent):
# going to realod the file after setting up the new watch. # going to realod the file after setting up the new watch.
self.callback(False) self.callback(False)
except errors.ConfdFatalError, err: except errors.ConfdFatalError, err:
logging.critical("Critical error, shutting down: %s" % err) logging.critical("Critical error, shutting down: %s", err)
sys.exit(constants.EXIT_FAILURE) sys.exit(constants.EXIT_FAILURE)
except: except:
# we need to catch any exception here, log it, but proceed, because even # we need to catch any exception here, log it, but proceed, because even
...@@ -157,12 +157,12 @@ class ConfdInotifyEventHandler(pyinotify.ProcessEvent): ...@@ -157,12 +157,12 @@ class ConfdInotifyEventHandler(pyinotify.ProcessEvent):
# usually happen in Ganeti, as the config file is normally replaced by a # usually happen in Ganeti, as the config file is normally replaced by a
# new one, at filesystem level, rather than actually modified (see # new one, at filesystem level, rather than actually modified (see
# utils.WriteFile) # utils.WriteFile)
logging.debug("Received 'modify' inotify event for %s" % event.path) logging.debug("Received 'modify' inotify event for %s", event.path)
try: try:
self.callback(True) self.callback(True)
except errors.ConfdFatalError, err: except errors.ConfdFatalError, err:
logging.critical("Critical error, shutting down: %s" % err) logging.critical("Critical error, shutting down: %s", err)
sys.exit(constants.EXIT_FAILURE) sys.exit(constants.EXIT_FAILURE)
except: except:
# we need to catch any exception here, log it, but proceed, because even # we need to catch any exception here, log it, but proceed, because even
...@@ -171,7 +171,7 @@ class ConfdInotifyEventHandler(pyinotify.ProcessEvent): ...@@ -171,7 +171,7 @@ class ConfdInotifyEventHandler(pyinotify.ProcessEvent):
logging.error("Unexpected exception", exc_info=True) logging.error("Unexpected exception", exc_info=True)
def process_default(self, event): def process_default(self, event):
logging.error("Received unhandled inotify event: %s" % event) logging.error("Received unhandled inotify event: %s", event)
class ConfdConfigurationReloader(object): class ConfdConfigurationReloader(object):
......
...@@ -331,7 +331,7 @@ class Watcher(object): ...@@ -331,7 +331,7 @@ class Watcher(object):
""" """
arch_count, left_count = client.AutoArchiveJobs(age) arch_count, left_count = client.AutoArchiveJobs(age)
logging.debug("Archived %s jobs, left %s" % (arch_count, left_count)) logging.debug("Archived %s jobs, left %s", arch_count, left_count)
def CheckDisks(self, notepad): def CheckDisks(self, notepad):
"""Check all nodes for restarted ones. """Check all nodes for restarted ones.
......
...@@ -201,40 +201,41 @@ class InstanceIpToNodePrimaryIpQuery(ConfdQuery): ...@@ -201,40 +201,41 @@ class InstanceIpToNodePrimaryIpQuery(ConfdQuery):
network_link = None network_link = None
mode = constants.CONFD_REQQ_IP mode = constants.CONFD_REQQ_IP
else: else:
logging.debug("Invalid query argument type for: %s" % query) logging.debug("Invalid query argument type for: %s", query)
return QUERY_ARGUMENT_ERROR return QUERY_ARGUMENT_ERROR
pnodes_list = [] pnodes_list = []
for instance_ip in instances_list: for instance_ip in instances_list:
if not isinstance(instance_ip, basestring): if not isinstance(instance_ip, basestring):
logging.debug("Invalid IP type for: %s" % instance_ip) logging.debug("Invalid IP type for: %s", instance_ip)
return QUERY_ARGUMENT_ERROR return QUERY_ARGUMENT_ERROR
instance = self.reader.GetInstanceByLinkIp(instance_ip, network_link) instance = self.reader.GetInstanceByLinkIp(instance_ip, network_link)
if not instance: if not instance:
logging.debug("Unknown instance IP: %s" % instance_ip) logging.debug("Unknown instance IP: %s", instance_ip)
pnodes_list.append(QUERY_UNKNOWN_ENTRY_ERROR) pnodes_list.append(QUERY_UNKNOWN_ENTRY_ERROR)
continue continue
pnode = self.reader.GetInstancePrimaryNode(instance) pnode = self.reader.GetInstancePrimaryNode(instance)
if not pnode: if not pnode:
logging.error("Instance '%s' doesn't have an associated primary" logging.error("Instance '%s' doesn't have an associated primary"
" node" % instance) " node", instance)
pnodes_list.append(QUERY_INTERNAL_ERROR) pnodes_list.append(QUERY_INTERNAL_ERROR)
continue continue
pnode_primary_ip = self.reader.GetNodePrimaryIp(pnode) pnode_primary_ip = self.reader.GetNodePrimaryIp(pnode)
if not pnode_primary_ip: if not pnode_primary_ip:
logging.error("Primary node '%s' doesn't have an associated" logging.error("Primary node '%s' doesn't have an associated"
" primary IP" % pnode) " primary IP", pnode)
pnodes_list.append(QUERY_INTERNAL_ERROR) pnodes_list.append(QUERY_INTERNAL_ERROR)
continue continue
pnodes_list.append((constants.CONFD_REPL_STATUS_OK, pnode_primary_ip)) pnodes_list.append((constants.CONFD_REPL_STATUS_OK, pnode_primary_ip))
# If a single ip was requested, return a single answer, otherwise the whole # If a single ip was requested, return a single answer, otherwise
# list, with a success status (since each entry has its own success/failure) # the whole list, with a success status (since each entry has its
# own success/failure)
if mode == constants.CONFD_REQQ_IP: if mode == constants.CONFD_REQQ_IP:
return pnodes_list[0] return pnodes_list[0]
......
...@@ -100,7 +100,7 @@ class ConfdProcessor(object): ...@@ -100,7 +100,7 @@ class ConfdProcessor(object):
payload_out = self.PackReply(reply, rsalt) payload_out = self.PackReply(reply, rsalt)
return payload_out return payload_out
except errors.ConfdRequestError, err: except errors.ConfdRequestError, err:
logging.info('Ignoring broken query from %s:%d: %s' % (ip, port, err)) logging.info('Ignoring broken query from %s:%d: %s', ip, port, err)
return None return None
def ExtractRequest(self, payload): def ExtractRequest(self, payload):
...@@ -110,7 +110,7 @@ class ConfdProcessor(object): ...@@ -110,7 +110,7 @@ class ConfdProcessor(object):
""" """
current_time = time.time() current_time = time.time()
logging.debug("Extracting request with size: %d" % (len(payload))) logging.debug("Extracting request with size: %d", len(payload))
try: try:
(message, salt) = serializer.LoadSigned(payload, self.hmac_key) (message, salt) = serializer.LoadSigned(payload, self.hmac_key)
except errors.SignatureError, err: except errors.SignatureError, err:
...@@ -142,7 +142,7 @@ class ConfdProcessor(object): ...@@ -142,7 +142,7 @@ class ConfdProcessor(object):
@return: tuple of reply and salt to add to the signature @return: tuple of reply and salt to add to the signature
""" """
logging.debug("Processing request: %s" % request) logging.debug("Processing request: %s", request)
if request.protocol != constants.CONFD_PROTOCOL_VERSION: if request.protocol != constants.CONFD_PROTOCOL_VERSION:
msg = "wrong protocol version %d" % request.protocol msg = "wrong protocol version %d" % request.protocol
raise errors.ConfdRequestError(msg) raise errors.ConfdRequestError(msg)
...@@ -165,7 +165,7 @@ class ConfdProcessor(object): ...@@ -165,7 +165,7 @@ class ConfdProcessor(object):
serial=self.reader.GetConfigSerialNo(), serial=self.reader.GetConfigSerialNo(),
) )
logging.debug("Sending reply: %s" % reply) logging.debug("Sending reply: %s", reply)
return (reply, rsalt) return (reply, rsalt)
......
...@@ -376,9 +376,8 @@ class KVMHypervisor(hv_base.BaseHypervisor): ...@@ -376,9 +376,8 @@ class KVMHypervisor(hv_base.BaseHypervisor):
vnc_arg = '%s:%d' % (vnc_bind_address, display) vnc_arg = '%s:%d' % (vnc_bind_address, display)
else: else:
logging.error("Network port is not a valid VNC display (%d < %d)." logging.error("Network port is not a valid VNC display (%d < %d)."
" Not starting VNC" % " Not starting VNC", instance.network_port,
(instance.network_port, constants.VNC_BASE_PORT)
constants.VNC_BASE_PORT))
vnc_arg = 'none' vnc_arg = 'none'
# Only allow tls and other option when not binding to a file, for now. # Only allow tls and other option when not binding to a file, for now.
...@@ -686,7 +685,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): ...@@ -686,7 +685,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
raise errors.HypervisorError("Migration %s at the kvm level" % raise errors.HypervisorError("Migration %s at the kvm level" %
status) status)
else: else:
logging.info("KVM: unknown migration status '%s'" % status) logging.info("KVM: unknown migration status '%s'", status)
time.sleep(2) time.sleep(2)
utils.KillProcess(pid) utils.KillProcess(pid)
......
...@@ -198,7 +198,7 @@ def main(): ...@@ -198,7 +198,7 @@ def main():
if vrfy: if vrfy:
logging.error("Errors after conversion:") logging.error("Errors after conversion:")
for item in vrfy: for item in vrfy:
logging.error(" - %s" % item) logging.error(" - %s", item)
del cfg del cfg
logging.info("File loaded successfully") logging.info("File loaded successfully")
......
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