Merge lp:~andrewjbeach/juju-release-tools/s3-container-arg into lp:juju-release-tools

Proposed by Andrew James Beach
Status: Merged
Merged at revision: 355
Proposed branch: lp:~andrewjbeach/juju-release-tools/s3-container-arg
Merge into: lp:juju-release-tools
Diff against target: 344 lines (+57/-42)
4 files modified
agent_archive.py (+15/-11)
lprelease.py (+5/-4)
tests/test_agent_archive.py (+36/-26)
tests/test_make_release_notes.py (+1/-1)
To merge this branch: bzr merge lp:~andrewjbeach/juju-release-tools/s3-container-arg
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+312097@code.launchpad.net

Description of the change

Added -s/--s3-container as a command line argument to agent_archive.py.

The preset value is now only used as a default, the value is passed down to
where it is used.

The test file now uses a fake value to help sperate the tests from any actual
runs of the script.

In addition I fixed some things scattered throughout that was causing
`make lint` to complain, just to clean the board.

Some more tests should be added but the diff was getting rather large.

To post a comment you must log in.
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 'agent_archive.py'
2--- agent_archive.py 2016-02-17 15:48:39 +0000
3+++ agent_archive.py 2016-11-29 22:29:55 +0000
4@@ -12,7 +12,7 @@
5
6
7 # The S3 container and path to add to and get from.
8-S3_CONTAINER = 's3://juju-qa-data/agent-archive'
9+S3_CONTAINER_DEFAULT = 's3://juju-qa-data/agent-archive'
10 # The set of agents to make.
11 AGENT_TEMPLATES = (
12 'juju-{}-centos7-amd64.tgz',
13@@ -26,7 +26,7 @@
14 'juju-{}-win8-amd64.tgz',
15 'juju-{}-win81-amd64.tgz',
16 'juju-{}-win10-amd64.tgz',
17-)
18+ )
19 # The versions of agent that may or will exist. The agents will
20 # always start with juju, the series will start with "win" and the
21 # arch is always amd64.
22@@ -70,7 +70,7 @@
23
24 Wrap deprecated raw_input for testing.
25 """
26- return raw_input(prompt) # pyflakes:ignore
27+ return raw_input(prompt) # NOQA
28
29
30 def listing_to_files(listing):
31@@ -82,7 +82,7 @@
32 return agents
33
34
35-def is_new_version(source_path, config, verbose=False):
36+def is_new_version(source_path, config, s3_container, verbose=False):
37 """Return True when the version is new, else False.
38
39 :raises: ValueError if the version exists and is different.
40@@ -91,7 +91,7 @@
41 if verbose:
42 print('Checking that %s does not already exist.' % source_path)
43 source_agent = os.path.basename(source_path)
44- agent_path = '%s/%s' % (S3_CONTAINER, source_agent)
45+ agent_path = '%s/%s' % (s3_container, source_agent)
46 existing_version = run(
47 ['ls', '--list-md5', agent_path], config=config, verbose=verbose)
48 if not existing_version:
49@@ -128,22 +128,23 @@
50 raise ValueError(
51 '%s does not match an expected version.' % source_agent)
52 source_path = os.path.abspath(os.path.expanduser(args.source_agent))
53- if not is_new_version(source_path, args.config, verbose=args.verbose):
54+ if not is_new_version(source_path, args.config, args.s3_container,
55+ verbose=args.verbose):
56 if args.verbose:
57 print("Nothing to do.")
58 return
59 # The fastest way to put the files in place is to upload the source_agent
60 # then use the s3cmd cp to make remote versions.
61 if args.verbose:
62- print('Uploading %s to %s' % (source_agent, S3_CONTAINER))
63- remote_source = '%s/%s' % (S3_CONTAINER, source_agent)
64+ print('Uploading %s to %s' % (source_agent, args.s3_container))
65+ remote_source = '%s/%s' % (args.s3_container, source_agent)
66 run(['put', source_path, remote_source],
67 config=args.config, dry_run=args.dry_run, verbose=args.verbose)
68 agent_versions.remove(source_agent)
69 os_name = get_source_agent_os(source_agent)
70 agent_versions = [a for a in agent_versions if os_name in a]
71 for agent_version in agent_versions:
72- destination = '%s/%s' % (S3_CONTAINER, agent_version)
73+ destination = '%s/%s' % (args.s3_container, agent_version)
74 if args.verbose:
75 print('Copying %s to %s' % (remote_source, destination))
76 run(['cp', remote_source, destination],
77@@ -153,7 +154,7 @@
78 def get_agents(args):
79 """Download agents matching a version to a destination path."""
80 version = args.version
81- agent_glob = '%s/juju-%s*' % (S3_CONTAINER, version)
82+ agent_glob = '%s/juju-%s*' % (args.s3_container, version)
83 destination = os.path.abspath(os.path.expanduser(args.destination))
84 output = run(
85 ['get', agent_glob, destination],
86@@ -169,7 +170,7 @@
87 matches the expected operation.
88 """
89 version = args.version
90- agent_glob = '%s/juju-%s*' % (S3_CONTAINER, version)
91+ agent_glob = '%s/juju-%s*' % (args.s3_container, version)
92 existing_versions = run(
93 ['ls', agent_glob], config=args.config, verbose=args.verbose)
94 if args.verbose:
95@@ -201,6 +202,9 @@
96 parser.add_argument(
97 '-c', '--config', action='store', default=None,
98 help='The S3 config file.')
99+ parser.add_argument(
100+ '-s', '--s3-container', action='store', default=S3_CONTAINER_DEFAULT,
101+ help='The S3 container to act on.')
102 subparsers = parser.add_subparsers(help='sub-command help')
103 # add juju-1.21.0-win2012-amd64.tgz
104 parser_add = subparsers.add_parser(
105
106=== modified file 'lprelease.py'
107--- lprelease.py 2016-09-29 21:51:22 +0000
108+++ lprelease.py 2016-11-29 22:29:55 +0000
109@@ -97,10 +97,11 @@
110 def defer_bugs(milestone, deferred_milestone, dry_run, verbose):
111 unfinished_bug_tasks = milestone.searchTasks(status=UNFINISHED)
112 for bug_task in unfinished_bug_tasks:
113- #This needs fixed; bug #1629115
114- #if verbose:
115- # print('Retargeting bug %s [%s] to %s' % (
116- # bug_task.bug.id, bug_task.bug.title, deferred_milestone.name))
117+ # This needs fixed; bug #1629115
118+ # if verbose:
119+ # print('Retargeting bug %s [%s] to %s' % (
120+ # bug_task.bug.id, bug_task.bug.title,
121+ # deferred_milestone.name))
122 bug_task.milestone = deferred_milestone
123 if not dry_run:
124 bug_task.lp_save()
125
126=== modified file 'tests/test_agent_archive.py'
127--- tests/test_agent_archive.py 2016-02-17 15:48:39 +0000
128+++ tests/test_agent_archive.py 2016-11-29 22:29:55 +0000
129@@ -16,19 +16,25 @@
130 from utils import temp_dir
131
132
133+# Name of a non-existant s3-container.
134+S3_CONTAINER_FAKE = 's3://juju-qa-fake/agent-archive'
135+
136+
137 class FakeArgs:
138
139 def __init__(self, source_agent=None, version=None, destination=None,
140- config=None, verbose=False, dry_run=False):
141+ config=None, verbose=False, dry_run=False,
142+ s3_container=S3_CONTAINER_FAKE):
143 self.source_agent = source_agent
144 self.version = version
145 self.destination = destination
146+ self.s3_container = s3_container
147 self.config = None
148 self.verbose = verbose
149 self.dry_run = dry_run
150
151
152-class AgentArchive(TestCase):
153+class TestAgentArchive(TestCase):
154
155 def test_main_options(self):
156 with patch('agent_archive.add_agents') as mock:
157@@ -108,7 +114,7 @@
158 get_source_agent_os('juju-1.24.footu-amd64.tgz')
159
160 def test_listing_to_files(self):
161- start = '2014-10-23 22:11 9820182 s3://juju-qa-data/agent-archive/%s'
162+ start = '2014-10-23 22:11 9820182 s3://juju-qa-fake/agent-archive/%s'
163 listing = []
164 expected_agents = []
165 agents = [
166@@ -118,15 +124,16 @@
167 for agent in agents:
168 listing.append(start % agent)
169 expected_agents.append(
170- 's3://juju-qa-data/agent-archive/%s' % agent)
171+ 's3://juju-qa-fake/agent-archive/%s' % agent)
172 agents = listing_to_files('\n'.join(listing))
173 self.assertEqual(expected_agents, agents)
174
175 def test_is_new_version(self):
176- agent = 's3://juju-qa-data/agent-archive/juju-1.21.0-win2012-amd64.tgz'
177+ agent = 's3://juju-qa-fake/agent-archive/juju-1.21.0-win2012-amd64.tgz'
178 with patch('agent_archive.run', return_value='') as mock:
179 result = is_new_version(
180- 'juju-1.21.0-win2012-amd64.tgz', 'config', verbose=False)
181+ 'juju-1.21.0-win2012-amd64.tgz', 'config',
182+ S3_CONTAINER_FAKE, verbose=False)
183 self.assertTrue(result)
184 mock.assert_called_with(
185 ['ls', '--list-md5', agent], config='config', verbose=False)
186@@ -134,26 +141,27 @@
187 def test_is_new_version_idential(self):
188 listing = (
189 '2015-05-27 14:16 8292541 b33aed8f3134996703dc39f9a7c95783 '
190- 's3://juju-qa-data/agent-archive/juju-1.21.0-win2012-amd64.tgz')
191+ 's3://juju-qa-fake/agent-archive/juju-1.21.0-win2012-amd64.tgz')
192 with temp_dir() as base:
193 local_agent = os.path.join(base, 'juju-1.21.0-win2012-amd64.tgz')
194 with open(local_agent, 'w') as f:
195 f.write('agent')
196 with patch('agent_archive.run', return_value=listing):
197- result = is_new_version(local_agent, 'config')
198+ result = is_new_version(local_agent, 'config',
199+ S3_CONTAINER_FAKE)
200 self.assertFalse(result)
201
202 def test_is_new_version_not_identical_error(self):
203 listing = (
204 '2015-05-27 14:16 8292541 69988f8072c3839fa2a364d80a652f3f '
205- 's3://juju-qa-data/agent-archive/juju-1.21.0-win2012-amd64.tgz')
206+ 's3://juju-qa-fake/agent-archive/juju-1.21.0-win2012-amd64.tgz')
207 with temp_dir() as base:
208 local_agent = os.path.join(base, 'juju-1.21.0-win2012-amd64.tgz')
209 with open(local_agent, 'w') as f:
210 f.write('agent')
211 with patch('agent_archive.run', return_value=listing):
212 with self.assertRaises(ValueError) as e:
213- is_new_version(local_agent, 'config')
214+ is_new_version(local_agent, 'config', S3_CONTAINER_FAKE)
215 self.assertIn('Agents cannot be changed', str(e.exception))
216
217 def test_add_agent_with_bad_source_raises_error(self):
218@@ -179,7 +187,8 @@
219 with self.assertRaises(ValueError):
220 add_agents(cmd_args)
221 agent_path = os.path.abspath(cmd_args.source_agent)
222- nv_mock.assert_called_with(agent_path, None, verbose=False)
223+ nv_mock.assert_called_with(agent_path, None, S3_CONTAINER_FAKE,
224+ verbose=False)
225
226 def test_add_agent_puts_and_copies_win(self):
227 cmd_args = FakeArgs(source_agent='juju-1.21.0-win2012-amd64.tgz')
228@@ -189,27 +198,27 @@
229 add_agents(cmd_args)
230 nv_mock.assert_called_with(
231 os.path.abspath('juju-1.21.0-win2012-amd64.tgz'),
232- None, verbose=False)
233+ None, S3_CONTAINER_FAKE, verbose=False)
234 self.assertEqual(10, mock.call_count)
235 output, args, kwargs = mock.mock_calls[0]
236 agent_path = os.path.abspath(cmd_args.source_agent)
237 self.assertEqual(
238 ['put', agent_path,
239- 's3://juju-qa-data/agent-archive/juju-1.21.0-win2012-amd64.tgz'],
240+ 's3://juju-qa-fake/agent-archive/juju-1.21.0-win2012-amd64.tgz'],
241 args[0])
242 # The remaining calls after the put is a fast cp to the other names.
243 output, args, kwargs = mock.mock_calls[1]
244 self.assertEqual(
245 ['cp',
246- 's3://juju-qa-data/agent-archive/juju-1.21.0-win2012-amd64.tgz',
247- 's3://juju-qa-data/agent-archive/'
248+ 's3://juju-qa-fake/agent-archive/juju-1.21.0-win2012-amd64.tgz',
249+ 's3://juju-qa-fake/agent-archive/'
250 'juju-1.21.0-win2012hvr2-amd64.tgz'],
251 args[0])
252 output, args, kwargs = mock.mock_calls[8]
253 self.assertEqual(
254 ['cp',
255- 's3://juju-qa-data/agent-archive/juju-1.21.0-win2012-amd64.tgz',
256- 's3://juju-qa-data/agent-archive/juju-1.21.0-win81-amd64.tgz'],
257+ 's3://juju-qa-fake/agent-archive/juju-1.21.0-win2012-amd64.tgz',
258+ 's3://juju-qa-fake/agent-archive/juju-1.21.0-win81-amd64.tgz'],
259 args[0])
260
261 def test_add_agent_puts_centos(self):
262@@ -219,12 +228,13 @@
263 return_value=True) as nv_mock:
264 add_agents(cmd_args)
265 agent_path = os.path.abspath(cmd_args.source_agent)
266- nv_mock.assert_called_with(agent_path, None, verbose=False)
267+ nv_mock.assert_called_with(agent_path, None, S3_CONTAINER_FAKE,
268+ verbose=False)
269 self.assertEqual(1, mock.call_count)
270 agent_path = os.path.abspath(cmd_args.source_agent)
271 mock.assert_called_with(
272 ['put', agent_path,
273- 's3://juju-qa-data/agent-archive/juju-1.24.0-centos7-amd64.tgz'],
274+ 's3://juju-qa-fake/agent-archive/juju-1.24.0-centos7-amd64.tgz'],
275 config=None, verbose=False, dry_run=False)
276
277 def test_get_agent(self):
278@@ -234,7 +244,7 @@
279 get_agents(cmd_args)
280 args, kwargs = mock.call_args
281 self.assertEqual(
282- (['get', 's3://juju-qa-data/agent-archive/juju-1.21.0*',
283+ (['get', 's3://juju-qa-fake/agent-archive/juju-1.21.0*',
284 destination], ),
285 args)
286
287@@ -246,7 +256,7 @@
288 self.assertIn('No 1.21.0 agents found', str(e.exception))
289 args, kwargs = mock.call_args
290 self.assertEqual(
291- (['ls', 's3://juju-qa-data/agent-archive/juju-1.21.0*'], ),
292+ (['ls', 's3://juju-qa-fake/agent-archive/juju-1.21.0*'], ),
293 args)
294 self.assertIs(None, kwargs['config'], )
295
296@@ -259,12 +269,12 @@
297 self.assertEqual(1, mock.call_count)
298 args, kwargs = mock.call_args
299 self.assertEqual(
300- (['ls', 's3://juju-qa-data/agent-archive/juju-1.21.0*'], ),
301+ (['ls', 's3://juju-qa-fake/agent-archive/juju-1.21.0*'], ),
302 args)
303
304 def test_delete_agent_with_yes(self):
305 cmd_args = FakeArgs(version='1.21.0')
306- start = '2014-10-23 22:11 9820182 s3://juju-qa-data/agent-archive/%s'
307+ start = '2014-10-23 22:11 9820182 s3://juju-qa-fake/agent-archive/%s'
308 listing = []
309 agents = [
310 'juju-1.21.0-win2012-amd64.tgz',
311@@ -279,17 +289,17 @@
312 self.assertEqual(3, mock.call_count)
313 output, args, kwargs = mock.mock_calls[0]
314 self.assertEqual(
315- ['ls', 's3://juju-qa-data/agent-archive/juju-1.21.0*'],
316+ ['ls', 's3://juju-qa-fake/agent-archive/juju-1.21.0*'],
317 args[0])
318 output, args, kwargs = mock.mock_calls[1]
319 self.assertEqual(
320 ['del',
321- 's3://juju-qa-data/agent-archive/juju-1.21.0-win2012-amd64.tgz'],
322+ 's3://juju-qa-fake/agent-archive/juju-1.21.0-win2012-amd64.tgz'],
323 args[0])
324 output, args, kwargs = mock.mock_calls[2]
325 self.assertEqual(
326 ['del',
327- 's3://juju-qa-data/agent-archive/juju-1.21.0-win8.1-amd64.tgz'],
328+ 's3://juju-qa-fake/agent-archive/juju-1.21.0-win8.1-amd64.tgz'],
329 args[0])
330 self.assertIs(None, kwargs['config'])
331 self.assertFalse(kwargs['dry_run'])
332
333=== modified file 'tests/test_make_release_notes.py'
334--- tests/test_make_release_notes.py 2016-08-25 19:00:50 +0000
335+++ tests/test_make_release_notes.py 2016-11-29 22:29:55 +0000
336@@ -123,7 +123,7 @@
337 self.assertIn(
338 'https://jujucharms.com/docs/devel/temp-release-notes', text)
339 self.assertIn('snap install juju --beta --devmode', text)
340-
341+
342 def test_make_notes_with_notable(self):
343 # The default value of None implies a stable bug fix release.
344 text = make_notes('1.20.1', DEVEL, "* One\n Lp 1", notable=None)

Subscribers

People subscribed via source and target branches