Merge lp:~rockstar/launchpad/recipe-too-new into lp:launchpad

Proposed by Paul Hummer
Status: Merged
Approved by: Aaron Bentley
Approved revision: no longer in the source branch.
Merged at revision: 11612
Proposed branch: lp:~rockstar/launchpad/recipe-too-new
Merge into: lp:launchpad
Diff against target: 123 lines (+45/-5)
4 files modified
lib/lp/code/browser/sourcepackagerecipe.py (+6/-0)
lib/lp/code/browser/tests/test_sourcepackagerecipe.py (+19/-0)
lib/lp/code/model/tests/test_sourcepackagerecipe.py (+8/-5)
lib/lp/code/tests/helpers.py (+12/-0)
To merge this branch: bzr merge lp:~rockstar/launchpad/recipe-too-new
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+36379@code.launchpad.net

Description of the change

This branch fixes an issue where users try to use a recipe format that we don't yet support. In this case, we have bzr-builder in source code, but Aaron can't land the support until the buildds have the newer bzr-builder.

I talked this over with Aaron, and we decided to monkey patch the actual NEWEST_VERSION in bzr-builder to a recipe format version we're never going to have (in this case, it's also the frequency of my local HAM radio repeater). This way, we won't have erroneous test failures when we actually add support for 0.3 formatted recipes.

While talking this over with Aaron, I found another potential place where this may occur in tests, and fixed that test as well.

To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) wrote :

The monkey patch needs to use a try/finally block to ensure the new value doesn't leak, or better yet, use a context manager for the purpose.

Other than that, looks fine.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/browser/sourcepackagerecipe.py'
--- lib/lp/code/browser/sourcepackagerecipe.py 2010-09-02 14:28:57 +0000
+++ lib/lp/code/browser/sourcepackagerecipe.py 2010-09-22 21:13:48 +0000
@@ -60,6 +60,7 @@
60 BuildAlreadyPending,60 BuildAlreadyPending,
61 NoSuchBranch,61 NoSuchBranch,
62 PrivateBranchRecipe,62 PrivateBranchRecipe,
63 TooNewRecipeFormat
63 )64 )
64from lp.code.interfaces.sourcepackagerecipe import (65from lp.code.interfaces.sourcepackagerecipe import (
65 ISourcePackageRecipe,66 ISourcePackageRecipe,
@@ -333,6 +334,11 @@
333 data['recipe_text'], data['description'], data['distros'],334 data['recipe_text'], data['description'], data['distros'],
334 data['daily_build_archive'], data['build_daily'])335 data['daily_build_archive'], data['build_daily'])
335 Store.of(source_package_recipe).flush()336 Store.of(source_package_recipe).flush()
337 except TooNewRecipeFormat:
338 self.setFieldError(
339 'recipe_text',
340 'The recipe format version specified is not available.')
341 return
336 except ForbiddenInstructionError:342 except ForbiddenInstructionError:
337 # XXX: bug=592513 We shouldn't be hardcoding "run" here.343 # XXX: bug=592513 We shouldn't be hardcoding "run" here.
338 self.setFieldError(344 self.setFieldError(
339345
=== modified file 'lib/lp/code/browser/tests/test_sourcepackagerecipe.py'
--- lib/lp/code/browser/tests/test_sourcepackagerecipe.py 2010-09-20 19:12:35 +0000
+++ lib/lp/code/browser/tests/test_sourcepackagerecipe.py 2010-09-22 21:13:48 +0000
@@ -40,6 +40,7 @@
40 SourcePackageRecipeBuildView,40 SourcePackageRecipeBuildView,
41 )41 )
42from lp.code.interfaces.sourcepackagerecipe import MINIMAL_RECIPE_TEXT42from lp.code.interfaces.sourcepackagerecipe import MINIMAL_RECIPE_TEXT
43from lp.code.tests.helpers import recipe_parser_newest_version
43from lp.registry.interfaces.pocket import PackagePublishingPocket44from lp.registry.interfaces.pocket import PackagePublishingPocket
44from lp.soyuz.model.processor import ProcessorFamily45from lp.soyuz.model.processor import ProcessorFamily
45from lp.testing import (46from lp.testing import (
@@ -304,6 +305,24 @@
304 self.assertEqual(305 self.assertEqual(
305 get_message_text(browser, 2), 'foo is not a branch on Launchpad.')306 get_message_text(browser, 2), 'foo is not a branch on Launchpad.')
306307
308 def test_create_recipe_format_too_new(self):
309 # If the recipe's format version is too new, we should notify the
310 # user.
311 product = self.factory.makeProduct(
312 name='ratatouille', displayname='Ratatouille')
313 branch = self.factory.makeBranch(
314 owner=self.chef, product=product, name='veggies')
315
316 with recipe_parser_newest_version(145.115):
317 recipe = dedent(u'''\
318 # bzr-builder format 145.115 deb-version 0+{revno}
319 %s
320 ''') % branch.bzr_identity
321 browser = self.createRecipe(recipe, branch)
322 self.assertEqual(
323 get_message_text(browser, 2),
324 'The recipe format version specified is not available.')
325
307 def test_create_dupe_recipe(self):326 def test_create_dupe_recipe(self):
308 # You shouldn't be able to create a duplicate recipe owned by the same327 # You shouldn't be able to create a duplicate recipe owned by the same
309 # person with the same name.328 # person with the same name.
310329
=== modified file 'lib/lp/code/model/tests/test_sourcepackagerecipe.py'
--- lib/lp/code/model/tests/test_sourcepackagerecipe.py 2010-09-21 19:02:44 +0000
+++ lib/lp/code/model/tests/test_sourcepackagerecipe.py 2010-09-22 21:13:48 +0000
@@ -53,6 +53,7 @@
53 SourcePackageRecipe,53 SourcePackageRecipe,
54 )54 )
55from lp.code.model.sourcepackagerecipebuild import SourcePackageRecipeBuildJob55from lp.code.model.sourcepackagerecipebuild import SourcePackageRecipeBuildJob
56from lp.code.tests.helpers import recipe_parser_newest_version
56from lp.registry.interfaces.pocket import PackagePublishingPocket57from lp.registry.interfaces.pocket import PackagePublishingPocket
57from lp.services.job.interfaces.job import (58from lp.services.job.interfaces.job import (
58 IJob,59 IJob,
@@ -246,11 +247,13 @@
246 old_branches, list(sp_recipe.getReferencedBranches()))247 old_branches, list(sp_recipe.getReferencedBranches()))
247248
248 def test_reject_newer_formats(self):249 def test_reject_newer_formats(self):
249 builder_recipe = self.factory.makeRecipe()250 with recipe_parser_newest_version(145.115):
250 builder_recipe.format = 0.3251 builder_recipe = self.factory.makeRecipe()
251 self.assertRaises(252 builder_recipe.format = 145.115
252 TooNewRecipeFormat,253 self.assertRaises(
253 self.factory.makeSourcePackageRecipe, recipe=str(builder_recipe))254 TooNewRecipeFormat,
255 self.factory.makeSourcePackageRecipe,
256 recipe=str(builder_recipe))
254257
255 def test_requestBuild(self):258 def test_requestBuild(self):
256 recipe = self.factory.makeSourcePackageRecipe()259 recipe = self.factory.makeSourcePackageRecipe()
257260
=== modified file 'lib/lp/code/tests/helpers.py'
--- lib/lp/code/tests/helpers.py 2010-09-15 20:41:46 +0000
+++ lib/lp/code/tests/helpers.py 2010-09-22 21:13:48 +0000
@@ -14,11 +14,13 @@
14 ]14 ]
1515
1616
17from contextlib import contextmanager
17from datetime import timedelta18from datetime import timedelta
18from difflib import unified_diff19from difflib import unified_diff
19from itertools import count20from itertools import count
20import transaction21import transaction
2122
23from bzrlib.plugins.builder.recipe import RecipeParser
22from zope.component import getUtility24from zope.component import getUtility
23from zope.security.proxy import (25from zope.security.proxy import (
24 isinstance as zisinstance,26 isinstance as zisinstance,
@@ -301,3 +303,13 @@
301 make_project_branch_with_revisions(303 make_project_branch_with_revisions(
302 factory, gen, project, revision_count=num_commits)304 factory, gen, project, revision_count=num_commits)
303 transaction.commit()305 transaction.commit()
306
307
308@contextmanager
309def recipe_parser_newest_version(version):
310 old_version = RecipeParser.NEWEST_VERSION
311 RecipeParser.NEWEST_VERSION = version
312 try:
313 yield
314 finally:
315 RecipeParser.NEWEST_VERSION = old_version