Skip to content

Commit

Permalink
Support func test zaza overlays
Browse files Browse the repository at this point in the history
Some charms define overlays in tests.yaml that map to
a job in osci.yaml.
  • Loading branch information
dosaboy committed Sep 30, 2024
1 parent 95bdea4 commit 048b706
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
2 changes: 2 additions & 0 deletions openstack/tools/charmed_openstack_functest_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ for target in ${!func_targets[@]}; do
fi
[[ -d src ]] && pushd src &>/dev/null || true
fail=false
# Remove substitutions and replace with whitespace
target=${target//+/ }
if ! $MANUAL_FUNCTESTS; then
tox ${tox_args} -- $target || fail=true
model=$(juju list-models| egrep -o "^zaza-\S+"|tr -d '*')
Expand Down
7 changes: 6 additions & 1 deletion openstack/tools/func_test_tools/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ def project_check_jobs(self):
if 'check' not in item['project']:
continue

yield from item['project']['check'].get('jobs', [])
for job in item['project']['check'].get('jobs', []):
# can be a dict with voting info
if isinstance(job, dict):
yield list(job.keys())[0]
else:
yield job

@property
def jobs(self):
Expand Down
47 changes: 38 additions & 9 deletions openstack/tools/func_test_tools/identify_charm_func_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,22 @@ def extract_targets(bundle_list):
extracted = []
for item in bundle_list or []:
if isinstance(item, dict):
extracted.append(list(item.values())[0])
values = list(item.values())
for value in values:
if isinstance(value, list):
# its a list of overlays so we get the key name and go find
# the corresponding job in osci.yaml
extracted.append(list(item.keys())[0])
else:
# its a bundle name
extracted.append(value)
else:
extracted.append(item)

return extracted


def get_aliased_targets():
def get_aliased_targets(bundles):
"""
Extract aliased targets. A charm can define aliased targets which is where
Zaza tests are run and use configuration steps from an alias section rather
Expand All @@ -38,23 +46,44 @@ def get_aliased_targets():
job definition in osci.yaml where the target name has a <alias>: prefix.
We extract any aliased targets here and return as a list.
@param bundles: list of extracted bundles
"""
targets = []
osci = OSCIConfig()
for jobname in osci.project_check_jobs:
project_check_jobs = list(osci.project_check_jobs)
jobs = project_check_jobs + bundles
for jobname in jobs:
for job in osci.jobs:
if job['name'] != jobname:
continue

if 'tox_extra_args' not in job['vars']:
continue

ret = re.search(r"-- (\S+:\S+)",
ret = re.search(r"-- (.+)",
str(job['vars']['tox_extra_args']))
if ret:
targets.append(ret.group(1))
target = ret.group(1)
# NOTE: will need to reverse this when we use the target name
target = target.replace(' ', '+')
targets.append(target)
for _target in target.split():
name = _target.partition(':')[2]
if name in bundles:
bundles.remove(name)

if jobname in bundles:
bundles.remove(jobname)

# Some jobs will depend on other tests that need to be run but
# are not defined in tests.yaml so we need to add them from
# here as well.
for name in job.get('dependencies', []):
if name in project_check_jobs:
bundles.append(name)

return targets
return targets + bundles


def get_tests_bundles():
Expand All @@ -76,6 +105,6 @@ def get_tests_bundles():


if __name__ == "__main__":
aliased_bundles = get_aliased_targets()
tests_bundles = get_tests_bundles()
print(' '.join(sorted(set(tests_bundles + aliased_bundles))))
_bundles = get_tests_bundles()
_bundles = get_aliased_targets(list(set(_bundles)))
print(' '.join(sorted(set(_bundles))))

0 comments on commit 048b706

Please sign in to comment.