Add --dracut-conf cmdline argument to lorax and livemedia-creator
This adds the ability to use a dracut.conf file instead of passing --dracut-arg on the cmdline multiple times.
This commit is contained in:
parent
a60cef3e1e
commit
a0fce98109
@ -236,7 +236,9 @@ def make_compose(cfg, results_dir):
|
|||||||
|
|
||||||
cfg_dict["lorax_templates"] = find_templates(cfg.share_dir)
|
cfg_dict["lorax_templates"] = find_templates(cfg.share_dir)
|
||||||
cfg_dict["tmp"] = cfg.tmp
|
cfg_dict["tmp"] = cfg.tmp
|
||||||
cfg_dict["dracut_args"] = None # Use default args for dracut
|
# Use default args for dracut
|
||||||
|
cfg_dict["dracut_conf"] = None
|
||||||
|
cfg_dict["dracut_args"] = None
|
||||||
|
|
||||||
# TODO How to support other arches?
|
# TODO How to support other arches?
|
||||||
cfg_dict["arch"] = None
|
cfg_dict["arch"] = None
|
||||||
|
@ -113,12 +113,15 @@ def lorax_parser(dracut_default=""):
|
|||||||
help="Use a plain squashfs filesystem for the runtime.")
|
help="Use a plain squashfs filesystem for the runtime.")
|
||||||
|
|
||||||
# dracut arguments
|
# dracut arguments
|
||||||
dracut_group = parser.add_argument_group("dracut arguments")
|
dracut_group = parser.add_argument_group("dracut arguments: (default: %s)" % dracut_default)
|
||||||
|
dracut_group.add_argument("--dracut-conf",
|
||||||
|
help="Path to a dracut.conf file to use instead of the "
|
||||||
|
"default arguments. See the dracut.conf(5) manpage.")
|
||||||
dracut_group.add_argument("--dracut-arg", action="append", dest="dracut_args",
|
dracut_group.add_argument("--dracut-arg", action="append", dest="dracut_args",
|
||||||
help="Argument to pass to dracut when "
|
help="Argument to pass to dracut when "
|
||||||
"rebuilding the initramfs. Pass this "
|
"rebuilding the initramfs. Pass this "
|
||||||
"once for each argument. NOTE: this "
|
"once for each argument. NOTE: this "
|
||||||
"overrides the default. (default: %s)" % dracut_default)
|
"overrides the defaults.")
|
||||||
|
|
||||||
# add the show version option
|
# add the show version option
|
||||||
parser.add_argument("-V", help="show program's version number and exit",
|
parser.add_argument("-V", help="show program's version number and exit",
|
||||||
@ -268,12 +271,15 @@ def lmc_parser(dracut_default=""):
|
|||||||
help="RNG device for QEMU (none for no RNG)")
|
help="RNG device for QEMU (none for no RNG)")
|
||||||
|
|
||||||
# dracut arguments
|
# dracut arguments
|
||||||
dracut_group = parser.add_argument_group("dracut arguments")
|
dracut_group = parser.add_argument_group("dracut arguments: (default: %s)" % dracut_default)
|
||||||
|
dracut_group.add_argument("--dracut-conf",
|
||||||
|
help="Path to a dracut.conf file to use instead of the "
|
||||||
|
"default arguments. See the dracut.conf(5) manpage.")
|
||||||
dracut_group.add_argument("--dracut-arg", action="append", dest="dracut_args",
|
dracut_group.add_argument("--dracut-arg", action="append", dest="dracut_args",
|
||||||
help="Argument to pass to dracut when "
|
help="Argument to pass to dracut when "
|
||||||
"rebuilding the initramfs. Pass this "
|
"rebuilding the initramfs. Pass this "
|
||||||
"once for each argument. NOTE: this "
|
"once for each argument. NOTE: this "
|
||||||
"overrides the default. (default: %s)" % dracut_default)
|
"overrides the defaults.")
|
||||||
|
|
||||||
# pxe to live arguments
|
# pxe to live arguments
|
||||||
pxelive_group = parser.add_argument_group("pxe to live arguments")
|
pxelive_group = parser.add_argument_group("pxe to live arguments")
|
||||||
|
@ -47,7 +47,7 @@ from pylorax.treebuilder import findkernels
|
|||||||
from pylorax.sysutils import joinpaths, remove
|
from pylorax.sysutils import joinpaths, remove
|
||||||
|
|
||||||
|
|
||||||
# Default parameters for rebuilding initramfs, override with --dracut-args
|
# Default parameters for rebuilding initramfs, override with --dracut-arg or --dracut-conf
|
||||||
DRACUT_DEFAULT = ["--xz", "--add", "livenet dmsquash-live dmsquash-live-ntfs convertfs pollcdrom qemu qemu-net",
|
DRACUT_DEFAULT = ["--xz", "--add", "livenet dmsquash-live dmsquash-live-ntfs convertfs pollcdrom qemu qemu-net",
|
||||||
"--omit", "plymouth", "--no-hostonly", "--debug", "--no-early-microcode"]
|
"--omit", "plymouth", "--no-hostonly", "--debug", "--no-early-microcode"]
|
||||||
|
|
||||||
@ -131,6 +131,21 @@ def squashfs_args(opts):
|
|||||||
compressargs = []
|
compressargs = []
|
||||||
return (compression, compressargs)
|
return (compression, compressargs)
|
||||||
|
|
||||||
|
def dracut_args(opts):
|
||||||
|
"""Return a list of the args to pass to dracut
|
||||||
|
|
||||||
|
Return the default argument list unless one of the dracut cmdline arguments
|
||||||
|
has been used.
|
||||||
|
"""
|
||||||
|
if opts.dracut_conf:
|
||||||
|
return ["--conf", opts.dracut_conf]
|
||||||
|
elif opts.dracut_args:
|
||||||
|
args = []
|
||||||
|
for arg in opts.dracut_args:
|
||||||
|
args += arg.split(" ", 1)
|
||||||
|
return args
|
||||||
|
else:
|
||||||
|
return DRACUT_DEFAULT
|
||||||
|
|
||||||
def make_appliance(disk_img, name, template, outfile, networks=None, ram=1024,
|
def make_appliance(disk_img, name, template, outfile, networks=None, ram=1024,
|
||||||
vcpus=1, arch=None, title="Linux", project="Linux",
|
vcpus=1, arch=None, title="Linux", project="Linux",
|
||||||
@ -223,15 +238,10 @@ def rebuild_initrds_for_live(opts, sys_root_dir, results_dir):
|
|||||||
:param str sys_root_dir: Path to root of the system
|
:param str sys_root_dir: Path to root of the system
|
||||||
:param str results_dir: Path of directory for storing results
|
:param str results_dir: Path of directory for storing results
|
||||||
"""
|
"""
|
||||||
if not opts.dracut_args:
|
# cmdline dracut args override the defaults, but need to be parsed
|
||||||
dracut_args = DRACUT_DEFAULT
|
log.info("dracut args = %s", dracut_args(opts))
|
||||||
else:
|
|
||||||
dracut_args = []
|
|
||||||
for arg in opts.dracut_args:
|
|
||||||
dracut_args += arg.split(" ", 1)
|
|
||||||
log.info("dracut args = %s", dracut_args)
|
|
||||||
|
|
||||||
dracut = ["dracut", "--nomdadmconf", "--nolvmconf"] + dracut_args
|
dracut = ["dracut", "--nomdadmconf", "--nolvmconf"] + dracut_args(opts)
|
||||||
|
|
||||||
kdir = "boot"
|
kdir = "boot"
|
||||||
if opts.ostree:
|
if opts.ostree:
|
||||||
@ -367,14 +377,8 @@ def make_livecd(opts, mount_dir, work_dir):
|
|||||||
templatedir=joinpaths(opts.lorax_templates,"live/"),
|
templatedir=joinpaths(opts.lorax_templates,"live/"),
|
||||||
extra_boot_args=opts.extra_boot_args)
|
extra_boot_args=opts.extra_boot_args)
|
||||||
log.info("Rebuilding initrds")
|
log.info("Rebuilding initrds")
|
||||||
if not opts.dracut_args:
|
log.info("dracut args = %s", dracut_args(opts))
|
||||||
dracut_args = DRACUT_DEFAULT
|
tb.rebuild_initrds(add_args=dracut_args(opts))
|
||||||
else:
|
|
||||||
dracut_args = []
|
|
||||||
for arg in opts.dracut_args:
|
|
||||||
dracut_args += arg.split(" ", 1)
|
|
||||||
log.info("dracut args = %s", dracut_args)
|
|
||||||
tb.rebuild_initrds(add_args=dracut_args)
|
|
||||||
log.info("Building boot.iso")
|
log.info("Building boot.iso")
|
||||||
tb.build()
|
tb.build()
|
||||||
|
|
||||||
|
@ -148,6 +148,9 @@ def main():
|
|||||||
if os.getuid() != 0:
|
if os.getuid() != 0:
|
||||||
errors.append("You need to run this as root")
|
errors.append("You need to run this as root")
|
||||||
|
|
||||||
|
if opts.dracut_args and opts.dracut_conf:
|
||||||
|
errors.append("argument --dracut-arg: not allowed with argument --dracut-conf")
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
list(log.error(e) for e in errors)
|
list(log.error(e) for e in errors)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -111,6 +111,10 @@ def main():
|
|||||||
parser.error("sharedir %s doesn't exist." % opts.sharedir)
|
parser.error("sharedir %s doesn't exist." % opts.sharedir)
|
||||||
if opts.config and not os.path.exists(opts.config):
|
if opts.config and not os.path.exists(opts.config):
|
||||||
parser.error("config file %s doesn't exist." % opts.config)
|
parser.error("config file %s doesn't exist." % opts.config)
|
||||||
|
if opts.dracut_args and opts.dracut_conf:
|
||||||
|
parser.error("argument --dracut-arg: not allowed with argument --dracut-conf")
|
||||||
|
if opts.dracut_conf and not os.path.exists(opts.dracut_conf):
|
||||||
|
parser.error("dracut config file %s doesn't exist." % opts.dracut_conf)
|
||||||
|
|
||||||
setup_logging(opts)
|
setup_logging(opts)
|
||||||
log.debug(opts)
|
log.debug(opts)
|
||||||
@ -191,6 +195,12 @@ def main():
|
|||||||
with open(lorax.conf.get("lorax", "logdir") + '/lorax.conf', 'w') as f:
|
with open(lorax.conf.get("lorax", "logdir") + '/lorax.conf', 'w') as f:
|
||||||
lorax.conf.write(f)
|
lorax.conf.write(f)
|
||||||
|
|
||||||
|
# Use a dracut config file instead of the default arguments
|
||||||
|
if opts.dracut_conf:
|
||||||
|
user_dracut_args = ["--conf %s" % opts.dracut_conf]
|
||||||
|
else:
|
||||||
|
user_dracut_args = opts.dracut_args
|
||||||
|
|
||||||
lorax.run(dnfbase, opts.product, opts.version, opts.release,
|
lorax.run(dnfbase, opts.product, opts.version, opts.release,
|
||||||
opts.variant, opts.bugurl, opts.isfinal,
|
opts.variant, opts.bugurl, opts.isfinal,
|
||||||
workdir=tempdir, outputdir=opts.outputdir, buildarch=opts.buildarch,
|
workdir=tempdir, outputdir=opts.outputdir, buildarch=opts.buildarch,
|
||||||
@ -202,7 +212,7 @@ def main():
|
|||||||
add_arch_templates=opts.add_arch_templates,
|
add_arch_templates=opts.add_arch_templates,
|
||||||
add_arch_template_vars=parsed_add_arch_template_vars,
|
add_arch_template_vars=parsed_add_arch_template_vars,
|
||||||
remove_temp=True, verify=opts.verify,
|
remove_temp=True, verify=opts.verify,
|
||||||
user_dracut_args=opts.dracut_args,
|
user_dracut_args=user_dracut_args,
|
||||||
squashfs_only=opts.squashfs_only)
|
squashfs_only=opts.squashfs_only)
|
||||||
|
|
||||||
# Release the lock on the tempdir
|
# Release the lock on the tempdir
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Copyright (C) 2018 Red Hat, Inc.
|
# Copyright (C) 2018-2020 Red Hat, Inc.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -17,6 +17,7 @@
|
|||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
from unittest import mock
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
# For kickstart check tests
|
# For kickstart check tests
|
||||||
@ -27,8 +28,8 @@ from ..lib import get_file_magic
|
|||||||
from pylorax import find_templates
|
from pylorax import find_templates
|
||||||
from pylorax.base import DataHolder
|
from pylorax.base import DataHolder
|
||||||
from pylorax.creator import FakeDNF, create_pxe_config, make_appliance, make_runtime, squashfs_args
|
from pylorax.creator import FakeDNF, create_pxe_config, make_appliance, make_runtime, squashfs_args
|
||||||
from pylorax.creator import calculate_disk_size
|
from pylorax.creator import calculate_disk_size, dracut_args, DRACUT_DEFAULT
|
||||||
from pylorax.creator import get_arch, find_ostree_root, check_kickstart
|
from pylorax.creator import get_arch, find_ostree_root, check_kickstart, make_livecd
|
||||||
from pylorax.executils import runcmd_output
|
from pylorax.executils import runcmd_output
|
||||||
from pylorax.sysutils import joinpaths
|
from pylorax.sysutils import joinpaths
|
||||||
|
|
||||||
@ -68,6 +69,21 @@ class CreatorTest(unittest.TestCase):
|
|||||||
opts = DataHolder(compression="xz", compress_args=["-X32767", "-Xbcj x86"], arch="x86_64")
|
opts = DataHolder(compression="xz", compress_args=["-X32767", "-Xbcj x86"], arch="x86_64")
|
||||||
self.assertEqual(squashfs_args(opts), ("xz", ["-X32767", "-Xbcj", "x86"]), (opts, squashfs_args(opts)))
|
self.assertEqual(squashfs_args(opts), ("xz", ["-X32767", "-Xbcj", "x86"]), (opts, squashfs_args(opts)))
|
||||||
|
|
||||||
|
def test_dracut_args(self):
|
||||||
|
"""Test dracut_args results"""
|
||||||
|
|
||||||
|
# Use default args
|
||||||
|
opts = DataHolder(dracut_args=None, dracut_conf=None)
|
||||||
|
self.assertEqual(dracut_args(opts), DRACUT_DEFAULT)
|
||||||
|
|
||||||
|
# Use a config file from --dracut-conf
|
||||||
|
opts = DataHolder(dracut_args=None, dracut_conf="/var/tmp/project/lmc-dracut.conf")
|
||||||
|
self.assertEqual(dracut_args(opts), ["--conf", "/var/tmp/project/lmc-dracut.conf"])
|
||||||
|
|
||||||
|
# Use --dracut-arg
|
||||||
|
opts = DataHolder(dracut_args=["--xz", "--omit plymouth", "--add livenet dmsquash-live dmsquash-live-ntfs"], dracut_conf=None)
|
||||||
|
self.assertEqual(dracut_args(opts), ["--xz", "--omit", "plymouth", "--add", "livenet dmsquash-live dmsquash-live-ntfs"])
|
||||||
|
|
||||||
def test_make_appliance(self):
|
def test_make_appliance(self):
|
||||||
"""Test creating the appliance description XML file"""
|
"""Test creating the appliance description XML file"""
|
||||||
lorax_templates = find_templates("./share/")
|
lorax_templates = find_templates("./share/")
|
||||||
@ -365,3 +381,34 @@ class CreatorTest(unittest.TestCase):
|
|||||||
"""Test the mount_boot_part_over_root ostree function"""
|
"""Test the mount_boot_part_over_root ostree function"""
|
||||||
# Make a fake disk image with a / and a /boot/loader.0
|
# Make a fake disk image with a / and a /boot/loader.0
|
||||||
# Mount the / partition
|
# Mount the / partition
|
||||||
|
|
||||||
|
def test_make_livecd_dracut(self):
|
||||||
|
"""Test the make_livecd function with dracut options"""
|
||||||
|
with tempfile.TemporaryDirectory(prefix="lorax.test.") as tmpdir:
|
||||||
|
# Make a fake kernel and initrd
|
||||||
|
mkFakeBoot(joinpaths(tmpdir, "mount_dir"))
|
||||||
|
os.makedirs(joinpaths(tmpdir, "mount_dir/tmp/config_files"))
|
||||||
|
|
||||||
|
lorax_templates = os.path.abspath(find_templates("./share/"))
|
||||||
|
with mock.patch('pylorax.treebuilder.TreeBuilder.build'):
|
||||||
|
with mock.patch('pylorax.treebuilder.TreeBuilder.rebuild_initrds') as ri:
|
||||||
|
# Test with no dracut args
|
||||||
|
opts = DataHolder(project="Fedora", releasever="32", lorax_templates=lorax_templates, volid=None,
|
||||||
|
domacboot=False, extra_boot_args="", dracut_args=None, dracut_conf=None)
|
||||||
|
make_livecd(opts, joinpaths(tmpdir, "mount_dir"), joinpaths(tmpdir, "work_dir"))
|
||||||
|
ri.assert_called_with(add_args=DRACUT_DEFAULT)
|
||||||
|
|
||||||
|
# Test with --dracut-arg
|
||||||
|
opts = DataHolder(project="Fedora", releasever="32", lorax_templates=lorax_templates, volid=None,
|
||||||
|
domacboot=False, extra_boot_args="",
|
||||||
|
dracut_args=["--xz", "--omit plymouth", "--add livenet dmsquash-live dmsquash-live-ntfs"], dracut_conf=None)
|
||||||
|
make_livecd(opts, joinpaths(tmpdir, "mount_dir"), joinpaths(tmpdir, "work_dir"))
|
||||||
|
ri.assert_called_with(add_args=["--xz", "--omit", "plymouth", "--add", "livenet dmsquash-live dmsquash-live-ntfs"])
|
||||||
|
|
||||||
|
|
||||||
|
# Test with --dracut-conf
|
||||||
|
opts = DataHolder(project="Fedora", releasever="32", lorax_templates=lorax_templates, volid=None,
|
||||||
|
domacboot=False, extra_boot_args="", dracut_args=None,
|
||||||
|
dracut_conf="/var/tmp/project/lmc-dracut.conf")
|
||||||
|
make_livecd(opts, joinpaths(tmpdir, "mount_dir"), joinpaths(tmpdir, "work_dir"))
|
||||||
|
ri.assert_called_with(add_args=["--conf", "/var/tmp/project/lmc-dracut.conf"])
|
||||||
|
Loading…
Reference in New Issue
Block a user