Merge lp:~tealeg/landscape-client/keystone-scoped-resynch into lp:~landscape/landscape-client/trunk

Proposed by Geoff Teale
Status: Merged
Approved by: Geoff Teale
Approved revision: 714
Merged at revision: 708
Proposed branch: lp:~tealeg/landscape-client/keystone-scoped-resynch
Merge into: lp:~landscape/landscape-client/trunk
Prerequisite: lp:~tealeg/landscape-client/centralise-resynch-handling
Diff against target: 125 lines (+60/-18)
3 files modified
landscape/manager/keystonetoken.py (+3/-3)
landscape/manager/tests/test_keystonetoken.py (+44/-15)
landscape/tests/helpers.py (+13/-0)
To merge this branch: bzr merge lp:~tealeg/landscape-client/keystone-scoped-resynch
Reviewer Review Type Date Requested Status
Jerry Seutter (community) Approve
Chris Glass (community) Approve
Review via email: mp+174289@code.launchpad.net

This proposal supersedes a proposal from 2013-07-05.

Commit message

This branch makes the keystone token plugin only respond
to resynchronize-clients events when they are either
"openstack" or global scope. Note, the server doesn't
currently send "openstack" scope, but I decided that all
plugins should have their scope defined so that we can
easily add scoped resynchs on the server when we need to.

Description of the change

This branch makes the keystone token plugin only respond to resynchronize-clients events when they are either "openstack" or global scope. Note, the server doesn't currently send "openstack" scope, but I decided that all plugins should have their scope defined so that we can easily add scoped resynchs on the server when we need to.

Note - this branch has now been re-based on the centralise-resynch-handling and will need re-review on that basis.

To post a comment you must log in.
Revision history for this message
Jerry Seutter (jseutter) wrote : Posted in a previous version of this proposal

+1, looks good.

review: Approve
Revision history for this message
Jerry Seutter (jseutter) wrote : Posted in a previous version of this proposal

Some lintian issues:

landscape/manager/tests/test_keystonetoken.py:9:1: E303 too many blank lines (3)
landscape/manager/tests/test_keystonetoken.py:125:80: E501 line too long (87 characters)
landscape/broker/tests/test_server.py:368:80: E501 line too long (80 characters)

Revision history for this message
Geoff Teale (tealeg) wrote : Posted in a previous version of this proposal

> Some lintian issues:
>
> landscape/manager/tests/test_keystonetoken.py:9:1: E303 too many blank lines
> (3)
> landscape/manager/tests/test_keystonetoken.py:125:80: E501 line too long (87
> characters)
> landscape/broker/tests/test_server.py:368:80: E501 line too long (80
> characters)

Cheers, all dealt with.

Revision history for this message
Chris Glass (tribaal) wrote : Posted in a previous version of this proposal

[1]
+class FakePersist(object):
+
+ def __init__(self):
+ self.called = False
+
+ def remove(self, key):
+ self.called = True

This should probably go to someplace else, like landscape/lib/persist or landscape/tests/helpers as I assume it can be reused by all other plugins using the persist mechanism?

(ongoing review, saving just because I'm afraid chromium will die on me again)

Revision history for this message
Chris Glass (tribaal) wrote : Posted in a previous version of this proposal

Alright, +1!

review: Approve
Revision history for this message
Geoff Teale (tealeg) wrote :

Chris, I addressed your previous review point.

Revision history for this message
Chris Glass (tribaal) wrote :

Looks good! Thanks!

review: Approve
Revision history for this message
Jerry Seutter (jseutter) wrote :

+1

landscape/tests/helpers.py:655:1: W391 blank line at end of file

review: Approve
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/manager/keystonetoken.py'
2--- landscape/manager/keystonetoken.py 2013-01-25 17:28:02 +0000
3+++ landscape/manager/keystonetoken.py 2013-07-17 07:49:27 +0000
4@@ -17,6 +17,7 @@
5 message_type = "keystone-token"
6 message_key = "data"
7 run_interval = 60 * 15
8+ scope = "openstack"
9
10 def __init__(self, keystone_config_file=KEYSTONE_CONFIG_FILE):
11 self._keystone_config_file = keystone_config_file
12@@ -26,13 +27,12 @@
13 self._persist_filename = os.path.join(self.registry.config.data_path,
14 "keystone.bpickle")
15 self._persist = Persist(filename=self._persist_filename)
16- self.registry.reactor.call_on("resynchronize", self._resynchronize)
17 self.registry.reactor.call_every(self.registry.config.flush_interval,
18 self.flush)
19
20- def _resynchronize(self):
21+ def _reset(self):
22 """
23- Recreate the persist upon C{_resynchronize}.
24+ Reset the persist.
25 """
26 self._persist.remove("data")
27
28
29=== modified file 'landscape/manager/tests/test_keystonetoken.py'
30--- landscape/manager/tests/test_keystonetoken.py 2013-01-25 17:28:02 +0000
31+++ landscape/manager/tests/test_keystonetoken.py 2013-07-17 07:49:27 +0000
32@@ -2,7 +2,7 @@
33 from landscape.tests.helpers import LandscapeTest
34
35 from landscape.manager.keystonetoken import KeystoneToken
36-from landscape.tests.helpers import ManagerHelper
37+from landscape.tests.helpers import ManagerHelper, FakePersist
38
39
40 class KeystoneTokenTest(LandscapeTest):
41@@ -88,20 +88,49 @@
42 self.reactor.advance(flush_interval)
43 self.assertTrue(os.path.exists(persist_filename))
44
45- def test_resynchronize_message_calls_resynchronize_method(self):
46- """
47- If the reactor fires a "resynchronize" even the C{_resynchronize}
48- method on the keystone plugin object is called.
49- """
50- self.called = False
51-
52- def stub_resynchronize():
53- self.called = True
54- self.plugin._resynchronize = stub_resynchronize
55-
56- self.manager.add(self.plugin)
57- self.reactor.fire("resynchronize")
58- self.assertTrue(self.called)
59+ def test_resynchronize_message_calls_reset_method(self):
60+ """
61+ If the reactor fires a "resynchronize", with 'openstack' scope, the
62+ C{_reset} method on the keystone plugin object is called.
63+ """
64+ self.manager.add(self.plugin)
65+ self.plugin._persist = FakePersist()
66+ openstack_scope = ["openstack"]
67+ self.reactor.fire("resynchronize", openstack_scope)
68+ self.assertTrue(self.plugin._persist.called)
69+
70+ def test_resynchronize_gets_new_session_id(self):
71+ """
72+ If L{KeystoneToken} reacts to a "resynchronize" event it should get a
73+ new session id as part of the process.
74+ """
75+ self.manager.add(self.plugin)
76+ session_id = self.plugin._session_id
77+ self.plugin._persist = FakePersist()
78+ self.plugin.client.broker.message_store.drop_session_ids()
79+ self.reactor.fire("resynchronize")
80+ self.assertNotEqual(session_id, self.plugin._session_id)
81+
82+ def test_resynchronize_with_global_scope(self):
83+ """
84+ If the reactor fires a "resynchronize", with global scope, we act as if
85+ it had 'openstack' scope.
86+ """
87+ self.manager.add(self.plugin)
88+ self.plugin._persist = FakePersist()
89+ self.reactor.fire("resynchronize")
90+ self.assertTrue(self.plugin._persist.called)
91+
92+ def test_do_not_resynchronize_with_other_scope(self):
93+ """
94+ If the reactor fires a "resynchronize", with an irrelevant scope, we do
95+ nothing.
96+ """
97+ self.manager.add(self.plugin)
98+ self.plugin._persist = FakePersist()
99+ disk_scope = ["disk"]
100+ self.reactor.fire("resynchronize", disk_scope)
101+ self.assertFalse(self.plugin._persist.called)
102
103 def test_send_message_with_no_data(self):
104 """
105
106=== modified file 'landscape/tests/helpers.py'
107--- landscape/tests/helpers.py 2013-04-30 14:02:42 +0000
108+++ landscape/tests/helpers.py 2013-07-17 07:49:27 +0000
109@@ -639,3 +639,16 @@
110 """Remove sample data for the process that matches C{process_id}."""
111 process_dir = os.path.join(self._sample_dir, str(process_id))
112 shutil.rmtree(process_dir)
113+
114+
115+class FakePersist(object):
116+ """
117+ Incompletely fake a C{landscape.lib.Persist} to simplify higher level tests
118+ that result in an attempt to clear down persisted data.
119+ """
120+
121+ def __init__(self):
122+ self.called = False
123+
124+ def remove(self, key):
125+ self.called = True

Subscribers

People subscribed via source and target branches

to all changes: