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
							
								
									ea4f9ed615
								
							
						
					
					
						commit
						0ce4197a1e
					
				| @ -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): | ||||
|  | ||||
| @ -303,6 +303,8 @@ 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", []) | ||||
| 
 | ||||
|         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): | ||||
| @ -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") | ||||
|  | ||||
| @ -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() | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user