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
17 # 0.1: This script boots the VM1 and allocates IP address from Nova
18 # Later, the VM2 boots then execute cloud-init to ping VM1.
19 # After successful ping, both the VMs are deleted.
20 # 0.2: measure test duration and publish results under json format
21 # 0.3: adapt push 2 DB after Test API refacroting
31 import functest.utils.functest_utils as functest_utils
36 python odlreport2db.py --xml=<output.xml> --help
37 -x, --xml xml file generated by robot test
38 -h, --help this message
43 def populate_detail(test):
45 detail['test_name'] = test['@name']
46 detail['test_status'] = test['status']
47 detail['test_doc'] = test['doc']
51 def parse_test(tests, details):
54 details.append(populate_detail(test))
56 # tests is not iterable
57 details.append(populate_detail(tests))
61 def parse_suites(suites):
68 data['details'] = parse_test(b['test'], details)
70 data['details'] = parse_test(a['test'], details)
72 # data['details'] = parse_test(suite['test'], details)
73 # suites is not iterable
80 opts, args = getopt.getopt(argv,
83 except getopt.GetoptError:
87 if opt in ('-x', '--xml'):
95 with open(xml_file, "r") as myfile:
96 xml_input = myfile.read().replace('\n', '')
98 # dictionary populated with data from xml file
99 all_data = xmltodict.parse(xml_input)['robot']
102 data = parse_suites(all_data['suite']['suite'])
103 data['description'] = all_data['suite']['@name']
104 data['version'] = all_data['@generator']
105 data['test_project'] = "functest"
106 data['case_name'] = "odl"
108 json.dumps(data, indent=4, separators=(',', ': '))
110 # success criteria for ODL = 100% of tests OK
112 # TODO as part of the tests are executed before in the bash
113 # start and stoptime have no real meaning
114 start_time = time.time()
115 stop_time = start_time
118 for v in data['details']:
119 if v['test_status']['@status'] == "PASS":
124 if (tests_failed < 1):
127 functest_utils.push_results_to_db(data['test_project'],
136 print("Error pushing ODL results into DB '%s'" % sys.exc_info()[0])
139 if __name__ == "__main__":