Skip to content

Commit

Permalink
Use local project functioan test template
Browse files Browse the repository at this point in the history
Need to make sure we use the local functional test template
when looking up voting info in zosci-config. Falls back to
default charm-functional-jobs if no local one found.
  • Loading branch information
dosaboy committed Oct 3, 2024
1 parent 3d40bea commit 87be919
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 43 deletions.
32 changes: 14 additions & 18 deletions openstack/tools/func_test_tools/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self):
with open('osci.yaml', encoding='utf-8') as fd:
self._osci_config = yaml.safe_load(fd)

@property
@cached_property
def project_templates(self):
""" Returns all project templates. """
for item in self._osci_config:
Expand All @@ -73,7 +73,7 @@ def project_templates(self):

return []

@property
@cached_property
def project_check_jobs(self):
""" Generator returning all project check jobs defined. """
for item in self._osci_config:
Expand Down Expand Up @@ -103,21 +103,17 @@ def get_job(self, name):

return None

def get_project_check_job(self, name):
""" Get job by name from project.check.jobs. Return can be string name
or dict.
class ProjectTemplatesConfig():
""" Extract information from project_templates.yaml """
def __init__(self, path):
if not os.path.exists(path):
self._config = {}
else:
with open(path, encoding='utf-8') as fd:
self._config = yaml.safe_load(fd)

@property
def project_templates(self):
""" Generator returning all project check jobs defined. """
for item in self._config:
if 'project-template' not in item:
continue
@param name: string name
"""
for job in self.project_check_jobs:
if isinstance(job, dict):
if name in job:
return job
elif job == name:
return job

yield item['project-template']
return None
65 changes: 40 additions & 25 deletions openstack/tools/func_test_tools/test_is_voting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,57 @@

from common import ( # pylint: disable=import-error
OSCIConfig,
ProjectTemplatesConfig,
ZOSCIConfig,
)


if __name__ == "__main__":
test_job = sys.argv[1]
zosci_path = os.path.join(os.environ['HOME'], "zosci-config")
project_templates = os.path.join(zosci_path,
"zuul.d/project-templates.yaml")
def is_job_voting(job, name):
"""
Jobs are voting by default so only return False if there is a match and it
is a dict with voting=False.
"""
if isinstance(job, dict):
if name in job:
return job[name].get('voting', True)

return True


def is_test_voting():
"""
First look for the func-target in osci
Exit with 1 if test is non-voting otherwise 0.
"""
test_job = sys.argv[1]
# First look for the func-target in osci
if os.path.exists('osci.yaml'):
osci_config = OSCIConfig()
try:
jobs = osci_config.project_check_jobs
for job in jobs:
if isinstance(job, dict) and test_job in job:
if not job[test_job]['voting']:
sys.exit(1)
else:
# default is true
sys.exit(0)
job = osci_config.get_project_check_job(test_job)
if not is_job_voting(job, test_job):
sys.exit(1)

# default is true
except KeyError as exc:
sys.stderr.write(f"ERROR: failed to process osci.yaml - assuming "
f"{test_job} is voting (key {exc} not found)."
"\n")

# If the target was not found in osci.yaml then osci will fallback to
# looking at https://github.com/openstack-charmers/zosci-config/blob/master/zuul.d/project-templates.yaml # noqa, pylint: disable=line-too-long
if os.path.exists(project_templates):
config = ProjectTemplatesConfig(project_templates)
for project in config.project_templates:
if project['name'] == "charm-functional-jobs":
for job in project['check']['jobs']:
if test_job in job:
if not job[test_job].get('voting', True):
sys.exit(1)
# If the target was not found in osci.yaml then osci will fallback to zosci
project_template = 'charm-functional-jobs'
for template in osci_config.project_templates:
if 'functional' in template:
project_template = template

path = os.path.join(os.environ['HOME'], 'zosci-config')
for project in ZOSCIConfig(path).project_templates:
t = project['project-template']
if ('functional' not in t['name'] or t['name'] != project_template):
continue

for job in t['check']['jobs']:
if not is_job_voting(job, test_job):
sys.exit(1)


if __name__ == "__main__":
is_test_voting()

0 comments on commit 87be919

Please sign in to comment.