1
0
Fork 0

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 <tkorbar@redhat.com>
This commit is contained in:
Tomas Korbar 2019-03-13 15:08:42 +01:00
parent cccbf6f11e
commit 4632629727

View file

@ -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