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
33 import functest.utils.functest_utils as functest_utils
38 python odlreport2db.py --xml=<output.xml> --pod=<pod name>
39 --installer=<installer> --database=<database url>
41 -x, --xml xml file generated by robot test
42 -p, --pod POD name where the test come from
45 -h, --help this message
50 def populate_detail(test):
52 detail['test_name'] = test['@name']
53 detail['test_status'] = test['status']
54 detail['test_doc'] = test['doc']
58 def parse_test(tests, details):
61 details.append(populate_detail(test))
63 # tests is not iterable
64 details.append(populate_detail(tests))
68 def parse_suites(suites):
73 data['details'] = parse_test(suite['test'], details)
75 # suites is not iterable
76 data['details'] = parse_test(suites['test'], details)
81 (xml_file, pod, installer, scenario) = None, None, None, None
83 opts, args = getopt.getopt(argv,
89 except getopt.GetoptError:
93 if opt in ('-h', '--help'):
95 elif opt in ('-x', '--xml'):
97 elif opt in ('-p', '--pod'):
99 elif opt in ('-i', '--installer'):
101 elif opt in ('-s', '--scenario'):
106 if not all(x is not None for x in (xml_file, pod, installer, scenario)):
109 with open(xml_file, "r") as myfile:
110 xml_input = myfile.read().replace('\n', '')
112 # dictionary populated with data from xml file
113 all_data = xmltodict.parse(xml_input)['robot']
115 data = parse_suites(all_data['suite']['suite'])
116 data['description'] = all_data['suite']['@name']
117 data['version'] = all_data['@generator']
118 data['test_project'] = "functest"
119 data['case_name'] = "ODL"
120 data['pod_name'] = pod
121 data['installer'] = installer
123 json.dumps(data, indent=4, separators=(',', ': '))
125 # Only used from container, we can set up absolute path
126 with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
127 functest_yaml = yaml.safe_load(f)
132 # python odlreport2db.py -x ~/Pictures/Perso/odl/output3.xml
137 # success criteria for ODL = 100% of tests OK
139 # TODO as part of the tests are executed before in the bash
140 # start and stoptime have no real meaning
141 start_time = time.time()
142 stop_time = start_time
146 for v in data['details']:
147 if v['test_status']['@status'] == "PASS":
152 if (tests_failed < 1):
155 print("Unable to set criteria" % sys.exc_info()[0])
157 functest_utils.push_results_to_db("functest",
166 print("Error pushing results into Database '%s'" % sys.exc_info()[0])
169 if __name__ == "__main__":