Fix logging formatting

This commit is contained in:
Alexander Todorov 2017-10-12 15:18:32 +03:00 committed by Brian C. Lane
parent 18528b4f47
commit 663b0f8378
9 changed files with 50 additions and 51 deletions

View File

@ -186,15 +186,15 @@ class Lorax(BaseLoraxClass):
self.init_stream_logging()
self.init_file_logging(logdir)
logger.debug("version is {0}".format(vernum))
logger.debug("using work directory {0.workdir}".format(self))
logger.debug("using log directory {0}".format(logdir))
logger.debug("version is %s", vernum)
logger.debug("using work directory %s", self.workdir)
logger.debug("using log directory %s", logdir)
# set up output directory
self.outputdir = outputdir or tempfile.mkdtemp(prefix="pylorax.out.")
if not os.path.isdir(self.outputdir):
os.makedirs(self.outputdir)
logger.debug("using output directory {0.outputdir}".format(self))
logger.debug("using output directory %s", self.outputdir)
# do we have root privileges?
logger.info("checking for root privileges")
@ -224,7 +224,7 @@ class Lorax(BaseLoraxClass):
logger.critical("no yum base object")
sys.exit(1)
self.inroot = ybo.conf.installroot
logger.debug("using install root: {0}".format(self.inroot))
logger.debug("using install root: %s", self.inroot)
if not buildarch:
buildarch = get_buildarch(ybo)
@ -238,12 +238,12 @@ class Lorax(BaseLoraxClass):
product = DataHolder(name=product, version=version, release=release,
variant=variant, bugurl=bugurl, isfinal=isfinal)
self.product = product
logger.debug("product data: %s" % product)
logger.debug("product data: %s", product)
# NOTE: if you change isolabel, you need to change pungi to match, or
# the pungi images won't boot.
isolabel = volid or "{0.name} {0.version} {1.basearch}".format(self.product,
self.arch)
isolabel = volid or "%s %s %s" % (self.product.name, self.product.version,
self.arch.basearch)
if len(isolabel) > 32:
logger.fatal("the volume id cannot be longer than 32 characters")

View File

@ -82,8 +82,8 @@ class KernelInfo(object):
self.boot_dir = boot_dir
self.list = self.get_kernels()
self.arch = self.get_kernel_arch()
log.debug("kernel_list for {0.boot_dir} = {0.list}".format(self))
log.debug("kernel_arch is {0.arch}".format(self))
log.debug("kernel_list for %s = %s", self.boot_dir, self.list)
log.debug("kernel_arch is %s", self.arch)
def get_kernels(self):
"""
@ -134,12 +134,12 @@ def make_appliance(disk_img, name, template, outfile, networks=None, ram=1024,
if not (disk_img and template and outfile):
return None
log.info("Creating appliance definition using {0}".format(template))
log.info("Creating appliance definition using %s", template)
if not arch:
arch = "x86_64"
log.info("Calculating SHA256 checksum of {0}".format(disk_img))
log.info("Calculating SHA256 checksum of %s", disk_img)
sha256 = hashlib.sha256()
with open(disk_img) as f:
while True:
@ -147,7 +147,7 @@ def make_appliance(disk_img, name, template, outfile, networks=None, ram=1024,
if not data:
break
sha256.update(data)
log.info("SHA256 of {0} is {1}".format(disk_img, sha256.hexdigest()))
log.info("SHA256 of %s is %s", disk_img, sha256.hexdigest())
disk_info = DataHolder(name=os.path.basename(disk_img), format="raw",
checksum_type="sha256", checksum=sha256.hexdigest())
try:
@ -201,7 +201,7 @@ def rebuild_initrds_for_live(opts, sys_root_dir, results_dir):
dracut_args = []
for arg in opts.dracut_args:
dracut_args += arg.split(" ", 1)
log.info("dracut args = {0}".format(dracut_args))
log.info("dracut args = %s", dracut_args)
dracut = ["dracut", "--nomdadmconf", "--nolvmconf"] + dracut_args
@ -321,7 +321,7 @@ def make_livecd(opts, mount_dir, work_dir):
isolabel = opts.volid or "{0.name} {0.version} {1.basearch}".format(product, arch)
if len(isolabel) > 32:
isolabel = isolabel[:32]
log.warn("Truncating isolabel to 32 chars: %s" % (isolabel,))
log.warn("Truncating isolabel to 32 chars: %s", isolabel)
tb = TreeBuilder(product=product, arch=arch, domacboot=opts.domacboot,
inroot=mount_dir, outroot=work_dir,
@ -334,7 +334,7 @@ def make_livecd(opts, mount_dir, work_dir):
dracut_args = []
for arg in opts.dracut_args:
dracut_args += arg.split(" ", 1)
log.info("dracut args = {0}".format(dracut_args))
log.info("dracut args = %s", dracut_args)
tb.rebuild_initrds(add_args=dracut_args)
log.info("Building boot.iso")
tb.build()
@ -416,7 +416,7 @@ def make_image(opts, ks):
virt_install(opts, install_log, disk_img, disk_size)
except InstallError as e:
log.error("Install failed: {0}".format(e))
log.error("Install failed: %s", e)
if not opts.keep_image:
log.info("Removing bad disk image")
os.unlink(disk_img)

View File

@ -112,7 +112,7 @@ def execWithRedirect(command, argv, stdin = None, stdout = None,
elif stderr is None or not isinstance(stderr, file):
stderr = sys.stderr.fileno()
program_log.info("Running... %s" % (" ".join([command] + argv),))
program_log.info("Running... %s", " ".join([command] + argv))
#prepare os pipes for feeding tee proceses
pstdout, pstdin = os.pipe()
@ -124,9 +124,9 @@ def execWithRedirect(command, argv, stdin = None, stdout = None,
if root:
preexec_fn = chroot
cwd = root
program_log.info("chrooting into %s" % (cwd,))
program_log.info("chrooting into %s", cwd)
elif cwd:
program_log.info("chdiring into %s" % (cwd,))
program_log.info("chdiring into %s", cwd)
try:
#prepare tee proceses
@ -223,7 +223,7 @@ def execWithCapture(command, argv, stdin = None, stderr = None, root=None,
elif stderr is None or not isinstance(stderr, file):
stderr = sys.stderr.fileno()
program_log.info("Running... %s" % (" ".join([command] + argv),))
program_log.info("Running... %s", " ".join([command] + argv))
env = os.environ.copy()
env.update({"LC_ALL": "C"})
@ -231,9 +231,9 @@ def execWithCapture(command, argv, stdin = None, stderr = None, root=None,
if root:
preexec_fn = chroot
cwd = root
program_log.info("chrooting into %s" % (cwd,))
program_log.info("chrooting into %s", cwd)
elif cwd:
program_log.info("chdiring into %s" % (cwd,))
program_log.info("chdiring into %s", cwd)
try:
proc = subprocess.Popen([command] + argv, stdin=stdin,
@ -302,7 +302,7 @@ def execWithCallback(command, argv, stdin = None, stdout = None,
elif stderr is None or not isinstance(stderr, file):
stderr = sys.stderr.fileno()
program_log.info("Running... %s" % (" ".join([command] + argv),))
program_log.info("Running... %s", " ".join([command] + argv))
p = os.pipe()
p_stderr = os.pipe()
@ -346,7 +346,7 @@ def execWithCallback(command, argv, stdin = None, stdout = None,
if pid != 0:
break
except OSError as e:
log.critical("exception from waitpid: %s %s" %(e.errno, e.strerror))
log.critical("exception from waitpid: %s %s", e.errno, e.strerror)
if len(s) < 1:
break
@ -376,7 +376,7 @@ def execWithCallback(command, argv, stdin = None, stdout = None,
if not pid:
(pid, status) = os.waitpid(childpid, 0)
except OSError as e:
log.critical("exception from waitpid: %s %s" %(e.errno, e.strerror))
log.critical("exception from waitpid: %s %s", e.errno, e.strerror)
closefds()

View File

@ -402,9 +402,9 @@ class PartitionMount(object):
except CalledProcessError:
logger.debug(traceback.format_exc())
if self.mount_dir:
logger.info("Partition mounted on {0} size={1}".format(self.mount_dir, self.mount_size))
logger.info("Partition mounted on %s size=%d", self.mount_dir, self.mount_size)
else:
logger.debug("Unable to mount anything from {0}".format(self.disk_img))
logger.debug("Unable to mount anything from %s", self.disk_img)
os.rmdir(mount_dir)
return self
@ -431,7 +431,7 @@ def mkfsimage(fstype, rootdir, outfile, size=None, mkfsargs=[], mountargs="", gr
try:
runcmd(["mkfs.%s" % fstype] + mkfsargs + [loopdev])
except CalledProcessError as e:
logger.error("mkfs exited with a non-zero return code: %d" % e.returncode)
logger.error("mkfs exited with a non-zero return code: %d", e.returncode)
logger.error(e.output)
sys.exit(e.returncode)

View File

@ -228,7 +228,7 @@ class VirtualInstall( object ):
Could use libvirt for this instead.
"""
log.info( "Shutting down {0}".format(self.virt_name) )
log.info( "Shutting down %s", self.virt_name)
subprocess.call(["virsh", "destroy", self.virt_name])
# Undefine the virt, UEFI installs need to have --nvram passed

View File

@ -175,7 +175,7 @@ class LoraxTemplateRunner(object):
def run(self, templatefile, **variables):
for k,v in self.defaults.items() + self.builtins.items():
variables.setdefault(k,v)
logger.debug("executing {0} with variables={1}".format(templatefile, variables))
logger.debug("executing %s with variables=%s", templatefile, variables)
self.templatefile = templatefile
t = LoraxTemplate(directories=[self.templatedir])
commands = t.parse(templatefile, variables)

View File

@ -268,7 +268,7 @@ class TreeBuilder(object):
for hook_script, dracut_path in hooks:
src = joinpaths(self.dracut_hooks_path, hook_script)
if not os.path.exists(src):
logger.error("Missing lorax dracut hook script %s" % (src))
logger.error("Missing lorax dracut hook script %s", src)
continue
dst = joinpaths(self.vars.inroot, "/tmp/", hook_script)
copy2(src, dst)
@ -302,7 +302,7 @@ def findkernels(root="/", kdir="boot"):
imgtype = 'initrd'
kernel[imgtype] = DataHolder(path=joinpaths(kdir, f))
logger.debug("kernels=%s" % kernels)
logger.debug("kernels=%s", kernels)
return kernels
# udev whitelist: 'a-zA-Z0-9#+.:=@_-' (see is_whitelisted in libudev-util.c)

View File

@ -115,7 +115,7 @@ class LoraxRpmCallback(yum.rpmtrans.RPMBaseCallback):
def filelog(self, package, action):
if self.fileaction.get(action) == "Installed":
logger.debug("{0} installed successfully".format(package))
logger.debug("%s installed successfully", package)
def errorlog(self, msg):
logger.warning("RPM transaction error: %s", msg)

View File

@ -254,13 +254,13 @@ if __name__ == '__main__':
sys.exit( 1 )
if opts.make_iso and not os.path.exists( opts.lorax_templates ):
log.error( "The lorax templates directory ({0}) doesn't"
" exist.".format( opts.lorax_templates ) )
log.error( "The lorax templates directory (%s) doesn't"
" exist.", opts.lorax_templates)
sys.exit( 1 )
if opts.result_dir and os.path.exists(opts.result_dir):
log.error( "The results_dir ({0}) should not exist, please delete or "
"move its contents".format( opts.result_dir ))
log.error( "The results_dir (%s) should not exist, please delete or "
"move its contents", opts.result_dir)
sys.exit( 1 )
# Default to putting results into tmp
@ -270,15 +270,15 @@ if __name__ == '__main__':
os.makedirs(opts.result_dir)
if opts.iso and not os.path.exists( opts.iso ):
log.error( "The iso {0} is missing.".format( opts.iso ) )
log.error( "The iso %s is missing.", opts.iso)
sys.exit( 1 )
if opts.disk_image and not os.path.exists( opts.disk_image ):
log.error( "The disk image {0} is missing.".format( opts.disk_image ) )
log.error( "The disk image %s is missing.", opts.disk_image)
sys.exit( 1 )
if opts.fs_image and not os.path.exists( opts.fs_image ):
log.error( "The filesystem image {0} is missing.".format( opts.fs_image ) )
log.error( "The filesystem image %s is missing.", opts.fs_image)
sys.exit( 1 )
is_install = not (opts.disk_image or opts.fs_image)
@ -309,8 +309,8 @@ if __name__ == '__main__':
"appliance/libvirt.tmpl")
if opts.make_appliance and not os.path.exists(opts.app_template):
log.error("The appliance template ({0}) doesn't "
"exist".format(opts.app_template))
log.error("The appliance template (%s) doesn't "
"exist", opts.app_template)
sys.exit(1)
if opts.image_name and os.path.exists(joinpaths(opts.result_dir, opts.image_name)):
@ -398,14 +398,14 @@ if __name__ == '__main__':
try:
disk_img = make_image(opts, ks)
except InstallError as e:
log.error("ERROR: Image creation failed: %s" % (e))
log.error("ERROR: Image creation failed: %s", e)
sys.exit(1)
if not opts.image_only:
result_dir = None
if opts.make_iso:
work_dir = tempfile.mkdtemp()
log.info("working dir is {0}".format(work_dir))
log.info("working dir is %s", work_dir)
if (opts.fs_image or opts.no_virt) and not opts.disk_image:
# Create iso from a filesystem image
@ -438,7 +438,7 @@ if __name__ == '__main__':
opts.vcpus, opts.arch, opts.title, opts.project, opts.releasever)
elif opts.make_pxe_live:
work_dir = tempfile.mkdtemp()
log.info("working dir is {0}".format(work_dir))
log.info("working dir is %s", work_dir)
if (opts.fs_image or opts.no_virt) and not opts.disk_image:
# Create pxe live images from a filesystem image
@ -472,12 +472,11 @@ if __name__ == '__main__':
log.info("SUMMARY")
log.info("-------")
log.info("Logs are in {0}".format(os.path.abspath(os.path.dirname(opts.logfile))))
log.info("Logs are in %s", os.path.abspath(os.path.dirname(opts.logfile)))
if disk_img:
log.info("Disk image is at {0}".format(disk_img))
log.info("Disk image is at %s", disk_img)
if opts.make_appliance:
log.info("Appliance description is in {0}".format(opts.app_file))
log.info("Results are in {0}".format(opts.result_dir or result_dir))
log.info("Appliance description is in %s", opts.app_file)
log.info("Results are in %s", opts.result_dir or result_dir)
sys.exit( 0 )