4 # - peter.bandzi@cisco.com
5 # - morgan.richomme@orange.com
8 # https://github.com/pbandzi/parse-robot/blob/master/convert_robot_to_json.py
10 # Copyright (c) 2015 All rights reserved
11 # This program and the accompanying materials
12 # are made available under the terms of the Apache License, Version 2.0
13 # which accompanies this distribution, and is available at
15 # http://www.apache.org/licenses/LICENSE-2.0
24 import functest.utils.functest_utils as functest_utils
29 python odlreport2db.py --xml=<output.xml> --help
30 -x, --xml xml file generated by robot test
31 -h, --help this message
36 def populate_detail(test):
38 detail['name'] = test['@name']
39 for x in ['status', 'critical', 'starttime', 'endtime']:
40 detail[x] = test['status']['@' + x]
41 if '#text' in test['status']:
42 detail['text'] = test['status']['#text']
46 def parse_test(tests, details):
49 details.append(populate_detail(test))
51 # tests is not iterable
52 details.append(populate_detail(tests))
56 def parse_suites(suites):
63 data['tests'] = parse_test(b['test'], details)
65 data['tests'] = parse_test(a['test'], details)
67 # data['details'] = parse_test(suite['test'], details)
68 # suites is not iterable
75 opts, args = getopt.getopt(argv,
78 except getopt.GetoptError:
82 if opt in ('-x', '--xml'):
90 with open(xml_file, "r") as myfile:
91 xml_input = myfile.read().replace('\n', '')
93 # dictionary populated with data from xml file
94 all_data = xmltodict.parse(xml_input)['robot']
97 data = parse_suites(all_data['suite']['suite'])
98 data['description'] = all_data['suite']['@name']
99 data['generator'] = all_data['@generator']
101 json.dumps(data, indent=4, separators=(',', ': '))
103 # success criteria for ODL = 100% of tests OK
105 # TODO as part of the tests are executed before in the bash
106 # start and stoptime have no real meaning
107 start_time = time.time()
108 stop_time = start_time
111 for v in data['tests']:
112 if v['status'] == "PASS":
117 if (tests_failed < 1):
120 functest_utils.push_results_to_db("functest",
129 print("Error pushing ODL results into DB '%s'" % sys.exc_info()[0])
132 if __name__ == "__main__":