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
31 import functest.utils.functest_utils as functest_utils
36 get-json-from-robot.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)
80 opts, args = getopt.getopt(argv,
86 except getopt.GetoptError:
90 if opt in ('-h', '--help'):
92 elif opt in ('-x', '--xml'):
94 elif opt in ('-p', '--pod'):
96 elif opt in ('-i', '--installer'):
98 elif opt in ('-s', '--scenario'):
103 with open(xml_file, "r") as myfile:
104 xml_input = myfile.read().replace('\n', '')
106 # dictionary populated with data from xml file
107 all_data = xmltodict.parse(xml_input)['robot']
109 data = parse_suites(all_data['suite']['suite'])
110 data['description'] = all_data['suite']['@name']
111 data['version'] = all_data['@generator']
112 data['test_project'] = "functest"
113 data['case_name'] = "ODL"
114 data['pod_name'] = pod
115 data['installer'] = installer
117 json.dumps(data, indent=4, separators=(',', ': '))
119 # Only used from container, we can set up absolute path
120 with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
121 functest_yaml = yaml.safe_load(f)
124 database = functest_yaml.get("results").get("test_db_url")
125 build_tag = functest_utils.get_build_tag()
129 # python odlreport2db.py -x ~/Pictures/Perso/odl/output3.xml
133 version = functest_utils.get_version()
135 # success criteria for ODL = 100% of tests OK
140 for v in data['details']:
141 if v['test_status']['@status'] == "PASS":
146 if (tests_failed < 1):
149 print("Unable to set criteria" % sys.exc_info()[0])
150 functest_utils.push_results_to_db(database,
161 print("Error pushing results into Database '%s'" % sys.exc_info()[0])
164 if __name__ == "__main__":