1
0
Fork 0

Merge pull request #171 from TomasKorbar/improve_tdadm_recommend

Improve logging of tuned-adm recommend
This commit is contained in:
Jaroslav Škarvada 2019-03-21 22:47:06 +01:00 committed by GitHub
commit 4f2f46da85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -33,7 +33,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 = {}
@ -49,12 +53,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):
@ -67,8 +71,11 @@ 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):
self._commands.execute(["virt-what"])[1], re.S):
match = False
elif option == "system":
if not re.match(value,