From cccbf6f11e4c5c105ca1047673f63342a20953b3 Mon Sep 17 00:00:00 2001 From: Tomas Korbar Date: Wed, 13 Mar 2019 14:45:15 +0100 Subject: [PATCH 1/2] Fix typo in profile_recommender Execute method from Commands class takes array of strings as arguments to execute not a name of executable. This caused bad format of logged error message in case of failure of execute method. Signed-off-by: Tomas Korbar --- tuned/utils/profile_recommender.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tuned/utils/profile_recommender.py b/tuned/utils/profile_recommender.py index 6ab97a5..df27184 100644 --- a/tuned/utils/profile_recommender.py +++ b/tuned/utils/profile_recommender.py @@ -67,7 +67,7 @@ class ProfileRecommender: value = r"^$" if option == "virt": if not re.match(value, - self._commands.execute("virt-what")[1], re.S): + self._commands.execute(["virt-what"])[1], re.S): match = False elif option == "system": if not re.match(value, From 4632629727c0ea3edf766f7448318069ff540589 Mon Sep 17 00:00:00 2001 From: Tomas Korbar Date: Wed, 13 Mar 2019 15:08:42 +0100 Subject: [PATCH 2/2] Add log of warning to profile recommenders parser of virt condition When profile recommender is executed without root privileges than he can not execute virt-what to determine virt conditions in recommend.d files. This caused several error messages which could be confusing for user. Add log of warning about this to profile recommender so user knows exactly what is happening and why profiles with virt recommendation condition are ommited from recommendation process when user has not root privileges. Behaviour of recommend process has not been changed. Signed-off-by: Tomas Korbar --- tuned/utils/profile_recommender.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tuned/utils/profile_recommender.py b/tuned/utils/profile_recommender.py index df27184..f6d77e2 100644 --- a/tuned/utils/profile_recommender.py +++ b/tuned/utils/profile_recommender.py @@ -32,7 +32,11 @@ class ProfileRecommender: profile = consts.DEFAULT_PROFILE if hardcoded: return profile - matching = self.process_config(consts.RECOMMEND_CONF_FILE) + has_root = os.geteuid() == 0 + if not has_root: + log.warning("Profile recommender is running without root privileges. Profiles with virt recommendation condition will be omitted.") + matching = self.process_config(consts.RECOMMEND_CONF_FILE, + has_root=has_root) if matching is not None: return matching files = {} @@ -48,12 +52,12 @@ class ProfileRecommender: files[name] = path for name in sorted(files.keys()): path = files[name] - matching = self.process_config(path) + matching = self.process_config(path, has_root=has_root) if matching is not None: return matching return profile - def process_config(self, fname): + def process_config(self, fname, has_root=True): matching_profile = None try: if not os.path.isfile(fname): @@ -66,6 +70,9 @@ class ProfileRecommender: if value == "": value = r"^$" if option == "virt": + if not has_root: + match = False + break if not re.match(value, self._commands.execute(["virt-what"])[1], re.S): match = False