~pwlars/ubuntu-test-cases/krillin-recovery

« back to all changes in this revision

Viewing changes to scripts/junit2utah.py

  • Committer: Paul Larson
  • Date: 2014-10-21 15:40:57 UTC
  • Revision ID: paul.larson@canonical.com-20141021154057-zk465lswaexddae7
Find a better default location for the wifi configuration

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import datetime
 
4
import sys
 
5
 
 
6
from xml.etree import ElementTree
 
7
 
 
8
import yaml
 
9
 
 
10
 
 
11
def _convert_testcase(tc):
 
12
    x = {
 
13
        'testcase': tc.attrib['name'],
 
14
        'testsuite': tc.attrib['classname'],
 
15
        'command': 'autopilot',
 
16
        'cmd_type': 'testcase_test',
 
17
        'stdout': '',
 
18
        'stderr': '',
 
19
        'returncode': 0
 
20
    }
 
21
    t = tc.attrib.get('time', False)
 
22
    if t:
 
23
        x['time_delta'] = t
 
24
 
 
25
    for e in tc.getchildren():
 
26
        if e.tag in ('failure', 'error'):
 
27
            x['stderr'] = e.text
 
28
            x['returncode'] = 1
 
29
        elif e.tag == 'skip':
 
30
            # NOTE: this isn't a real thing in UTAH. However, the
 
31
            # qa-dashboard code doesn't care and will display it as skipped
 
32
            x['cmd_type'] = 'testcase_skipped'
 
33
            x['stdout'] = e.text
 
34
        else:
 
35
            raise RuntimeError('Unknown element type: %s' % e.tag)
 
36
    return x
 
37
 
 
38
 
 
39
def _get_results(stream):
 
40
    tree = ElementTree.fromstring(stream.read())
 
41
    results = {
 
42
        'errors': int(tree.attrib.get('errors', '0')),
 
43
        'failures': int(tree.attrib.get('failures', '0')),
 
44
        'commands': [],
 
45
        'fetch_errors': 0,
 
46
        'uname': 'n/a',
 
47
        'media-info': 'n/a',
 
48
        'install_type': 'n/a',
 
49
        'arch': 'n/a',
 
50
        'release': 'n/a',
 
51
        'build_number': 'n/a',
 
52
        'name': 'unamed',
 
53
        'runlist': 'n/a',
 
54
        'ran_at': datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'),
 
55
    }
 
56
    results['passes'] = \
 
57
        int(tree.attrib['tests']) - results['errors'] - results['failures']
 
58
 
 
59
    for tc in tree.getchildren():
 
60
        results['commands'].append(_convert_testcase(tc))
 
61
    return results
 
62
 
 
63
 
 
64
def _main(stream):
 
65
    results = _get_results(stream)
 
66
    print(yaml.safe_dump(results, default_flow_style=False))
 
67
 
 
68
 
 
69
if __name__ == '__main__':
 
70
    exit(_main(sys.stdin))