Merge ~cjwatson/launchpad:remove-server-scopes into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 4341bdab89825ee29d29c6098f8451ca1ac1daaa
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:remove-server-scopes
Merge into: launchpad:master
Diff against target: 165 lines (+10/-58)
5 files modified
lib/lp/app/templates/base-layout.pt (+0/-1)
lib/lp/services/features/__init__.py (+7/-6)
lib/lp/services/features/scopes.py (+2/-23)
lib/lp/services/features/tests/test_flags.py (+1/-1)
lib/lp/services/features/tests/test_webapp.py (+0/-27)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+431820@code.launchpad.net

Commit message

Remove server feature scopes

Description of the change

We don't seem to use these in practice, and I can't really think of many situations where it would be more convenient to do so rather than just setting appropriate feature rules on each instance. The only somewhat relevant piece of configuration that we have right now is the `is_demo` flag, but that isn't implemented using server scopes anyway and it wouldn't be worth maintaining that code just for the sake of a single boolean.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/app/templates/base-layout.pt b/lib/lp/app/templates/base-layout.pt
2index 63a8ca8..74b4f45 100644
3--- a/lib/lp/app/templates/base-layout.pt
4+++ b/lib/lp/app/templates/base-layout.pt
5@@ -8,7 +8,6 @@
6 devmode modules/lp.services.config/config/launchpad/devmode;
7 rooturl modules/lp.services.webapp.vhosts/allvhosts/configs/mainsite/rooturl;
8 is_demo modules/lp.services.config/config/launchpad/is_demo;
9- is_lpnet modules/lp.services.config/config/launchpad/is_lpnet;
10 site_message modules/lp.services.config/config/launchpad/site_message;
11 icingroot string:${rooturl}+icing/rev${revision};
12 features request/features;
13diff --git a/lib/lp/services/features/__init__.py b/lib/lp/services/features/__init__.py
14index a672f29..181f7b4 100644
15--- a/lib/lp/services/features/__init__.py
16+++ b/lib/lp/services/features/__init__.py
17@@ -25,10 +25,10 @@ that apply to that request, by finding the I{rule} with the highest
18 I{priority}.
19
20 Flags are defined by a I{name} that typically looks like a Python
21-identifier, for example C{notification.global.text}. A definition is
22-given for a particular I{scope}, which also looks like a dotted identifier,
23-for example C{user.beta} or C{server.lpnet}. This is just a naming
24-convention, and they do not need to correspond to Python modules.
25+identifier, for example C{notification.global.text}. A definition is given
26+for a particular I{scope}, for example C{pageid:Person:+editemails} or
27+C{team:admins}. This is just a naming convention, and they do not need to
28+correspond to Python modules.
29
30 The value is stored in the database as just a Unicode string, and it might
31 be interpreted as a boolean, number, human-readable string or whatever.
32@@ -99,8 +99,9 @@ Templates can also check whether the request is in a particular scope, but
33 before using this consider whether the code will always be bound to that
34 scope or whether it would be more correct to define a new feature::
35
36- <p tal:condition="feature_scopes/server.staging">
37- Staging server: all data will be discarded daily!</p>
38+ <p tal:condition="feature_scopes/team:admins">
39+ You are a Launchpad administrator. Be careful!
40+ </p>
41
42 Checking flags in code
43 ======================
44diff --git a/lib/lp/services/features/scopes.py b/lib/lp/services/features/scopes.py
45index 4e114f5..cc848aa 100644
46--- a/lib/lp/services/features/scopes.py
47+++ b/lib/lp/services/features/scopes.py
48@@ -4,7 +4,7 @@
49 """Connect feature flags into scopes where they can be used.
50
51 The most common is flags scoped by some attribute of a web request, such as
52-the page ID or the server name. But other types of scope can also match code
53+the page ID or a team name. But other types of scope can also match code
54 run from cron scripts and potentially also other places.
55 """
56
57@@ -24,7 +24,6 @@ __all__ = [
58 import re
59 from itertools import zip_longest
60
61-import lp.services.config
62 from lp.registry.interfaces.person import IPerson
63 from lp.services.propertycache import cachedproperty
64
65@@ -182,25 +181,6 @@ class UserSliceScope(ScopeWithPerson):
66 return (person_id % divisor) == modulus
67
68
69-class ServerScope(BaseScope):
70- """Matches the current server.
71-
72- For example, the scope server.lpnet is active when is_lpnet is set to True
73- in the Launchpad configuration.
74- """
75-
76- pattern = r"server\."
77-
78- def lookup(self, scope_name):
79- """Match the current server as a scope."""
80- server_name = scope_name.split(".", 1)[1]
81- try:
82- return lp.services.config.config["launchpad"]["is_" + server_name]
83- except KeyError:
84- pass
85- return False
86-
87-
88 class ScriptScope(BaseScope):
89 """Matches the name of the currently running script.
90
91@@ -236,7 +216,7 @@ class FixedScope(BaseScope):
92 # we can for example show all of them in an admin page. Any new scope will
93 # need a scope handler and that scope handler has to be added to this list.
94 # See BaseScope for hints as to what a scope handler should look like.
95-HANDLERS = {DefaultScope, PageScope, TeamScope, ServerScope, ScriptScope}
96+HANDLERS = {DefaultScope, PageScope, TeamScope, ScriptScope}
97
98
99 class MultiScopeHandler:
100@@ -296,7 +276,6 @@ class ScopesFromRequest(MultiScopeHandler):
101 scopes.extend(
102 [
103 PageScope(request),
104- ServerScope(),
105 TeamScope(person_from_request),
106 UserSliceScope(person_from_request),
107 ]
108diff --git a/lib/lp/services/features/tests/test_flags.py b/lib/lp/services/features/tests/test_flags.py
109index 548c0d7..04a919b 100644
110--- a/lib/lp/services/features/tests/test_flags.py
111+++ b/lib/lp/services/features/tests/test_flags.py
112@@ -186,7 +186,7 @@ class TestFeatureFlags(TestCase):
113 self.assertEqual(dict(), f.usedScopes())
114
115 def testScopeDict(self):
116- # can get scopes as a dict, for use by "feature_scopes/server.demo"
117+ # can get scopes as a dict, for use by "feature_scopes/..."
118 f, call_log = self.makeControllerInScopes(["beta_user"])
119 self.assertEqual(True, f.scopes["beta_user"])
120 self.assertEqual(False, f.scopes["alpha_user"])
121diff --git a/lib/lp/services/features/tests/test_webapp.py b/lib/lp/services/features/tests/test_webapp.py
122index c61504d..37de309 100644
123--- a/lib/lp/services/features/tests/test_webapp.py
124+++ b/lib/lp/services/features/tests/test_webapp.py
125@@ -3,9 +3,6 @@
126
127 """Tests for webapp glue."""
128
129-from textwrap import dedent
130-
131-from lp.services.config import config
132 from lp.services.features import getFeatureFlag, webapp
133 from lp.services.features.testing import FeatureFixture
134 from lp.services.webapp.errorlog import globalErrorUtility
135@@ -55,30 +52,6 @@ class TestScopesFromRequest(TestCase):
136 scopes = webapp.ScopesFromRequest(request)
137 self.assertTrue(scopes.lookup("default"))
138
139- def test_server(self):
140- request = LaunchpadTestRequest()
141- scopes = webapp.ScopesFromRequest(request)
142- self.assertFalse(scopes.lookup("server.lpnet"))
143- config.push(
144- "ensure_lpnet",
145- dedent(
146- """\
147- [launchpad]
148- is_lpnet: True
149- """
150- ),
151- )
152- try:
153- self.assertTrue(scopes.lookup("server.lpnet"))
154- finally:
155- config.pop("ensure_lpnet")
156-
157- def test_server_missing_key(self):
158- request = LaunchpadTestRequest()
159- scopes = webapp.ScopesFromRequest(request)
160- # There is no such key in the config, so this returns False.
161- self.assertFalse(scopes.lookup("server.pink"))
162-
163 def test_unknown_scope(self):
164 # Asking about an unknown scope is not an error.
165 request = LaunchpadTestRequest()

Subscribers

People subscribed via source and target branches

to status/vote changes: