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

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: Joshua Blount
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~verterok/ubuntuone-client/volumes_for_LR
Merge into: lp:ubuntuone-client
Prerequisite: lp:~verterok/ubuntuone-client/volumemanager_udfs-2
Diff against target: 175 lines (+100/-5)
6 files modified
contrib/testing/testcase.py (+10/-0)
tests/syncdaemon/test_fsm.py (+26/-0)
tests/syncdaemon/test_vm.py (+33/-0)
ubuntuone/syncdaemon/filesystem_manager.py (+16/-0)
ubuntuone/syncdaemon/local_rescan.py (+2/-5)
ubuntuone/syncdaemon/volume_manager.py (+13/-0)
To merge this branch: bzr merge lp:~verterok/ubuntuone-client/volumes_for_LR
Reviewer Review Type Date Requested Status
Joshua Blount (community) Approve
Natalia Bidart (community) Approve
Review via email: mp+17379@code.launchpad.net

Commit message

volumes API for LocalRescan and FSM api to get node info for server rescan by path

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

This branch is another one of the Volumenanager+UDF support, in this case:
 - new VolumeManager.get_volumes method that returns shares + subscribed UDFs
 - new FilesystemManager.get_for_server_rescan_by_path
 - tests for all this stuff :)

317. By Guillermo Gonzalez

merge with trunk

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Nice! I need this ;-)

review: Approve
Revision history for this message
Joshua Blount (jblount) :
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-01-14 14:38:22 +0000
3+++ contrib/testing/testcase.py 2010-01-14 15:30:27 +0000
4@@ -507,11 +507,21 @@
5 """
6
7 def get_volume(self, id):
8+ """Returns a share or a UDF."""
9 try:
10 return self.shares[id]
11 except KeyError:
12 return self.udfs[id]
13
14+ def get_volumes(self, access_level='Modify'):
15+ """Simple get_volumes for FakeVolumeManager."""
16+ for share in self.shares.values():
17+ if share.access_level == access_level:
18+ yield share
19+ for udf in self.udfs.values():
20+ if udf.subscribed:
21+ yield udf
22+
23
24 # OAuth stubs
25 class FakeLoginProcessor(LoginProcessor):
26
27=== modified file 'tests/syncdaemon/test_fsm.py'
28--- tests/syncdaemon/test_fsm.py 2009-12-09 14:58:21 +0000
29+++ tests/syncdaemon/test_fsm.py 2010-01-14 15:30:27 +0000
30@@ -2752,6 +2752,32 @@
31 self.assertEqual(expected, sorted(actual))
32
33
34+class ServerRescanDataTestCase(FSMTestCase):
35+ """Test FSM services to get server rescan data."""
36+
37+ def test_get_for_server_rescan_by_path(self):
38+ """Test FSM.get_for_server_rescan_by_path method"""
39+ # create the share fsm object
40+ share_mdid = self.fsm.create(self.share_path, self.share.id)
41+ self.fsm.set_node_id(self.share_path, "share_uuid")
42+ # create a few nodes
43+ path1 = os.path.join(self.share_path, "path1")
44+ path2 = os.path.join(self.share_path, "path1", "path2")
45+ path_out = os.path.join(self.root_dir, "path1")
46+ mdid1 = self.fsm.create(path1, "share", is_dir=True)
47+ mdid2 = self.fsm.create(path2, "share")
48+ mdid_out = self.fsm.create(path_out, "")
49+ self.fsm.set_node_id(path1, "uuid1")
50+ self.fsm.set_node_id(path2, "uuid2")
51+ self.fsm.set_node_id(path_out, "uuid3")
52+ data = list(self.fsm.get_for_server_rescan_by_path(self.share.path))
53+ self.assertEquals(len(data), 3)
54+ self.assertTrue(("share", "uuid1", "") in data)
55+ self.assertTrue(("share", "uuid2", "") in data)
56+ self.assertTrue(("share", "share_uuid", "") in data)
57+ self.assertFalse(("", "uuid3", "") in data)
58+
59+
60 def test_suite():
61 # pylint: disable-msg=C0111
62 return unittest.TestLoader().loadTestsFromName(__name__)
63
64=== modified file 'tests/syncdaemon/test_vm.py'
65--- tests/syncdaemon/test_vm.py 2010-01-12 15:32:43 +0000
66+++ tests/syncdaemon/test_vm.py 2010-01-14 15:30:27 +0000
67@@ -1140,6 +1140,39 @@
68 self.vm.handle_SV_VOLUME_DELETED(udf_volume.volume_id)
69 return d
70
71+ def test_get_volumes(self):
72+ """Tests for VolumeManager.get_volumes."""
73+ share_path = os.path.join(self.shares_dir, 'fake_share')
74+ share_modify = Share(share_path, share_id='share_id', access_level='Modify')
75+ share_path_view = os.path.join(self.shares_dir, 'fake_share_view')
76+ share_view = Share(share_path, share_id='share_id_view', access_level='View')
77+ self.vm.add_share(share_modify)
78+ self.vm.add_share(share_view)
79+ shared_path = os.path.join(self.root_dir, 'fake_shared')
80+ shared = Share(shared_path, share_id='shared_id')
81+ self.vm.add_shared(shared)
82+ suggested_path = "suggested_path"
83+ udf_subscribed, _ = self._create_udf(uuid.uuid4(), 'udf_node_id',
84+ '~/' + suggested_path, subscribed=True)
85+ udf_unsubscribed, _ = self._create_udf(uuid.uuid4(), 'udf_node_id',
86+ '~/' + suggested_path, subscribed=False)
87+ self.vm.add_udf(udf_subscribed)
88+ self.vm.add_udf(udf_unsubscribed)
89+ volumes = list(self.vm.get_volumes())
90+ volumes_ids = [v.id for v in volumes]
91+ self.assertIn(share_modify.id, volumes_ids)
92+ self.assertNotIn(share_view.id, volumes_ids)
93+ self.assertNotIn(shared.id, volumes_ids)
94+ self.assertIn(udf_subscribed.id, volumes_ids)
95+ self.assertNotIn(udf_unsubscribed.id, volumes_ids)
96+ volumes_view = list(self.vm.get_volumes(access_level='View'))
97+ volumes_view_ids = [v.id for v in volumes_view]
98+ self.assertNotIn(share_modify.id, volumes_view_ids)
99+ self.assertIn(share_view.id, volumes_view_ids)
100+ self.assertNotIn(shared.id, volumes_view_ids)
101+ self.assertIn(udf_subscribed.id, volumes_view_ids)
102+ self.assertNotIn(udf_unsubscribed.id, volumes_view_ids)
103+
104
105 class ShareShelfUpgradeTests(BaseTwistedTestCase):
106 """ Tests for shares shelf upgrades"""
107
108=== modified file 'ubuntuone/syncdaemon/filesystem_manager.py'
109--- ubuntuone/syncdaemon/filesystem_manager.py 2010-01-05 23:36:00 +0000
110+++ ubuntuone/syncdaemon/filesystem_manager.py 2010-01-14 15:30:27 +0000
111@@ -510,6 +510,22 @@
112 (v['share_id'], v['node_id'], v['server_hash']))
113 return all_data
114
115+ def get_for_server_rescan_by_path(self, base_path):
116+ """
117+ Generates all the (share, node, hash) tuples, for the nodes
118+ starting with 'path', needed for rescan.
119+
120+ """
121+ all_data = []
122+ for path, _ in self.get_paths_starting_with(base_path):
123+ mdid = self._idx_path[path]
124+ mdobj = self.fs[mdid]
125+ if mdobj['node_id']:
126+ all_data.append((mdobj['share_id'],
127+ mdobj['node_id'],
128+ mdobj['server_hash']))
129+ return all_data
130+
131 def get_by_mdid(self, mdid):
132 """Returns the md object according to the mdid."""
133 mdobj = self.fs[mdid]
134
135=== modified file 'ubuntuone/syncdaemon/local_rescan.py'
136--- ubuntuone/syncdaemon/local_rescan.py 2009-12-03 21:11:21 +0000
137+++ ubuntuone/syncdaemon/local_rescan.py 2010-01-14 15:30:27 +0000
138@@ -80,11 +80,8 @@
139 self.aq.unlink(share_id, parent_id, node_id)
140
141 def _get_shares(self, access_level="Modify"):
142- """Get all the shares to compare."""
143- for sid in self.vm.shares:
144- share = self.vm.shares[sid]
145- if share.access_level == access_level:
146- yield share
147+ """Get all the shares and udfs to compare."""
148+ return self.vm.get_volumes(access_level)
149
150 def scan_dir(self, mdid, direct):
151 """Compares one directory between metadata and disk."""
152
153=== modified file 'ubuntuone/syncdaemon/volume_manager.py'
154--- ubuntuone/syncdaemon/volume_manager.py 2010-01-12 20:00:42 +0000
155+++ ubuntuone/syncdaemon/volume_manager.py 2010-01-14 15:30:27 +0000
156@@ -594,6 +594,19 @@
157 raise KeyError(id)
158 return volume
159
160+ def get_volumes(self, access_level="Modify"):
161+ """Return a generator for the list of volumes.
162+ This list contains subscribed UDFs and shares with
163+ access_level == 'access_level', defaults to 'Modify'.
164+
165+ """
166+ for share_id, share in self.shares.items():
167+ if share.access_level == access_level:
168+ yield share
169+ for udf_id, udf in self.udfs.items():
170+ if udf.subscribed:
171+ yield udf
172+
173 def create_udf(self, path):
174 """Request the creation of a UDF to AQ."""
175 self.log.debug('create udf(%r)', path)

Subscribers

People subscribed via source and target branches