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:
parent
8ff851c6f5
commit
c74582a647
@ -62,7 +62,7 @@ def compress(command, rootdir, outfile, compression="xz", compressargs=None):
|
|||||||
archive = Popen(command, stdin=find.stdout, stdout=PIPE, cwd=rootdir)
|
archive = Popen(command, stdin=find.stdout, stdout=PIPE, cwd=rootdir)
|
||||||
comp = Popen([compression] + compressargs,
|
comp = Popen([compression] + compressargs,
|
||||||
stdin=archive.stdout, stdout=open(outfile, "wb"))
|
stdin=archive.stdout, stdout=open(outfile, "wb"))
|
||||||
comp.wait()
|
(_stdout, _stderr) = comp.communicate()
|
||||||
return comp.returncode
|
return comp.returncode
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
@ -308,6 +308,18 @@ def estimate_size(rootdir, graft=None, fstype=None, blocksize=4096, overhead=128
|
|||||||
total = max(256*1024*1024, total) # btrfs minimum size: 256MB
|
total = max(256*1024*1024, total) # btrfs minimum size: 256MB
|
||||||
return total
|
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 ##############
|
######## Execution contexts - use with the 'with' statement ##############
|
||||||
|
|
||||||
class LoopDev(object):
|
class LoopDev(object):
|
||||||
|
@ -288,11 +288,13 @@ def novirt_install(opts, disk_img, disk_size, repo_url):
|
|||||||
else:
|
else:
|
||||||
# If anaconda failed the disk image may still be in use by dm
|
# If anaconda failed the disk image may still be in use by dm
|
||||||
execWithRedirect("anaconda-cleanup", [])
|
execWithRedirect("anaconda-cleanup", [])
|
||||||
dm_name = os.path.splitext(os.path.basename(disk_img))[0]
|
|
||||||
dm_path = "/dev/mapper/"+dm_name
|
if disk_img:
|
||||||
if os.path.exists(dm_path):
|
dm_name = os.path.splitext(os.path.basename(disk_img))[0]
|
||||||
dm_detach(dm_path)
|
dm_path = "/dev/mapper/"+dm_name
|
||||||
loop_detach(get_loop_name(disk_img))
|
if os.path.exists(dm_path):
|
||||||
|
dm_detach(dm_path)
|
||||||
|
loop_detach(get_loop_name(disk_img))
|
||||||
|
|
||||||
if selinux_enforcing:
|
if selinux_enforcing:
|
||||||
selinux.security_setenforce(1)
|
selinux.security_setenforce(1)
|
||||||
@ -307,6 +309,7 @@ def novirt_install(opts, disk_img, disk_size, repo_url):
|
|||||||
|
|
||||||
rc = mktar(ROOT_PATH, disk_img, opts.compression, compress_args)
|
rc = mktar(ROOT_PATH, disk_img, opts.compression, compress_args)
|
||||||
shutil.rmtree(ROOT_PATH)
|
shutil.rmtree(ROOT_PATH)
|
||||||
|
log.info("tar finished with rc=%d", rc)
|
||||||
|
|
||||||
if rc:
|
if rc:
|
||||||
raise InstallError("novirt_install failed")
|
raise InstallError("novirt_install failed")
|
||||||
|
@ -36,7 +36,7 @@ from pylorax import vernum
|
|||||||
from pylorax.creator import DRACUT_DEFAULT, mount_boot_part_over_root
|
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_appliance, make_image, make_livecd, make_live_images
|
||||||
from pylorax.creator import make_runtime, make_squashfs
|
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.imgutils import Mount, PartitionMount, umount
|
||||||
from pylorax.installer import InstallError
|
from pylorax.installer import InstallError
|
||||||
from pylorax.sysutils import joinpaths
|
from pylorax.sysutils import joinpaths
|
||||||
@ -223,19 +223,6 @@ def setup_logging(opts):
|
|||||||
program_log.addHandler(fh)
|
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():
|
def main():
|
||||||
# parse the arguments
|
# parse the arguments
|
||||||
parser = lorax_parser()
|
parser = lorax_parser()
|
||||||
|
Loading…
Reference in New Issue
Block a user