1
0
mirror of https://pagure.io/fedora-qa/os-autoinst-distri-fedora.git synced 2025-09-01 03:55:53 +00:00

Allow nested ProfileGroups

OK, this is getting kinda close to over-engineering, but what
the heck. With this, a profile group can contain another profile
group. There is no infinite recursion protection yet.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
This commit is contained in:
Adam Williamson 2025-05-15 16:40:11 -07:00
parent 4781fc28ce
commit 900629606b
3 changed files with 23 additions and 5 deletions

View File

@ -222,6 +222,22 @@ def merge_inputs(inputs, validate=False, clean=False):
return (machines, flavors, products, profiles, pgroups, testsuites, jobtemplates) return (machines, flavors, products, profiles, pgroups, testsuites, jobtemplates)
def recurse_pgroup(pgroup, baseprio, pgroups, seen):
"""Recursion handler allowing nested profile groups. Takes the
top-level profile group name and priority, the full ProfileGroups
dict, and a set for infinite recursion checking.
"""
profiles = {}
for (item, prio) in pgroups[pgroup].items():
if item in seen:
sys.exit(f"Infinite recursion between profile groups {pgroup} and {item}")
seen.add(item)
if item in pgroups:
profiles.update(recurse_pgroup(item, prio+baseprio, pgroups, seen))
else:
profiles[item] = prio+baseprio
return profiles
def generate_job_templates(products, profiles, pgroups, testsuites): def generate_job_templates(products, profiles, pgroups, testsuites):
"""Given machines, products, profiles and testsuites (after """Given machines, products, profiles and testsuites (after
merging and handling of flavors, but still in intermediate format), merging and handling of flavors, but still in intermediate format),
@ -231,10 +247,7 @@ def generate_job_templates(products, profiles, pgroups, testsuites):
for (name, suite) in testsuites.items(): for (name, suite) in testsuites.items():
suiteprofs = {} suiteprofs = {}
for (pgroup, baseprio) in suite.get('profile_groups', {}).items(): for (pgroup, baseprio) in suite.get('profile_groups', {}).items():
if pgroup not in pgroups: suiteprofs.update(recurse_pgroup(pgroup, baseprio, pgroups, set()))
sys.exit(f"Error: profile group {pgroup} does not exist!")
for (gotprof, pprio) in pgroups[pgroup].items():
suiteprofs[gotprof] = pprio+baseprio
suiteprofs.update(suite.get('profiles', {})) suiteprofs.update(suite.get('profiles', {}))
if not suiteprofs: if not suiteprofs:
print("Warning: no profiles for test suite {}".format(name)) print("Warning: no profiles for test suite {}".format(name))

View File

@ -67,7 +67,7 @@
}, },
"ProfileGroups": { "ProfileGroups": {
"fedora-server-2arch": { "fedora-server-2arch": {
"fedora-Server-dvd-iso-ppc64le-*-ppc64le": 0, "fedora-server-1arch": 0,
"fedora-Server-dvd-iso-x86_64-*-64bit": 1 "fedora-Server-dvd-iso-x86_64-*-64bit": 1
}, },
"fedora-server-1arch": { "fedora-server-1arch": {

View File

@ -129,6 +129,11 @@ def test_generate_job_templates():
assert len(aboots) == 4 assert len(aboots) == 4
assert {t['machine_name'] for t in aboots} == {'ppc64le', '64bit'} assert {t['machine_name'] for t in aboots} == {'ppc64le', '64bit'}
# test the recursion check
pgroups['fedora-server-1arch']['fedora-server-2arch'] = 0
with pytest.raises(SystemExit, match=r"^Infinite recursion.*"):
templates = fifloader.generate_job_templates(products, profiles, pgroups, testsuites)
def test_reverse_qol(): def test_reverse_qol():
"""Test for reverse_qol.""" """Test for reverse_qol."""
(machines, flavors, products, _, _, testsuites, _) = _get_merged() (machines, flavors, products, _, _, testsuites, _) = _get_merged()