X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=testcases%2FControllers%2FODL%2Fodlreport2db.py;h=6b3fb913db856fb98c9e0320d3610da927293f57;hb=9b830f30a6e93643e4aa1312f9439e34f2d74530;hp=8eb78b19a2ea0b2e10cd50ad2205c533578915a0;hpb=7a55bacfa9d2c2fff84904578e7ebff0eb4cfb09;p=functest.git diff --git a/testcases/Controllers/ODL/odlreport2db.py b/testcases/Controllers/ODL/odlreport2db.py index 8eb78b19a..6b3fb913d 100644 --- a/testcases/Controllers/ODL/odlreport2db.py +++ b/testcases/Controllers/ODL/odlreport2db.py @@ -14,32 +14,20 @@ # # http://www.apache.org/licenses/LICENSE-2.0 # -# 0.1: This script boots the VM1 and allocates IP address from Nova -# Later, the VM2 boots then execute cloud-init to ping VM1. -# After successful ping, both the VMs are deleted. -# 0.2: measure test duration and publish results under json format -# -# import getopt import json -import os import sys +import time import xmltodict -import yaml import functest.utils.functest_utils as functest_utils def usage(): print """Usage: - python odlreport2db.py --xml= --pod= - --installer= --database= - --scenario= + python odlreport2db.py --xml= --help -x, --xml xml file generated by robot test - -p, --pod POD name where the test come from - -i, --installer - -s, --scenario -h, --help this message """ sys.exit(2) @@ -47,9 +35,11 @@ def usage(): def populate_detail(test): detail = {} - detail['test_name'] = test['@name'] - detail['test_status'] = test['status'] - detail['test_doc'] = test['doc'] + detail['name'] = test['@name'] + for x in ['status', 'critical', 'starttime', 'endtime']: + detail[x] = test['status']['@' + x] + if '#text' in test['status']: + detail['text'] = test['status']['#text'] return detail @@ -66,42 +56,35 @@ def parse_test(tests, details): def parse_suites(suites): data = {} details = [] - try: - for suite in suites: - data['details'] = parse_test(suite['test'], details) - except TypeError: - # suites is not iterable - data['details'] = parse_test(suites['test'], details) + for suite in suites: + a = suite['suite'] + if type(a) == list: + for b in a: + data['tests'] = parse_test(b['test'], details) + else: + data['tests'] = parse_test(a['test'], details) + + # data['details'] = parse_test(suite['test'], details) + # suites is not iterable return data def main(argv): - (xml_file, pod, installer, scenario) = None, None, None, None + xml_file = None try: opts, args = getopt.getopt(argv, - 'x:p:i:s:h', - ['xml=', 'pod=', - 'installer=', - 'scenario=', - 'help']) + 'x:h', + ['xml=', 'help']) except getopt.GetoptError: usage() for opt, arg in opts: - if opt in ('-h', '--help'): - usage() - elif opt in ('-x', '--xml'): + if opt in ('-x', '--xml'): xml_file = arg - elif opt in ('-p', '--pod'): - pod = arg - elif opt in ('-i', '--installer'): - installer = arg - elif opt in ('-s', '--scenario'): - scenario = arg else: usage() - if not all(x is not None for x in (xml_file, pod, installer, scenario)): + if xml_file is None: usage() with open(xml_file, "r") as myfile: @@ -110,59 +93,40 @@ def main(argv): # dictionary populated with data from xml file all_data = xmltodict.parse(xml_input)['robot'] - data = parse_suites(all_data['suite']['suite']) - data['description'] = all_data['suite']['@name'] - data['version'] = all_data['@generator'] - data['test_project'] = "functest" - data['case_name'] = "ODL" - data['pod_name'] = pod - data['installer'] = installer - - json.dumps(data, indent=4, separators=(',', ': ')) - - # Only used from container, we can set up absolute path - with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f: - functest_yaml = yaml.safe_load(f) - f.close() - - database = functest_yaml.get("results").get("test_db_url") - build_tag = functest_utils.get_build_tag() - try: - # example: - # python odlreport2db.py -x ~/Pictures/Perso/odl/output3.xml - # -i fuel - # -p opnfv-jump-2 - # -s os-odl_l2-ha - version = functest_utils.get_version() + data = parse_suites(all_data['suite']['suite']) + data['description'] = all_data['suite']['@name'] + data['generator'] = all_data['@generator'] + + json.dumps(data, indent=4, separators=(',', ': ')) # success criteria for ODL = 100% of tests OK - status = "failed" - try: - tests_passed = 0 - tests_failed = 0 - for v in data['details']: - if v['test_status']['@status'] == "PASS": - tests_passed += 1 - else: - tests_failed += 1 - - if (tests_failed < 1): - status = "passed" - except: - print("Unable to set criteria" % sys.exc_info()[0]) - functest_utils.push_results_to_db(database, - "functest", - data['case_name'], + status = "FAIL" + # TODO as part of the tests are executed before in the bash + # start and stoptime have no real meaning + start_time = time.time() + stop_time = start_time + tests_passed = 0 + tests_failed = 0 + for v in data['tests']: + if v['status'] == "PASS": + tests_passed += 1 + else: + tests_failed += 1 + + if (tests_failed < 1): + status = "PASS" + + functest_utils.push_results_to_db("functest", + "odl", None, - data['pod_name'], - version, - scenario, + start_time, + stop_time, status, - build_tag, data) + except: - print("Error pushing results into Database '%s'" % sys.exc_info()[0]) + print("Error pushing ODL results into DB '%s'" % sys.exc_info()[0]) if __name__ == "__main__":