diff --git a/src/pylorax/imgutils.py b/src/pylorax/imgutils.py index 86f7a6e8..8efe142b 100644 --- a/src/pylorax/imgutils.py +++ b/src/pylorax/imgutils.py @@ -62,7 +62,7 @@ def compress(command, rootdir, outfile, compression="xz", compressargs=None): archive = Popen(command, stdin=find.stdout, stdout=PIPE, cwd=rootdir) comp = Popen([compression] + compressargs, stdin=archive.stdout, stdout=open(outfile, "wb")) - comp.wait() + (_stdout, _stderr) = comp.communicate() return comp.returncode except OSError as e: logger.error(e) @@ -329,6 +329,18 @@ def estimate_size(rootdir, graft=None, fstype=None, blocksize=4096, overhead=128 total = max(256*1024*1024, total) # btrfs minimum size: 256MB return total +def default_image_name(compression, basename): + """ Return a default image name with the correct suffix for the compression type. + + :param str compression: Compression type + :param str basename: Base filename + :returns: basename with compression suffix + + If the compression is unknown it defaults to xz + """ + SUFFIXES = {"xz": ".xz", "gzip": ".gz", "bzip2": ".bz2", "lzma": ".lzma"} + return basename + SUFFIXES.get(compression, ".xz") + ######## Execution contexts - use with the 'with' statement ############## class LoopDev(object): diff --git a/src/pylorax/installer.py b/src/pylorax/installer.py index ab393036..9b76e213 100644 --- a/src/pylorax/installer.py +++ b/src/pylorax/installer.py @@ -303,11 +303,13 @@ def novirt_install(opts, disk_img, disk_size, repo_url): else: # If anaconda failed the disk image may still be in use by dm execWithRedirect("anaconda-cleanup", []) - dm_name = os.path.splitext(os.path.basename(disk_img))[0] - dm_path = "/dev/mapper/"+dm_name - if os.path.exists(dm_path): - dm_detach(dm_path) - loop_detach(get_loop_name(disk_img)) + + if disk_img: + dm_name = os.path.splitext(os.path.basename(disk_img))[0] + dm_path = "/dev/mapper/"+dm_name + if os.path.exists(dm_path): + dm_detach(dm_path) + loop_detach(get_loop_name(disk_img)) if selinux_enforcing: selinux.security_setenforce(1) @@ -322,6 +324,7 @@ def novirt_install(opts, disk_img, disk_size, repo_url): rc = mktar(ROOT_PATH, disk_img, opts.compression, compress_args) shutil.rmtree(ROOT_PATH) + log.info("tar finished with rc=%d", rc) if rc: raise InstallError("novirt_install failed") diff --git a/src/sbin/livemedia-creator b/src/sbin/livemedia-creator index fb23d33f..2ec93d93 100755 --- a/src/sbin/livemedia-creator +++ b/src/sbin/livemedia-creator @@ -36,7 +36,7 @@ from pylorax import vernum from pylorax.creator import DRACUT_DEFAULT, mount_boot_part_over_root from pylorax.creator import make_appliance, make_image, make_livecd, make_live_images from pylorax.creator import make_runtime, make_squashfs -from pylorax.imgutils import copytree +from pylorax.imgutils import copytree, default_image_name from pylorax.imgutils import Mount, PartitionMount, umount from pylorax.installer import InstallError from pylorax.sysutils import joinpaths @@ -226,19 +226,6 @@ def setup_logging(opts): program_log.addHandler(fh) -def default_image_name(compression, basename): - """ Return a default image name with the correct suffix for the compression type. - - :param str compression: Compression type - :param str basename: Base filename - :returns: basename with compression suffix - - If the compression is unknown it defaults to xz - """ - SUFFIXES = {"xz": ".xz", "gzip": ".gz", "bzip2": ".bz2", "lzma": ".lzma"} - return basename + SUFFIXES.get(compression, ".xz") - - def main(): # parse the arguments parser = lorax_parser()