Merge lp:~abentley/charmworld/polish-ingest-bundle into lp:~juju-jitsu/charmworld/trunk

Proposed by Aaron Bentley
Status: Merged
Approved by: Aaron Bentley
Approved revision: 335
Merged at revision: 334
Proposed branch: lp:~abentley/charmworld/polish-ingest-bundle
Merge into: lp:~juju-jitsu/charmworld/trunk
Diff against target: 80 lines (+30/-7)
2 files modified
charmworld/jobs/ingest.py (+9/-7)
charmworld/jobs/tests/test_ingest.py (+21/-0)
To merge this branch: bzr merge lp:~abentley/charmworld/polish-ingest-bundle
Reviewer Review Type Date Requested Status
Benji York (community) code Approve
Review via email: mp+178376@code.launchpad.net

Commit message

Stop ingest from crashing with bundles.

Description of the change

This branch fixes two obvious problems with ingesting bundles:
1. When retrieving files from a branch, the branch is not read-locked first.
2. When decorating bundles, the basket _id is needed, but not supplied.

2. was more confused because the variable was called basket_data, but it was the basket contents, not its data (which does have an _id).

With these changes, local ingests work.

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

This looks good. I think I introduced the non-lock bug you fixed, so I'm glad to see it fixed. Having tests is wonderful too. Thanks.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmworld/jobs/ingest.py'
2--- charmworld/jobs/ingest.py 2013-08-01 15:12:08 +0000
3+++ charmworld/jobs/ingest.py 2013-08-02 20:15:57 +0000
4@@ -49,8 +49,9 @@
5 from charmworld.utils import (
6 quote_key,
7 quote_yaml,
8+ read_locked,
9+ timestamp,
10 unquote_yaml,
11- timestamp,
12 )
13
14 # XXX Why not "from charmworld.jobs.config import..."? (Benji)
15@@ -285,18 +286,19 @@
16 return '%s%s-%d' % (owner_segment, basket_data['name'], revno)
17
18 @staticmethod
19- def decorate_bundles(basket_data):
20+ def decorate_bundles(basket_contents, basket_id):
21 # Give each bundle a unique ID.
22- for bundle_name, bundle in basket_data.items():
23- bundle['_id'] = '%s/%s' % (basket_data['_id'], bundle_name)
24+ for bundle_name, bundle in basket_contents.items():
25+ bundle['_id'] = '%s/%s' % (basket_id, bundle_name)
26
27 def decorate_basket(self, basket_data, fs):
28 branch_dir = fetch_branch(self.working_dir, basket_data, self.log)
29 branch = Branch.open(branch_dir)
30 revno = branch.revision_id_to_revno(basket_data['commit'])
31- tree = branch.repository.revision_tree(basket_data['commit'])
32 basket_data['_id'] = self.construct_basket_id(basket_data, revno)
33- basket_data['file_hashes'] = quote_yaml(slurp_files(fs, tree))
34+ with read_locked(branch):
35+ tree = branch.repository.revision_tree(basket_data['commit'])
36+ basket_data['file_hashes'] = quote_yaml(slurp_files(fs, tree))
37
38 @staticmethod
39 def get_deployer_config(fs, basket_data):
40@@ -310,7 +312,7 @@
41 self.decorate_basket(basket_data, fs)
42 self.db.baskets.save(basket_data)
43 deployer_config = self.get_deployer_config(fs, basket_data)
44- self.decorate_bundles(deployer_config)
45+ self.decorate_bundles(deployer_config, basket_data['_id'])
46 self.store_bundles(deployer_config, basket_data['_id'])
47
48
49
50=== modified file 'charmworld/jobs/tests/test_ingest.py'
51--- charmworld/jobs/tests/test_ingest.py 2013-07-31 14:41:29 +0000
52+++ charmworld/jobs/tests/test_ingest.py 2013-08-02 20:15:57 +0000
53@@ -385,6 +385,27 @@
54
55 self.assertTrue(bundle_data['_id'].endswith('-8'))
56
57+ def test_decorate_basket_stores_files(self):
58+ job = UpdateBundleJob()
59+ fs = getfs(self.db, collection='hashed-files')
60+ bundle_data = factory.get_payload_json()
61+ with bzr_isolation() as source_branch_dir:
62+ wt = BzrDir.create_standalone_workingtree(source_branch_dir)
63+ wt.bzrdir.root_transport.put_bytes(
64+ 'bundles.yaml', '{foo: {}}')
65+ wt.add('bundles.yaml')
66+ bundle_data['commit'] = wt.commit('commit message')
67+ with bundle_update_environment(source_branch_dir):
68+ job.decorate_basket(bundle_data, fs)
69+ bundles_hash = bundle_data['file_hashes'].get('bundles%2Eyaml')
70+ self.assertIsNot(None, bundles_hash)
71+ self.assertEqual('{foo: {}}', fs.get(bundles_hash).read())
72+
73+ def test_decorate_bundles(self):
74+ basket_contents = {'foo': {}}
75+ UpdateBundleJob.decorate_bundles(basket_contents, '~bar/baz')
76+ self.assertEqual({'foo': {'_id': '~bar/baz/foo'}}, basket_contents)
77+
78 def test_missing_revisions_generate_errors(self):
79 job = UpdateBundleJob()
80 job.setup(self.db)

Subscribers

People subscribed via source and target branches