1
0
Fork 0

Merge pull request #428 from yarda/syspurpose-fix

recommend: do not ignore syspurpose_role if there is no syspurpose
This commit is contained in:
Jaroslav Škarvada 2022-06-30 15:33:37 +02:00 committed by GitHub
commit 70732a5796
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -56,6 +56,7 @@ class ProfileRecommender:
def process_config(self, fname, has_root=True):
matching_profile = None
syspurpose_error_logged = False
try:
if not os.path.isfile(fname):
return None
@ -97,11 +98,11 @@ class ProfileRecommender:
if not re.match(value, chassis_type, re.IGNORECASE):
match = False
elif option == "syspurpose_role":
role = ""
if have_syspurpose:
s = syspurpose.files.SyspurposeStore(
syspurpose.files.USER_SYSPURPOSE,
raise_on_error = True)
role = ""
try:
s.read_file()
role = s.contents["role"]
@ -109,11 +110,13 @@ class ProfileRecommender:
if hasattr(e, "errno") and e.errno != errno.ENOENT:
log.error("Failed to load the syspurpose\
file: %s" % e)
if re.match(value, role, re.IGNORECASE) is None:
match = False
else:
log.error("Failed to process 'syspurpose_role' in '%s'\
, the syspurpose module is not available" % fname)
if not syspurpose_error_logged:
log.error("Failed to process 'syspurpose_role' in '%s'\
, the syspurpose module is not available" % fname)
syspurpose_error_logged = True
if re.match(value, role, re.IGNORECASE) is None:
match = False
if match:
# remove the ",.*" suffix