Merge lp:~abentley/charmworld/remove-bzr-ingest-job into lp:~juju-jitsu/charmworld/trunk
- remove-bzr-ingest-job
- Merge into trunk
Proposed by
Aaron Bentley
Status: | Merged |
---|---|
Approved by: | Curtis Hovey |
Approved revision: | 282 |
Merged at revision: | 280 |
Proposed branch: | lp:~abentley/charmworld/remove-bzr-ingest-job |
Merge into: | lp:~juju-jitsu/charmworld/trunk |
Diff against target: |
471 lines (+150/-142) 5 files modified
charmworld/jobs/ingest.py (+96/-91) charmworld/jobs/tests/test_bzr.py (+33/-34) charmworld/jobs/tests/test_ingest.py (+8/-6) charmworld/jobs/tests/test_scan.py (+6/-7) charmworld/views/tests/test_charms.py (+7/-4) |
To merge this branch: | bzr merge lp:~abentley/charmworld/remove-bzr-ingest-job |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Curtis Hovey (community) | code | Approve | |
Review via email: mp+170899@code.launchpad.net |
Commit message
Remove BzrIngestJob.
Description of the change
This branch removes BzrIngestJob, converting its functionality into a set of functions.
Follow-on branches will remove other Job functionality, such as ScanIngestJob and FSIngestJob, and refactor the functions themselves into sensible collections of functionlality.
The main entry point is now do_bzr_update, which basically gathers resources and then calls update_
To post a comment you must log in.
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-06-14 21:08:36 +0000 | |||
3 | +++ charmworld/jobs/ingest.py 2013-06-21 20:10:35 +0000 | |||
4 | @@ -76,7 +76,7 @@ | |||
5 | 76 | pass | 76 | pass |
6 | 77 | 77 | ||
7 | 78 | def run(self, charm_data): | 78 | def run(self, charm_data): |
9 | 79 | raise NotImplemented | 79 | raise NotImplementedError |
10 | 80 | 80 | ||
11 | 81 | 81 | ||
12 | 82 | class DBIngestJob(IngestJob): | 82 | class DBIngestJob(IngestJob): |
13 | @@ -97,95 +97,101 @@ | |||
14 | 97 | self.fs = fs | 97 | self.fs = fs |
15 | 98 | 98 | ||
16 | 99 | 99 | ||
48 | 100 | class BzrIngestJob(FSIngestJob): | 100 | def do_bzr_update(charm_data, root_dir=None, db=None, fs=None, retry=True): |
49 | 101 | 101 | """Fetch a branch from bzr, and augment charm data.""" | |
50 | 102 | name = 'bzr' | 102 | job = FSIngestJob() |
51 | 103 | 103 | job.setup(db, fs) | |
52 | 104 | def setup(self, root_dir=None, db=None, fs=None): | 104 | if not root_dir: |
53 | 105 | super(BzrIngestJob, self).setup(db, fs) | 105 | root_dir = CHARM_DIR |
54 | 106 | if not root_dir: | 106 | root_dir = root_dir |
55 | 107 | root_dir = CHARM_DIR | 107 | if not os.path.exists(root_dir): |
56 | 108 | self.root_dir = root_dir | 108 | os.makedirs(root_dir) |
57 | 109 | if not os.path.exists(self.root_dir): | 109 | update_charm_files(root_dir, job.fs, charm_data, job.log, retry) |
58 | 110 | os.makedirs(self.root_dir) | 110 | |
59 | 111 | 111 | ||
60 | 112 | def store_branch_files(self, charm_data): | 112 | def update_charm_branch(root_dir, fs, charm_data, branch_dir, log, |
61 | 113 | """Process the bzr branch for files that need to be stored in gridfs. | 113 | retry=False): |
62 | 114 | """ | 114 | log.debug("Updating branch lp:%s", charm_data["branch_spec"]) |
63 | 115 | self.log.info('Storing files of branch into gridfs') | 115 | try: |
33 | 116 | filestore = CharmFileSet.save_files( | ||
34 | 117 | self.fs, charm_data, charm_data['branch_dir'], self.log) | ||
35 | 118 | self.log.info('Completed gridfs storage.') | ||
36 | 119 | return filestore | ||
37 | 120 | |||
38 | 121 | def add_files(self, charm_data): | ||
39 | 122 | charm_data['files'] = dict([ | ||
40 | 123 | (quote_key(cfile.filename), dict(cfile)) for cfile in | ||
41 | 124 | self.store_branch_files(charm_data) | ||
42 | 125 | ]) | ||
43 | 126 | return charm_data | ||
44 | 127 | |||
45 | 128 | def checkout_charm(self, charm_data, branch_dir): | ||
46 | 129 | # The branch has never been seen before. Original branch. | ||
47 | 130 | self.log.info("Branching charm lp:%s", charm_data["branch_spec"]) | ||
64 | 131 | subprocess.check_output( | 116 | subprocess.check_output( |
122 | 132 | ["/usr/bin/bzr", "co", "-q", | 117 | ["/usr/bin/bzr", "update", "-q"], |
123 | 133 | "lp:%s" % charm_data["branch_spec"], branch_dir]) | 118 | cwd=branch_dir, |
124 | 134 | charm_data = self.add_files(charm_data) | 119 | stderr=subprocess.STDOUT) |
125 | 135 | 120 | charm_data = add_files(fs, charm_data, log) | |
126 | 136 | def charm_is_current(self, charm_data, branch_dir): | 121 | except subprocess.CalledProcessError: |
127 | 137 | # It exists and check if it's the latest revision already. | 122 | # Update failed for some reason; destroy it and start over. |
128 | 138 | self.log.debug( | 123 | if retry: |
129 | 139 | "Existing charm from lp:%s", charm_data["branch_spec"]) | 124 | shutil.rmtree(branch_dir) |
130 | 140 | transport = get_transport(branch_dir) | 125 | return update_charm_files(root_dir, fs, charm_data, log, |
131 | 141 | branch = Branch.open_from_transport(transport) | 126 | retry=False) |
132 | 142 | cur_rev_id = branch.last_revision() | 127 | raise |
133 | 143 | return cur_rev_id == charm_data['commit'] | 128 | |
134 | 144 | 129 | ||
135 | 145 | def update_charm(self, charm_data, branch_dir, retry=False): | 130 | def charm_branch_is_current(charm_data, branch_dir, log): |
136 | 146 | self.log.debug("Updating branch lp:%s", charm_data["branch_spec"]) | 131 | # It exists and check if it's the latest revision already. |
137 | 147 | try: | 132 | log.debug( |
138 | 148 | subprocess.check_output( | 133 | "Existing charm from lp:%s", charm_data["branch_spec"]) |
139 | 149 | ["/usr/bin/bzr", "update", "-q"], | 134 | transport = get_transport(branch_dir) |
140 | 150 | cwd=branch_dir, | 135 | branch = Branch.open_from_transport(transport) |
141 | 151 | stderr=subprocess.STDOUT) | 136 | cur_rev_id = branch.last_revision() |
142 | 152 | charm_data = self.add_files(charm_data) | 137 | return cur_rev_id == charm_data['commit'] |
143 | 153 | except subprocess.CalledProcessError: | 138 | |
144 | 154 | # Update failed for some reason; destroy it and start over. | 139 | |
145 | 155 | if retry: | 140 | def checkout_charm(fs, charm_data, branch_dir, log): |
146 | 156 | shutil.rmtree(branch_dir) | 141 | # The branch has never been seen before. Original branch. |
147 | 157 | return self.run(charm_data, retry=False) | 142 | log.info("Branching charm lp:%s", charm_data["branch_spec"]) |
148 | 158 | raise | 143 | subprocess.check_output( |
149 | 159 | 144 | ["/usr/bin/bzr", "co", "-q", | |
150 | 160 | def run(self, charm_data, retry=True): | 145 | "lp:%s" % charm_data["branch_spec"], branch_dir]) |
151 | 161 | """Fetch a branch from bzr, and augment charm data.""" | 146 | charm_data = add_files(fs, charm_data, log) |
152 | 162 | if charm_data['branch_deleted']: | 147 | |
153 | 163 | return | 148 | |
154 | 164 | branch_dir = os.path.abspath( | 149 | def store_branch_files(fs, charm_data, log): |
155 | 165 | str(os.path.join(self.root_dir, | 150 | """Process the bzr branch for files that need to be stored in gridfs. |
156 | 166 | charm_data["series"], | 151 | """ |
157 | 167 | charm_data["owner"], | 152 | log.info('Storing files of branch into gridfs') |
158 | 168 | charm_data["name"], | 153 | filestore = CharmFileSet.save_files( |
159 | 169 | charm_data["bname"]))) | 154 | fs, charm_data, charm_data['branch_dir'], log) |
160 | 170 | 155 | log.info('Completed gridfs storage.') | |
161 | 171 | if not os.path.exists(os.path.dirname(branch_dir)): | 156 | return filestore |
162 | 172 | os.makedirs(os.path.dirname(branch_dir)) | 157 | |
163 | 173 | # Store the branch directory | 158 | |
164 | 174 | charm_data["branch_dir"] = branch_dir | 159 | def add_files(fs, charm_data, log): |
165 | 175 | 160 | charm_data['files'] = dict([ | |
166 | 176 | if not os.path.exists(branch_dir): | 161 | (quote_key(cfile.filename), dict(cfile)) for cfile in |
167 | 177 | # Charm doesn't exist; check it out. | 162 | store_branch_files(fs, charm_data, log) |
168 | 178 | self.checkout_charm(charm_data, branch_dir) | 163 | ]) |
169 | 179 | return | 164 | return charm_data |
170 | 180 | elif self.charm_is_current(charm_data, branch_dir): | 165 | |
171 | 181 | # Charm exists, and is current; log and finish. | 166 | |
172 | 182 | charm_data = self.add_files(charm_data) | 167 | def update_charm_files(root_dir, fs, charm_data, log, retry): |
173 | 183 | self.log.debug( | 168 | if charm_data['branch_deleted']: |
174 | 184 | "Already up to date lp:%s", charm_data["branch_spec"]) | 169 | return |
175 | 185 | return | 170 | branch_dir = os.path.abspath( |
176 | 186 | else: | 171 | str(os.path.join(root_dir, |
177 | 187 | # Charm exists, but needs updating; update it. | 172 | charm_data["series"], |
178 | 188 | self.update_charm(charm_data, branch_dir, retry) | 173 | charm_data["owner"], |
179 | 174 | charm_data["name"], | ||
180 | 175 | charm_data["bname"]))) | ||
181 | 176 | |||
182 | 177 | if not os.path.exists(os.path.dirname(branch_dir)): | ||
183 | 178 | os.makedirs(os.path.dirname(branch_dir)) | ||
184 | 179 | # Store the branch directory | ||
185 | 180 | charm_data["branch_dir"] = branch_dir | ||
186 | 181 | |||
187 | 182 | if not os.path.exists(branch_dir): | ||
188 | 183 | # Charm doesn't exist; check it out. | ||
189 | 184 | checkout_charm(fs, charm_data, branch_dir, log) | ||
190 | 185 | return | ||
191 | 186 | elif charm_branch_is_current(charm_data, branch_dir, log): | ||
192 | 187 | # Charm exists, and is current; log and finish. | ||
193 | 188 | charm_data = add_files(fs, charm_data, log) | ||
194 | 189 | log.debug( | ||
195 | 190 | "Already up to date lp:%s", charm_data["branch_spec"]) | ||
196 | 191 | return | ||
197 | 192 | else: | ||
198 | 193 | # Charm exists, but needs updating; update it. | ||
199 | 194 | update_charm_branch(charm_data, branch_dir, retry) | ||
200 | 189 | 195 | ||
201 | 190 | 196 | ||
202 | 191 | def log(stage, level, exc, charm_data, tb=None): | 197 | def log(stage, level, exc, charm_data, tb=None): |
203 | @@ -228,8 +234,7 @@ | |||
204 | 228 | charm_data.pop('error', None) | 234 | charm_data.pop('error', None) |
205 | 229 | log = logging.getLogger("charm.update_charm") | 235 | log = logging.getLogger("charm.update_charm") |
206 | 230 | try: | 236 | try: |
209 | 231 | if not run_job(BzrIngestJob(), charm_data, db=db): | 237 | do_bzr_update(charm_data, db=db) |
208 | 232 | return False | ||
210 | 233 | if not run_job(StoreIngestJob(), charm_data): | 238 | if not run_job(StoreIngestJob(), charm_data): |
211 | 234 | return False | 239 | return False |
212 | 235 | if not run_job(ProofIngestJob(), charm_data): | 240 | if not run_job(ProofIngestJob(), charm_data): |
213 | 236 | 241 | ||
214 | === modified file 'charmworld/jobs/tests/test_bzr.py' | |||
215 | --- charmworld/jobs/tests/test_bzr.py 2013-06-07 12:36:30 +0000 | |||
216 | +++ charmworld/jobs/tests/test_bzr.py 2013-06-21 20:10:35 +0000 | |||
217 | @@ -11,8 +11,10 @@ | |||
218 | 11 | 11 | ||
219 | 12 | 12 | ||
220 | 13 | from charmworld.jobs.ingest import ( | 13 | from charmworld.jobs.ingest import ( |
222 | 14 | BzrIngestJob, | 14 | add_files, |
223 | 15 | do_bzr_update, | ||
224 | 15 | ChangelogIngestJob, | 16 | ChangelogIngestJob, |
225 | 17 | FSIngestJob, | ||
226 | 16 | ) | 18 | ) |
227 | 17 | from charmworld.testing import ( | 19 | from charmworld.testing import ( |
228 | 18 | factory, | 20 | factory, |
229 | @@ -27,38 +29,32 @@ | |||
230 | 27 | ZRH = 'Z. Random Hacker <zrandom@example.com>' | 29 | ZRH = 'Z. Random Hacker <zrandom@example.com>' |
231 | 28 | 30 | ||
232 | 29 | 31 | ||
234 | 30 | class TestBzrJob(JobTestBase): | 32 | class TestBzrOperations(JobTestBase): |
235 | 31 | 33 | ||
236 | 32 | def setUp(self): | 34 | def setUp(self): |
239 | 33 | super(TestBzrJob, self).setUp() | 35 | super(TestBzrOperations, self).setUp() |
240 | 34 | self.test_dir = 'test_bzr_job' | 36 | self.test_dir = 'test_bzr_operations' |
241 | 35 | os.mkdir(self.test_dir) | 37 | os.mkdir(self.test_dir) |
242 | 36 | 38 | ||
243 | 37 | def tearDown(self): | 39 | def tearDown(self): |
244 | 38 | shutil.rmtree(self.test_dir) | 40 | shutil.rmtree(self.test_dir) |
246 | 39 | super(TestBzrJob, self).tearDown() | 41 | super(TestBzrOperations, self).tearDown() |
247 | 40 | 42 | ||
248 | 41 | def test_run_creates_charm_directory(self): | 43 | def test_run_creates_charm_directory(self): |
249 | 42 | job = BzrIngestJob() | ||
250 | 43 | job.setup(root_dir=self.test_dir, db=self.db) | ||
251 | 44 | ignore, charm = factory.makeCharm(self.db, branch_root=self.test_dir) | 44 | ignore, charm = factory.makeCharm(self.db, branch_root=self.test_dir) |
254 | 45 | with patch.object(job, 'checkout_charm'): | 45 | with patch('charmworld.jobs.ingest.checkout_charm'): |
255 | 46 | job.run(charm) | 46 | do_bzr_update(charm, self.test_dir, self.db) |
256 | 47 | expected_path = os.path.abspath(os.path.join( | 47 | expected_path = os.path.abspath(os.path.join( |
257 | 48 | self.test_dir, charm['series'], charm['owner'], charm['name'])) | 48 | self.test_dir, charm['series'], charm['owner'], charm['name'])) |
258 | 49 | self.assertTrue(os.path.exists(expected_path)) | 49 | self.assertTrue(os.path.exists(expected_path)) |
259 | 50 | 50 | ||
260 | 51 | def test_run_checkouts_new_charms(self): | 51 | def test_run_checkouts_new_charms(self): |
261 | 52 | job = BzrIngestJob() | ||
262 | 53 | job.setup(root_dir=self.test_dir, db=self.db) | ||
263 | 54 | ignore, charm = factory.makeCharm(self.db, branch_root=self.test_dir) | 52 | ignore, charm = factory.makeCharm(self.db, branch_root=self.test_dir) |
266 | 55 | with patch.object(job, 'checkout_charm') as mock: | 53 | with patch('charmworld.jobs.ingest.checkout_charm') as mock: |
267 | 56 | job.run(charm) | 54 | do_bzr_update(charm, self.test_dir, self.db) |
268 | 57 | self.assertTrue(mock.called) | 55 | self.assertTrue(mock.called) |
269 | 58 | 56 | ||
270 | 59 | def test_run_updates_exising_charms_if_not_current(self): | 57 | def test_run_updates_exising_charms_if_not_current(self): |
271 | 60 | job = BzrIngestJob() | ||
272 | 61 | job.setup(root_dir=self.test_dir, db=self.db) | ||
273 | 62 | ignore, charm = factory.makeCharm(self.db, branch_root=self.test_dir) | 58 | ignore, charm = factory.makeCharm(self.db, branch_root=self.test_dir) |
274 | 63 | charm_path = os.path.abspath(os.path.join( | 59 | charm_path = os.path.abspath(os.path.join( |
275 | 64 | self.test_dir, | 60 | self.test_dir, |
276 | @@ -67,14 +63,13 @@ | |||
277 | 67 | charm['name'], | 63 | charm['name'], |
278 | 68 | charm['bname'])) | 64 | charm['bname'])) |
279 | 69 | os.makedirs(charm_path) | 65 | os.makedirs(charm_path) |
283 | 70 | with patch.object(job, 'charm_is_current', lambda x, y: False): | 66 | with patch('charmworld.jobs.ingest.charm_branch_is_current', |
284 | 71 | with patch.object(job, 'update_charm') as mock: | 67 | lambda x, y, z: False): |
285 | 72 | job.run(charm) | 68 | with patch('charmworld.jobs.ingest.update_charm_branch') as mock: |
286 | 69 | do_bzr_update(charm, self.test_dir, self.db) | ||
287 | 73 | self.assertTrue(mock.called) | 70 | self.assertTrue(mock.called) |
288 | 74 | 71 | ||
289 | 75 | def test_run_does_not_update_exising_charms_if_current(self): | 72 | def test_run_does_not_update_exising_charms_if_current(self): |
290 | 76 | job = BzrIngestJob() | ||
291 | 77 | job.setup(root_dir=self.test_dir, db=self.db) | ||
292 | 78 | ignore, charm = factory.makeCharm(self.db, branch_root=self.test_dir) | 73 | ignore, charm = factory.makeCharm(self.db, branch_root=self.test_dir) |
293 | 79 | charm_path = os.path.abspath(os.path.join( | 74 | charm_path = os.path.abspath(os.path.join( |
294 | 80 | self.test_dir, | 75 | self.test_dir, |
295 | @@ -83,10 +78,12 @@ | |||
296 | 83 | charm['name'], | 78 | charm['name'], |
297 | 84 | charm['bname'])) | 79 | charm['bname'])) |
298 | 85 | os.makedirs(charm_path) | 80 | os.makedirs(charm_path) |
303 | 86 | with patch.object(job, 'charm_is_current', lambda x, y: True): | 81 | with patch('charmworld.jobs.ingest.charm_branch_is_current', |
304 | 87 | with patch.object(job, 'add_files'): | 82 | lambda x, y, z: True): |
305 | 88 | with patch.object(job, 'update_charm') as mock: | 83 | with patch('charmworld.jobs.ingest.add_files'): |
306 | 89 | job.run(charm) | 84 | with patch( |
307 | 85 | 'charmworld.jobs.ingest.update_charm_branch') as mock: | ||
308 | 86 | do_bzr_update(charm, self.test_dir, self.db) | ||
309 | 90 | self.assertFalse(mock.called) | 87 | self.assertFalse(mock.called) |
310 | 91 | 88 | ||
311 | 92 | def test_add_files(self): | 89 | def test_add_files(self): |
312 | @@ -98,17 +95,15 @@ | |||
313 | 98 | 'name': 'sample_charm', | 95 | 'name': 'sample_charm', |
314 | 99 | 'bname': 'trunk', | 96 | 'bname': 'trunk', |
315 | 100 | } | 97 | } |
317 | 101 | job = BzrIngestJob() | 98 | job = FSIngestJob() |
318 | 102 | job.setup(db=self.db) | 99 | job.setup(db=self.db) |
320 | 103 | job.add_files(charm_data) | 100 | add_files(job.fs, charm_data, job.log) |
321 | 104 | self.assertIn('files', charm_data) | 101 | self.assertIn('files', charm_data) |
322 | 105 | self.assertNotIn('icon', charm_data) | 102 | self.assertNotIn('icon', charm_data) |
323 | 106 | 103 | ||
324 | 107 | def test_deleted_branch(self): | 104 | def test_deleted_branch(self): |
326 | 108 | # If the Launchpad branch of a charm is deleted, BzrJob does | 105 | # If the Launchpad branch of a charm is deleted, do_bzr_update does |
327 | 109 | # not do anything. | 106 | # not do anything. |
328 | 110 | job = BzrIngestJob() | ||
329 | 111 | job.setup(root_dir=self.test_dir, db=self.db) | ||
330 | 112 | ignore, charm = factory.makeCharm( | 107 | ignore, charm = factory.makeCharm( |
331 | 113 | self.db, branch_root=self.test_dir, branch_deleted=True) | 108 | self.db, branch_root=self.test_dir, branch_deleted=True) |
332 | 114 | charm_path = os.path.abspath(os.path.join( | 109 | charm_path = os.path.abspath(os.path.join( |
333 | @@ -117,11 +112,15 @@ | |||
334 | 117 | charm['owner'], | 112 | charm['owner'], |
335 | 118 | charm['name'], | 113 | charm['name'], |
336 | 119 | charm['bname'])) | 114 | charm['bname'])) |
342 | 120 | with patch.object(job, 'checkout_charm') as checkout_mock: | 115 | with patch('charmworld.jobs.ingest.checkout_charm') as checkout_mock: |
343 | 121 | with patch.object(job, 'charm_is_current') as is_current_mock: | 116 | with patch('charmworld.jobs.ingest.charm_branch_is_current') as ( |
344 | 122 | with patch.object(job, 'add_files') as add_files_mock: | 117 | is_current_mock): |
345 | 123 | with patch.object(job, 'update_charm') as update_mock: | 118 | with patch('charmworld.jobs.ingest.add_files') as ( |
346 | 124 | job.run(charm) | 119 | add_files_mock): |
347 | 120 | with patch( | ||
348 | 121 | 'charmworld.jobs.ingest.update_charm_branch') as ( | ||
349 | 122 | update_mock): | ||
350 | 123 | do_bzr_update(charm, self.test_dir, self.db) | ||
351 | 125 | self.assertFalse(os.path.exists(charm_path)) | 124 | self.assertFalse(os.path.exists(charm_path)) |
352 | 126 | self.assertFalse(checkout_mock.called) | 125 | self.assertFalse(checkout_mock.called) |
353 | 127 | self.assertFalse(is_current_mock.called) | 126 | self.assertFalse(is_current_mock.called) |
354 | 128 | 127 | ||
355 | === modified file 'charmworld/jobs/tests/test_ingest.py' | |||
356 | --- charmworld/jobs/tests/test_ingest.py 2013-06-07 12:36:30 +0000 | |||
357 | +++ charmworld/jobs/tests/test_ingest.py 2013-06-21 20:10:35 +0000 | |||
358 | @@ -19,6 +19,7 @@ | |||
359 | 19 | 19 | ||
360 | 20 | from charmworld.charmstore import get_address | 20 | from charmworld.charmstore import get_address |
361 | 21 | from charmworld.jobs.ingest import ( | 21 | from charmworld.jobs.ingest import ( |
362 | 22 | add_files, | ||
363 | 22 | IngestError, | 23 | IngestError, |
364 | 23 | IngestJob, | 24 | IngestJob, |
365 | 24 | run_job, | 25 | run_job, |
366 | @@ -64,16 +65,16 @@ | |||
367 | 64 | 65 | ||
368 | 65 | @contextmanager | 66 | @contextmanager |
369 | 66 | def update_environment(real_charm_data, index_client): | 67 | def update_environment(real_charm_data, index_client): |
371 | 67 | def checkout_charm(self, charm_data, branch_dir): | 68 | def checkout_charm(fs, charm_data, branch_dir, log): |
372 | 68 | wt = BzrDir.create_standalone_workingtree(branch_dir) | 69 | wt = BzrDir.create_standalone_workingtree(branch_dir) |
373 | 69 | wt.bzrdir.root_transport.mkdir('hooks') | 70 | wt.bzrdir.root_transport.mkdir('hooks') |
374 | 70 | wt.bzrdir.root_transport.put_bytes('metadata.yaml', json.dumps({ | 71 | wt.bzrdir.root_transport.put_bytes('metadata.yaml', json.dumps({ |
375 | 71 | 'name': charm_data['name'], | 72 | 'name': charm_data['name'], |
376 | 72 | 'summary': real_charm_data['summary'], | 73 | 'summary': real_charm_data['summary'], |
377 | 73 | })) | 74 | })) |
379 | 74 | self.add_files(charm_data) | 75 | add_files(fs, charm_data, log) |
380 | 75 | checkout_patch = patch( | 76 | checkout_patch = patch( |
382 | 76 | 'charmworld.jobs.ingest.BzrIngestJob.checkout_charm', checkout_charm) | 77 | 'charmworld.jobs.ingest.checkout_charm', checkout_charm) |
383 | 77 | 78 | ||
384 | 78 | @urlmatch(path='/charm-info') | 79 | @urlmatch(path='/charm-info') |
385 | 79 | def mock_store_data(url, request): | 80 | def mock_store_data(url, request): |
386 | @@ -150,15 +151,16 @@ | |||
387 | 150 | # Induce improbable error -- bname must be a string. | 151 | # Induce improbable error -- bname must be a string. |
388 | 151 | charm_data['bname'] = None | 152 | charm_data['bname'] = None |
389 | 152 | update_handler = self.get_handler('charm.update') | 153 | update_handler = self.get_handler('charm.update') |
391 | 153 | bzr_handler = self.get_handler('charm.bzr') | 154 | update_charm_handler = self.get_handler('charm.update_charm') |
392 | 154 | run_job(UpdateCharmJob(), self.payload(charm_data), db=self.db) | 155 | run_job(UpdateCharmJob(), self.payload(charm_data), db=self.db) |
393 | 155 | self.assertIsNot( | 156 | self.assertIsNot( |
394 | 156 | None, self.db.charms.find_one(charm_data['_id'])) | 157 | None, self.db.charms.find_one(charm_data['_id'])) |
395 | 157 | logs = ''.join(r.getMessage() for r in update_handler.buffer) | 158 | logs = ''.join(r.getMessage() for r in update_handler.buffer) |
397 | 158 | bzr_logs = ''.join(r.getMessage() for r in bzr_handler.buffer) | 159 | update_charm_logs = ''.join(r.getMessage() |
398 | 160 | for r in update_charm_handler.buffer) | ||
399 | 159 | self.assertEqual('Saving %s' % charm_data['_id'], logs) | 161 | self.assertEqual('Saving %s' % charm_data['_id'], logs) |
400 | 160 | self.assertIn("'NoneType' object has no attribute 'startswith'", | 162 | self.assertIn("'NoneType' object has no attribute 'startswith'", |
402 | 161 | bzr_logs) | 163 | update_charm_logs) |
403 | 162 | 164 | ||
404 | 163 | def test_updates_promulgated(self): | 165 | def test_updates_promulgated(self): |
405 | 164 | charm_data = factory.get_charm_json(promulgated=False) | 166 | charm_data = factory.get_charm_json(promulgated=False) |
406 | 165 | 167 | ||
407 | === modified file 'charmworld/jobs/tests/test_scan.py' | |||
408 | --- charmworld/jobs/tests/test_scan.py 2013-05-27 10:26:40 +0000 | |||
409 | +++ charmworld/jobs/tests/test_scan.py 2013-06-21 20:10:35 +0000 | |||
410 | @@ -1,12 +1,13 @@ | |||
411 | 1 | # Copyright 2012, 2013 Canonical Ltd. This software is licensed under the | 1 | # Copyright 2012, 2013 Canonical Ltd. This software is licensed under the |
412 | 2 | # GNU Affero General Public License version 3 (see the file LICENSE). | 2 | # GNU Affero General Public License version 3 (see the file LICENSE). |
413 | 3 | 3 | ||
417 | 4 | from charmworld.jobs.ingest import BzrIngestJob | 4 | from charmworld.jobs.ingest import ( |
418 | 5 | from charmworld.jobs.ingest import IngestError | 5 | IngestError, |
419 | 6 | from charmworld.jobs.ingest import ScanIngestJob | 6 | ScanIngestJob, |
420 | 7 | store_branch_files, | ||
421 | 8 | ) | ||
422 | 7 | from charmworld.testing import factory | 9 | from charmworld.testing import factory |
423 | 8 | from charmworld.testing import JobTestBase | 10 | from charmworld.testing import JobTestBase |
424 | 9 | from charmworld.testing import REAL_FILE_CHARM_DIR | ||
425 | 10 | from charmworld.utils import quote_key | 11 | from charmworld.utils import quote_key |
426 | 11 | 12 | ||
427 | 12 | 13 | ||
428 | @@ -14,14 +15,12 @@ | |||
429 | 14 | 15 | ||
430 | 15 | def setUp(self): | 16 | def setUp(self): |
431 | 16 | super(TestScanJob, self).setUp() | 17 | super(TestScanJob, self).setUp() |
432 | 17 | self.bzr_job = BzrIngestJob() | ||
433 | 18 | self.bzr_job.setup(db=self.db, root_dir=REAL_FILE_CHARM_DIR) | ||
434 | 19 | self.scan_job = ScanIngestJob() | 18 | self.scan_job = ScanIngestJob() |
435 | 20 | self.scan_job.setup(db=self.db) | 19 | self.scan_job.setup(db=self.db) |
436 | 21 | ignore, self.charm = factory.makeCharm(self.db, with_real_files=True) | 20 | ignore, self.charm = factory.makeCharm(self.db, with_real_files=True) |
437 | 22 | self.charm['files'] = dict([ | 21 | self.charm['files'] = dict([ |
438 | 23 | (quote_key(cfile.filename), dict(cfile)) for cfile in | 22 | (quote_key(cfile.filename), dict(cfile)) for cfile in |
440 | 24 | self.bzr_job.store_branch_files(self.charm) | 23 | store_branch_files(self.scan_job.fs, self.charm, self.scan_job.log) |
441 | 25 | ]) | 24 | ]) |
442 | 26 | 25 | ||
443 | 27 | def test_config_metadata_with_dotted_keys(self): | 26 | def test_config_metadata_with_dotted_keys(self): |
444 | 28 | 27 | ||
445 | === modified file 'charmworld/views/tests/test_charms.py' | |||
446 | --- charmworld/views/tests/test_charms.py 2013-06-19 20:45:35 +0000 | |||
447 | +++ charmworld/views/tests/test_charms.py 2013-06-21 20:10:35 +0000 | |||
448 | @@ -1,7 +1,10 @@ | |||
449 | 1 | # Copyright 2012, 2013 Canonical Ltd. This software is licensed under the | 1 | # Copyright 2012, 2013 Canonical Ltd. This software is licensed under the |
450 | 2 | # GNU Affero General Public License version 3 (see the file LICENSE). | 2 | # GNU Affero General Public License version 3 (see the file LICENSE). |
451 | 3 | 3 | ||
453 | 4 | from charmworld.jobs.ingest import BzrIngestJob | 4 | from charmworld.jobs.ingest import ( |
454 | 5 | add_files, | ||
455 | 6 | FSIngestJob, | ||
456 | 7 | ) | ||
457 | 5 | from charmworld.models import Charm | 8 | from charmworld.models import Charm |
458 | 6 | from charmworld.models import CharmSource | 9 | from charmworld.models import CharmSource |
459 | 7 | from charmworld.testing import factory | 10 | from charmworld.testing import factory |
460 | @@ -282,9 +285,9 @@ | |||
461 | 282 | ignore, charm = factory.makeCharm( | 285 | ignore, charm = factory.makeCharm( |
462 | 283 | self.db, owner='bar', series='precise', | 286 | self.db, owner='bar', series='precise', |
463 | 284 | promulgated=promulgated, with_real_files=True) | 287 | promulgated=promulgated, with_real_files=True) |
467 | 285 | bzr_job = BzrIngestJob() | 288 | fs_job = FSIngestJob() |
468 | 286 | bzr_job.setup(root_dir=None, db=self.db) | 289 | fs_job.setup(db=self.db) |
469 | 287 | bzr_job.add_files(charm) | 290 | add_files(fs_job.fs, charm, fs_job.log) |
470 | 288 | self.db.charms.update({'_id': charm['_id']}, charm) | 291 | self.db.charms.update({'_id': charm['_id']}, charm) |
471 | 289 | return charm | 292 | return charm |
472 | 290 | 293 |
Thank you.