Merge lp:~brian-murray/cupstream2distro/bug-1541258 into lp:cupstream2distro

Proposed by Brian Murray
Status: Merged
Merged at revision: 1353
Proposed branch: lp:~brian-murray/cupstream2distro/bug-1541258
Merge into: lp:cupstream2distro
Diff against target: 255 lines (+38/-64)
7 files modified
citrain/recipes/base.py (+1/-19)
citrain/recipes/manager.py (+6/-0)
cupstream2distro/archive.py (+1/-1)
cupstream2distro/silomanager.py (+1/-14)
tests/unit/test_recipe_base.py (+1/-9)
tests/unit/test_recipe_manager.py (+26/-0)
tests/unit/test_silomanager.py (+2/-21)
To merge this branch: bzr merge lp:~brian-murray/cupstream2distro/bug-1541258
Reviewer Review Type Date Requested Status
Robert Bruce Park (community) Approve
Review via email: mp+284970@code.launchpad.net

Description of the change

I wasn't sure how to make test_manager_get_published_versions work without having get_published_versions still return the versions dict.

To post a comment you must log in.
Revision history for this message
Robert Bruce Park (robru) wrote :

I like the direction this is going in, just a couple comments inline.

review: Needs Fixing
Revision history for this message
Robert Bruce Park (robru) wrote :

On second thought, instead of calling the method from the end of get_states, consider merging the method into get_states directly. No point iterating over the builds twice.

1356. By Brian Murray

address some feedback from robru

1357. By Brian Murray

move get_published_versions info into get_states

Revision history for this message
Robert Bruce Park (robru) wrote :

Great, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'citrain/recipes/base.py'
2--- citrain/recipes/base.py 2016-01-15 21:31:00 +0000
3+++ citrain/recipes/base.py 2016-02-03 23:29:24 +0000
4@@ -44,12 +44,10 @@
5 )
6 from cupstream2distro.utils import (
7 SILO_DIR,
8- atomic_write,
9 env,
10 log_value_of,
11 name_ppa,
12 suppress,
13- utf8_open,
14 )
15
16
17@@ -134,6 +132,7 @@
18 our_version = None
19 packagelist = None
20 authorized = None
21+ published = None
22 failures = set()
23
24 def __init__(self, source_name, series, dest, silo_ppa, primary=None):
25@@ -232,23 +231,6 @@
26 """Identify where keyfiles are located."""
27 return '{}_{}'.format(self.path, key)
28
29- def set_file(self, key, value):
30- """Atomically write a value to a file."""
31- filename = self.find_file(key)
32- log_value_of.value('Writing')
33- log_value_of.filename('To')
34- with atomic_write(filename, 'w') as data:
35- data.write(str(value))
36-
37- def get_file(self, key):
38- """Read value from disk.
39-
40- :param key: Fragment of filename to read from.
41- """
42- with suppress(FileNotFoundError):
43- with utf8_open(self.find_file(key)) as data:
44- return data.read().strip()
45-
46 def validate_phase(self):
47 """Stub validate phase."""
48 pass
49
50=== modified file 'citrain/recipes/manager.py'
51--- citrain/recipes/manager.py 2016-01-22 02:33:07 +0000
52+++ citrain/recipes/manager.py 2016-02-03 23:29:24 +0000
53@@ -18,6 +18,7 @@
54 These classes manage the instantiation of recipes and execution of phases.
55 """
56
57+import json
58 import logging
59
60 from collections import defaultdict
61@@ -110,8 +111,13 @@
62 """Report the statuses of all packages in this silo."""
63 self.do() # Instantiates build objects if necessary.
64 states = defaultdict(list)
65+ versions = defaultdict(dict)
66 for name, build in sorted(self.builds.items()):
67 states[build.check_status()].append(
68 '{}/{}'.format(build.name, build.series.name))
69+ if not build.published:
70+ continue
71+ versions[build.name][build.series.name] = build.published
72+ self.silo_state.published_versions = json.dumps(versions)
73 log_value_of.states()
74 return pretty_print_states(states)
75
76=== modified file 'cupstream2distro/archive.py'
77--- cupstream2distro/archive.py 2016-01-10 10:12:24 +0000
78+++ cupstream2distro/archive.py 2016-02-03 23:29:24 +0000
79@@ -229,7 +229,7 @@
80 version=version)
81 if dest:
82 if self.archive_id(source) == self.archive_id(dest):
83- self.set_file('published', version)
84+ self.published = version
85 return dest.pocket + ' pocket'
86 return 'Needs rebuild due to burned version number'
87
88
89=== modified file 'cupstream2distro/silomanager.py'
90--- cupstream2distro/silomanager.py 2016-02-02 22:55:33 +0000
91+++ cupstream2distro/silomanager.py 2016-02-03 23:29:24 +0000
92@@ -27,7 +27,7 @@
93 import sys
94
95 import os
96-from os.path import basename, dirname, join
97+from os.path import dirname, join
98
99 from glob import glob
100 from random import shuffle
101@@ -354,19 +354,6 @@
102 self.push_to_ppa_description()
103
104 @property
105- def published_versions(self):
106- """Return a dictionary of what versions have been published."""
107- versions = defaultdict(dict)
108- fileglob = join(SILOS_DIR, self.siloname, '*', '*', '*published')
109- for filename in sorted(glob(fileglob)):
110- source = basename(filename).split('_')[0].split('+')[0]
111- series = filename.split('/')[-3]
112- with utf8_open(filename) as data:
113- version = data.read().strip()
114- versions[source][series] = version
115- return json.dumps(versions, sort_keys=True)
116-
117- @property
118 def all_projects(self):
119 """Get a list of all projects."""
120 return sorted(set(self.mps) | set(self.sources))
121
122=== modified file 'tests/unit/test_recipe_base.py'
123--- tests/unit/test_recipe_base.py 2016-01-15 21:31:00 +0000
124+++ tests/unit/test_recipe_base.py 2016-02-03 23:29:24 +0000
125@@ -95,7 +95,7 @@
126 makedirs(build.path, exist_ok=True)
127 build.get_package_version = Mock(return_value='42-0ubuntu1')
128 self.assertEqual(build.check_status(), 'Proposed pocket')
129- self.assertEqual(build.get_file('published'), '42-0ubuntu1')
130+ self.assertEqual(build.published, '42-0ubuntu1')
131
132 @patch('cupstream2distro.archive.newest')
133 def test_archive_pocket_mismatch(self, new):
134@@ -211,14 +211,6 @@
135 build2.buildstate = 'Successfully built'
136 self.assertEqual(build.check_status(), 'Diff missing')
137
138- def test_get_file(self):
139- """Ensure we can read files from disk."""
140- build = BuildBase('getattr', self.series, self.dest, self.ppa)
141- makedirs(build.path, exist_ok=True)
142- build.set_file('published', 'hello')
143- self.assertEqual(build.get_file('published'), 'hello')
144- self.assertIsNone(build.get_file('nonexistent'))
145-
146 def test_pre_validate(self):
147 """Test some nops."""
148 mock = Mock()
149
150=== modified file 'tests/unit/test_recipe_manager.py'
151--- tests/unit/test_recipe_manager.py 2016-01-22 02:33:07 +0000
152+++ tests/unit/test_recipe_manager.py 2016-02-03 23:29:24 +0000
153@@ -15,6 +15,8 @@
154
155 """Tests for CI Train Recipe Manager."""
156
157+import json
158+
159 from mock import Mock, call, patch
160
161 from tests.unit import DirectoryAwareTestCase
162@@ -165,8 +167,10 @@
163 silo_state = Mock()
164 one = Mock(check_status=Mock(return_value='Successfully built'))
165 one.name = 'one'
166+ one.published = '1'
167 two = Mock(check_status=Mock(return_value='Successfully built'))
168 two.name = 'two'
169+ two.published = '2'
170 one.series.name = two.series.name = 'xenial'
171 bman = Manager(silo_state)
172 bman.types = True
173@@ -178,8 +182,10 @@
174 silo_state = Mock()
175 one = Mock(check_status=Mock(return_value='Successfully built'))
176 one.name = 'one'
177+ one.published = '1'
178 two = Mock(check_status=Mock(return_value='Failed to build'))
179 two.name = 'two'
180+ two.published = '2'
181 one.series.name = two.series.name = 'xenial'
182 bman = Manager(silo_state)
183 bman.types = True
184@@ -187,3 +193,23 @@
185 self.assertEqual(
186 bman.get_states(),
187 'Failed to build (two/xenial). Successfully built (one/xenial).')
188+
189+ def test_manager_published_versions(self):
190+ """Fetch the series and versions from a build."""
191+ silo_state = Mock()
192+ vivid = Mock(check_status=Mock(return_value='Successfully built'))
193+ vivid.name = 'foo'
194+ vivid.series.name = 'vivid'
195+ vivid.published = '1'
196+ xenial = Mock(check_status=Mock(return_value='Failed to build'))
197+ xenial.name = 'bar'
198+ xenial.series.name = 'xenial'
199+ xenial.published = None
200+ bman = Manager(silo_state)
201+ bman.types = True
202+ bman.builds = dict(one=vivid, two=xenial)
203+ bman.get_states()
204+ versions = {'foo': {'vivid': '1'}}
205+ self.assertEqual(
206+ silo_state.published_versions,
207+ json.dumps(versions))
208
209=== modified file 'tests/unit/test_silomanager.py'
210--- tests/unit/test_silomanager.py 2016-02-02 22:09:56 +0000
211+++ tests/unit/test_silomanager.py 2016-02-03 23:29:24 +0000
212@@ -20,7 +20,7 @@
213 import signal
214 import logging
215
216-from os.path import dirname, join
217+from os.path import join
218 from os import makedirs
219
220 from mock import Mock, patch, call
221@@ -29,7 +29,7 @@
222
223 from cupstream2distro import silomanager
224 from cupstream2distro.silomanager import SiloState, splitter, stock_main
225-from cupstream2distro.utils import env, utf8_open
226+from cupstream2distro.utils import env
227 from cupstream2distro.errors import PrepError, NoStatusError
228
229
230@@ -608,25 +608,6 @@
231 self.assertEqual(self.state.dest, lp_mock.get_ppa.return_value)
232 lp_mock.get_ppa.assert_called_once_with('team/ubuntu/ppa')
233
234- def test_published_versions(self):
235- """Return a json string representing the published versions."""
236- expected = dict(
237- alpha=['1.0+15.04', '1.0+16.04'],
238- beta=['1.0+15.04', '1.0+16.04'],
239- )
240- silodir = join(self.tempdir, self.state.siloname)
241- for source, versions in expected.items():
242- for version in versions:
243- series = 'vivid' if '15.04' in version else 'xenial'
244- path = join(silodir, series, source, source + '_published')
245- makedirs(dirname(path), exist_ok=True)
246- with utf8_open(path, 'w') as data:
247- data.write(version)
248- self.assertEqual(
249- self.state.published_versions,
250- '{"alpha": {"vivid": "1.0+15.04", "xenial": "1.0+16.04"}, '
251- '"beta": {"vivid": "1.0+15.04", "xenial": "1.0+16.04"}}')
252-
253 @patch('cupstream2distro.silomanager.SiloState.sources', ['foobar'])
254 @patch('cupstream2distro.silomanager.SiloState.mps', dict(merger=[]))
255 def test_silostate_all_projects(self):

Subscribers

People subscribed via source and target branches

to all changes: