From 3795d3ee74afc82d059a05c4ef6cb44bd1beae07 Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Wed, 2 Oct 2024 19:19:25 +0100 Subject: [PATCH] Respect project templates as defined in charm Need to use the project template defined in the charm osci.yaml which will not always be the new/global charm-functional-jobs. --- openstack/tools/func_test_tools/common.py | 40 ++++++++++++++++--- .../identify_charm_func_test_jobs.py | 3 +- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/openstack/tools/func_test_tools/common.py b/openstack/tools/func_test_tools/common.py index 88a856b8..23a1c458 100644 --- a/openstack/tools/func_test_tools/common.py +++ b/openstack/tools/func_test_tools/common.py @@ -19,7 +19,7 @@ def project_templates(self): encoding='utf-8') as fd: yield from yaml.safe_load(fd) - def get_branch_jobs(self, branch): + def get_branch_jobs(self, branch, project_templates): """ For a given branch name, find all jobs that need to be run against that branch. @@ -27,11 +27,28 @@ def get_branch_jobs(self, branch): test_jobs = [] for t in self.project_templates: t = t['project-template'] - if t['name'] == 'charm-functional-jobs': - for jobs in t['check']['jobs']: - for job, info in jobs.items(): - if branch in info['branches']: - test_jobs.append(job) + + # only look at functional test jobs + if 'functional' not in t['name']: + continue + + if t['name'] not in project_templates: + continue + + if 'check' not in t or 'jobs' not in t['check']: + continue + + for jobs in t['check']['jobs']: + if not isinstance(jobs, dict): + test_jobs.append(jobs) + continue + + for job, info in jobs.items(): + if t['name'] == 'charm-functional-jobs': + if branch not in info['branches']: + continue + + test_jobs.append(job) return test_jobs @@ -45,6 +62,17 @@ def __init__(self): with open('osci.yaml', encoding='utf-8') as fd: self._osci_config = yaml.safe_load(fd) + @property + def project_templates(self): + """ Returns all project templates. """ + for item in self._osci_config: + if 'project' not in item: + continue + + return item['project'].get('templates', []) + + return [] + @property def project_check_jobs(self): """ Generator returning all project check jobs defined. """ diff --git a/openstack/tools/func_test_tools/identify_charm_func_test_jobs.py b/openstack/tools/func_test_tools/identify_charm_func_test_jobs.py index 7fecab06..99ef00af 100644 --- a/openstack/tools/func_test_tools/identify_charm_func_test_jobs.py +++ b/openstack/tools/func_test_tools/identify_charm_func_test_jobs.py @@ -49,7 +49,8 @@ def get_default_jobs(): c = configparser.ConfigParser() c.read('.gitreview') branch = c['gerrit']['defaultbranch'] - jobs = ZOSCIConfig(path).get_branch_jobs(branch) + osci = OSCIConfig() + jobs = ZOSCIConfig(path).get_branch_jobs(branch, osci.project_templates) return jobs