1
0
Fork 0

bootloader: improved inheritance

Now it supports the following extended syntax:

parent profile:
[bootloader]
cmdline=opt1 opt2

child profile:
[bootloader]
cmdline1=+opt3
cmdline2=opt4
cmdline3=-opt2

Resulting cmdline:
opt1 opt3 opt4

It recognizes "cmdline*" and postprocess it to extend the inheritance.
It recognizes '+' and '-' on the very beginning of the option and adds
or removes the string from the command line. When using
'+' or '-' it takes the string after the sign till end of the line. To
add option starting with e.g. '+' you need to use '++opt'. If '+' is
omitted in succesive command lines, it's taken implicitly (e.g. opt4).

If you need to replace the whole command line in child profile, use:

[bootloader]
replace=true
cmdline=opt1 opt2

This will drop all 'cmdline*' setting from the parent profile(s).

Resolves: rhbz#1274464

Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
This commit is contained in:
Jaroslav Škarvada 2017-02-08 12:19:35 +01:00
parent e57df645ad
commit 66d550b94d

View file

@ -39,6 +39,37 @@ class BootloaderPlugin(base.Plugin):
"cmdline": "",
}
def _get_effective_options(self, options):
"""Merge provided options with plugin default options and merge all cmdline.* options."""
effective = self._get_config_options().copy()
cmdline_keys = []
for key in options:
if str(key).startswith("cmdline"):
cmdline_keys.append(key)
elif key in effective:
effective[key] = options[key]
else:
log.warn("Unknown option '%s' for plugin '%s'." % (key, self.__class__.__name__))
cmdline_keys.sort()
cmdline = ""
for key in cmdline_keys:
val = options[key]
if val is None or val == "":
continue
op = val[0]
vals = val[1:].strip()
if op == "+" and vals != "":
cmdline += " " + vals
elif op == "-" and vals != "":
regex = re.escape(vals)
cmdline = re.sub(r"(\A|\s)" + regex + r"(?=\Z|\s)", r"", cmdline)
else:
cmdline += " " + val
cmdline = cmdline.strip()
if cmdline != "":
effective["cmdline"] = cmdline
return effective
def _get_grub2_cfg_file(self):
for f in consts.GRUB2_CFG_FILES:
if os.path.exists(f):