Commit f03386a3 authored by Marco Mariani's avatar Marco Mariani

grid: logger usage % -> ,

parent 0018e9a2
......@@ -124,7 +124,7 @@ class Software(object):
""" Fetches binary cache if possible.
Installs from buildout otherwise.
"""
self.logger.info("Installing software release %s..." % self.url)
self.logger.info('Installing software release %s...', self.url)
cache_dir = tempfile.mkdtemp()
try:
tarpath = os.path.join(cache_dir, self.software_url_hash)
......@@ -263,10 +263,10 @@ class Software(object):
func(path)
try:
if os.path.exists(self.software_path):
self.logger.info('Removing path %r' % self.software_path)
self.logger.info('Removing path %r', self.software_path)
shutil.rmtree(self.software_path, onerror=retry)
else:
self.logger.info('Path %r does not exists, no need to remove.' %
self.logger.info('Path %r does not exist, no need to remove.',
self.software_path)
except IOError as exc:
raise IOError("I/O error while removing software (%s): %s" % (self.url, exc))
......@@ -334,9 +334,9 @@ class Partition(object):
if old_content != new_content:
if old_content is None:
self.logger.info('Missing %s file. Creating %r' % (name, path))
self.logger.info('Missing %s file. Creating %r', name, path)
else:
self.logger.info('Changed %s content. Updating %r' % (name, path))
self.logger.info('Changed %s content. Updating %r', name, path)
with os.fdopen(os.open(path, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o400), 'wb') as fout:
fout.write(new_content)
......@@ -391,8 +391,8 @@ class Partition(object):
""" Creates configuration file from template in software_path, then
installs the software partition with the help of buildout
"""
self.logger.info("Installing Computer Partition %s..."
% self.computer_partition.getId())
self.logger.info('Installing Computer Partition %s...',
self.computer_partition.getId())
# Checks existence and permissions of Partition directory
# Note : Partitions have to be created and configured before running slapgrid
if not os.path.isdir(self.instance_path):
......@@ -430,7 +430,7 @@ class Partition(object):
self.software_release_url, instance_cfg))
buildout_cfg = os.path.join(self.instance_path, 'buildout.cfg')
self.logger.debug("Copying %r to %r" % (instance_cfg, buildout_cfg))
self.logger.debug('Copying %r to %r', instance_cfg, buildout_cfg)
with open(buildout_cfg, 'w') as fout:
fout.write(open(instance_cfg).read())
......@@ -462,8 +462,7 @@ class Partition(object):
os.chown(buildout_cfg, -1, int(gid))
if len(bootstrap_candidate_list) == 0:
buildout_binary = os.path.join(self.software_path, 'bin', 'buildout')
self.logger.warning("Falling back to default buildout %r" %
buildout_binary)
self.logger.warning('Falling back to default buildout %r', buildout_binary)
else:
if len(bootstrap_candidate_list) != 1:
raise ValueError('More than one bootstrap candidate found.')
......@@ -477,8 +476,8 @@ class Partition(object):
invocation_list = first_line[2:].split()
invocation_list.append(bootstrap_file)
self.logger.debug('Invoking %r in %r' % (' '.join(invocation_list),
self.instance_path))
self.logger.debug('Invoking %r in %r', ' '.join(invocation_list),
self.instance_path)
process_handler = SlapPopen(invocation_list,
preexec_fn=lambda: dropPrivileges(uid, gid, logger=self.logger),
cwd=self.instance_path,
......@@ -526,7 +525,7 @@ class Partition(object):
if os.path.isdir(self.service_path):
service_list = os.listdir(self.service_path)
if len(runner_list) == 0 and len(service_list) == 0:
self.logger.warning('No runners nor services found for partition %r' %
self.logger.warning('No runners nor services found for partition %r',
self.partition_id)
if os.path.exists(self.supervisord_partition_configuration_path):
os.unlink(self.supervisord_partition_configuration_path)
......@@ -557,10 +556,9 @@ class Partition(object):
supervisor.startProcessGroup(partition_id, False)
except xmlrpclib.Fault as exc:
if exc.faultString.startswith('BAD_NAME:'):
self.logger.info("Nothing to start on %s..." %
self.computer_partition.getId())
self.logger.info('Nothing to start on %s...', self.computer_partition.getId())
else:
self.logger.info("Requested start of %s..." % self.computer_partition.getId())
self.logger.info('Requested start of %s...', self.computer_partition.getId())
def stop(self):
"""Asks supervisord to stop the instance."""
......@@ -570,9 +568,9 @@ class Partition(object):
supervisor.stopProcessGroup(partition_id, False)
except xmlrpclib.Fault as exc:
if exc.faultString.startswith('BAD_NAME:'):
self.logger.info('Partition %s not known in supervisord, ignoring' % partition_id)
self.logger.info('Partition %s not known in supervisord, ignoring', partition_id)
else:
self.logger.info("Requested stop of %s..." % self.computer_partition.getId())
self.logger.info('Requested stop of %s...', self.computer_partition.getId())
def _pre_destroy(self, destroy_binary):
uid, gid = self.getUserGroupId()
......@@ -593,8 +591,8 @@ class Partition(object):
def destroy(self):
"""Destroys the partition and makes it available for subsequent use."
"""
self.logger.info("Destroying Computer Partition %s..."
% self.computer_partition.getId())
self.logger.info('Destroying Computer Partition %s...',
self.computer_partition.getId())
# Launches "destroy" binary if exists
destroy_binary = os.path.join(self.instance_path, 'sbin', 'destroy')
......@@ -644,21 +642,21 @@ class Partition(object):
fails = [res for res in results
if res['status'] == xmlrpc.Faults.FAILED]
if fails:
self.logger.warning('Problem while stopping process %r, will try later' % gname)
self.logger.warning('Problem while stopping process %r, will try later', gname)
else:
self.logger.info('Stopped %r' % gname)
self.logger.info('Stopped %r', gname)
supervisor.removeProcessGroup(gname)
self.logger.info('Removed %r' % gname)
self.logger.info('Removed %r', gname)
for gname in changed:
results = supervisor.stopProcessGroup(gname)
self.logger.info('Stopped %r' % gname)
self.logger.info('Stopped %r', gname)
supervisor.removeProcessGroup(gname)
supervisor.addProcessGroup(gname)
self.logger.info('Updated %r' % gname)
self.logger.info('Updated %r', gname)
for gname in added:
supervisor.addProcessGroup(gname)
self.logger.info('Updated %r' % gname)
self.logger.info('Updated %r', gname)
self.logger.debug('Supervisord updated')
......@@ -426,9 +426,9 @@ class Slapgrid(object):
fout.write(time.asctime())
elif state == 'destroyed':
if os.path.exists(software_path):
self.logger.info('Destroying %r...' % software_release_uri)
self.logger.info('Destroying %r...', software_release_uri)
software.destroy()
self.logger.info('Destroyed %r.' % software_release_uri)
self.logger.info('Destroyed %r.', software_release_uri)
# Send log before exiting
except (SystemExit, KeyboardInterrupt):
software_release.error(traceback.format_exc(), logger=self.logger)
......@@ -540,7 +540,7 @@ class Slapgrid(object):
(computer_partition_id not in self.computer_partition_filter_list):
return
self.logger.info('Processing Computer Partition %s.' % computer_partition_id)
self.logger.info('Processing Computer Partition %s.', computer_partition_id)
instance_path = os.path.join(self.instance_root, computer_partition_id)
......@@ -606,9 +606,9 @@ class Slapgrid(object):
os.remove(timestamp_path)
self.logger.exception('')
self.logger.info(' Software URL: %s' % software_url)
self.logger.info(' Software path: %s' % software_path)
self.logger.info(' Instance path: %s' % instance_path)
self.logger.info(' Software URL: %s', software_url)
self.logger.info(' Software path: %s', software_path)
self.logger.info(' Instance path: %s', instance_path)
local_partition = Partition(
software_path=software_path,
......@@ -791,8 +791,8 @@ class Slapgrid(object):
try:
document = etree.fromstring(to_be_validated)
except (etree.XMLSyntaxError, etree.DocumentInvalid) as exc:
self.logger.info('Failed to parse this XML report : %s\n%s' %
(to_be_validated, _formatXMLError(exc)))
self.logger.info('Failed to parse this XML report : %s\n%s',
to_be_validated, _formatXMLError(exc))
self.logger.error(_formatXMLError(exc))
return False
......@@ -823,11 +823,11 @@ class Slapgrid(object):
try:
root = etree.fromstring(computer_partition_usage.usage)
except UnicodeError as exc:
self.logger.info("Failed to read %s." % computer_partition_usage.usage)
self.logger.info('Failed to read %s.', computer_partition_usage.usage)
self.logger.error(UnicodeError)
raise UnicodeError("Failed to read %s: %s" % (computer_partition_usage.usage, exc))
except (etree.XMLSyntaxError, etree.DocumentInvalid) as exc:
self.logger.info("Failed to parse %s." % (computer_partition_usage.usage))
self.logger.info('Failed to parse %s.', computer_partition_usage.usage)
self.logger.error(exc)
raise _formatXMLError(exc)
except Exception as exc:
......@@ -934,12 +934,12 @@ class Slapgrid(object):
if process_handler.returncode != 0:
clean_run = False
failed_script_list.append("Script %r failed." % script)
self.logger.warning('Failed to run %r' % invocation_list)
self.logger.warning('Failed to run %r', invocation_list)
if len(failed_script_list):
computer_partition.error('\n'.join(failed_script_list), logger=self.logger)
# Whatever happens, don't stop processing other instances
except Exception:
self.logger.exception('Cannot run usage script(s) for %r:' %
self.logger.exception('Cannot run usage script(s) for %r:',
computer_partition.getId())
#Now we loop through the different computer partitions to report
......@@ -968,7 +968,7 @@ class Slapgrid(object):
if not self.validateXML(usage, partition_consumption_model):
self.logger.info('WARNING: The XML file %s generated by slapreport is '
'not valid - This report is left as is at %s where you can '
'inspect what went wrong ' % (filename, dir_reports))
'inspect what went wrong', filename, dir_reports)
# Warn the SlapOS Master that a partition generates corrupted xml
# report
else:
......@@ -978,7 +978,7 @@ class Slapgrid(object):
computer_partition_usage_list.append(computer_partition_usage)
filename_delete_list.append(filename)
else:
self.logger.debug('Usage report %r not found, ignored' % file_path)
self.logger.debug('Usage report %r not found, ignored', file_path)
#After sending the aggregated file we remove all the valid xml reports
for filename in filename_delete_list:
......@@ -986,12 +986,13 @@ class Slapgrid(object):
# Whatever happens, don't stop processing other instances
except Exception:
self.logger.exception('Cannot run usage script(s) for %r:' %
self.logger.exception('Cannot run usage script(s) for %r:',
computer_partition.getId())
for computer_partition_usage in computer_partition_usage_list:
self.logger.info('computer_partition_usage_list: %s - %s' %
(computer_partition_usage.usage, computer_partition_usage.getId()))
self.logger.info('computer_partition_usage_list: %s - %s',
computer_partition_usage.usage,
computer_partition_usage.getId())
#If there is, at least, one report
if computer_partition_usage_list != []:
......@@ -999,7 +1000,7 @@ class Slapgrid(object):
#We generate the final XML report with asXML method
computer_consumption = self.asXML(computer_partition_usage_list)
self.logger.info('Final xml report: %s' % computer_consumption)
self.logger.info('Final xml report: %s', computer_consumption)
#We test the XML report before sending it
if self.validateXML(computer_consumption, computer_consumption_model):
......@@ -1052,7 +1053,7 @@ class Slapgrid(object):
except Exception:
pass
if computer_partition.getId() in report_usage_issue_cp_list:
self.logger.info('Ignoring destruction of %r, as no report usage was sent' %
self.logger.info('Ignoring destruction of %r, as no report usage was sent',
computer_partition.getId())
continue
local_partition.destroy()
......@@ -1068,12 +1069,13 @@ class Slapgrid(object):
computer_partition.destroyed()
except NotFoundError:
self.logger.debug('Ignored slap error while trying to inform about '
'destroying not fully configured Computer Partition %r' %
'destroying not fully configured Computer Partition %r',
computer_partition.getId())
except ServerError as server_error:
self.logger.debug('Ignored server error while trying to inform about '
'destroying Computer Partition %r. Error is:\n%r' %
(computer_partition.getId(), server_error.args[0]))
'destroying Computer Partition %r. Error is:\n%r',
computer_partition.getId(),
server_error.args[0])
self.logger.info('Finished usage reports.')
......
......@@ -92,7 +92,7 @@ def launchSupervisord(socket, configuration_file, logger):
result = supervisord_popen.communicate()[0]
if supervisord_popen.returncode:
logger.warning('Supervisord unknown problem: %s' % result)
logger.warning('Supervisord unknown problem: %s', result)
return
try:
......@@ -107,13 +107,13 @@ def launchSupervisord(socket, configuration_file, logger):
if status['statename'] == 'RUNNING' and status['statecode'] == 1:
return
logger.warning('Wrong status name %(statename)r and code '
'%(statecode)r, trying again' % status)
'%(statecode)r, trying again', status)
trynum += 1
except Exception:
current_timeout = 5 * trynum
trynum += 1
else:
logger.info('Supervisord started correctly in try %s.' % trynum)
logger.info('Supervisord started correctly in try %s.', trynum)
return
logger.warning('Issue while checking supervisord.')
finally:
......
......@@ -130,8 +130,8 @@ def getCleanEnvironment(logger, home_path='/tmp'):
removed_env.append(k)
changed_env['HOME'] = env['HOME'] = home_path
for k in sorted(changed_env.iterkeys()):
logger.debug('Overridden %s = %r' % (k, changed_env[k]))
logger.debug('Removed from environment: %s' % ', '.join(sorted(removed_env)))
logger.debug('Overridden %s = %r', k, changed_env[k])
logger.debug('Removed from environment: %s', ', '.join(sorted(removed_env)))
return env
......@@ -146,9 +146,9 @@ def setRunning(logger, pidfile):
# XXX This could use psutil library.
if pid and os.path.exists("/proc/%s" % pid):
logger.info('New slapos process started, but another slapos '
'process is aleady running with pid %s, exiting.' % pid)
'process is aleady running with pid %s, exiting.', pid)
sys.exit(10)
logger.info('Existing pid file %r was stale, overwritten' % pidfile)
logger.info('Existing pid file %r was stale, overwritten', pidfile)
# Start new process
write_pid(logger, pidfile)
......@@ -165,7 +165,7 @@ def write_pid(logger, pidfile):
with open(pidfile, 'w') as fout:
fout.write('%s' % os.getpid())
except (IOError, OSError):
logger.critical('slapgrid could not write pidfile %s' % pidfile)
logger.critical('slapgrid could not write pidfile %s', pidfile)
raise
......@@ -185,7 +185,7 @@ def dropPrivileges(uid, gid, logger):
'gid = %r is too dangerous' % (uid, gid))
if current_uid or current_gid:
logger.debug('Running as uid = %r, gid = %r, dropping '
'not needed and not possible' % (current_uid, current_gid))
'not needed and not possible', current_uid, current_gid)
return
# drop privileges
user_name = pwd.getpwuid(uid)[0]
......@@ -224,7 +224,7 @@ def dropPrivileges(uid, gid, logger):
else:
raise ValueError('%s it was possible to go back to uid = %r and gid = '
'%r which is fatal.' % (message_pre, current_uid, current_gid))
logger.debug('Succesfully dropped privileges to uid=%r gid=%r' % (uid, gid))
logger.debug('Succesfully dropped privileges to uid=%r gid=%r', uid, gid)
def bootstrapBuildout(path, logger, buildout=None,
......@@ -260,9 +260,8 @@ def bootstrapBuildout(path, logger, buildout=None,
invocation_list.append('bootstrap')
try:
umask = os.umask(SAFE_UMASK)
logger.debug('Set umask from %03o to %03o' % (umask, SAFE_UMASK))
logger.debug('Invoking: %r in directory %r' % (' '.join(invocation_list),
path))
logger.debug('Set umask from %03o to %03o', umask, SAFE_UMASK)
logger.debug('Invoking: %r in directory %r', ' '.join(invocation_list), path)
process_handler = SlapPopen(invocation_list,
preexec_fn=lambda: dropPrivileges(uid, gid, logger=logger),
cwd=path,
......@@ -274,11 +273,11 @@ def bootstrapBuildout(path, logger, buildout=None,
logger.error(message)
raise BuildoutFailedError('%s:\n%s\n' % (message, process_handler.output))
except OSError as exc:
logger.exception(exc)
logger.exception('')
raise BuildoutFailedError(exc)
finally:
old_umask = os.umask(umask)
logger.debug('Restore umask from %03o to %03o' % (old_umask, umask))
logger.debug('Restore umask from %03o to %03o', old_umask, umask)
def launchBuildout(path, buildout_binary, logger,
......@@ -302,9 +301,8 @@ def launchBuildout(path, buildout_binary, logger,
invocation_list.extend(additional_buildout_parameter_list)
try:
umask = os.umask(SAFE_UMASK)
logger.debug('Set umask from %03o to %03o' % (umask, SAFE_UMASK))
logger.debug('Invoking: %r in directory %r' % (' '.join(invocation_list),
path))
logger.debug('Set umask from %03o to %03o', umask, SAFE_UMASK)
logger.debug('Invoking: %r in directory %r', ' '.join(invocation_list), path)
process_handler = SlapPopen(invocation_list,
preexec_fn=lambda: dropPrivileges(uid, gid, logger=logger),
cwd=path,
......@@ -318,11 +316,11 @@ def launchBuildout(path, buildout_binary, logger,
logger.error(message)
raise BuildoutFailedError('%s:\n%s\n' % (message, process_handler.output))
except OSError as exc:
logger.exception(exc)
logger.exception('')
raise BuildoutFailedError(exc)
finally:
old_umask = os.umask(umask)
logger.debug('Restore umask from %03o to %03o' % (old_umask, umask))
logger.debug('Restore umask from %03o to %03o', old_umask, umask)
def updateFile(file_path, content, mode=0o600):
......
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