Merge lp:~verterok/ubuntuone-client/vm_root_handling into lp:ubuntuone-client

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: Eric Casteleijn
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~verterok/ubuntuone-client/vm_root_handling
Merge into: lp:ubuntuone-client
Diff against target: 388 lines (+53/-63)
6 files modified
contrib/testing/testcase.py (+3/-1)
tests/syncdaemon/test_vm.py (+37/-26)
ubuntuone/syncdaemon/action_queue.py (+5/-1)
ubuntuone/syncdaemon/event_queue.py (+2/-0)
ubuntuone/syncdaemon/main.py (+0/-18)
ubuntuone/syncdaemon/volume_manager.py (+6/-17)
To merge this branch: bzr merge lp:~verterok/ubuntuone-client/vm_root_handling
Reviewer Review Type Date Requested Status
Eric Casteleijn (community) Approve
Rick McBride (community) Approve
Review via email: mp+20559@code.launchpad.net

Commit message

Unify root handling via events, and push SYS_ROOT_MISMATCH if the root is different.

To post a comment you must log in.
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

This branch unifies root handling via events, and adds two new events: SYS_ROOT_RECEIVED and SYS_ROOT_MISMATCH.
SYS_ROOT_MISMATCH is pushed in the case the user connect syncdaemon with the tokens of a different account (and a different root)

In a following branch a new DBus signal will be added to notify this to the outside world.

Revision history for this message
Rick McBride (rmcbride) wrote :

Looks good!

review: Approve
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Code looks good, tests pass!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'contrib/testing/testcase.py'
2--- contrib/testing/testcase.py 2010-02-27 00:13:55 +0000
3+++ contrib/testing/testcase.py 2010-03-03 15:09:17 +0000
4@@ -489,6 +489,7 @@
5 except Exception, e: # pylint: disable-msg=W0703
6 error_handler(e)
7
8+
9 class FakeVolumeManager(object):
10 """ A volume manager that only knows one share, the root"""
11
12@@ -513,7 +514,7 @@
13 """Add udf to the udfs dict."""
14 self.udfs[udf.id] = udf
15
16- def on_server_root(self, _):
17+ def handle_SYS_ROOT_RECEIVED(self, root_id):
18 """Do nothing."""
19
20 def share_deleted(self, _):
21@@ -544,6 +545,7 @@
22 def delete_volume(self, volume_id):
23 """Request the deletion of a volume."""
24
25+
26 # OAuth stubs
27 class FakeLoginProcessor(LoginProcessor):
28 """Stub login processor."""
29
30=== modified file 'tests/syncdaemon/test_vm.py'
31--- tests/syncdaemon/test_vm.py 2010-02-24 18:45:49 +0000
32+++ tests/syncdaemon/test_vm.py 2010-03-03 15:09:17 +0000
33@@ -104,21 +104,22 @@
34 class VolumeManagerTests(BaseVolumeManagerTests):
35 """ Tests for Volume Manager internal API. """
36
37- def test_on_server_root(self):
38- """ check that list_shares is called in on_server_root """
39+ def test_handle_SYS_ROOT_RECEIVED(self):
40+ """Check that list_shares is called in handle_SYS_ROOT_RECEIVED """
41 d = defer.Deferred()
42 # helper method, pylint: disable-msg=C0111
43 def list_shares():
44 mdobj = self.main.fs.get_by_path(self.root_dir)
45+ self.assertEquals('root_uuid', mdobj.node_id)
46 d.callback(mdobj)
47 self.main.action_q.list_shares = list_shares
48- self.vm.on_server_root('root_uuid')
49+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
50 return d
51
52 def test_add_share(self):
53 """ test the add_share method. """
54 # initialize the the root
55- self.vm.on_server_root('root_uuid')
56+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
57 share_path = os.path.join(self.shares_dir, 'fake_share')
58 share = Share(path=share_path, volume_id='share_id')
59 self.vm.add_share(share)
60@@ -127,7 +128,7 @@
61 def test_share_deleted(self):
62 """ Check that a share is deleted from the share mapping. """
63 # initialize the the root
64- self.vm.on_server_root('root_uuid')
65+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
66 share_path = os.path.join(self.shares_dir, 'fake_share')
67 share = Share(path=share_path, volume_id='share_id')
68 self.vm.add_share(share)
69@@ -138,7 +139,7 @@
70 def test_share_deleted_with_content(self):
71 """ Check that a share is deleted from the share mapping. """
72 # initialize the the root
73- self.vm.on_server_root('root_uuid')
74+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
75 share_path = os.path.join(self.shares_dir, 'fake_share')
76 share = Share(path=share_path, volume_id='share_id',
77 node_id='share_node_id', access_level='Modify',
78@@ -180,7 +181,7 @@
79 'test_username',
80 'visible_name', 'Modify')
81 # initialize the the root
82- self.vm.on_server_root('root_uuid')
83+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
84 share_path = os.path.join(self.shares_dir, share_holder.share_name)
85 share = Share(path=share_path, volume_id=share_holder.share_id,
86 access_level='View')
87@@ -197,7 +198,7 @@
88 'visible_username', 'yes',
89 'View')
90 # initialize the the root
91- self.vm.on_server_root('root_uuid')
92+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
93 response = ListShares(None)
94 response.shares = [share_response]
95 self.vm.handle_AQ_SHARES_LIST(response)
96@@ -216,7 +217,7 @@
97 'test_username',
98 'visible_name', 'Modify')
99 # initialize the the root
100- self.vm.on_server_root('root_uuid')
101+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
102 # create a share
103 share_path = os.path.join(self.shares_dir, share_holder.share_name)
104 share = Share(path=share_path, volume_id=str(share_holder.share_id),
105@@ -253,7 +254,7 @@
106 'my_visible_name', 'yes',
107 'Modify')
108 # initialize the the root
109- self.vm.on_server_root('root_uuid')
110+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
111 shared_dir = os.path.join(self.root_dir, 'shared_dir')
112 self.main.fs.create(path=shared_dir, share_id="", is_dir=True)
113 self.main.fs.set_node_id(shared_dir, shared_response.subtree)
114@@ -329,7 +330,6 @@
115 self.main.action_q.create_share = fake_create_share
116 self.vm.create_share(path, 'fake_user', 'shared_name', 'View')
117
118-
119 @defer.inlineCallbacks
120 def test_create_share_missing_node_id(self):
121 """Test VolumeManager.create_share in the case of missing node_id."""
122@@ -363,7 +363,7 @@
123 def test_accept_share(self):
124 """ Test the accept_share method. """
125 d = defer.Deferred()
126- self.vm.on_server_root('root_uuid')
127+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
128 share_path = os.path.join(self.shares_dir, 'fake_share')
129 share = Share(path=share_path, volume_id='share_id', node_id="node_id")
130 self.vm.add_share(share)
131@@ -392,7 +392,7 @@
132 'my_visible_name', 'yes',
133 'Modify')
134 # initialize the the root
135- self.vm.on_server_root('root_uuid')
136+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
137 response = ListShares(None)
138 response.shares = [shared_response]
139 self.vm.handle_AQ_SHARES_LIST(response)
140@@ -410,7 +410,7 @@
141 self.main.fs.set_node_id(path, 'node_id')
142 self.main.fs.get_by_node_id("", 'node_id')
143 # initialize the the root
144- self.vm.on_server_root('root_uuid')
145+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
146 # add the shared folder
147 share = Share(path=path, volume_id='share_id', access_level='View')
148 self.vm.add_shared(share)
149@@ -426,7 +426,7 @@
150 self.main.fs.set_node_id(path, 'node_id')
151 self.main.fs.get_by_node_id("", 'node_id')
152 # initialize the the root
153- self.vm.on_server_root('root_uuid')
154+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
155 self.assertNotIn('share_id', self.vm.shared)
156 # check that a answer notify of a missing share don't blowup
157 self.vm.handle_SV_SHARE_ANSWERED('share_id', 'Yes')
158@@ -448,7 +448,7 @@
159 'visible_username', False,
160 'View')
161 # initialize the the root
162- self.vm.on_server_root('root_uuid')
163+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
164 response = ListShares(None)
165 response.shares = [share_response, share_response_1]
166 self.vm.handle_AQ_SHARES_LIST(response)
167@@ -540,6 +540,17 @@
168 self.vm._create_fsm_object(path, "", "node_id")
169 self.assertTrue(self.main.fs.get_by_path(path), path)
170
171+ @defer.inlineCallbacks
172+ def test_root_mismatch(self):
173+ """Test that SYS_ROOT_MISMATCH is pushed."""
174+ self.vm.handle_SYS_ROOT_RECEIVED('root_node_id')
175+ d = defer.Deferred()
176+ self._listen_for('SYS_ROOT_MISMATCH', d.callback)
177+ self.vm.handle_SYS_ROOT_RECEIVED('root_id')
178+ current_id, new_id = yield d
179+ self.assertEquals('root_node_id', current_id)
180+ self.assertEquals('root_id', new_id)
181+
182
183 class VolumeManagerUnicodeTests(BaseVolumeManagerTests):
184 """Tests for Volume Manager unicode capabilities."""
185@@ -552,7 +563,7 @@
186 'visible', 'yes',
187 'View')
188 # initialize the the root
189- self.vm.on_server_root('root_uuid')
190+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
191 response = ListShares(None)
192 response.shares = [share_response]
193 self.vm.handle_AQ_SHARES_LIST(response)
194@@ -571,7 +582,7 @@
195 u'Darío Toño', 'yes',
196 'View')
197 # initialize the the root
198- self.vm.on_server_root('root_uuid')
199+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
200 response = ListShares(None)
201 response.shares = [share_response]
202 self.vm.handle_AQ_SHARES_LIST(response)
203@@ -588,7 +599,7 @@
204 u'año',
205 'test_username',
206 'visible', 'Modify')
207- self.vm.on_server_root('root_uuid')
208+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
209 self.vm.handle_SV_SHARE_CHANGED('changed', share_holder)
210 shouldbe_dir = os.path.join(self.shares_dir,
211 u"año".encode("utf8") + " from visible")
212@@ -600,7 +611,7 @@
213 'share',
214 'test_username',
215 u'Ramón', 'Modify')
216- self.vm.on_server_root('root_uuid')
217+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
218 self.vm.handle_SV_SHARE_CHANGED('changed', share_holder)
219 shouldbe_dir = os.path.join(self.shares_dir,
220 "share from " + u"Ramón".encode("utf8"))
221@@ -869,7 +880,7 @@
222 udf_volume = volumes.UDFVolume(udf_id, 'udf_uuid',
223 u'~/ñoño'.encode("utf8") )
224 # initialize the the root
225- self.vm.on_server_root('root_uuid')
226+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
227 response = [share_volume, udf_volume]
228 d = defer.Deferred()
229 self._listen_for('VM_UDF_CREATED', d.callback)
230@@ -1353,7 +1364,7 @@
231 'username', 'visible_username',
232 True, 'View')
233 # initialize the the root
234- self.vm.on_server_root('root_uuid')
235+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
236 self._listen_for('VM_UDF_CREATED', d.callback)
237 def check_udf(info):
238 """The udf creation callback"""
239@@ -1415,7 +1426,7 @@
240 yield self.vm.add_udf(udf)
241 self.vm.add_share(share)
242 # initialize the the root
243- self.vm.on_server_root('root_uuid')
244+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
245 d = defer.Deferred()
246 self._listen_for('VM_VOLUME_DELETED', d.callback)
247 with environ('HOME', self.home_dir):
248@@ -1522,7 +1533,7 @@
249 def test_no_UDFs_inside_root(self):
250 """Test that a UDF can't be created inside the root"""
251 # initialize the root
252- self.vm.on_server_root('root_node_id')
253+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
254 udf_path = os.path.join(self.root_dir, 'udf_inside_root')
255 # patch FakeAQ
256 def create_udf(path, name, marker):
257@@ -1633,7 +1644,7 @@
258 share = Share.from_share_volume(share_volume, share_path)
259 # get the root
260 root = self.vm.get_volume('')
261- self.vm.on_server_root('root_node_id')
262+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
263 # create a UDF
264 udf_id = uuid.uuid4()
265 udf, volume = self._create_udf(udf_id, 'udf_node_id', '~/UDF')
266@@ -1676,7 +1687,7 @@
267 share = Share.from_share_volume(share_volume, share_path)
268 # get the root
269 root = self.vm.get_volume('')
270- self.vm.on_server_root('root_node_id')
271+ self.vm.handle_SYS_ROOT_RECEIVED('root_node_id')
272 # create a UDF
273 udf_id = uuid.uuid4()
274 udf, volume = self._create_udf(udf_id, 'udf_node_id', '~/UDF')
275
276=== modified file 'ubuntuone/syncdaemon/action_queue.py'
277--- ubuntuone/syncdaemon/action_queue.py 2010-02-27 00:13:55 +0000
278+++ ubuntuone/syncdaemon/action_queue.py 2010-03-03 15:09:17 +0000
279@@ -1025,7 +1025,11 @@
280 d.addCallbacks(*log.callbacks())
281 d.addCallbacks(passit(lambda root: self.uuid_map.set(marker, root)),
282 passit(lambda f: self.uuid_map.err(marker, f)))
283-
284+ def handle_root(root_id):
285+ """Push SYS_ROOT_RECEIVED event"""
286+ self.event_queue.push('SYS_ROOT_RECEIVED', root_id=root_id)
287+ return root_id
288+ d.addCallback(handle_root)
289 return d
290
291 def make_file(self, share_id, parent_id, name, marker):
292
293=== modified file 'ubuntuone/syncdaemon/event_queue.py'
294--- ubuntuone/syncdaemon/event_queue.py 2010-02-25 12:40:39 +0000
295+++ ubuntuone/syncdaemon/event_queue.py 2010-03-03 15:09:17 +0000
296@@ -125,6 +125,8 @@
297 'SYS_CLEANUP_FINISHED': (),
298 'SYS_UNKNOWN_ERROR': (),
299 'SYS_HANDSHAKE_TIMEOUT': (),
300+ 'SYS_ROOT_RECEIVED': ('root_id',),
301+ 'SYS_ROOT_MISMATCH': ('root_id', 'new_root_id'),
302
303 'VM_UDF_SUBSCRIBED': ('udf',),
304 'VM_UDF_SUBSCRIBE_ERROR': ('udf_id', 'error'),
305
306=== modified file 'ubuntuone/syncdaemon/main.py'
307--- ubuntuone/syncdaemon/main.py 2010-02-16 14:50:18 +0000
308+++ ubuntuone/syncdaemon/main.py 2010-03-03 15:09:17 +0000
309@@ -219,24 +219,6 @@
310 """
311 self.quit(exit_value=42, with_restart=True)
312
313- def get_root(self, root_mdid):
314- """Ask que AQ for our root's uuid."""
315- def _worker():
316- """Actually do the asking."""
317- d = self.action_q.get_root(root_mdid)
318- def root_node_cb(root):
319- """Root node fetched callback."""
320- root_mdid = self.vm.on_server_root(root)
321- self.action_q.uuid_map.set(root_mdid, root)
322- d.addCallback(root_node_cb)
323- return d
324- if self.action_q.client is None:
325- # aq not yet connected
326- self.action_q.deferred.addCallback(_worker)
327- return self.action_q.deferred
328- else:
329- return _worker()
330-
331 def check_version(self):
332 """Check the client protocol version matches that of the server."""
333 self.action_q.check_version()
334
335=== modified file 'ubuntuone/syncdaemon/volume_manager.py'
336--- ubuntuone/syncdaemon/volume_manager.py 2010-02-24 18:02:00 +0000
337+++ ubuntuone/syncdaemon/volume_manager.py 2010-03-03 15:09:17 +0000
338@@ -350,10 +350,10 @@
339 self.m.fs.create(path=self.root.path,
340 share_id=request.ROOT, is_dir=True)
341
342- def on_server_root(self, root):
343- """Asociate server root"""
344- self.log.debug('on_server_root(%s)', root)
345- self._set_root(root)
346+ def handle_SYS_ROOT_RECEIVED(self, root_id):
347+ """Got the root, map it to the root share."""
348+ self.log.debug('handle_SYS_ROOT_RECEIVED(%s)', root_id)
349+ self._set_root(root_id)
350 self.m.action_q.inquire_account_info()
351 self.m.action_q.inquire_free_space(request.ROOT)
352 self.refresh_volumes()
353@@ -369,6 +369,8 @@
354 self.m.fs.set_node_id(self.root.path, node_id)
355 self.root.node_id = root.node_id = node_id
356 self.shares[request.ROOT] = root
357+ elif root.node_id != node_id:
358+ self.m.event_q.push('SYS_ROOT_MISMATCH', root.node_id, node_id)
359
360 def refresh_shares(self):
361 """Request the list of shares to the server."""
362@@ -378,18 +380,6 @@
363 """Request the list of volumes to the server."""
364 self.m.action_q.list_volumes()
365
366- def handle_SYS_CONNECTION_MADE(self):
367- """
368- The system is connected!. If we don't know our root's uuid yet, ask
369- for it.
370- """
371- share = self.shares[request.ROOT]
372- if share.node_id is None:
373- mdobj = self.m.fs.get_by_path(share.path)
374- self.m.get_root(MDMarker(mdobj.mdid))
375- else:
376- self.on_server_root(share.node_id)
377-
378 def handle_AQ_LIST_VOLUMES(self, volumes):
379 """Handle AQ_LIST_VOLUMES event."""
380 self.log.debug('handling volumes list')
381@@ -466,7 +456,6 @@
382 self._cleanup_shared(shared)
383 self._cleanup_shares(shares)
384
385-
386 def _cleanup_volumes(self, shares=None, udfs=None):
387 """Remove missing shares from the shares and shared shelfs."""
388 # housekeeping of the shares, shared and udfs shelf's each time we

Subscribers

People subscribed via source and target branches