~ubuntu-on-ec2/vmbuilder/jenkins_kvm-add-azure-cc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/python

#
# This reads the Jenkins json results and computes commands to run
# against the ISOTracker

import argparse
import json
import urllib2
import sys
import time

from pprint import pprint as pp

parser = argparse.ArgumentParser()
parser.add_argument('--host',
        action="store",
        default="localhost:8080",
        help="Host address to hit")
parser.add_argument('--test',
        action="store",
        default=None,
        help="Test suite to parse")
parser.add_argument('--suite',
        action="store",
        default="raring",
        required=True,
        help="Which suite are we working with")
parser.add_argument('--milestone',
        action="store",
        default=None,
        required=True,
        help="Which milestone?")
parser.add_argument('--out',
        action="store",
        default=None,
        required=True,
        help="Output file of commands")
parser.add_argument('--serial',
        action="store",
        default=None,
        required=True,
        help="Serial to use")

opts = parser.parse_args()

sys.stderr.write("Using host: %s\n" % opts.host)

if not opts.test:
    sys.stderr.write("Must define test with --test\n")
    sys.exit(3)


# Translations for values.
translations = {
    'us-east-1': "US-East",
    'ap-northeast-1': "Asia-Pacific-NorthEast",
    'ap-southeast-1': "Asia-Pacific-SouthEast",
    'ap-southeast-2': "Asia-Pacific-SouthEast-Australia",
    'eu-west-1': "Europe",
    'eu-central-1': 'Europe-Central',
    'sa-east-1': "South-America-East-1",
    'us-west-1': "US-West-1",
    'us-west-2': "US-West-2",
    'simple-user-data': "EC2 User Data",
    'multi-instance': "EC2 Multiple Instances Run",
    'all-types': "EC2 Multiple Instances Run",
    'instance-store': "Instance",
    'ebs': "EBS",
    'ebs-ssd': "EBS-SSD",
    'ebs-io1': "EBS-IO1",
    'hvm:EBS': "HVM",
    'hvm:EBS-SSD': "HVM-SSD",
    'hvm:EBS-IO1': "HVM-IO1",
    'hvm:Instance': "HVM Instance",
    }

# Get the ami lookup
url = "http://cloud-images.ubuntu.com/query/%s/server/daily.txt" % \
    opts.suite.lower()
print "Fetching AMI listing..."
response = urllib2.urlopen(url)
ami_lookup = {}
serial = None
for line in str(response.read()).splitlines():

    if len(line.split()) == 9:
        suite, _, _, serial, disk, arch, region, ami, virt = \
            line.split()
    else:
        suite, _, _, serial, disk, arch, region, ami, _, virt = \
            line.split()

    # Make sure we're reading the write file
    if suite != opts.suite.lower():
        raise Exception("Suite does not match suite query!")

    # Make sure we're using the right serial
    if opts.serial != serial:
        continue

    if region not in ami_lookup:
        ami_lookup[region] = {}

    if arch not in ami_lookup[region]:
        ami_lookup[region][arch] = {}

    if virt not in ami_lookup[region][arch]:
        ami_lookup[region][arch][virt] = {}

    if disk not in ami_lookup[region][arch][virt]:
        ami_lookup[region][arch][virt][disk] = ami


# Get the json for parsing
url = "http://%s/job/%s/api/json?pretty=true" % (opts.host, opts.test)
print "Fetching results..."
response = urllib2.urlopen(url)
json_out = response.read()
json_d = json.loads(json_out)
results= json_d['activeConfigurations']

pass_count, fail_count = 0, 0
status = []
for result in results:
    r = {}
    url = result['url']
    r['URL'] = url

    # Extract the elements
    for item in (url.rstrip('/').split('/'))[-1].split(','):
        k, v = item.split('=')
        v = v.replace('/','')
        r[k] = v

    # Assume we're PV, unless otherwise stated
    if 'VIRT_TYPE' not in r or r['VIRT_TYPE'] == 'paravirt':
       r['VIRT_TYPE'] = 'paravirtual'

    # Get the AMI id
    ami = ami_lookup[r['REGION']][r['ARCH']][r['VIRT_TYPE']][r['STORAGE']]
    r['AMI'] = ami
    r['SERIAL'] = serial
    r['STORAGE'] = translations[r['STORAGE']]
    r['REGION'] = translations[r['REGION']]
    r['MILESTONE'] = "%s %s" % (opts.suite.title(), opts.milestone.title())

    if r['VIRT_TYPE'] == 'hvm':
        r['STORAGE'] = translations['hvm:%s' % r['STORAGE']]

    # Label the build
    r['PRODUCT'] = '"Ubuntu Server EC2 %(STORAGE)s (%(REGION)s) %(ARCH)s"' \
        % r

    # Make a comment
    r['COMMENT'] = \
        "[ %(SERIAL)s %(ARCH)s/%(STORAGE)s/%(TEST)s/%(REGION)s ]" \
        % r

    # Translate the values
    for k, v in r.iteritems():
        if v in translations:
            r[k] = translations[v]

    if result['color'] == 'blue':
        r['PASS'] = 'Passed'
        pass_count += 1
    else:
        r['PASS'] = 'Failed'
        fail_count += 1

    status.append(r)

print "Failed Count: %s" % fail_count
print "Pass Count: %s" % pass_count

with open(opts.out, 'w') as f:
    for item in status:
        cmd = \
"""tracker_update_result -u ${API_USER} -p ${API_KEY} --debug """ \
""" "--comment=%(COMMENT)s" "%(MILESTONE)s" """ \
""" %(PRODUCT)s "%(TEST)s" %(AMI)s %(PASS)s\n""" % item
        f.write(cmd)

f.close()

print "Wrote %s" % opts.out