Merge lp:~abentley/juju-release-tools/image-compatibility into lp:juju-release-tools

Proposed by Aaron Bentley
Status: Merged
Merged at revision: 301
Proposed branch: lp:~abentley/juju-release-tools/image-compatibility
Merge into: lp:juju-release-tools
Diff against target: 193 lines (+79/-14)
3 files modified
build-juju (+30/-0)
make_aws_image_streams.py (+33/-4)
tests/test_make_aws_image_streams.py (+16/-10)
To merge this branch: bzr merge lp:~abentley/juju-release-tools/image-compatibility
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+294290@code.launchpad.net

Commit message

Write image streams in a way compatible with old jujus.

Description of the change

Improve the compatibility of our image streams with old jujus.

Old jujus expected to find root_store and virt at the item level, but we were storing it at a higher level. The simplestreams authoring tools support forcing an attribute to be stored at the item level with the 'sticky' parameter.

Unfortunately, the 'sticky' parameter was not exposed by write_juju_streams, so I had to copy its implementation in order to set 'sticky'.

Let me know if you want more unit tests for write_juju_streams.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you.

review: Approve (code)
Revision history for this message
Aaron Bentley (abentley) wrote :

On 2016-05-10 03:38 PM, Curtis Hovey wrote:
> Is your tree stale? I reviewed this some time ago and it is in the tree.

I forgot to push after I merged it locally. I'm not sure why it was in
your tree.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'build-juju'
2--- build-juju 1970-01-01 00:00:00 +0000
3+++ build-juju 2016-05-10 19:18:04 +0000
4@@ -0,0 +1,30 @@
5+#!/bin/bash
6+set -eu
7+usage() {
8+ cat <<EOT
9+usage: $0 BRANCH [REPO_PATH]"
10+Build the specified juju branch to a package. Intended for manual testing.
11+
12+BRANCH is the branch to build.
13+REPO_PATH is end of the github repo URL. It defaults to juju/juju.
14+
15+Packages are built for the current machine's series and the amd64 architecture.
16+DEBEMAIL and DEBFULLNAME are derived from "bzr whoami".
17+EOT
18+exit 1
19+}
20+test $# -gt 0 || usage
21+set -x
22+
23+TOOLS_DIR=$(dirname $(readlink -f $0))
24+PATH=$TOOLS_DIR:$PATH
25+BRANCH=$1
26+REPO=https://github.com/${2-juju/juju}
27+DEBEMAIL=$(bzr whoami --email -d $TOOLS_DIR)
28+DEBFULLNAME=$(bzr whoami -d $TOOLS_DIR|sed 's/ *<.*>//')
29+SERIES=$(lsb_release --codename -s)
30+export PATH DEBEMAIL DEBFULLNAME
31+make-release-tarball.bash $BRANCH $REPO
32+build_package.py -v source ./juju-core_*.tar.gz ./ $SERIES 999999999
33+build_package.py -v binary juju-build-$SERIES-all/juju-core_*.dsc \
34+ ./build-binary-$SERIES-amd64 $SERIES amd64
35
36=== modified file 'make_aws_image_streams.py'
37--- make_aws_image_streams.py 2016-03-18 17:38:16 +0000
38+++ make_aws_image_streams.py 2016-05-10 19:18:04 +0000
39@@ -2,6 +2,7 @@
40 from __future__ import print_function
41
42 from argparse import ArgumentParser
43+from copy import deepcopy
44 from datetime import datetime
45 import os
46 import sys
47@@ -10,13 +11,16 @@
48
49 from boto import ec2
50 from simplestreams.generate_simplestreams import (
51+ generate_index,
52 items2content_trees,
53+ json_dump,
54 )
55 from simplestreams.json2streams import (
56 Item,
57- write_juju_streams,
58+ JujuFileNamer,
59+ write_release_index,
60 )
61-from simplestreams.util import timestamp
62+from simplestreams import util
63
64
65 def get_parameters(argv=None):
66@@ -190,10 +194,35 @@
67 """
68 items = [make_item(i, now) for i in iter_centos_images(
69 credentials, china_credentials)]
70- updated = timestamp()
71+ updated = util.timestamp()
72 data = {'updated': updated, 'datatype': 'image-ids'}
73 trees = items2content_trees(items, data)
74- write_juju_streams(streams, trees, updated)
75+ write_juju_streams(streams, trees, updated, [
76+ 'path', 'sha256', 'md5', 'size', 'virt', 'root_store'])
77+
78+
79+def write_juju_streams(out_d, trees, updated, sticky):
80+ # Based on simplestreams.json2streams.write_juju_streams +
81+ # simplestreams.generate_simplestreams.write_streams,
82+ # but allows sticky to be specified.
83+ namer = JujuFileNamer
84+ index = generate_index(trees, updated, namer)
85+ to_write = [(namer.get_index_path(), index,)]
86+ # Don't let products_condense modify the input
87+ trees = deepcopy(trees)
88+ for content_id in trees:
89+ util.products_condense(
90+ trees[content_id], sticky=sticky)
91+ content = trees[content_id]
92+ to_write.append((index['index'][content_id]['path'], content,))
93+ out_filenames = []
94+ for (outfile, data) in to_write:
95+ filef = os.path.join(out_d, outfile)
96+ util.mkdir_p(os.path.dirname(filef))
97+ json_dump(data, filef)
98+ out_filenames.append(filef)
99+ out_filenames.append(write_release_index(out_d))
100+ return out_filenames
101
102
103 def main():
104
105=== modified file 'tests/test_make_aws_image_streams.py'
106--- tests/test_make_aws_image_streams.py 2016-03-18 17:34:57 +0000
107+++ tests/test_make_aws_image_streams.py 2016-05-10 19:18:04 +0000
108@@ -179,7 +179,7 @@
109
110 def test_happy_path(self):
111 image = make_mock_image()
112- now = datetime(2001, 02, 03)
113+ now = datetime(2001, 2, 3)
114 item = make_item(image, now)
115 self.assertEqual(item.content_id, 'com.ubuntu.cloud.released:aws')
116 self.assertEqual(item.product_name,
117@@ -204,7 +204,7 @@
118 def test_china(self):
119 image = make_mock_image()
120 image.region.endpoint = 'foo.amazonaws.com.cn'
121- now = datetime(2001, 02, 03)
122+ now = datetime(2001, 2, 3)
123 item = make_item(image, now)
124 self.assertEqual(item.content_id, 'com.ubuntu.cloud.released:aws-cn')
125 self.assertEqual(item.data['endpoint'], 'https://foo.amazonaws.com.cn')
126@@ -212,7 +212,7 @@
127 def test_not_x86_64(self):
128 image = make_mock_image()
129 image.architecture = 'ppc128'
130- now = datetime(2001, 02, 03)
131+ now = datetime(2001, 2, 3)
132 with self.assertRaisesRegexp(ValueError,
133 'Architecture is "ppc128", not'
134 ' "x86_64".'):
135@@ -221,7 +221,7 @@
136 def test_not_centos_7(self):
137 image = make_mock_image()
138 image.name = 'CentOS Linux 8'
139- now = datetime(2001, 02, 03)
140+ now = datetime(2001, 2, 3)
141 with self.assertRaisesRegexp(ValueError,
142 'Name "CentOS Linux 8" does not begin'
143 ' with "CentOS Linux 7".'):
144@@ -264,7 +264,7 @@
145 class TestWriteStreams(TestCase):
146
147 def test_write_streams(self):
148- now = datetime(2001, 02, 03)
149+ now = datetime(2001, 2, 3)
150 credentials = {'name': 'aws'}
151 china_credentials = {'name': 'aws-cn'}
152 east_conn = Mock()
153@@ -277,7 +277,7 @@
154 with patch('make_aws_image_streams.iter_region_connection',
155 return_value=[east_conn, west_conn],
156 autospec=True) as irc_mock:
157- with patch('make_aws_image_streams.timestamp',
158+ with patch('simplestreams.util.timestamp',
159 return_value='now'):
160 with patch('sys.stderr'):
161 write_streams(credentials, china_credentials, now,
162@@ -304,21 +304,27 @@
163 'updated': 'now',
164 'datatype': 'image-ids',
165 'products': {'com.ubuntu.cloud:server:centos7:amd64': {
166- 'root_store': 'ebs',
167 'endpoint': 'https://foo',
168 'arch': 'amd64',
169 'release_title': 'Centos 7',
170 'label': 'release',
171 'release_codename': 'centos7',
172 'version': 'centos7',
173- 'virt': 'hvm',
174 'release': 'centos7',
175 'os': 'centos',
176 'id': 'qux',
177 'versions': {'20010203': {
178 'items': {
179- 'usww1he': {'region': 'us-west-1'},
180- 'usee1he': {'region': 'us-east-1'},
181+ 'usww1he': {
182+ 'region': 'us-west-1',
183+ 'root_store': 'ebs',
184+ 'virt': 'hvm',
185+ },
186+ 'usee1he': {
187+ 'region': 'us-east-1',
188+ 'root_store': 'ebs',
189+ 'virt': 'hvm',
190+ },
191 }
192 }},
193 }},

Subscribers

People subscribed via source and target branches