1
0
mirror of https://pagure.io/fedora-qa/createhdds.git synced 2024-11-13 20:34:21 +00:00
createhdds/openqa_trigger/report_job_results.py

92 lines
3.0 KiB
Python
Raw Normal View History

2015-01-28 10:00:58 +00:00
import requests
import argparse
import os
import time
import conf_test_suites
API_ROOT = "http://localhost/api/v1"
2015-01-28 10:00:58 +00:00
SLEEPTIME = 60
def get_passed_testcases(job_ids):
"""
job_ids ~ list of int (job ids)
Returns ~ list of str - names of passed testcases
"""
running_jobs = dict([(job_id, "%s/jobs/%s" % (API_ROOT, job_id)) for job_id in job_ids])
finished_jobs = {}
while running_jobs:
for job_id, url in running_jobs.items():
job_state = requests.get(url).json()['job']
if job_state['state'] == 'done':
print "Job %s is done" % job_id
2015-01-28 10:00:58 +00:00
finished_jobs[job_id] = job_state
del running_jobs[job_id]
if running_jobs:
time.sleep(SLEEPTIME)
passed_testcases = {} # key = VERSION_BUILD_ARCH
for job_id in job_ids:
job = finished_jobs[job_id]
if job['result'] =='passed':
key = (job['settings']['VERSION'], job['settings']['FLAVOR'], job['settings'].get('BUILD', None), job['settings']['ARCH'])
passed_testcases.setdefault(key, [])
passed_testcases[key].extend(conf_test_suites.TESTSUITES[job['settings']['TEST']])
for key, value in passed_testcases.iteritems():
passed_testcases[key] = sorted(list(set(value)))
return passed_testcases
def get_relval_commands(passed_testcases):
2015-02-11 12:25:10 +00:00
relval_template = "relval report-auto"
2015-01-28 10:00:58 +00:00
commands = []
for key in passed_testcases:
cmd_ = relval_template
handling scheduling of jobs for multiple images This handles scheduling of jobs for more than one type of image; currently we'll run tests for Workstation live as well. It requires some cleverness to run some tests for *all* images (currently just default_boot_and_install) but run all the tests that can be run with any non-live installer image with the best image available for the compose. We introduce a special (openQA, not fedfind) 'flavor' called 'universal'; we run a couple of checks to find the best image in the compose for running the universal tests, and schedule tests for the 'universal' flavor with that image. The 'best' image is a server or 'generic' DVD if possible, and if not, a server or 'generic' boot.iso. ISO files have the compose's version identifier prepended to their names. Otherwise they retain their original names, which should usually be unique within a given compose, except for boot.iso files, which have their payload and arch added into their names to ensure they don't overwrite each other. This also adds a mechanism for TESTCASES (in conf_test_suites) to define a callback which will be called with the flavor of the image being tested; the result of the callback will be used as the 'test name' for relval result reporting purposes. This allows us to report results against the correct 'test instance' for the image being tested, for tests like Boot_default_install which have 'test instances' for each image. We can extend this general approach in future for other cases where we have multiple 'test instances' for a single test case.
2015-03-18 21:51:01 +00:00
version, flavor, build, arch = key
Use python-wikitcms and fedfind The basic approach is that openqa_trigger gets a ValidationEvent from python-wikitcms - either the Wiki.current_event property for 'current', or the event specified, obtained via the newly-added Wiki.get_validation_event(), for 'event'. For 'event' it then just goes ahead and runs the jobs and prints the IDs. For 'current' it checks the last run compose version for each arch and runs if needed, as before. The ValidationEvent's 'sortname' property is the value written out to PERSISTENT to track the 'last run' - this property is intended to always sort compose events 'correctly', so we should always run when appropriate even when going from Rawhide to Branched, Branched to a TC, TC to RC, RC to (next milestone) TC. On both paths it gets a fedfind.Release object via the ValidationEvent - ValidationEvents have a ff_release property which is the fedfind.Release object that matches that event. It then queries fedfind for image locations using a query that tries to get just *one* generic-ish network install image for each arch. It passes the location to download_image(), which is just download_rawhide_iso() renamed and does the same job, only it can be simpler now. From there it works pretty much as before, except we use the ValidationEvent's 'version' property as the BUILD setting for OpenQA, and report_job_results get_relval_commands() is tweaked slightly to parse this properly to produce a correct report-auto command. Probably the most likely bits to break here are the sortname thing (see wikitcms helpers.py fedora_release_sort(), it's pretty stupid, I should re-write it) and the image query, which might wind up getting more than one image depending on how exactly the F22 Alpha composes look. I'll keep a close eye on that. We can always take the list from fedfind and further filter it so we have just one image per arch. Image objects have a .arch attribute so this will be easy to do if necessary. I *could* give the fedfind query code a 'I'm feeling lucky'- ish mode to only return one image per (whatever), but not sure if that would be too specialized, I'll think about it.
2015-02-16 17:01:58 +00:00
cmd_ += ' --release "%s" --milestone "%s" --compose "%s"' % tuple(build.split('_'))
2015-01-28 10:00:58 +00:00
for tc_name in passed_testcases[key]:
testcase = conf_test_suites.TESTCASES[tc_name]
tc_env = arch if testcase['env'] == '$RUNARCH$' else testcase['env']
tc_type = testcase['type']
tc_section = testcase['section']
handling scheduling of jobs for multiple images This handles scheduling of jobs for more than one type of image; currently we'll run tests for Workstation live as well. It requires some cleverness to run some tests for *all* images (currently just default_boot_and_install) but run all the tests that can be run with any non-live installer image with the best image available for the compose. We introduce a special (openQA, not fedfind) 'flavor' called 'universal'; we run a couple of checks to find the best image in the compose for running the universal tests, and schedule tests for the 'universal' flavor with that image. The 'best' image is a server or 'generic' DVD if possible, and if not, a server or 'generic' boot.iso. ISO files have the compose's version identifier prepended to their names. Otherwise they retain their original names, which should usually be unique within a given compose, except for boot.iso files, which have their payload and arch added into their names to ensure they don't overwrite each other. This also adds a mechanism for TESTCASES (in conf_test_suites) to define a callback which will be called with the flavor of the image being tested; the result of the callback will be used as the 'test name' for relval result reporting purposes. This allows us to report results against the correct 'test instance' for the image being tested, for tests like Boot_default_install which have 'test instances' for each image. We can extend this general approach in future for other cases where we have multiple 'test instances' for a single test case.
2015-03-18 21:51:01 +00:00
if 'name_cb' in testcase:
tc_name = testcase['name_cb'](flavor)
2015-01-28 10:00:58 +00:00
2015-02-11 12:25:10 +00:00
commands.append('%s --environment "%s" --testtype "%s" --section "%s" --testcase "%s" pass' % (cmd_, tc_env, tc_type, tc_section, tc_name))
2015-01-28 10:00:58 +00:00
return commands
def report_results(job_ids):
commands = get_relval_commands(get_passed_testcases(job_ids))
print "Running relval commands:"
2015-01-28 10:00:58 +00:00
for command in commands:
print command
2015-01-28 10:00:58 +00:00
os.system(command)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Evaluate per-testcase results from OpenQA job runs")
parser.add_argument('jobs', type=int, nargs='+')
parser.add_argument('--report', default=False, action='store_true')
2015-01-28 10:00:58 +00:00
args = parser.parse_args()
passed_testcases = get_passed_testcases(args.jobs)
commands = get_relval_commands(passed_testcases)
2015-01-28 10:00:58 +00:00
import pprint
pprint.pprint(passed_testcases)
if not args.report:
print "\n\n### No reporting is done! ###\n\n"
pprint.pprint(commands)
else:
for command in commands:
print command
os.system(command)
2015-01-28 10:00:58 +00:00