2015-01-28 10:00:58 +00:00
|
|
|
import argparse
|
2015-03-24 02:31:47 +00:00
|
|
|
import sys
|
2015-01-28 10:00:58 +00:00
|
|
|
import time
|
2015-07-09 08:31:53 +00:00
|
|
|
import logging
|
2015-01-28 10:00:58 +00:00
|
|
|
import conf_test_suites
|
|
|
|
|
2015-03-24 02:31:47 +00:00
|
|
|
from operator import attrgetter
|
2015-07-09 11:30:17 +00:00
|
|
|
from openqa_client.client import OpenQA_Client
|
2015-03-24 02:31:47 +00:00
|
|
|
from wikitcms.wiki import Wiki, ResTuple
|
2015-01-28 10:00:58 +00:00
|
|
|
|
|
|
|
SLEEPTIME = 60
|
2015-07-09 08:31:53 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2015-01-28 10:00:58 +00:00
|
|
|
|
|
|
|
|
2015-07-09 11:30:17 +00:00
|
|
|
def get_passed_testcases(job_ids, client):
|
2015-01-28 10:00:58 +00:00
|
|
|
"""
|
|
|
|
job_ids ~ list of int (job ids)
|
|
|
|
Returns ~ list of str - names of passed testcases
|
|
|
|
"""
|
2015-07-09 11:30:17 +00:00
|
|
|
running_jobs = dict([(job_id, "jobs/%s" % job_id) for job_id in job_ids])
|
2015-07-09 08:31:53 +00:00
|
|
|
logger.info("running jobs: %s", running_jobs)
|
2015-01-28 10:00:58 +00:00
|
|
|
finished_jobs = {}
|
|
|
|
|
|
|
|
while running_jobs:
|
|
|
|
for job_id, url in running_jobs.items():
|
2015-07-09 11:30:17 +00:00
|
|
|
output = client.openqa_request('GET', url)
|
|
|
|
job_state = output['job']
|
2015-01-28 10:00:58 +00:00
|
|
|
if job_state['state'] == 'done':
|
2015-07-09 08:31:53 +00:00
|
|
|
logger.info("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)
|
2015-07-09 08:31:53 +00:00
|
|
|
logger.info("all jobs finished")
|
2015-01-28 10:00:58 +00:00
|
|
|
|
2015-03-24 02:31:47 +00:00
|
|
|
passed_testcases = set()
|
2015-01-28 10:00:58 +00:00
|
|
|
for job_id in job_ids:
|
|
|
|
job = finished_jobs[job_id]
|
2015-07-09 11:30:17 +00:00
|
|
|
if job['result'] == 'passed':
|
2015-03-24 02:31:47 +00:00
|
|
|
(release, milestone, compose) = job['settings']['BUILD'].split('_')
|
|
|
|
testsuite = job['settings']['TEST']
|
|
|
|
arch = job['settings']['ARCH']
|
|
|
|
flavor = job['settings']['FLAVOR']
|
|
|
|
|
|
|
|
for testcase in conf_test_suites.TESTSUITES[testsuite]:
|
|
|
|
# each 'testsuite' is a list using testcase names to indicate which Wikitcms tests have
|
|
|
|
# passed if this job passes. Each testcase name is the name of a dict in the TESTCASES
|
|
|
|
# dict-of-dicts which more precisely identifies the 'test instance' (when there is more
|
|
|
|
# than one for a testcase) and environment for which the result should be filed.
|
|
|
|
uniqueres = conf_test_suites.TESTCASES[testcase]
|
|
|
|
testname = ''
|
|
|
|
if 'name_cb' in uniqueres:
|
|
|
|
testname = uniqueres['name_cb'](flavor)
|
|
|
|
env = arch if uniqueres['env'] == '$RUNARCH$' else uniqueres['env']
|
|
|
|
result = ResTuple(
|
|
|
|
testtype=uniqueres['type'], release=release, milestone=milestone, compose=compose,
|
2015-04-22 23:20:36 +00:00
|
|
|
testcase=testcase, section=uniqueres['section'], testname=testname, env=env, status='pass',
|
|
|
|
bot=True)
|
2015-03-24 02:31:47 +00:00
|
|
|
passed_testcases.add(result)
|
|
|
|
|
|
|
|
return sorted(list(passed_testcases), key=attrgetter('testcase'))
|
|
|
|
|
2015-07-09 11:30:17 +00:00
|
|
|
def report_results(job_ids, client, verbose=False, report=True):
|
|
|
|
passed_testcases = get_passed_testcases(job_ids, client)
|
2015-07-09 08:31:53 +00:00
|
|
|
if verbose:
|
2015-03-24 02:31:47 +00:00
|
|
|
for restup in passed_testcases:
|
2015-07-09 08:31:53 +00:00
|
|
|
print restup
|
|
|
|
logger.info("passed testcases: %s", passed_testcases)
|
2015-03-24 02:31:47 +00:00
|
|
|
|
|
|
|
if report:
|
2015-07-09 08:31:53 +00:00
|
|
|
if verbose:
|
|
|
|
print "Reporting test passes:"
|
|
|
|
logger.info("reporting test passes")
|
2015-03-24 02:31:47 +00:00
|
|
|
wiki = Wiki()
|
|
|
|
wiki.login()
|
|
|
|
if not wiki.logged_in:
|
2015-07-09 08:31:53 +00:00
|
|
|
logger.error("could not log in to wiki")
|
2015-03-24 02:31:47 +00:00
|
|
|
sys.exit("Could not log in to wiki!")
|
|
|
|
|
|
|
|
# Submit the results
|
|
|
|
(insuffs, dupes) = wiki.report_validation_results(passed_testcases)
|
|
|
|
for dupe in dupes:
|
2015-07-09 08:31:53 +00:00
|
|
|
tmpl = "already reported result for test %s, env %s! Will not report dupe."
|
|
|
|
if verbose:
|
|
|
|
print tmpl % (dupe.testcase, dupe.env)
|
|
|
|
logger.info(tmpl, dupe.testcases, dupe.env)
|
2015-01-28 10:00:58 +00:00
|
|
|
|
2015-03-24 02:31:47 +00:00
|
|
|
else:
|
2015-07-09 08:31:53 +00:00
|
|
|
if verbose:
|
|
|
|
print "\n\n### No reporting is done! ###\n\n"
|
|
|
|
logger.warning("no reporting is done")
|
2015-01-28 10:00:58 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(description="Evaluate per-testcase results from OpenQA job runs")
|
|
|
|
parser.add_argument('jobs', type=int, nargs='+')
|
2015-01-30 13:58:12 +00:00
|
|
|
parser.add_argument('--report', default=False, action='store_true')
|
2015-01-28 10:00:58 +00:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
2015-07-09 11:30:17 +00:00
|
|
|
client = OpenQA_Client() # uses first server from ~/.config/openqa/client.conf
|
|
|
|
report_results(args.jobs, client, verbose=True, report=args.report)
|