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
=== modified file 'tests/syncdaemon/test_interaction_interfaces.py'
--- tests/syncdaemon/test_interaction_interfaces.py 2011-11-02 16:51:32 +0000
+++ tests/syncdaemon/test_interaction_interfaces.py 2011-12-12 21:07:26 +0000
@@ -1559,6 +1559,7 @@
1559 info = yield d1559 info = yield d
15601560
1561 udf.subscribed = True1561 udf.subscribed = True
1562 udf.local_rescanning = False
1562 self.assertEqual(get_udf_dict(udf), info)1563 self.assertEqual(get_udf_dict(udf), info)
15631564
1564 @defer.inlineCallbacks1565 @defer.inlineCallbacks
@@ -1589,6 +1590,7 @@
1589 info = yield d1590 info = yield d
15901591
1591 udf.subscribed = False1592 udf.subscribed = False
1593 udf.local_rescanning = False
1592 self.assertEqual(get_udf_dict(udf), info)1594 self.assertEqual(get_udf_dict(udf), info)
15931595
1594 @defer.inlineCallbacks1596 @defer.inlineCallbacks
@@ -1648,6 +1650,7 @@
1648 info = yield d1650 info = yield d
16491651
1650 share.subscribed = True1652 share.subscribed = True
1653 share.local_rescanning = False
1651 self.assertEqual(get_share_dict(share), info)1654 self.assertEqual(get_share_dict(share), info)
16521655
1653 @defer.inlineCallbacks1656 @defer.inlineCallbacks
@@ -1678,6 +1681,7 @@
1678 info = yield d1681 info = yield d
16791682
1680 share.subscribed = False1683 share.subscribed = False
1684 share.local_rescanning = False
1681 self.assertEqual(get_share_dict(share), info)1685 self.assertEqual(get_share_dict(share), info)
16821686
1683 @defer.inlineCallbacks1687 @defer.inlineCallbacks
16841688
=== modified file 'tests/syncdaemon/test_vm.py'
--- tests/syncdaemon/test_vm.py 2011-11-30 19:54:45 +0000
+++ tests/syncdaemon/test_vm.py 2011-12-12 21:07:26 +0000
@@ -1462,6 +1462,34 @@
1462 'watch for %r should be present.' % udf.path)1462 'watch for %r should be present.' % udf.path)
14631463
1464 @defer.inlineCallbacks1464 @defer.inlineCallbacks
1465 def test_add_udf_with_content(self):
1466 """Test for VolumeManager.add_udf with content on disk."""
1467 # create a sync instance
1468 from ubuntuone.syncdaemon import sync
1469 sync = sync.Sync(self.main)
1470 suggested_path = u"~/suggested_path"
1471 udf = self._create_udf(suggested_path=suggested_path,
1472 subscribed=True)
1473 # create some files inside it
1474 make_dir(udf.path)
1475 for i in range(10):
1476 with open_file(os.path.join(udf.path, 'file_%d' % (i,)), 'wb') as f:
1477 f.write(os.urandom(10))
1478 self.assertEqual(len(os.listdir(udf.path)), 10)
1479 # patch the fake action queue to intercept make_file calls
1480 called = []
1481 self.main.action_q.make_file = lambda *a: called.append(a)
1482 yield self.vm.add_udf(udf)
1483 self.assertEqual(len(called), 10)
1484 # check that the UDF is in the fsm metadata
1485 mdobj = self.main.fs.get_by_path(udf.path)
1486 self.assertEqual(mdobj.node_id, udf.node_id)
1487 self.assertEqual(mdobj.share_id, udf.volume_id)
1488 # check that there is a watch in the UDF
1489 self.assertIn(udf.path, self.watches,
1490 'watch for %r should be present.' % udf.path)
1491
1492 @defer.inlineCallbacks
1465 def test_add_udf_calls_AQ(self):1493 def test_add_udf_calls_AQ(self):
1466 """Test that VolumeManager.add_udf calls AQ.rescan_from_scratch."""1494 """Test that VolumeManager.add_udf calls AQ.rescan_from_scratch."""
1467 udf = self._create_udf(subscribed=True)1495 udf = self._create_udf(subscribed=True)
14681496
=== modified file 'ubuntuone/syncdaemon/volume_manager.py'
--- ubuntuone/syncdaemon/volume_manager.py 2011-11-17 14:49:05 +0000
+++ ubuntuone/syncdaemon/volume_manager.py 2011-12-12 21:07:26 +0000
@@ -120,8 +120,12 @@
120120
121 # default generation for all volumes without a value in the metadata121 # default generation for all volumes without a value in the metadata
122 generation = None122 generation = None
123 # transient value used in local rescan during resubscribe. Set it always to
124 # False no matter what is passed to the constructor
125 local_rescanning = False
123126
124 def __init__(self, volume_id, node_id, generation=None, subscribed=False):127 def __init__(self, volume_id, node_id, generation=None, subscribed=False,
128 local_rescanning=None):
125 """Create the volume."""129 """Create the volume."""
126 # id and node_id should be str or None130 # id and node_id should be str or None
127 assert isinstance(volume_id, basestring) or volume_id is None131 assert isinstance(volume_id, basestring) or volume_id is None
@@ -231,7 +235,7 @@
231 @property235 @property
232 def active(self):236 def active(self):
233 """Return True if this Share is accepted."""237 """Return True if this Share is accepted."""
234 return self.accepted and self.subscribed238 return self.accepted and self.subscribed and not self.local_rescanning
235239
236 def __eq__(self, other):240 def __eq__(self, other):
237 result = (super(Share, self).__eq__(other) and241 result = (super(Share, self).__eq__(other) and
@@ -347,7 +351,7 @@
347 @property351 @property
348 def active(self):352 def active(self):
349 """Returns True if the UDF is subscribed."""353 """Returns True if the UDF is subscribed."""
350 return self.subscribed354 return self.subscribed and not self.local_rescanning
351355
352 @classmethod356 @classmethod
353 def from_udf_volume(cls, udf_volume, path):357 def from_udf_volume(cls, udf_volume, path):
@@ -862,13 +866,13 @@
862 self._create_share_dir(share)866 self._create_share_dir(share)
863 self.log.debug('add_share: volume active, temporarly unsubscribe '867 self.log.debug('add_share: volume active, temporarly unsubscribe '
864 'to rescan (scan_local? %r).', share.can_write())868 'to rescan (scan_local? %r).', share.can_write())
865 share.subscribed = False869 share.local_rescanning = True
866 self.shares[share.volume_id] = share870 self.shares[share.volume_id] = share
867871
868 def subscribe(result):872 def subscribe(result):
869 """Subscribe the share after the local rescan."""873 """Subscribe the share after the local rescan."""
870 volume = self.get_volume(share.volume_id)874 volume = self.get_volume(share.volume_id)
871 volume.subscribed = True875 volume.local_rescanning = False
872 self.store_volume(volume)876 self.store_volume(volume)
873 return result877 return result
874878
@@ -1090,7 +1094,7 @@
1090 if udf.subscribed:1094 if udf.subscribed:
1091 self.log.debug('add_udf: volume subscribed, '1095 self.log.debug('add_udf: volume subscribed, '
1092 'temporarly unsubscribe to do local rescan.')1096 'temporarly unsubscribe to do local rescan.')
1093 udf.subscribed = False1097 udf.local_rescanning = True
1094 self.udfs[udf.volume_id] = udf1098 self.udfs[udf.volume_id] = udf
1095 if not path_exists(udf.path):1099 if not path_exists(udf.path):
1096 make_dir(udf.path, recursive=True)1100 make_dir(udf.path, recursive=True)
@@ -1103,7 +1107,7 @@
11031107
1104 """1108 """
1105 volume = self.get_volume(udf.volume_id)1109 volume = self.get_volume(udf.volume_id)
1106 volume.subscribed = True1110 volume.local_rescanning = False
1107 self.store_volume(volume)1111 self.store_volume(volume)
1108 return result1112 return result
11091113
@@ -1278,11 +1282,14 @@
12781282
1279 """1283 """
1280 volume = self.get_volume(volume_id)1284 volume = self.get_volume(volume_id)
1285 volume.local_rescanning = False
1286 self.store_volume(volume)
1287 return result
1288
1289 try:
1281 volume.subscribed = True1290 volume.subscribed = True
1291 volume.local_rescanning = True
1282 self.store_volume(volume)1292 self.store_volume(volume)
1283 return result
1284
1285 try:
1286 d = self._scan_volume(volume, scan_local=volume.can_write())1293 d = self._scan_volume(volume, scan_local=volume.can_write())
1287 except KeyError, e:1294 except KeyError, e:
1288 push_error(error="METADATA_DOES_NOT_EXIST")1295 push_error(error="METADATA_DOES_NOT_EXIST")

Subscribers

People subscribed via source and target branches