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> --pod=<pod name>
37 --installer=<installer> --database=<database url>
39 -x, --xml xml file generated by robot test
40 -p, --pod POD name where the test come from
43 -h, --help this message
48 def populate_detail(test):
50 detail['test_name'] = test['@name']
51 detail['test_status'] = test['status']
52 detail['test_doc'] = test['doc']
56 def parse_test(tests, details):
59 details.append(populate_detail(test))
61 # tests is not iterable
62 details.append(populate_detail(tests))
66 def parse_suites(suites):
71 data['details'] = parse_test(suite['test'], details)
73 # suites is not iterable
74 data['details'] = parse_test(suites['test'], details)
79 (xml_file, pod, installer, scenario) = None, None, None, None
81 opts, args = getopt.getopt(argv,
87 except getopt.GetoptError:
91 if opt in ('-h', '--help'):
93 elif opt in ('-x', '--xml'):
95 elif opt in ('-p', '--pod'):
97 elif opt in ('-i', '--installer'):
99 elif opt in ('-s', '--scenario'):
104 if not all(x is not None for x in (xml_file, pod, installer, scenario)):
107 with open(xml_file, "r") as myfile:
108 xml_input = myfile.read().replace('\n', '')
110 # dictionary populated with data from xml file
111 all_data = xmltodict.parse(xml_input)['robot']
113 data = parse_suites(all_data['suite']['suite'])
114 data['description'] = all_data['suite']['@name']
115 data['version'] = all_data['@generator']
116 data['test_project'] = "functest"
117 data['case_name'] = "ODL"
118 data['pod_name'] = pod
119 data['installer'] = installer
121 json.dumps(data, indent=4, separators=(',', ': '))
125 # python odlreport2db.py -x ~/Pictures/Perso/odl/output3.xml
130 # success criteria for ODL = 100% of tests OK
132 # TODO as part of the tests are executed before in the bash
133 # start and stoptime have no real meaning
134 start_time = time.time()
135 stop_time = start_time
139 for v in data['details']:
140 if v['test_status']['@status'] == "PASS":
145 if (tests_failed < 1):
148 print("Unable to set criteria" % sys.exc_info()[0])
150 functest_utils.push_results_to_db("functest",
159 print("Error pushing results into Database '%s'" % sys.exc_info()[0])
162 if __name__ == "__main__":