~ubuntu-archive/ubuntu-archive-tools/trunk

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
#! /usr/bin/python3

# Copyright (C) 2010, 2011, 2012  Canonical Ltd.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import argparse
import os
import sys

# See isotracker.py for setup instructions.
from isotracker import ISOTracker

# USAGE:  post-amis-to-iso-tracker /<localpath>/published-ec2-daily.txt
#         it will return silently if successful.  Check by looking at:
#         http://iso.qa.ubuntu.com/qatracker/build/all
#
# URLs to wget locally first are of the form:
#  http://uec-images.ubuntu.com/server/natty/20110302.2/published-ec2-daily.txt
#
# See isotracker.py for setup instructions.
#
# Reminder 2011/03/02 - check with jibel what's happening in the iso.tracker
# right now, and if this is still necessary.
# Also,  why are the paths for downloading the images from the isotracker not
# synching up with what was in the published-ec2-daily.txt.
# 2011/03/29 - added in ap-northeast images

ec2_to_product_map = {
    'eu-west-1-amd64-ebs': 'Ubuntu Server EC2 EBS (Europe) amd64',
    'eu-west-1-i386-ebs': 'Ubuntu Server EC2 EBS (Europe) i386',
    'eu-west-1-amd64-hvm': 'Ubuntu Server EC2 HVM (Europe) amd64',
    'us-east-1-amd64-ebs': 'Ubuntu Server EC2 EBS (US-East) amd64',
    'us-east-1-i386-ebs': 'Ubuntu Server EC2 EBS (US-East) i386',
    'us-west-1-amd64-ebs': 'Ubuntu Server EC2 EBS (US-West-1) amd64',
    'us-west-1-i386-ebs': 'Ubuntu Server EC2 EBS (US-West-1) i386',
    'us-west-2-amd64-ebs': 'Ubuntu Server EC2 EBS (US-West-2) amd64',
    'us-west-2-i386-ebs': 'Ubuntu Server EC2 EBS (US-West-2) i386',
    'us-west-2-amd64-hvm': 'Ubuntu Server EC2 HVM (US-West-2) amd64',
    'us-east-1-amd64-hvm': 'Ubuntu Server EC2 HVM (US-East) amd64',
    'eu-west-1-amd64-instance': 'Ubuntu Server EC2 instance (Europe) amd64',
    'eu-west-1-i386-instance': 'Ubuntu Server EC2 instance (Europe) i386',
    'us-east-1-amd64-instance': 'Ubuntu Server EC2 instance (US-East) amd64',
    'us-east-1-i386-instance': 'Ubuntu Server EC2 instance (US-East) i386',
    'us-west-1-amd64-instance': 'Ubuntu Server EC2 instance (US-West-1) amd64',
    'us-west-1-i386-instance': 'Ubuntu Server EC2 instance (US-West-1) i386',
    'us-west-2-amd64-instance': 'Ubuntu Server EC2 instance (US-West-2) amd64',
    'us-west-2-i386-instance': 'Ubuntu Server EC2 instance (US-West-2) i386',
    'ap-southeast-1-amd64-instance': (
        'Ubuntu Server EC2 instance (Asia-Pacific-SouthEast) amd64'),
    'ap-southeast-1-i386-instance': (
        'Ubuntu Server EC2 instance (Asia-Pacific-SouthEast) i386'),
    'ap-southeast-1-amd64-ebs': (
        'Ubuntu Server EC2 EBS (Asia-Pacific-SouthEast) amd64'),
    'ap-southeast-1-i386-ebs': (
        'Ubuntu Server EC2 EBS (Asia-Pacific-SouthEast) i386'),
    'ap-northeast-1-amd64-instance': (
        'Ubuntu Server EC2 instance (Asia-Pacific-NorthEast) amd64'),
    'ap-northeast-1-i386-instance': (
        'Ubuntu Server EC2 instance (Asia-Pacific-NorthEast) i386'),
    'ap-northeast-1-amd64-ebs': (
        'Ubuntu Server EC2 EBS (Asia-Pacific-NorthEast) amd64'),
    'ap-northeast-1-i386-ebs': (
        'Ubuntu Server EC2 EBS (Asia-Pacific-NorthEast) i386'),
    'sa-east-1-amd64-ebs': (
        'Ubuntu Server EC2 EBS (South-America-East-1) amd64'),
    'sa-east-1-i386-ebs': 'Ubuntu Server EC2 EBS (South-America-East-1) i386',
    'sa-east-1-amd64-instance': (
        'Ubuntu Server EC2 instance (South-America-East-1) amd64'),
    'sa-east-1-i386-instance': (
        'Ubuntu Server EC2 instance (South-America-East-1) i386'),
}


def main():
    parser = argparse.ArgumentParser(
        description="Publish a provided list of AMIs to the QA tracker.")
    parser.add_argument('-m', '--milestone',
                        help='post to MILESTONE rather than the default')
    parser.add_argument('-n', '--note', default="",
                        help='set the note field on the build')
    parser.add_argument('-t', '--target',
                        help='post to an alternate QATracker')
    parser.add_argument("input_file", type=str,
                        help="An input file (published-ec2-daily.txt)")
    args = parser.parse_args()

    isotracker = ISOTracker(target=args.target)

    if not os.path.exists(args.input_file):
        print("Can't find input file: %s" % args.input_file)
        sys.exit(1)

    if args.milestone is None:
        args.milestone = isotracker.default_milestone()

    with open(args.input_file, 'r') as handle:
        for line in handle:
            zone, ami, arch, store = line.split()[0:4]
            if not ami.startswith('ami-'):
                continue
            if store == 'instance-store':
                store = 'instance'
            try:
                product = ec2_to_product_map['%s-%s-%s' % (zone, arch, store)]
            except KeyError:
                print("Can't find: %s-%s-%s" % (zone, arch, store))
                continue

            try:
                isotracker.post_build(product, ami,
                                      milestone=args.milestone,
                                      note=args.note)
            except KeyError as e:
                print(e)
                continue


if __name__ == '__main__':
    main()