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