From 66d550b94d6e7198043ea0c8379fa330da947a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Wed, 8 Feb 2017 12:19:35 +0100 Subject: [PATCH] bootloader: improved inheritance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- tuned/plugins/plugin_bootloader.py | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tuned/plugins/plugin_bootloader.py b/tuned/plugins/plugin_bootloader.py index 6f27677..8e2ae91 100644 --- a/tuned/plugins/plugin_bootloader.py +++ b/tuned/plugins/plugin_bootloader.py @@ -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):