Skip to content

Commit

Permalink
creator: Select compression type based on rootfs type
Browse files Browse the repository at this point in the history
squashfs and erofs have different options. This changes the cmdline
default to None and uses a couple of functions to determine the defaults
to use when nothing has been set.

TODO cleanup use of opts.compression that assume it is not None.
  • Loading branch information
bcl committed Jun 28, 2024
1 parent 8483d7e commit a94dba2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/pylorax/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ def lmc_parser(dracut_default=""):
help="Create qcow2 image instead of raw sparse image when making disk images.")
image_group.add_argument("--qcow2-arg", action="append", dest="qemu_args", default=[],
help="Arguments to pass to qemu-img. Pass once for each argument, they will be used for ALL calls to qemu-img.")
image_group.add_argument("--compression", default="xz",
help="Compression binary for make-tar. xz, lzma, gzip, and bzip2 are supported. xz is the default.")
image_group.add_argument("--compression", default=None,
help="Compression type. Depends on whether squashfs or erofs are being used. See manpages for mksquashfs or mkfs.erofs for details.")
image_group.add_argument("--compress-arg", action="append", dest="compress_args", default=[],
help="Arguments to pass to compression. Pass once for each argument")
# Group of arguments for appliance creation
Expand Down
20 changes: 18 additions & 2 deletions src/pylorax/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ def squashfs_args(opts):
compressargs = []
return (compression, compressargs)

def erofs_args(opts):
""" Returns the compression type and args to use when making erofs
:param opts: ArgumentParser object with compression and compressopts
:returns: tuple of compression type and args
:rtype: tuple
"""
compression = opts.compression or "lzma"
compressargs = []
if opts.compress_args:
for arg in opts.compress_args:
compressargs += arg.split(" ", 1)
return (compression, compressargs)

def dracut_args(opts):
"""Return a list of the args to pass to dracut
Expand Down Expand Up @@ -219,21 +233,23 @@ def make_runtime(opts, mount_dir, work_dir, size=None):
variant=opts.variant, bugurl=opts.bugurl, isfinal=opts.isfinal)

rb = RuntimeBuilder(product, arch, skip_branding=True, root=mount_dir)
compression, compressargs = squashfs_args(opts)

if opts.rootfs_type == "squashfs":
log.info("Creating a squashfs only runtime")
compression, compressargs = squashfs_args(opts)
return rb.create_squashfs_runtime(joinpaths(work_dir, RUNTIME), size=size,
compression=compression, compressargs=compressargs)
elif opts.rootfs_type == "squashfs-ext4":
log.info("Creating a squashfs+ext4 runtime")
compression, compressargs = squashfs_args(opts)
return rb.create_ext4_runtime(joinpaths(work_dir, RUNTIME), size=size,
compression=compression, compressargs=compressargs)
elif opts.rootfs_type == "erofs":
log.info("Creating a erofs only runtime")
compression, compressargs = erofs_args(opts)
return rb.create_erofs_runtime(joinpaths(work_dir, RUNTIME), size=size)
elif opts.rootfs_type == "erofs-ext4":
log.info("Creating a erofs+ext4 runtime")
compression, compressargs = erofs_args(opts)
return rb.create_erofs_ext4_runtime(joinpaths(work_dir, RUNTIME), size=size)
else:
raise RuntimeError(f"{opts.rootfs_type} is not a supported type for the root filesystem")
Expand Down

0 comments on commit a94dba2

Please sign in to comment.