Merge lp:~verterok/ubuntuone-client/fix-869920 into lp:ubuntuone-client

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: Facundo Batista
Approved revision: 1167
Merged at revision: 1168
Proposed branch: lp:~verterok/ubuntuone-client/fix-869920
Merge into: lp:ubuntuone-client
Diff against target: 162 lines (+49/-10)
3 files modified
tests/syncdaemon/test_interaction_interfaces.py (+4/-0)
tests/syncdaemon/test_vm.py (+28/-0)
ubuntuone/syncdaemon/volume_manager.py (+17/-10)
To merge this branch: bzr merge lp:~verterok/ubuntuone-client/fix-869920
Reviewer Review Type Date Requested Status
Facundo Batista (community) Approve
Joshua Hoover (community) tested Approve
Review via email: mp+85392@code.launchpad.net

Commit message

Fix creation of volumes (with content) by adding a new "volatile" variable to signal when the volume is being processes by local rescan.

Description of the change

Fix creation of volumes (with content) by adding a new "volatile" variable to signal when the volume is being processes by local rescan.

To post a comment you must log in.
Revision history for this message
Joshua Hoover (joshuahoover) wrote :

Test from bug #869920 passed using this branch.

review: Approve (tested)
Revision history for this message
Facundo Batista (facundo) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/syncdaemon/test_interaction_interfaces.py'
2--- tests/syncdaemon/test_interaction_interfaces.py 2011-11-02 16:51:32 +0000
3+++ tests/syncdaemon/test_interaction_interfaces.py 2011-12-12 21:07:26 +0000
4@@ -1559,6 +1559,7 @@
5 info = yield d
6
7 udf.subscribed = True
8+ udf.local_rescanning = False
9 self.assertEqual(get_udf_dict(udf), info)
10
11 @defer.inlineCallbacks
12@@ -1589,6 +1590,7 @@
13 info = yield d
14
15 udf.subscribed = False
16+ udf.local_rescanning = False
17 self.assertEqual(get_udf_dict(udf), info)
18
19 @defer.inlineCallbacks
20@@ -1648,6 +1650,7 @@
21 info = yield d
22
23 share.subscribed = True
24+ share.local_rescanning = False
25 self.assertEqual(get_share_dict(share), info)
26
27 @defer.inlineCallbacks
28@@ -1678,6 +1681,7 @@
29 info = yield d
30
31 share.subscribed = False
32+ share.local_rescanning = False
33 self.assertEqual(get_share_dict(share), info)
34
35 @defer.inlineCallbacks
36
37=== modified file 'tests/syncdaemon/test_vm.py'
38--- tests/syncdaemon/test_vm.py 2011-11-30 19:54:45 +0000
39+++ tests/syncdaemon/test_vm.py 2011-12-12 21:07:26 +0000
40@@ -1462,6 +1462,34 @@
41 'watch for %r should be present.' % udf.path)
42
43 @defer.inlineCallbacks
44+ def test_add_udf_with_content(self):
45+ """Test for VolumeManager.add_udf with content on disk."""
46+ # create a sync instance
47+ from ubuntuone.syncdaemon import sync
48+ sync = sync.Sync(self.main)
49+ suggested_path = u"~/suggested_path"
50+ udf = self._create_udf(suggested_path=suggested_path,
51+ subscribed=True)
52+ # create some files inside it
53+ make_dir(udf.path)
54+ for i in range(10):
55+ with open_file(os.path.join(udf.path, 'file_%d' % (i,)), 'wb') as f:
56+ f.write(os.urandom(10))
57+ self.assertEqual(len(os.listdir(udf.path)), 10)
58+ # patch the fake action queue to intercept make_file calls
59+ called = []
60+ self.main.action_q.make_file = lambda *a: called.append(a)
61+ yield self.vm.add_udf(udf)
62+ self.assertEqual(len(called), 10)
63+ # check that the UDF is in the fsm metadata
64+ mdobj = self.main.fs.get_by_path(udf.path)
65+ self.assertEqual(mdobj.node_id, udf.node_id)
66+ self.assertEqual(mdobj.share_id, udf.volume_id)
67+ # check that there is a watch in the UDF
68+ self.assertIn(udf.path, self.watches,
69+ 'watch for %r should be present.' % udf.path)
70+
71+ @defer.inlineCallbacks
72 def test_add_udf_calls_AQ(self):
73 """Test that VolumeManager.add_udf calls AQ.rescan_from_scratch."""
74 udf = self._create_udf(subscribed=True)
75
76=== modified file 'ubuntuone/syncdaemon/volume_manager.py'
77--- ubuntuone/syncdaemon/volume_manager.py 2011-11-17 14:49:05 +0000
78+++ ubuntuone/syncdaemon/volume_manager.py 2011-12-12 21:07:26 +0000
79@@ -120,8 +120,12 @@
80
81 # default generation for all volumes without a value in the metadata
82 generation = None
83+ # transient value used in local rescan during resubscribe. Set it always to
84+ # False no matter what is passed to the constructor
85+ local_rescanning = False
86
87- def __init__(self, volume_id, node_id, generation=None, subscribed=False):
88+ def __init__(self, volume_id, node_id, generation=None, subscribed=False,
89+ local_rescanning=None):
90 """Create the volume."""
91 # id and node_id should be str or None
92 assert isinstance(volume_id, basestring) or volume_id is None
93@@ -231,7 +235,7 @@
94 @property
95 def active(self):
96 """Return True if this Share is accepted."""
97- return self.accepted and self.subscribed
98+ return self.accepted and self.subscribed and not self.local_rescanning
99
100 def __eq__(self, other):
101 result = (super(Share, self).__eq__(other) and
102@@ -347,7 +351,7 @@
103 @property
104 def active(self):
105 """Returns True if the UDF is subscribed."""
106- return self.subscribed
107+ return self.subscribed and not self.local_rescanning
108
109 @classmethod
110 def from_udf_volume(cls, udf_volume, path):
111@@ -862,13 +866,13 @@
112 self._create_share_dir(share)
113 self.log.debug('add_share: volume active, temporarly unsubscribe '
114 'to rescan (scan_local? %r).', share.can_write())
115- share.subscribed = False
116+ share.local_rescanning = True
117 self.shares[share.volume_id] = share
118
119 def subscribe(result):
120 """Subscribe the share after the local rescan."""
121 volume = self.get_volume(share.volume_id)
122- volume.subscribed = True
123+ volume.local_rescanning = False
124 self.store_volume(volume)
125 return result
126
127@@ -1090,7 +1094,7 @@
128 if udf.subscribed:
129 self.log.debug('add_udf: volume subscribed, '
130 'temporarly unsubscribe to do local rescan.')
131- udf.subscribed = False
132+ udf.local_rescanning = True
133 self.udfs[udf.volume_id] = udf
134 if not path_exists(udf.path):
135 make_dir(udf.path, recursive=True)
136@@ -1103,7 +1107,7 @@
137
138 """
139 volume = self.get_volume(udf.volume_id)
140- volume.subscribed = True
141+ volume.local_rescanning = False
142 self.store_volume(volume)
143 return result
144
145@@ -1278,11 +1282,14 @@
146
147 """
148 volume = self.get_volume(volume_id)
149+ volume.local_rescanning = False
150+ self.store_volume(volume)
151+ return result
152+
153+ try:
154 volume.subscribed = True
155+ volume.local_rescanning = True
156 self.store_volume(volume)
157- return result
158-
159- try:
160 d = self._scan_volume(volume, scan_local=volume.can_write())
161 except KeyError, e:
162 push_error(error="METADATA_DOES_NOT_EXIST")

Subscribers

People subscribed via source and target branches