From 2cc251c3f14e7cb80c7a6127cb9a0a14d18d8b88 Mon Sep 17 00:00:00 2001 From: Jiri Mencak Date: Wed, 27 Oct 2021 14:34:38 +0200 Subject: [PATCH] Add conditional profile loading Normally, inclusion of any profile that is not found in profile directories (/etc/tuned and /usr/lib/tuned) will fail at profile application time. Conditional profile loading can be useful in situations we do not necessarily expect a certain included profile to exist. Profile application failures are undesirable in such cases. Augment the TuneD profile hierarchies by adding a functionality to conditionally include a profile by prefixing its name by '-' symbol. Example: [main] summary=An example TuneD profile demonstrating conditional loading include=-profile1,profile2 In this example, the profile "profile1" is conditionally loaded/included and no error/failure will be reported if the profile does not exist. Then, the profile "profile2" is unconditionally loaded and errors will be reported if it is not found in profile directories. Signed-off-by: Jiri Mencak --- tuned/profiles/locator.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tuned/profiles/locator.py b/tuned/profiles/locator.py index 994bdfb..c250104 100644 --- a/tuned/profiles/locator.py +++ b/tuned/profiles/locator.py @@ -31,6 +31,10 @@ class Locator(object): def get_config(self, profile_name, skip_files=None): ret = None + conditional_load = profile_name[0:1] == "-" + if conditional_load: + profile_name = profile_name[1:] + for dir_name in reversed(self._load_directories): # basename is protection not to get out of the path config_file = self._get_config_filename(dir_name, os.path.basename(profile_name)) @@ -42,6 +46,9 @@ class Locator(object): if os.path.isfile(config_file): return config_file + if conditional_load and ret is None: + ret = "" + return ret def check_profile_name_format(self, profile_name):