Merge lp:~jtv/launchpad/bug-739986 into lp:launchpad

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: no longer in the source branch.
Merged at revision: 12644
Proposed branch: lp:~jtv/launchpad/bug-739986
Merge into: lp:launchpad
Diff against target: 73 lines (+15/-10)
3 files modified
lib/lp/services/features/__init__.py (+7/-5)
lib/lp/services/scripts/base.py (+1/-2)
lib/lp/services/scripts/tests/test_feature_controller.py (+7/-3)
To merge this branch: bzr merge lp:~jtv/launchpad/bug-739986
Reviewer Review Type Date Requested Status
Steve Kowalik (community) Approve
Review via email: mp+54299@code.launchpad.net

Commit message

[r=stevenk][bug=739986] Script feature controller wasn't installing properly.

Description of the change

= Summary =

The script feature controller wasn't being set up due to a last-minute API change.

make_script_feature_controller installed the feature controller it created, rather than returning it (it returned None). But the script code tried to install the feature controller that make_script_feature_controller returned, so it ended up installing None.

== Proposed fix ==

Return a feature controller from make_script_feature_controller without installing it. This makes the existing usage in LaunchpadCronScript.run correct.

== Pre-implementation notes ==

I wholeheartedly apologize for the pain this caused StevenK.

== Implementation details ==

The way LaunchpadScript installs its feature controller had changed a bit at the last moment. It used to do that in the constructor, but because some scripts' "name" property isn't callable yet at that point, I've made it internal to "run." Which probably makes more sense anyway, except that I neglected to call "run" in the relevant test.

In the script test I added a check that the observed feature controller really is a FeatureController. That's not necessary to detect the actual bug (the test will fail before then, once we remember to call run()) but it would have helped spot the mistake of not calling run.

== Tests ==

{{{
./bin/test -vvc lp.services.scripts.tests.test_feature_controller
}}}

== Demo and Q/A ==

Steve will be able to observe the difference in his ongoing work.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/services/scripts/base.py
  lib/lp/services/features/__init__.py
  lib/lp/services/scripts/tests/test_feature_controller.py

To post a comment you must log in.
Revision history for this message
Steve Kowalik (stevenk) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/services/features/__init__.py'
2--- lib/lp/services/features/__init__.py 2011-03-16 07:56:02 +0000
3+++ lib/lp/services/features/__init__.py 2011-03-22 06:47:10 +0000
4@@ -211,13 +211,15 @@
5
6
7 def make_script_feature_controller(script_name):
8- """Create and install a `FeatureController` for the named script."""
9+ """Create a `FeatureController` for the named script.
10+
11+ You can then install this feature controller using
12+ `install_feature_controller`.
13+ """
14 # Avoid circular import.
15 from lp.services.features.flags import FeatureController
16 from lp.services.features.rulesource import StormFeatureRuleSource
17 from lp.services.features.scopes import ScopesForScript
18
19- install_feature_controller(
20- FeatureController(
21- ScopesForScript(script_name).lookup,
22- StormFeatureRuleSource()))
23+ return FeatureController(
24+ ScopesForScript(script_name).lookup, StormFeatureRuleSource())
25
26=== modified file 'lib/lp/services/scripts/base.py'
27--- lib/lp/services/scripts/base.py 2011-03-21 04:50:12 +0000
28+++ lib/lp/services/scripts/base.py 2011-03-22 06:47:10 +0000
29@@ -1,4 +1,4 @@
30-# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
31+# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
32 # GNU Affero General Public License version 3 (see the file LICENSE).
33
34 __metaclass__ = type
35@@ -40,7 +40,6 @@
36 )
37 from canonical.lp import initZopeless
38 from lp.services.features import (
39- getFeatureFlag,
40 get_relevant_feature_controller,
41 install_feature_controller,
42 make_script_feature_controller,
43
44=== modified file 'lib/lp/services/scripts/tests/test_feature_controller.py'
45--- lib/lp/services/scripts/tests/test_feature_controller.py 2011-03-16 09:14:41 +0000
46+++ lib/lp/services/scripts/tests/test_feature_controller.py 2011-03-22 06:47:10 +0000
47@@ -10,8 +10,10 @@
48 get_relevant_feature_controller,
49 install_feature_controller,
50 )
51-from lp.services.features.flags import NullFeatureController
52-from lp.services.features.testing import FeatureFixture
53+from lp.services.features.flags import (
54+ FeatureController,
55+ NullFeatureController,
56+ )
57 from lp.services.scripts.base import LaunchpadScript
58 from lp.testing import TestCase
59 from lp.testing.fakemethod import FakeMethod
60@@ -48,10 +50,12 @@
61
62 def test_script_installs_script_feature_controller(self):
63 script = FakeScript(name="bongo")
64- script_feature_controller = get_relevant_feature_controller()
65+ script.run()
66 self.assertNotEqual(
67 self.original_controller, script.observed_feature_controller)
68 self.assertNotEqual(None, script.observed_feature_controller)
69+ self.assertIsInstance(
70+ script.observed_feature_controller, FeatureController)
71
72 def test_script_restores_feature_controller(self):
73 previous_controller = NullFeatureController()