4
We always run the system-settle test before and after an autopilot test. This
5
script takes the results of the before/after results and combines them in with
6
the junit xml results from the autopilot test so we have one unified report.
13
from xml.etree import ElementTree
17
('settle_before', 'settle_before'),
18
('setup_setup', 'setup'),
22
('settle_after', 'settle_after'),
23
('setup_teardown', 'teardown'),
27
def _build_node(classname, name, rcfile, stdout):
28
e = ElementTree.Element('testcase')
29
e.attrib['classname'] = classname
30
e.attrib['name'] = name
32
if not os.path.exists(rcfile):
35
rc = int(open(rcfile).read())
37
f = ElementTree.Element('failure')
39
f.attrib['type'] = 'testtools.testresult.real._StringException'
40
f.text = open(stdout).read()
44
def _get_results(apfile):
46
tree = ElementTree.parse(apfile)
47
except Exception as ex:
48
e = ElementTree.Element('testsuite')
49
tree = ElementTree.ElementTree(e)
50
e.attrib['errors'] = '1'
51
e.attrib['failures'] = '0'
52
e.attrib['tests'] = '1'
54
# make a guess at the classname:
55
classname = os.path.basename(os.path.dirname(apfile))
57
t = ElementTree.Element('testcase')
59
t.attrib['classname'] = classname
60
t.attrib['name'] = 'phablet-test-run'
62
f = ElementTree.Element('failure')
64
f.attrib['type'] = 'testtools.testresult.real._StringException'
70
def _get_classname(results):
74
cname = results[0].attrib.get('classname')
76
cname = cname.split('.')[0]
83
ap_file = os.path.join(resdir, 'test_results.xml')
84
tree = _get_results(ap_file)
85
ap_results = tree.getroot()
88
errors = int(ap_results.attrib['errors'])
90
classname = _get_classname(ap_results)
92
for basename, label in PRE_COMBINE:
93
rc = os.path.join(resdir, basename + '.rc')
94
log = os.path.join(resdir, basename + '.log')
95
node, failed = _build_node(classname, label, rc, log)
97
ap_results.insert(0, node)
102
for basename, label in POST_COMBINE:
103
rc = os.path.join(resdir, basename + '.rc')
104
log = os.path.join(resdir, basename + '.log')
105
node, failed = _build_node(classname, label, rc, log)
107
ap_results.append(node)
112
num = int(ap_results.attrib['tests']) + added_results
113
ap_results.attrib['tests'] = str(num)
114
ap_results.attrib['errors'] = str(errors)
119
if __name__ == '__main__':
120
if len(sys.argv) != 2:
121
print('usage: {} <results directory>'.format(sys.argv[0]))