Merge lp:~abentley/juju-release-tools/agents-stanzas-2 into lp:juju-release-tools

Proposed by Aaron Bentley
Status: Merged
Merged at revision: 233
Proposed branch: lp:~abentley/juju-release-tools/agents-stanzas-2
Merge into: lp:juju-release-tools
Diff against target: 181 lines (+106/-36)
2 files modified
make-ubuntu-agent.bash (+2/-2)
make_agent_json.py (+104/-34)
To merge this branch: bzr merge lp:~abentley/juju-release-tools/agents-stanzas-2
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+277051@code.launchpad.net

Commit message

Support all kinds of stanzas.

Description of the change

This branch adds support for alternate agent generation.

It supports Windows and Centos, but also supports using a single agent for all "living" ubuntus.

Because the number of parameters was getting unweildy, it creates a class to hold them. This class has various factory methods to support different generation approaches.

Since make_stanza can now make multiple stanzas, it is renamed to make_agent_json.

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

I have a few comments inline.

review: Needs Information (code)
237. By Aaron Bentley

Updates from review.

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

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

I've pushed a new version with the changes you asked for.

>> + self.version_name = date.today().strftime('%Y%m%d')
>
> Could this get weird if we build on machines in different
> timezones? maybe datetime.utcnow().strftime('%Y%m%d') is safer

The odds are low, because versions are only relevant if there are
competing item_names for a given content_id, and we don't do that.

Even if we did, items with the a given item_name will typically be built
on the same machine every time, so they will have the same timezone.

Still, there's no harm in using UTC time. Done.

>> + self.filename = filename + + @classmethod + def
>> for_ubuntu(cls, release, series, arch, version, revision_build,
>
> As an aside, I am constantly annoyed that debian calls the
> series/codename release, so when I work with lxc templates or
> scripts that make changelogs, I pass the series as the release.
> What we call a release is closer to debian version. While we don't
> see it often, I see that precise and trusty in the clouds are
> actually 12.04.5 and 14.04.2. There is no right ways to think about
> this.

The vagueness about release/series/codename bugs me, too. (And I can't
help wondering whether we really need both :-) Still, I tried to use
the terminology of the job. That meant that I had to do to do
"stanza['release'] = series" in make_stanzas(). Ugh.

> We need a single definition of this list that can be imported. Can
> you make this list a module level constant? I want formal
> definition of the series we support.

Done.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJWQgD5AAoJEK84cMOcf+9hAQQH/0+zqHNBoQ6+J4EwYMWcUln4
M0JaHGfe2XJXlrmlwqGRpYBtTrEcH9DWiCih1/2I7QyY4dXcpVoUtqkPqA8ROBTD
gZNjJRVQapWSStxs+4snfDVatGxmaM+/A+ayq4Vzp8XGSiteSxOQZVQRs0b3d+cE
3HooPlNx2m2pdqiY4s+6fDFkhqUSjJmyxq4un03LAmH/gjOhuZcyNzpt9+PjBfjI
6iI/xtC2U/hBW3gcZW8Qk7HyVCHPOW6aGKomMGNN9HX/E0vkZAfOihEdBc7xZYp2
H4hdA+s6UjzO9QjNDF37t7STmzLSXTYQeMmUF92rr9+yQed1leuU7BL6naPBkfQ=
=8nzG
-----END PGP SIGNATURE-----

Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'make-ubuntu-agent.bash'
2--- make-ubuntu-agent.bash 2015-11-06 21:00:26 +0000
3+++ make-ubuntu-agent.bash 2015-11-10 14:34:57 +0000
4@@ -10,5 +10,5 @@
5 (.*)\/bin\/jujud/\1/")
6 tarfile=juju-$version-$SERIES-$ARCH.tgz
7 tar -czvf $tarfile -C $(dirname $jujud) jujud
8-$RELEASE_TOOLS/make_stanza.py ubuntu $RELEASE $SERIES $ARCH $version \
9- $revision_build $tarfile
10+$RELEASE_TOOLS/make_agent_json.py ubuntu $tarfile $revision_build $version\
11+ $ARCH $RELEASE $SERIES
12
13=== renamed file 'make_stanza.py' => 'make_agent_json.py'
14--- make_stanza.py 2015-11-06 21:00:26 +0000
15+++ make_agent_json.py 2015-11-10 14:34:57 +0000
16@@ -1,61 +1,131 @@
17 #!/usr/bin/env python
18 from argparse import ArgumentParser
19-from datetime import date
20+from copy import deepcopy
21+from datetime import datetime
22 import hashlib
23 import os
24 import sys
25
26+from build_package import juju_series
27 from generate_simplestreams import json_dump
28
29
30+supported_windows_releases = (
31+ 'win2012', 'win2012hv', 'win2012hvr2', 'win2012r2', 'win7', 'win81',
32+ 'win8',
33+ )
34+
35+
36 def parse_args():
37 parser = ArgumentParser()
38 parsers = parser.add_subparsers(dest='command')
39 ubuntu = parsers.add_parser('ubuntu')
40+ living_ubuntu = parsers.add_parser('living-ubuntu')
41+ windows = parsers.add_parser('windows')
42+ centos = parsers.add_parser('centos')
43+ for subparser in [ubuntu, living_ubuntu, windows, centos]:
44+ subparser.add_argument('tarfile')
45+ subparser.add_argument('revision_build')
46+ subparser.add_argument('version')
47+ for subparser in [ubuntu, living_ubuntu]:
48+ subparser.add_argument('arch')
49 ubuntu.add_argument('release')
50 ubuntu.add_argument('series')
51- ubuntu.add_argument('arch')
52- ubuntu.add_argument('version')
53- ubuntu.add_argument('revision_build')
54- ubuntu.add_argument('tarfile')
55 return parser.parse_args()
56
57
58-def write_stanzas(release, series, arch, version, revision_build, tarfile):
59- path = 'agent/revision-build-{}/{}'.format(revision_build,
60- os.path.basename(tarfile))
61- hash_obj = hashlib.sha256()
62- with open(tarfile) as tarfile_fp:
63- content = tarfile_fp.read()
64- stanza = {
65- 'content_id': 'com.ubuntu.juju:revision-build-{}:tools'.format(
66- revision_build),
67- 'version_name': date.today().strftime('%Y%m%d'),
68- 'item_name': '{}-{}-{}'.format(version, series, arch),
69- 'product_name': 'com.ubuntu.juju:{}:{}'.format(release, arch),
70- 'path': path,
71- 'arch': arch,
72- 'version': version,
73- 'format': 'products:1.0',
74- 'release': series,
75- 'ftype': 'tar.gz',
76- 'size': len(content),
77- }
78- for hash_algorithm in ['sha256', 'md5', 'sha1']:
79- hash_obj = hashlib.new(hash_algorithm)
80- hash_obj.update(content)
81- stanza[hash_algorithm] = hash_obj.hexdigest()
82- filename = 'revision-build-{}-{}-{}.json'.format(revision_build, series,
83- arch)
84- json_dump([stanza], filename)
85+class StanzaWriter:
86+
87+ def __init__(self, releases, arch, version, revision_build,
88+ tarfile, filename):
89+ self.releases = releases
90+ self.arch = arch
91+ self.version = version
92+ self.revision_build = revision_build
93+ self.tarfile = tarfile
94+ self.version_name = datetime.utcnow().strftime('%Y%m%d')
95+ self.filename = filename
96+
97+ @classmethod
98+ def for_ubuntu(cls, release, series, arch, version, revision_build,
99+ tarfile):
100+ filename = 'revision-build-{}-{}-{}.json'.format(
101+ revision_build, series, arch)
102+ return cls(
103+ [(release, series)], arch, version, revision_build, tarfile,
104+ filename)
105+
106+ @classmethod
107+ def for_living_ubuntu(cls, arch, version, revision_build, tarfile):
108+ filename = 'revision-build-ubuntu-{}.json'.format(arch)
109+ releases = [
110+ (juju_series.get_version(name), name) for name
111+ in juju_series.get_living_names()]
112+ return cls(
113+ releases, arch, version, revision_build, tarfile, filename)
114+
115+ @classmethod
116+ def for_windows(cls, version, revision_build, tarfile):
117+ filename = 'revision-build-{}-windows.json'.format(
118+ revision_build)
119+ releases = [(r, r) for r in supported_windows_releases]
120+ return cls(releases, 'amd64', version, revision_build, tarfile,
121+ filename)
122+
123+ @classmethod
124+ def for_centos(cls, version, revision_build, tarfile):
125+ filename = 'revision-build-{}-centos.json'.format(revision_build)
126+ return cls([('centos7', 'centos7')], 'amd64', version, revision_build,
127+ tarfile, filename)
128+
129+ def write_stanzas(self):
130+ path = 'agent/revision-build-{}/{}'.format(
131+ self.revision_build, os.path.basename(self.tarfile))
132+ with open(self.tarfile) as tarfile_fp:
133+ content = tarfile_fp.read()
134+ hashes = {}
135+ for hash_algorithm in ['sha256', 'md5', 'sha1']:
136+ hash_obj = hashlib.new(hash_algorithm)
137+ hash_obj.update(content)
138+ hashes[hash_algorithm] = hash_obj.hexdigest()
139+ stanzas = list(self.make_stanzas(path, hashes, len(content)))
140+ json_dump(stanzas, self.filename)
141+
142+ def make_stanzas(self, path, hashes, size):
143+ for release, series in self.releases:
144+ stanza = {
145+ 'content_id': 'com.ubuntu.juju:revision-build-{}:tools'.format(
146+ self.revision_build),
147+ 'version_name': self.version_name,
148+ 'item_name': '{}-{}-{}'.format(self.version, series,
149+ self.arch),
150+ 'product_name': 'com.ubuntu.juju:{}:{}'.format(release,
151+ self.arch),
152+ 'path': path,
153+ 'arch': self.arch,
154+ 'version': self.version,
155+ 'format': 'products:1.0',
156+ 'release': series,
157+ 'ftype': 'tar.gz',
158+ 'size': size,
159+ }
160+ stanza.update(deepcopy(hashes))
161+ yield stanza
162
163
164 def main():
165 args = parse_args()
166 kwargs = dict(args.__dict__)
167 del kwargs['command']
168- write_stanzas(**kwargs)
169-
170+ if args.command == 'ubuntu':
171+ writer = StanzaWriter.for_ubuntu(**kwargs)
172+ if args.command == 'living-ubuntu':
173+ writer = StanzaWriter.for_living_ubuntu(**kwargs)
174+ elif args.command == 'windows':
175+ writer = StanzaWriter.for_windows(**kwargs)
176+ elif args.command == 'centos':
177+ writer = StanzaWriter.for_centos(**kwargs)
178+ writer.write_stanzas()
179
180 if __name__ == '__main__':
181 sys.exit(main())

Subscribers

People subscribed via source and target branches