Change compress to use communicate instead of wait

Also move default_image_name into imgutils so it can be used in other
places.

When running from lorax-composer the wait() call wasn't waiting until
the tar was finished. I think this is due to gevent monkey-patching
something. Using communicate() solves this problem.
This commit is contained in:
Brian C. Lane 2018-01-18 13:41:40 -08:00
parent ea4f9ed615
commit 0ce4197a1e
3 changed files with 22 additions and 20 deletions

View File

@ -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):

View File

@ -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")

View File

@ -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()