Merge lp:~verterok/ubuntuone-client/vm-refactor into lp:ubuntuone-client
- vm-refactor
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Rick McBride |
Approved revision: | not available |
Merged at revision: | not available |
Proposed branch: | lp:~verterok/ubuntuone-client/vm-refactor |
Merge into: | lp:ubuntuone-client |
Prerequisite: | lp:~verterok/ubuntuone-client/vm-pre-refactor-api-3 |
Diff against target: |
2464 lines (+1161/-420) 9 files modified
tests/syncdaemon/test_dbus.py (+49/-34) tests/syncdaemon/test_eq_inotify.py (+108/-21) tests/syncdaemon/test_eventqueue.py (+3/-1) tests/syncdaemon/test_tools.py (+2/-2) tests/syncdaemon/test_vm.py (+562/-218) ubuntuone/syncdaemon/dbus_interface.py (+6/-2) ubuntuone/syncdaemon/event_queue.py (+115/-55) ubuntuone/syncdaemon/tools.py (+6/-6) ubuntuone/syncdaemon/volume_manager.py (+310/-81) |
To merge this branch: | bzr merge lp:~verterok/ubuntuone-client/vm-refactor |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Zachery Bir (community) | Approve | ||
Facundo Batista (community) | Approve | ||
Review via email: mp+18088@code.launchpad.net |
Commit message
VolumeManager Volume hierarchy refactor and metadata migration to new version
Description of the change
Guillermo Gonzalez (verterok) wrote : | # |
- 328. By Guillermo Gonzalez
-
merge with trunk
- 329. By Guillermo Gonzalez
- 330. By Guillermo Gonzalez
-
fix tools.show_folders function to use volume_id instead of id
Facundo Batista (facundo) wrote : | # |
=======
[ERROR]: tests.syncdaemo
Traceback (most recent call last):
File "/usr/lib/
result = result.
File "/usr/lib/
return g.throw(self.type, self.value, self.tb)
File "/home/
yield d
File "/usr/lib/
self.result = callback(
File "/home/
d.addCallba
File "/home/
out.
exceptions.
-------
Guillermo Gonzalez (verterok) wrote : | # |
Already pushed and fixed in revno: 330, thanks!
Facundo Batista (facundo) wrote : | # |
Ok, that is already fixed, and all the tests went ok!
Zachery Bir (urbanape) wrote : | # |
All tests pass. Gonna say go.
Preview Diff
1 | === modified file 'tests/syncdaemon/test_dbus.py' | |||
2 | --- tests/syncdaemon/test_dbus.py 2010-01-25 22:28:46 +0000 | |||
3 | +++ tests/syncdaemon/test_dbus.py 2010-01-26 20:35:29 +0000 | |||
4 | @@ -36,7 +36,7 @@ | |||
5 | 36 | DBUS_IFACE_FOLDERS_NAME, | 36 | DBUS_IFACE_FOLDERS_NAME, |
6 | 37 | EventListener, | 37 | EventListener, |
7 | 38 | ) | 38 | ) |
9 | 39 | from ubuntuone.syncdaemon.volume_manager import Share, UDF | 39 | from ubuntuone.syncdaemon.volume_manager import Share, Shared, UDF |
10 | 40 | from ubuntuone.syncdaemon.tools import DBusClient | 40 | from ubuntuone.syncdaemon.tools import DBusClient |
11 | 41 | from ubuntuone.syncdaemon import event_queue, states, main, config | 41 | from ubuntuone.syncdaemon import event_queue, states, main, config |
12 | 42 | from contrib.testing.testcase import ( | 42 | from contrib.testing.testcase import ( |
13 | @@ -500,21 +500,23 @@ | |||
14 | 500 | access_level='Read', accepted=False)) | 500 | access_level='Read', accepted=False)) |
15 | 501 | client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME) | 501 | client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME) |
16 | 502 | d = defer.Deferred() | 502 | d = defer.Deferred() |
18 | 503 | def shares_handler(shares): | 503 | def check(shares): |
19 | 504 | """ handle get_shares reply """ | 504 | """ handle get_shares reply """ |
20 | 505 | self.assertEquals(1, len(shares)) | 505 | self.assertEquals(1, len(shares)) |
21 | 506 | for share in shares: | 506 | for share in shares: |
24 | 507 | if share['id'] == '': | 507 | if share['volume_id'] == '': |
25 | 508 | self.assertEquals('', str(share['id'])) | 508 | self.assertEquals('', str(share['volume_id'])) |
26 | 509 | self.assertEquals(self.root_dir, str(share['path'])) | 509 | self.assertEquals(self.root_dir, str(share['path'])) |
27 | 510 | self.assertEquals('Modify', str(share['access_level'])) | 510 | self.assertEquals('Modify', str(share['access_level'])) |
28 | 511 | self.assertEquals('False', str(share['accepted'])) | 511 | self.assertEquals('False', str(share['accepted'])) |
29 | 512 | else: | 512 | else: |
31 | 513 | self.assertEquals('share_id', str(share['id'])) | 513 | self.assertEquals('share_id', str(share['volume_id'])) |
32 | 514 | self.assertEquals(share_path, str(share['path'])) | 514 | self.assertEquals(share_path, str(share['path'])) |
33 | 515 | self.assertEquals('Read', str(share['access_level'])) | 515 | self.assertEquals('Read', str(share['access_level'])) |
34 | 516 | self.assertEquals('False', str(share['accepted'])) | 516 | self.assertEquals('False', str(share['accepted'])) |
36 | 517 | d.callback(True) | 517 | |
37 | 518 | def shares_handler(shares): | ||
38 | 519 | d.callback(shares) | ||
39 | 518 | 520 | ||
40 | 519 | client.call_method('get_shares', reply_handler=shares_handler, | 521 | client.call_method('get_shares', reply_handler=shares_handler, |
41 | 520 | error_handler=self.error_handler) | 522 | error_handler=self.error_handler) |
42 | @@ -539,7 +541,7 @@ | |||
43 | 539 | def check(result): | 541 | def check(result): |
44 | 540 | """the async checker""" | 542 | """the async checker""" |
45 | 541 | self.assertEquals('Yes', result['answer']) | 543 | self.assertEquals('Yes', result['answer']) |
47 | 542 | self.assertEquals('share_id', result['share_id']) | 544 | self.assertEquals('share_id', result['volume_id']) |
48 | 543 | self.assertEquals(True, self.main.vm.shares['share_id'].accepted) | 545 | self.assertEquals(True, self.main.vm.shares['share_id'].accepted) |
49 | 544 | 546 | ||
50 | 545 | d.addCallback(check) | 547 | d.addCallback(check) |
51 | @@ -563,7 +565,7 @@ | |||
52 | 563 | def check(result): | 565 | def check(result): |
53 | 564 | """the async checker""" | 566 | """the async checker""" |
54 | 565 | self.assertEquals('No', result['answer']) | 567 | self.assertEquals('No', result['answer']) |
56 | 566 | self.assertEquals('share_id', result['share_id']) | 568 | self.assertEquals('share_id', result['volume_id']) |
57 | 567 | self.assertEquals(False, self.main.vm.shares['share_id'].accepted) | 569 | self.assertEquals(False, self.main.vm.shares['share_id'].accepted) |
58 | 568 | 570 | ||
59 | 569 | d.addCallback(check) | 571 | d.addCallback(check) |
60 | @@ -648,8 +650,8 @@ | |||
61 | 648 | self.assertEquals(1, len(results)) | 650 | self.assertEquals(1, len(results)) |
62 | 649 | shared = results[0] | 651 | shared = results[0] |
63 | 650 | self.assertEquals(a_dir, str(shared['path'])) | 652 | self.assertEquals(a_dir, str(shared['path'])) |
66 | 651 | self.assertEquals('node_id', str(shared['subtree'])) | 653 | self.assertEquals('node_id', str(shared['node_id'])) |
67 | 652 | self.assertEquals('share_id', str(shared['id'])) | 654 | self.assertEquals('share_id', str(shared['volume_id'])) |
68 | 653 | self.assertEquals('View', str(shared['access_level'])) | 655 | self.assertEquals('View', str(shared['access_level'])) |
69 | 654 | d.callback(True) | 656 | d.callback(True) |
70 | 655 | client.call_method('get_shared', | 657 | client.call_method('get_shared', |
71 | @@ -680,14 +682,15 @@ | |||
72 | 680 | self.assertEquals(1, len(results)) | 682 | self.assertEquals(1, len(results)) |
73 | 681 | shared = results[0] | 683 | shared = results[0] |
74 | 682 | self.assertEquals('', str(shared['path'])) | 684 | self.assertEquals('', str(shared['path'])) |
77 | 683 | self.assertEquals('node_id', str(shared['subtree'])) | 685 | self.assertEquals('node_id', str(shared['node_id'])) |
78 | 684 | self.assertEquals('share_id', str(shared['id'])) | 686 | self.assertEquals('share_id', str(shared['volume_id'])) |
79 | 685 | self.assertEquals('View', str(shared['access_level'])) | 687 | self.assertEquals('View', str(shared['access_level'])) |
80 | 686 | d.callback(True) | 688 | d.callback(True) |
81 | 687 | client.call_method('get_shared', | 689 | client.call_method('get_shared', |
82 | 688 | reply_handler=reply_handler, | 690 | reply_handler=reply_handler, |
83 | 689 | error_handler=self.error_handler) | 691 | error_handler=self.error_handler) |
84 | 690 | return d | 692 | return d |
85 | 693 | |||
86 | 691 | def test_refresh_shares(self): | 694 | def test_refresh_shares(self): |
87 | 692 | """ Just check that refresh_shares method API works. """ | 695 | """ Just check that refresh_shares method API works. """ |
88 | 693 | client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME) | 696 | client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME) |
89 | @@ -800,7 +803,7 @@ | |||
90 | 800 | a_dir = os.path.join(self.root_dir, u'ñoño'.encode('utf-8')) | 803 | a_dir = os.path.join(self.root_dir, u'ñoño'.encode('utf-8')) |
91 | 801 | self.fs_manager.create(a_dir, "", is_dir=True) | 804 | self.fs_manager.create(a_dir, "", is_dir=True) |
92 | 802 | self.fs_manager.set_node_id(a_dir, "node_id") | 805 | self.fs_manager.set_node_id(a_dir, "node_id") |
94 | 803 | share = Share(path=a_dir, volume_id='shared_id', name=u'ñoño_shared', | 806 | share = Shared(path=a_dir, volume_id='shared_id', name=u'ñoño_shared', |
95 | 804 | access_level='View', other_username=u'test_username', | 807 | access_level='View', other_username=u'test_username', |
96 | 805 | node_id='node_id') | 808 | node_id='node_id') |
97 | 806 | self.main.vm.add_shared(share) | 809 | self.main.vm.add_shared(share) |
98 | @@ -812,8 +815,8 @@ | |||
99 | 812 | self.assertEquals(1, len(results)) | 815 | self.assertEquals(1, len(results)) |
100 | 813 | shared = results[0] | 816 | shared = results[0] |
101 | 814 | self.assertEquals(a_dir, shared['path'].encode('utf-8')) | 817 | self.assertEquals(a_dir, shared['path'].encode('utf-8')) |
104 | 815 | self.assertEquals('node_id', str(shared['subtree'])) | 818 | self.assertEquals('node_id', str(shared['node_id'])) |
105 | 816 | self.assertEquals('shared_id', str(shared['id'])) | 819 | self.assertEquals('shared_id', str(shared['volume_id'])) |
106 | 817 | self.assertEquals('View', str(shared['access_level'])) | 820 | self.assertEquals('View', str(shared['access_level'])) |
107 | 818 | 821 | ||
108 | 819 | d.addCallback(check) | 822 | d.addCallback(check) |
109 | @@ -1072,14 +1075,15 @@ | |||
110 | 1072 | u'visible_name', 'Write') | 1075 | u'visible_name', 'Write') |
111 | 1073 | 1076 | ||
112 | 1074 | d = defer.Deferred() | 1077 | d = defer.Deferred() |
114 | 1075 | def share_handler(share): | 1078 | def check(share): |
115 | 1076 | """ handler for ShareChanged signal. """ | 1079 | """ handler for ShareChanged signal. """ |
117 | 1077 | self.assertEquals('a_share_id', str(share['id'])) | 1080 | self.assertEquals('a_share_id', str(share['volume_id'])) |
118 | 1078 | self.assertEquals(share_path, str(share['path'])) | 1081 | self.assertEquals(share_path, str(share['path'])) |
119 | 1079 | self.assertEquals('Write', str(share['access_level'])) | 1082 | self.assertEquals('Write', str(share['access_level'])) |
123 | 1080 | self.assertEquals('False', str(share['accepted'])) | 1083 | self.assertEquals('', str(share['accepted'])) |
124 | 1081 | d.callback(True) | 1084 | d.addCallback(check) |
125 | 1082 | 1085 | def share_handler(result): | |
126 | 1086 | d.callback(result) | ||
127 | 1083 | match = self.bus.add_signal_receiver(share_handler, | 1087 | match = self.bus.add_signal_receiver(share_handler, |
128 | 1084 | signal_name='ShareChanged') | 1088 | signal_name='ShareChanged') |
129 | 1085 | self.signal_receivers.add(match) | 1089 | self.signal_receivers.add(match) |
130 | @@ -1089,25 +1093,36 @@ | |||
131 | 1089 | def test_share_deleted(self): | 1093 | def test_share_deleted(self): |
132 | 1090 | """ Test the ShareDeleted signal. """ | 1094 | """ Test the ShareDeleted signal. """ |
133 | 1091 | share_path = os.path.join(self.main.shares_dir, 'share') | 1095 | share_path = os.path.join(self.main.shares_dir, 'share') |
134 | 1092 | self.main.vm.add_share(Share(path=share_path, volume_id='a_share_id', | ||
135 | 1093 | access_level='Read', accepted=False)) | ||
136 | 1094 | share_holder = NotifyShareHolder.from_params('a_share_id', 'subtree', | 1096 | share_holder = NotifyShareHolder.from_params('a_share_id', 'subtree', |
137 | 1095 | u'fake_share', | 1097 | u'fake_share', |
138 | 1096 | u'test_username', | 1098 | u'test_username', |
139 | 1097 | u'visible_name', 'Read') | 1099 | u'visible_name', 'Read') |
140 | 1098 | 1100 | ||
141 | 1101 | self.main.vm.add_share(Share.from_notify_holder(share_holder, share_path)) | ||
142 | 1099 | d = defer.Deferred() | 1102 | d = defer.Deferred() |
143 | 1100 | def share_handler(share_dict): | 1103 | def share_handler(share_dict): |
144 | 1101 | """ handler for ShareDeletedsignal. """ | 1104 | """ handler for ShareDeletedsignal. """ |
150 | 1102 | expected_dict = dict(share_id='a_share_id', | 1105 | d.callback(share_dict) |
151 | 1103 | subtree='subtree', | 1106 | |
152 | 1104 | share_name=u'fake_share', | 1107 | match = self.bus.add_signal_receiver(share_handler, |
153 | 1105 | from_username=u'test_username', | 1108 | signal_name='ShareDeleted') |
154 | 1106 | from_visible_name=u'visible_name', | 1109 | self.signal_receivers.add(match) |
155 | 1110 | |||
156 | 1111 | def check(share_dict): | ||
157 | 1112 | """Check the result.""" | ||
158 | 1113 | expected_dict = dict(volume_id='a_share_id', | ||
159 | 1114 | node_id='subtree', | ||
160 | 1115 | name=u'fake_share', | ||
161 | 1116 | other_username=u'test_username', | ||
162 | 1117 | other_visible_name=u'visible_name', | ||
163 | 1118 | free_bytes='', | ||
164 | 1119 | path=share_path, | ||
165 | 1120 | accepted='', | ||
166 | 1107 | access_level='Read') | 1121 | access_level='Read') |
167 | 1122 | expected_dict['type'] = 'Share' | ||
168 | 1108 | for k, v in share_dict.items(): | 1123 | for k, v in share_dict.items(): |
169 | 1109 | self.assertEquals(expected_dict[str(k)], str(v)) | 1124 | self.assertEquals(expected_dict[str(k)], str(v)) |
171 | 1110 | d.callback(True) | 1125 | d.addCallback(check) |
172 | 1111 | 1126 | ||
173 | 1112 | match = self.bus.add_signal_receiver(share_handler, | 1127 | match = self.bus.add_signal_receiver(share_handler, |
174 | 1113 | signal_name='ShareDeleted') | 1128 | signal_name='ShareDeleted') |
175 | @@ -1495,7 +1510,7 @@ | |||
176 | 1495 | udf_dict = self.dbus_iface.folders._get_udf_dict(udf) | 1510 | udf_dict = self.dbus_iface.folders._get_udf_dict(udf) |
177 | 1496 | # check the path it's unicode | 1511 | # check the path it's unicode |
178 | 1497 | self.assertEquals(udf_dict['path'], udf.path.decode('utf-8')) | 1512 | self.assertEquals(udf_dict['path'], udf.path.decode('utf-8')) |
180 | 1498 | self.assertEquals(udf_dict['id'], udf.volume_id) | 1513 | self.assertEquals(udf_dict['volume_id'], udf.id) |
181 | 1499 | self.assertEquals(udf_dict['suggested_path'], udf.suggested_path) | 1514 | self.assertEquals(udf_dict['suggested_path'], udf.suggested_path) |
182 | 1500 | self.assertEquals(udf_dict['node_id'], udf.node_id) | 1515 | self.assertEquals(udf_dict['node_id'], udf.node_id) |
183 | 1501 | self.assertFalse(udf_dict['subscribed']) | 1516 | self.assertFalse(udf_dict['subscribed']) |
184 | @@ -1684,13 +1699,13 @@ | |||
185 | 1684 | d = defer.Deferred() | 1699 | d = defer.Deferred() |
186 | 1685 | def delete_volume(path): | 1700 | def delete_volume(path): |
187 | 1686 | """Fake delete_volume""" | 1701 | """Fake delete_volume""" |
189 | 1687 | self.main.event_q.push("AQ_DELETE_VOLUME_OK", volume_id=udf.volume_id) | 1702 | self.main.event_q.push("AQ_DELETE_VOLUME_OK", volume_id=udf.id) |
190 | 1688 | self.main.action_q.delete_volume = delete_volume | 1703 | self.main.action_q.delete_volume = delete_volume |
191 | 1689 | def deleted_handler(info): | 1704 | def deleted_handler(info): |
192 | 1690 | """FolderDeleted handler.""" | 1705 | """FolderDeleted handler.""" |
193 | 1691 | self.assertRaises(KeyError, self.main.fs.get_by_path, | 1706 | self.assertRaises(KeyError, self.main.fs.get_by_path, |
194 | 1692 | info['path'].decode('utf-8')) | 1707 | info['path'].decode('utf-8')) |
196 | 1693 | self.assertRaises(KeyError, self.main.vm.get_volume, info['id']) | 1708 | self.assertRaises(KeyError, self.main.vm.get_volume, info['volume_id']) |
197 | 1694 | d.callback(True) | 1709 | d.callback(True) |
198 | 1695 | match = self.bus.add_signal_receiver(deleted_handler, | 1710 | match = self.bus.add_signal_receiver(deleted_handler, |
199 | 1696 | signal_name='FolderDeleted') | 1711 | signal_name='FolderDeleted') |
200 | @@ -1719,7 +1734,7 @@ | |||
201 | 1719 | self.main.action_q.delete_volume = delete_volume | 1734 | self.main.action_q.delete_volume = delete_volume |
202 | 1720 | def deleted_error_handler(info, error): | 1735 | def deleted_error_handler(info, error): |
203 | 1721 | """FolderDeleteError handler""" | 1736 | """FolderDeleteError handler""" |
205 | 1722 | self.assertEquals(info['id'], udf.volume_id) | 1737 | self.assertEquals(info['volume_id'], udf.volume_id) |
206 | 1723 | self.assertEquals(error, "I'm broken") | 1738 | self.assertEquals(error, "I'm broken") |
207 | 1724 | d.callback(True) | 1739 | d.callback(True) |
208 | 1725 | match = self.bus.add_signal_receiver(deleted_error_handler, | 1740 | match = self.bus.add_signal_receiver(deleted_error_handler, |
209 | @@ -1821,7 +1836,7 @@ | |||
210 | 1821 | """FolderDeleted handler.""" | 1836 | """FolderDeleted handler.""" |
211 | 1822 | self.assertRaises(KeyError, self.main.fs.get_by_path, | 1837 | self.assertRaises(KeyError, self.main.fs.get_by_path, |
212 | 1823 | info['path'].decode('utf-8')) | 1838 | info['path'].decode('utf-8')) |
214 | 1824 | self.assertRaises(KeyError, self.main.vm.get_volume, info['id']) | 1839 | self.assertRaises(KeyError, self.main.vm.get_volume, info['volume_id']) |
215 | 1825 | d.callback(True) | 1840 | d.callback(True) |
216 | 1826 | match = self.bus.add_signal_receiver(deleted_handler, | 1841 | match = self.bus.add_signal_receiver(deleted_handler, |
217 | 1827 | signal_name='ShareDeleted') | 1842 | signal_name='ShareDeleted') |
218 | @@ -1852,7 +1867,7 @@ | |||
219 | 1852 | self.main.action_q.delete_volume = delete_volume | 1867 | self.main.action_q.delete_volume = delete_volume |
220 | 1853 | def deleted_error_handler(info, error): | 1868 | def deleted_error_handler(info, error): |
221 | 1854 | """FolderDeleteError handler""" | 1869 | """FolderDeleteError handler""" |
223 | 1855 | self.assertEquals(info['id'], share.volume_id) | 1870 | self.assertEquals(info['volume_id'], share.volume_id) |
224 | 1856 | self.assertEquals(error, "I'm broken") | 1871 | self.assertEquals(error, "I'm broken") |
225 | 1857 | d.callback(True) | 1872 | d.callback(True) |
226 | 1858 | match = self.bus.add_signal_receiver(deleted_error_handler, | 1873 | match = self.bus.add_signal_receiver(deleted_error_handler, |
227 | 1859 | 1874 | ||
228 | === modified file 'tests/syncdaemon/test_eq_inotify.py' | |||
229 | --- tests/syncdaemon/test_eq_inotify.py 2010-01-26 19:15:10 +0000 | |||
230 | +++ tests/syncdaemon/test_eq_inotify.py 2010-01-26 20:35:29 +0000 | |||
231 | @@ -33,31 +33,104 @@ | |||
232 | 33 | class WatchTests(BaseEQTestCase): | 33 | class WatchTests(BaseEQTestCase): |
233 | 34 | """Test the EQ API to add and remove watchs.""" | 34 | """Test the EQ API to add and remove watchs.""" |
234 | 35 | 35 | ||
237 | 36 | def test_add_watch(self): | 36 | def _create_udf(self, path): |
238 | 37 | """Test that watchs can be added.""" | 37 | """Create an UDF and returns it and the volume""" |
239 | 38 | os.makedirs(path) | ||
240 | 39 | udf = volume_manager.UDF("vol_id", "node_id", path, path, True) | ||
241 | 40 | self.vm.add_udf(udf) | ||
242 | 41 | |||
243 | 42 | def test_add_general_watch(self): | ||
244 | 43 | """Test that general watchs can be added.""" | ||
245 | 38 | # we should have what we asked for | 44 | # we should have what we asked for |
246 | 39 | self.eq.inotify_add_watch(self.root_dir) | 45 | self.eq.inotify_add_watch(self.root_dir) |
256 | 40 | # pylint: disable-msg=W0212 | 46 | |
257 | 41 | self.assertTrue(self.root_dir in self.eq._watchs) | 47 | # check only added dir in watchs |
258 | 42 | 48 | # pylint: disable-msg=W0212 | |
259 | 43 | # we shouldn't have other stuff | 49 | self.assertTrue(self.root_dir in self.eq._general_watchs) |
260 | 44 | self.assertTrue("not-added-dir" not in self.eq._watchs) | 50 | self.assertTrue("not-added-dir" not in self.eq._general_watchs) |
261 | 45 | 51 | ||
262 | 46 | def test_rm_watch(self): | 52 | # nothing in the udf ancestors watch |
263 | 47 | """Test that watchs can be removed.""" | 53 | self.assertEqual(self.eq._ancestors_watchs, {}) |
264 | 48 | # remove what we added | 54 | |
265 | 55 | def test_add_watch_on_udf_ancestor(self): | ||
266 | 56 | """Test that ancestors watchs can be added.""" | ||
267 | 57 | # create the udf and add the watch | ||
268 | 58 | path_udf = os.path.join(self.home_dir, "path/to/UDF") | ||
269 | 59 | self._create_udf(path_udf) | ||
270 | 60 | path_ancestor = os.path.join(self.home_dir, "path") | ||
271 | 61 | self.eq.inotify_add_watch(path_ancestor) | ||
272 | 62 | |||
273 | 63 | # check only added dir in watchs | ||
274 | 64 | # pylint: disable-msg=W0212 | ||
275 | 65 | self.assertTrue(path_ancestor in self.eq._ancestors_watchs) | ||
276 | 66 | self.assertTrue("not-added-dir" not in self.eq._ancestors_watchs) | ||
277 | 67 | |||
278 | 68 | # nothing in the general watch | ||
279 | 69 | self.assertEqual(self.eq._general_watchs, {}) | ||
280 | 70 | |||
281 | 71 | def test_add_watch_on_udf_exact(self): | ||
282 | 72 | """Test adding the watch exactly on UDF.""" | ||
283 | 73 | # create the udf and add the watch | ||
284 | 74 | path_udf = os.path.join(self.home_dir, "path/to/UDF") | ||
285 | 75 | self._create_udf(path_udf) | ||
286 | 76 | self.eq.inotify_add_watch(path_udf) | ||
287 | 77 | |||
288 | 78 | # pylint: disable-msg=W0212 | ||
289 | 79 | self.assertTrue(path_udf in self.eq._general_watchs) | ||
290 | 80 | self.assertEqual(self.eq._ancestors_watchs, {}) | ||
291 | 81 | |||
292 | 82 | def test_add_watch_on_udf_child(self): | ||
293 | 83 | """Test adding the watch inside UDF.""" | ||
294 | 84 | # create the udf and add the watch | ||
295 | 85 | path_udf = os.path.join(self.home_dir, "path/to/UDF") | ||
296 | 86 | self._create_udf(path_udf) | ||
297 | 87 | path_ancestor = os.path.join(self.home_dir, "path/to/UDF/inside") | ||
298 | 88 | os.mkdir(path_ancestor) | ||
299 | 89 | self.eq.inotify_add_watch(path_ancestor) | ||
300 | 90 | |||
301 | 91 | # pylint: disable-msg=W0212 | ||
302 | 92 | self.assertTrue(path_ancestor in self.eq._general_watchs) | ||
303 | 93 | self.assertEqual(self.eq._ancestors_watchs, {}) | ||
304 | 94 | |||
305 | 95 | def test_rm_watch_wrong(self): | ||
306 | 96 | """Test that general watchs can be removed.""" | ||
307 | 97 | # add two types of watchs | ||
308 | 49 | self.eq.inotify_add_watch(self.root_dir) | 98 | self.eq.inotify_add_watch(self.root_dir) |
312 | 50 | self.eq.inotify_rm_watch(self.root_dir) | 99 | path_udf = os.path.join(self.home_dir, "path/to/UDF") |
313 | 51 | # pylint: disable-msg=W0212 | 100 | self._create_udf(path_udf) |
314 | 52 | self.assertTrue(self.root_dir not in self.eq._watchs) | 101 | path_ancestor = os.path.join(self.home_dir, "path") |
315 | 102 | self.eq.inotify_add_watch(path_ancestor) | ||
316 | 53 | 103 | ||
317 | 54 | # remove different stuff | 104 | # remove different stuff |
318 | 55 | self.eq.inotify_add_watch(self.root_dir) | ||
319 | 56 | self.assertRaises(ValueError, | 105 | self.assertRaises(ValueError, |
320 | 57 | self.eq.inotify_rm_watch, "not-added-dir") | 106 | self.eq.inotify_rm_watch, "not-added-dir") |
321 | 58 | 107 | ||
324 | 59 | def test_has_watch(self): | 108 | def test_rm_watch_general(self): |
325 | 60 | """Test that a path is watched.""" | 109 | """Test that general watchs can be removed.""" |
326 | 110 | # remove what we added | ||
327 | 111 | self.eq.inotify_add_watch(self.root_dir) | ||
328 | 112 | self.eq.inotify_rm_watch(self.root_dir) | ||
329 | 113 | |||
330 | 114 | # pylint: disable-msg=W0212 | ||
331 | 115 | self.assertEqual(self.eq._general_watchs, {}) | ||
332 | 116 | self.assertEqual(self.eq._ancestors_watchs, {}) | ||
333 | 117 | |||
334 | 118 | def test_rm_watch_ancestor(self): | ||
335 | 119 | """Test that ancestor watchs can be removed.""" | ||
336 | 120 | # create the udf and add the watch | ||
337 | 121 | path_udf = os.path.join(self.home_dir, "path/to/UDF") | ||
338 | 122 | self._create_udf(path_udf) | ||
339 | 123 | path_ancestor = os.path.join(self.home_dir, "path") | ||
340 | 124 | self.eq.inotify_add_watch(path_ancestor) | ||
341 | 125 | |||
342 | 126 | # remove what we added | ||
343 | 127 | self.eq.inotify_rm_watch(path_ancestor) | ||
344 | 128 | # pylint: disable-msg=W0212 | ||
345 | 129 | self.assertEqual(self.eq._general_watchs, {}) | ||
346 | 130 | self.assertEqual(self.eq._ancestors_watchs, {}) | ||
347 | 131 | |||
348 | 132 | def test_has_watch_general(self): | ||
349 | 133 | """Test that a general path is watched.""" | ||
350 | 61 | self.assertFalse(self.eq.inotify_has_watch(self.root_dir)) | 134 | self.assertFalse(self.eq.inotify_has_watch(self.root_dir)) |
351 | 62 | 135 | ||
352 | 63 | # add | 136 | # add |
353 | @@ -68,6 +141,24 @@ | |||
354 | 68 | self.eq.inotify_rm_watch(self.root_dir) | 141 | self.eq.inotify_rm_watch(self.root_dir) |
355 | 69 | self.assertFalse(self.eq.inotify_has_watch(self.root_dir)) | 142 | self.assertFalse(self.eq.inotify_has_watch(self.root_dir)) |
356 | 70 | 143 | ||
357 | 144 | def test_has_watch_ancestor(self): | ||
358 | 145 | """Test that an ancestor path is watched.""" | ||
359 | 146 | path_udf = os.path.join(self.home_dir, "path/to/UDF") | ||
360 | 147 | self._create_udf(path_udf) | ||
361 | 148 | path_ancestor = os.path.join(self.home_dir, "path") | ||
362 | 149 | |||
363 | 150 | self.assertFalse(self.eq.inotify_has_watch(path_ancestor)) | ||
364 | 151 | |||
365 | 152 | # add | ||
366 | 153 | # create the udf and add the watch | ||
367 | 154 | self.eq.inotify_add_watch(path_ancestor) | ||
368 | 155 | self.assertTrue(self.eq.inotify_has_watch(path_ancestor)) | ||
369 | 156 | |||
370 | 157 | # remove | ||
371 | 158 | self.eq.inotify_rm_watch(path_ancestor) | ||
372 | 159 | self.assertFalse(self.eq.inotify_has_watch(path_ancestor)) | ||
373 | 160 | |||
374 | 161 | |||
375 | 71 | class DynamicHitMe(object): | 162 | class DynamicHitMe(object): |
376 | 72 | """Helper class to test a sequence of signals.""" | 163 | """Helper class to test a sequence of signals.""" |
377 | 73 | 164 | ||
378 | @@ -1157,7 +1248,6 @@ | |||
379 | 1157 | 1248 | ||
380 | 1158 | @param msg: A string describing the failure that's included in the | 1249 | @param msg: A string describing the failure that's included in the |
381 | 1159 | exception. | 1250 | exception. |
382 | 1160 | |||
383 | 1161 | """ | 1251 | """ |
384 | 1162 | if not first == second: | 1252 | if not first == second: |
385 | 1163 | if msg is None: | 1253 | if msg is None: |
386 | @@ -1246,9 +1336,6 @@ | |||
387 | 1246 | suggested_path, path, True) | 1336 | suggested_path, path, True) |
388 | 1247 | other_ancestors = other_udf.ancestors | 1337 | other_ancestors = other_udf.ancestors |
389 | 1248 | 1338 | ||
390 | 1249 | # pylint: disable-msg=W0212 | ||
391 | 1250 | assert not self.eq._processor._is_udf_ancestor(path) | ||
392 | 1251 | |||
393 | 1252 | os.makedirs(path) | 1339 | os.makedirs(path) |
394 | 1253 | # every ancestor has a watch already, added by LocalRescan. Copy that. | 1340 | # every ancestor has a watch already, added by LocalRescan. Copy that. |
395 | 1254 | self.eq.inotify_add_watch(other_udf.path) | 1341 | self.eq.inotify_add_watch(other_udf.path) |
396 | 1255 | 1342 | ||
397 | === modified file 'tests/syncdaemon/test_eventqueue.py' | |||
398 | --- tests/syncdaemon/test_eventqueue.py 2009-11-20 22:00:25 +0000 | |||
399 | +++ tests/syncdaemon/test_eventqueue.py 2010-01-26 20:35:29 +0000 | |||
400 | @@ -39,9 +39,11 @@ | |||
401 | 39 | self.fsmdir = self.mktemp('fsmdir') | 39 | self.fsmdir = self.mktemp('fsmdir') |
402 | 40 | self.partials_dir = self.mktemp('partials_dir') | 40 | self.partials_dir = self.mktemp('partials_dir') |
403 | 41 | self.root_dir = self.mktemp('root_dir') | 41 | self.root_dir = self.mktemp('root_dir') |
404 | 42 | self.home_dir = self.mktemp('home_dir') | ||
405 | 43 | self.vm = testcase.FakeVolumeManager(self.root_dir) | ||
406 | 42 | self.fs = filesystem_manager.FileSystemManager(self.fsmdir, | 44 | self.fs = filesystem_manager.FileSystemManager(self.fsmdir, |
407 | 43 | self.partials_dir, | 45 | self.partials_dir, |
409 | 44 | testcase.FakeVolumeManager(self.root_dir)) | 46 | self.vm) |
410 | 45 | self.fs.create(path=self.root_dir, | 47 | self.fs.create(path=self.root_dir, |
411 | 46 | share_id='', is_dir=True) | 48 | share_id='', is_dir=True) |
412 | 47 | self.fs.set_by_path(path=self.root_dir, | 49 | self.fs.set_by_path(path=self.root_dir, |
413 | 48 | 50 | ||
414 | === modified file 'tests/syncdaemon/test_tools.py' | |||
415 | --- tests/syncdaemon/test_tools.py 2010-01-26 19:11:29 +0000 | |||
416 | +++ tests/syncdaemon/test_tools.py 2010-01-26 20:35:29 +0000 | |||
417 | @@ -182,7 +182,7 @@ | |||
418 | 182 | def check(result): | 182 | def check(result): |
419 | 183 | """do the asserts""" | 183 | """do the asserts""" |
420 | 184 | self.assertEquals('Yes', result['answer']) | 184 | self.assertEquals('Yes', result['answer']) |
422 | 185 | self.assertEquals('share_id', result['share_id']) | 185 | self.assertEquals('share_id', result['volume_id']) |
423 | 186 | self.assertEquals(True, self.main.vm.shares['share_id'].accepted) | 186 | self.assertEquals(True, self.main.vm.shares['share_id'].accepted) |
424 | 187 | 187 | ||
425 | 188 | d.addCallback(check) | 188 | d.addCallback(check) |
426 | @@ -199,7 +199,7 @@ | |||
427 | 199 | def check(result): | 199 | def check(result): |
428 | 200 | """do the asserts""" | 200 | """do the asserts""" |
429 | 201 | self.assertEquals('No', result['answer']) | 201 | self.assertEquals('No', result['answer']) |
431 | 202 | self.assertEquals('share_id', result['share_id']) | 202 | self.assertEquals('share_id', result['volume_id']) |
432 | 203 | self.assertEquals(False, self.main.vm.shares['share_id'].accepted) | 203 | self.assertEquals(False, self.main.vm.shares['share_id'].accepted) |
433 | 204 | 204 | ||
434 | 205 | d.addCallback(check) | 205 | d.addCallback(check) |
435 | 206 | 206 | ||
436 | === modified file 'tests/syncdaemon/test_vm.py' | |||
437 | --- tests/syncdaemon/test_vm.py 2010-01-26 19:40:05 +0000 | |||
438 | +++ tests/syncdaemon/test_vm.py 2010-01-26 20:35:29 +0000 | |||
439 | @@ -21,7 +21,6 @@ | |||
440 | 21 | import logging | 21 | import logging |
441 | 22 | import os | 22 | import os |
442 | 23 | import uuid | 23 | import uuid |
443 | 24 | import sys | ||
444 | 25 | 24 | ||
445 | 26 | from ubuntuone.storageprotocol.client import ListShares, ListVolumes | 25 | from ubuntuone.storageprotocol.client import ListShares, ListVolumes |
446 | 27 | from ubuntuone.storageprotocol.sharersp import ( | 26 | from ubuntuone.storageprotocol.sharersp import ( |
447 | @@ -36,10 +35,16 @@ | |||
448 | 36 | ) | 35 | ) |
449 | 37 | from ubuntuone.syncdaemon.volume_manager import ( | 36 | from ubuntuone.syncdaemon.volume_manager import ( |
450 | 38 | Share, | 37 | Share, |
451 | 38 | Shared, | ||
452 | 39 | UDF, | ||
453 | 40 | Root, | ||
454 | 41 | _Share, | ||
455 | 42 | _UDF, | ||
456 | 39 | allow_writes, | 43 | allow_writes, |
457 | 40 | UDF, | ||
458 | 41 | VolumeManager, | 44 | VolumeManager, |
459 | 42 | LegacyShareFileShelf, | 45 | LegacyShareFileShelf, |
460 | 46 | MetadataUpgrader, | ||
461 | 47 | VMFileShelf, | ||
462 | 43 | ) | 48 | ) |
463 | 44 | from twisted.internet import defer, reactor | 49 | from twisted.internet import defer, reactor |
464 | 45 | 50 | ||
465 | @@ -1373,64 +1378,118 @@ | |||
466 | 1373 | self.assertTrue(isinstance(share.node_id, basestring)) | 1378 | self.assertTrue(isinstance(share.node_id, basestring)) |
467 | 1374 | 1379 | ||
468 | 1375 | 1380 | ||
471 | 1376 | class ShareShelfUpgradeTests(BaseTwistedTestCase): | 1381 | class MetadataTestCase(BaseTwistedTestCase): |
472 | 1377 | """ Tests for shares shelf upgrades""" | 1382 | md_version_None = False |
473 | 1383 | main = None | ||
474 | 1384 | data_dir = None | ||
475 | 1385 | share_md_dir = None | ||
476 | 1386 | shared_md_dir = None | ||
477 | 1387 | partials_dir = None | ||
478 | 1388 | u1_dir = None | ||
479 | 1389 | root_dir = None | ||
480 | 1390 | shares_dir = None | ||
481 | 1391 | shares_dir_link = None | ||
482 | 1378 | 1392 | ||
483 | 1379 | def setUp(self): | 1393 | def setUp(self): |
485 | 1380 | """ setup the test """ | 1394 | """Create some directories.""" |
486 | 1381 | BaseTwistedTestCase.setUp(self) | 1395 | BaseTwistedTestCase.setUp(self) |
492 | 1382 | self.root_dir = self.mktemp('Ubuntu One') | 1396 | self.data_dir = os.path.join(self.tmpdir, 'data_dir') |
493 | 1383 | self.data_dir = self.mktemp('data_dir') | 1397 | self.vm_data_dir = os.path.join(self.tmpdir, 'data_dir', 'vm') |
494 | 1384 | self.partials_dir = self.mktemp('partials_dir') | 1398 | self.partials_dir = self.mktemp('partials') |
495 | 1385 | self.shares_dir = self.mktemp(os.path.join('Ubuntu One', | 1399 | self.u1_dir = os.path.join(self.tmpdir, 'Ubuntu One') |
496 | 1386 | 'Shared with Me')) | 1400 | self.version_file = os.path.join(self.vm_data_dir, '.version') |
497 | 1387 | 1401 | ||
498 | 1388 | def tearDown(self): | 1402 | def tearDown(self): |
509 | 1389 | """Cleanup main and remove the temp dir.""" | 1403 | """Cleanup all the cruft.""" |
510 | 1390 | main = getattr(self, 'main', None) | 1404 | for path in [self.data_dir, self.partials_dir, self.root_dir, |
511 | 1391 | if main: | 1405 | self.shares_dir]: |
512 | 1392 | main.shutdown() | 1406 | if path and os.path.exists(path): |
513 | 1393 | if os.path.exists(self.root_dir): | 1407 | self.rmtree(path) |
514 | 1394 | self.rmtree(self.root_dir) | 1408 | if self.main: |
515 | 1395 | if os.path.exists(self.data_dir): | 1409 | self.main.shutdown() |
506 | 1396 | self.rmtree(self.data_dir) | ||
507 | 1397 | if os.path.exists(self.shares_dir): | ||
508 | 1398 | self.rmtree(self.shares_dir) | ||
516 | 1399 | VolumeManager.METADATA_VERSION = CURRENT_METADATA_VERSION | 1410 | VolumeManager.METADATA_VERSION = CURRENT_METADATA_VERSION |
518 | 1400 | return BaseTwistedTestCase.tearDown(self) | 1411 | BaseTwistedTestCase.tearDown(self) |
519 | 1401 | 1412 | ||
520 | 1402 | def check_version(self): | 1413 | def check_version(self): |
524 | 1403 | """ check if the current version in the .version file is the lastone. | 1414 | """Check if the current version in the .version file is the last one.""" |
525 | 1404 | """ | 1415 | with open(self.version_file, 'r') as fd: |
523 | 1405 | with open(os.path.join(self.data_dir, 'vm', '.version'), 'r') as fd: | ||
526 | 1406 | self.assertEquals(CURRENT_METADATA_VERSION, fd.read().strip()) | 1416 | self.assertEquals(CURRENT_METADATA_VERSION, fd.read().strip()) |
527 | 1407 | 1417 | ||
534 | 1408 | def test_0_to_1(self): | 1418 | def set_md_version(self, md_version): |
535 | 1409 | """ Test the upgrade from the first shelf layout version to v. 1""" | 1419 | """Write md_version to the .version file.""" |
536 | 1410 | # ensure a clean data_dir | 1420 | if not os.path.exists(self.vm_data_dir): |
537 | 1411 | self.rmtree(self.data_dir) | 1421 | os.makedirs(self.vm_data_dir) |
538 | 1412 | vm_data_dir = os.path.join(self.data_dir, 'vm') | 1422 | with open(self.version_file, 'w') as fd: |
539 | 1413 | old_shelf = LegacyShareFileShelf(vm_data_dir) | 1423 | fd.write(md_version) |
540 | 1424 | |||
541 | 1425 | |||
542 | 1426 | class MetadataOldLayoutTests(MetadataTestCase): | ||
543 | 1427 | """Tests for 'old' layouts and metadata upgrade""" | ||
544 | 1428 | |||
545 | 1429 | def setUp(self): | ||
546 | 1430 | MetadataTestCase.setUp(self) | ||
547 | 1431 | self.root_dir = os.path.join(self.u1_dir, 'My Files') | ||
548 | 1432 | self.shares_dir = os.path.join(self.u1_dir, 'Shared With Me') | ||
549 | 1433 | self.new_root_dir = self.u1_dir | ||
550 | 1434 | self.new_shares_dir = self.mktemp('shares_dir') | ||
551 | 1435 | |||
552 | 1436 | def tearDown(self): | ||
553 | 1437 | """Cleanup all the cruft.""" | ||
554 | 1438 | for path in [self.u1_dir, self.new_shares_dir]: | ||
555 | 1439 | if path and os.path.exists(path): | ||
556 | 1440 | self.rmtree(path) | ||
557 | 1441 | MetadataTestCase.tearDown(self) | ||
558 | 1442 | |||
559 | 1443 | def _build_layout_version_0(self): | ||
560 | 1444 | """Build the dir structure to mimic md v.0/None.""" | ||
561 | 1445 | self.share_md_dir = os.path.join(self.tmpdir, 'data_dir', 'vm') | ||
562 | 1446 | os.makedirs(self.share_md_dir) | ||
563 | 1447 | os.makedirs(self.root_dir) | ||
564 | 1448 | os.makedirs(self.shares_dir) | ||
565 | 1449 | |||
566 | 1450 | def _build_layout_version_1(self): | ||
567 | 1451 | """Build the dir structure to mimic md v.1""" | ||
568 | 1452 | self.share_md_dir = os.path.join(self.vm_data_dir, 'shares') | ||
569 | 1453 | self.shared_md_dir = os.path.join(self.vm_data_dir, 'shared') | ||
570 | 1454 | os.makedirs(self.share_md_dir) | ||
571 | 1455 | os.makedirs(self.shared_md_dir) | ||
572 | 1456 | os.makedirs(self.root_dir) | ||
573 | 1457 | os.makedirs(self.shares_dir) | ||
574 | 1458 | |||
575 | 1459 | def _set_permissions(self): | ||
576 | 1460 | """Set the RO perms in the root and the shares directory.""" | ||
577 | 1461 | os.chmod(self.shares_dir, 0500) | ||
578 | 1462 | os.chmod(self.u1_dir, 0500) | ||
579 | 1463 | |||
580 | 1464 | def test_upgrade_0(self): | ||
581 | 1465 | """Test the upgrade from the first shelf layout version.""" | ||
582 | 1466 | self._build_layout_version_0() | ||
583 | 1467 | old_shelf = LegacyShareFileShelf(self.share_md_dir) | ||
584 | 1414 | # add the root_uuid key | 1468 | # add the root_uuid key |
586 | 1415 | root_share = Share(path=self.root_dir) | 1469 | root_share = _Share(path=self.root_dir) |
587 | 1416 | root_share.access_level = 'Modify' | 1470 | root_share.access_level = 'Modify' |
588 | 1417 | old_shelf[''] = root_share | 1471 | old_shelf[''] = root_share |
589 | 1418 | for idx in range(1, 10): | 1472 | for idx in range(1, 10): |
593 | 1419 | old_shelf[str(uuid.uuid4())] = \ | 1473 | sid = str(uuid.uuid4()) |
594 | 1420 | Share(path=os.path.join(self.shares_dir, str(idx))) | 1474 | old_shelf[sid] = _Share(path=os.path.join(self.shares_dir, str(idx)), |
595 | 1421 | # LegacyShareFileShelf.keys returns a generator | 1475 | share_id=sid) |
596 | 1476 | # ShareFileShelf.keys returns a generator | ||
597 | 1422 | old_keys = [key for key in old_shelf.keys()] | 1477 | old_keys = [key for key in old_shelf.keys()] |
598 | 1423 | self.assertEquals(10, len(old_keys)) | 1478 | self.assertEquals(10, len(old_keys)) |
599 | 1479 | if self.md_version_None: | ||
600 | 1480 | self.set_md_version('') | ||
601 | 1481 | # set the ro permissions | ||
602 | 1482 | self._set_permissions() | ||
603 | 1424 | # we want to keep a refernece to main in order to shutdown | 1483 | # we want to keep a refernece to main in order to shutdown |
604 | 1425 | # pylint: disable-msg=W0201 | 1484 | # pylint: disable-msg=W0201 |
606 | 1426 | self.main = FakeMain(self.root_dir, self.shares_dir, | 1485 | self.main = FakeMain(self.new_root_dir, self.new_shares_dir, |
607 | 1427 | self.data_dir, self.partials_dir) | 1486 | self.data_dir, self.partials_dir) |
608 | 1428 | new_keys = [new_key for new_key in self.main.vm.shares.keys()] | 1487 | new_keys = [new_key for new_key in self.main.vm.shares.keys()] |
609 | 1429 | self.assertEquals(10, len(new_keys)) | 1488 | self.assertEquals(10, len(new_keys)) |
610 | 1430 | for new_key in new_keys: | 1489 | for new_key in new_keys: |
611 | 1431 | self.assertIn(new_key, old_keys) | 1490 | self.assertIn(new_key, old_keys) |
612 | 1432 | # check the old data is still there (in the backup) | 1491 | # check the old data is still there (in the backup) |
614 | 1433 | backup_shelf = LegacyShareFileShelf(os.path.join(vm_data_dir, '0.bkp')) | 1492 | backup_shelf = LegacyShareFileShelf(os.path.join(self.vm_data_dir, '0.bkp')) |
615 | 1434 | backup_keys = [key for key in backup_shelf.keys()] | 1493 | backup_keys = [key for key in backup_shelf.keys()] |
616 | 1435 | for old_key in old_keys: | 1494 | for old_key in old_keys: |
617 | 1436 | self.assertIn(old_key, backup_keys) | 1495 | self.assertIn(old_key, backup_keys) |
618 | @@ -1438,18 +1497,13 @@ | |||
619 | 1438 | self.assertIn(new_key, backup_keys) | 1497 | self.assertIn(new_key, backup_keys) |
620 | 1439 | self.check_version() | 1498 | self.check_version() |
621 | 1440 | 1499 | ||
629 | 1441 | def test_1_to_2(self): | 1500 | def test_upgrade_1(self): |
630 | 1442 | """ Test the upgrade from v.1 of the metadata to v.2""" | 1501 | """ Test the upgrade from v.1""" |
631 | 1443 | # ensure a clean data_dir | 1502 | self._build_layout_version_1() |
625 | 1444 | self.rmtree(self.data_dir) | ||
626 | 1445 | vm_data_dir = os.path.join(self.data_dir, 'vm') | ||
627 | 1446 | vm_shares_dir = os.path.join(vm_data_dir, 'shares') | ||
628 | 1447 | os.makedirs(vm_data_dir) | ||
632 | 1448 | # write the .version file with v.1 | 1503 | # write the .version file with v.1 |
635 | 1449 | with open(os.path.join(vm_data_dir, '.version'), 'w') as fd: | 1504 | self.set_md_version('1') |
634 | 1450 | fd.write('1') | ||
636 | 1451 | 1505 | ||
638 | 1452 | share_file = os.path.join(vm_shares_dir, | 1506 | share_file = os.path.join(self.share_md_dir, |
639 | 1453 | '0/6/6/0664f050-9254-45c5-9f31-3482858709e4') | 1507 | '0/6/6/0664f050-9254-45c5-9f31-3482858709e4') |
640 | 1454 | os.makedirs(os.path.dirname(share_file)) | 1508 | os.makedirs(os.path.dirname(share_file)) |
641 | 1455 | # this is the str of a version 2 pickle | 1509 | # this is the str of a version 2 pickle |
642 | @@ -1465,222 +1519,228 @@ | |||
643 | 1465 | with open(share_file, 'w') as fd: | 1519 | with open(share_file, 'w') as fd: |
644 | 1466 | fd.write(share_value) | 1520 | fd.write(share_value) |
645 | 1467 | 1521 | ||
646 | 1468 | # fake the old namespace | ||
647 | 1469 | sys.modules['canonical.ubuntuone.storage.syncdaemon.volume_manager'] = \ | ||
648 | 1470 | sys.modules['ubuntuone.syncdaemon.volume_manager'] | ||
649 | 1471 | # try to load the shelf | 1522 | # try to load the shelf |
651 | 1472 | old_shelf = LegacyShareFileShelf(vm_shares_dir) | 1523 | old_shelf = LegacyShareFileShelf(self.share_md_dir) |
652 | 1473 | share = old_shelf['0664f050-9254-45c5-9f31-3482858709e4'] | 1524 | share = old_shelf['0664f050-9254-45c5-9f31-3482858709e4'] |
653 | 1474 | self.assertTrue(share is not None) | 1525 | self.assertTrue(share is not None) |
655 | 1475 | del sys.modules['canonical.ubuntuone.storage.syncdaemon.volume_manager'] | 1526 | if self.md_version_None: |
656 | 1527 | self.set_md_version('') | ||
657 | 1528 | |||
658 | 1529 | self._set_permissions() | ||
659 | 1476 | # now use the real VolumeManager | 1530 | # now use the real VolumeManager |
660 | 1477 | # we want to keep a refernece to main in order to shutdown | 1531 | # we want to keep a refernece to main in order to shutdown |
661 | 1478 | # pylint: disable-msg=W0201 | 1532 | # pylint: disable-msg=W0201 |
663 | 1479 | self.main = FakeMain(self.root_dir, self.shares_dir, | 1533 | self.main = FakeMain(self.new_root_dir, self.new_shares_dir, |
664 | 1480 | self.data_dir, self.partials_dir) | 1534 | self.data_dir, self.partials_dir) |
665 | 1481 | new_keys = [new_key for new_key in self.main.vm.shares.keys()] | 1535 | new_keys = [new_key for new_key in self.main.vm.shares.keys()] |
666 | 1482 | self.assertEquals(2, len(new_keys)) # the fake share plus root | 1536 | self.assertEquals(2, len(new_keys)) # the fake share plus root |
668 | 1483 | for key in ['', share.volume_id]: | 1537 | for key in ['', share.id]: |
669 | 1484 | self.assertIn(key, new_keys) | 1538 | self.assertIn(key, new_keys) |
670 | 1485 | self.check_version() | 1539 | self.check_version() |
671 | 1486 | 1540 | ||
678 | 1487 | def test_2_to_3(self): | 1541 | def test_upgrade_2(self): |
679 | 1488 | """ Test the upgrade from v.2 of the metadata to v.3""" | 1542 | """Test the upgrade from v.2.""" |
680 | 1489 | vm_data_dir = os.path.join(self.data_dir, 'vm') | 1543 | self._build_layout_version_1() |
681 | 1490 | os.makedirs(vm_data_dir) | 1544 | self.set_md_version('2') |
676 | 1491 | with open(os.path.join(vm_data_dir, '.version'), 'w') as fd: | ||
677 | 1492 | fd.write('2') | ||
682 | 1493 | open(self.root_dir + '/foo.conflict', 'w').close() | 1545 | open(self.root_dir + '/foo.conflict', 'w').close() |
683 | 1494 | open(self.root_dir + '/foo.conflict.23', 'w').close() | 1546 | open(self.root_dir + '/foo.conflict.23', 'w').close() |
684 | 1495 | open(self.shares_dir + '/bar.partial', 'w').close() | 1547 | open(self.shares_dir + '/bar.partial', 'w').close() |
685 | 1496 | os.mkdir(self.shares_dir + '/baz/') | 1548 | os.mkdir(self.shares_dir + '/baz/') |
686 | 1497 | open(self.shares_dir + '/baz/baz.conflict', 'w').close() | 1549 | open(self.shares_dir + '/baz/baz.conflict', 'w').close() |
687 | 1498 | os.chmod(self.shares_dir + '/baz/', 0500) | 1550 | os.chmod(self.shares_dir + '/baz/', 0500) |
689 | 1499 | self.main = FakeMain(self.root_dir, self.shares_dir, | 1551 | if self.md_version_None: |
690 | 1552 | self.set_md_version('') | ||
691 | 1553 | self._set_permissions() | ||
692 | 1554 | self.main = FakeMain(self.new_root_dir, self.new_shares_dir, | ||
693 | 1500 | self.data_dir, self.partials_dir) | 1555 | self.data_dir, self.partials_dir) |
698 | 1501 | self.assertTrue(os.path.exists(self.root_dir + '/foo.u1conflict')) | 1556 | self.assertTrue(os.path.exists(self.new_root_dir + '/foo.u1conflict')) |
699 | 1502 | self.assertTrue(os.path.exists(self.root_dir + '/foo.u1conflict.23')) | 1557 | self.assertTrue(os.path.exists(self.new_root_dir + '/foo.u1conflict.23')) |
700 | 1503 | self.assertTrue(os.path.exists(self.shares_dir + '/.u1partial.bar')) | 1558 | self.assertTrue(os.path.exists(self.new_shares_dir + '/.u1partial.bar')) |
701 | 1504 | self.assertTrue(os.path.exists(self.shares_dir + '/baz/baz.u1conflict')) | 1559 | self.assertTrue(os.path.exists(self.new_shares_dir + '/baz/baz.u1conflict')) |
702 | 1560 | self.check_version() | ||
703 | 1505 | 1561 | ||
710 | 1506 | def test_2_to_3_more(self): | 1562 | def test_upgrade_2_more(self): |
711 | 1507 | """ Test the upgrade from v.2 of the metadata to v.3 some more""" | 1563 | """Test the upgrade from v.2 some more.""" |
712 | 1508 | vm_data_dir = os.path.join(self.data_dir, 'vm') | 1564 | self._build_layout_version_1() |
713 | 1509 | os.makedirs(vm_data_dir) | 1565 | self.set_md_version('2') |
708 | 1510 | with open(os.path.join(vm_data_dir, '.version'), 'w') as fd: | ||
709 | 1511 | fd.write('2') | ||
714 | 1512 | 1566 | ||
715 | 1513 | expected = [] | 1567 | expected = [] |
716 | 1514 | 1568 | ||
718 | 1515 | for dirname in self.root_dir, self.shares_dir: | 1569 | for dirname, new_dirname in [(self.root_dir, self.new_root_dir), |
719 | 1570 | (self.shares_dir, self.new_shares_dir)]: | ||
720 | 1516 | # a plain .conflict... | 1571 | # a plain .conflict... |
721 | 1517 | # ...on a file | 1572 | # ...on a file |
722 | 1518 | open(dirname + '/1a.conflict', 'w').close() | 1573 | open(dirname + '/1a.conflict', 'w').close() |
724 | 1519 | expected.append(dirname + '/1a.u1conflict') | 1574 | expected.append(new_dirname + '/1a.u1conflict') |
725 | 1520 | # ...on an empty directory | 1575 | # ...on an empty directory |
726 | 1521 | os.mkdir(dirname + '/1b.conflict') | 1576 | os.mkdir(dirname + '/1b.conflict') |
728 | 1522 | expected.append(dirname + '/1b.u1conflict') | 1577 | expected.append(new_dirname + '/1b.u1conflict') |
729 | 1523 | # ...on a directory with content | 1578 | # ...on a directory with content |
730 | 1524 | os.mkdir(dirname + '/1c.conflict') | 1579 | os.mkdir(dirname + '/1c.conflict') |
731 | 1525 | os.mkdir(dirname + '/1c.conflict/1c') | 1580 | os.mkdir(dirname + '/1c.conflict/1c') |
733 | 1526 | expected.append(dirname + '/1c.u1conflict/1c') | 1581 | expected.append(new_dirname + '/1c.u1conflict/1c') |
734 | 1527 | # ...in a readonly directory | 1582 | # ...in a readonly directory |
735 | 1528 | os.mkdir(dirname + '/1d') | 1583 | os.mkdir(dirname + '/1d') |
736 | 1529 | os.mkdir(dirname + '/1d/1d.conflict') | 1584 | os.mkdir(dirname + '/1d/1d.conflict') |
737 | 1530 | os.chmod(dirname + '/1d', 0500) | 1585 | os.chmod(dirname + '/1d', 0500) |
739 | 1531 | expected.append(dirname + '/1d/1d.u1conflict') | 1586 | expected.append(new_dirname + '/1d/1d.u1conflict') |
740 | 1532 | # ...in a directory that is also a .conflict | 1587 | # ...in a directory that is also a .conflict |
741 | 1533 | os.mkdir(dirname + '/1e.conflict') | 1588 | os.mkdir(dirname + '/1e.conflict') |
742 | 1534 | os.mkdir(dirname + '/1e.conflict/1e.conflict') | 1589 | os.mkdir(dirname + '/1e.conflict/1e.conflict') |
744 | 1535 | expected.append(dirname + '/1e.u1conflict/1e.u1conflict') | 1590 | expected.append(new_dirname + '/1e.u1conflict/1e.u1conflict') |
745 | 1536 | 1591 | ||
746 | 1537 | # a numbered .conflict... | 1592 | # a numbered .conflict... |
747 | 1538 | # ...on a file | 1593 | # ...on a file |
748 | 1539 | open(dirname + '/2a.conflict.2', 'w').close() | 1594 | open(dirname + '/2a.conflict.2', 'w').close() |
750 | 1540 | expected.append(dirname + '/2a.u1conflict.2') | 1595 | expected.append(new_dirname + '/2a.u1conflict.2') |
751 | 1541 | # ...on an empty directory | 1596 | # ...on an empty directory |
752 | 1542 | os.mkdir(dirname + '/2b.conflict.3') | 1597 | os.mkdir(dirname + '/2b.conflict.3') |
754 | 1543 | expected.append(dirname + '/2b.u1conflict.3') | 1598 | expected.append(new_dirname + '/2b.u1conflict.3') |
755 | 1544 | # ...on a directory with content | 1599 | # ...on a directory with content |
756 | 1545 | os.mkdir(dirname + '/2c.conflict.4') | 1600 | os.mkdir(dirname + '/2c.conflict.4') |
757 | 1546 | os.mkdir(dirname + '/2c.conflict.4/2c') | 1601 | os.mkdir(dirname + '/2c.conflict.4/2c') |
759 | 1547 | expected.append(dirname + '/2c.u1conflict.4/2c') | 1602 | expected.append(new_dirname + '/2c.u1conflict.4/2c') |
760 | 1548 | # ...in a readonly directory | 1603 | # ...in a readonly directory |
761 | 1549 | os.mkdir(dirname + '/2d') | 1604 | os.mkdir(dirname + '/2d') |
762 | 1550 | os.mkdir(dirname + '/2d/2d.conflict.5') | 1605 | os.mkdir(dirname + '/2d/2d.conflict.5') |
763 | 1551 | os.chmod(dirname + '/2d', 0500) | 1606 | os.chmod(dirname + '/2d', 0500) |
765 | 1552 | expected.append(dirname + '/2d/2d.u1conflict.5') | 1607 | expected.append(new_dirname + '/2d/2d.u1conflict.5') |
766 | 1553 | # ...in a directory that is also a .conflict | 1608 | # ...in a directory that is also a .conflict |
767 | 1554 | os.mkdir(dirname + '/2e.conflict') | 1609 | os.mkdir(dirname + '/2e.conflict') |
768 | 1555 | os.mkdir(dirname + '/2e.conflict/2e.conflict.6') | 1610 | os.mkdir(dirname + '/2e.conflict/2e.conflict.6') |
770 | 1556 | expected.append(dirname + '/2e.u1conflict/2e.u1conflict.6') | 1611 | expected.append(new_dirname + '/2e.u1conflict/2e.u1conflict.6') |
771 | 1557 | 1612 | ||
772 | 1558 | # a plain .conflict of which there already exists a .u1conflict... | 1613 | # a plain .conflict of which there already exists a .u1conflict... |
773 | 1559 | # ...on a file | 1614 | # ...on a file |
774 | 1560 | open(dirname + '/3a.conflict', 'w').close() | 1615 | open(dirname + '/3a.conflict', 'w').close() |
775 | 1561 | open(dirname + '/3a.u1conflict', 'w').close() | 1616 | open(dirname + '/3a.u1conflict', 'w').close() |
778 | 1562 | expected.append(dirname + '/3a.u1conflict') | 1617 | expected.append(new_dirname + '/3a.u1conflict') |
779 | 1563 | expected.append(dirname + '/3a.u1conflict.1') | 1618 | expected.append(new_dirname + '/3a.u1conflict.1') |
780 | 1564 | # ...on an empty directory | 1619 | # ...on an empty directory |
781 | 1565 | os.mkdir(dirname + '/3b.conflict') | 1620 | os.mkdir(dirname + '/3b.conflict') |
782 | 1566 | os.mkdir(dirname + '/3b.u1conflict') | 1621 | os.mkdir(dirname + '/3b.u1conflict') |
785 | 1567 | expected.append(dirname + '/3b.u1conflict') | 1622 | expected.append(new_dirname + '/3b.u1conflict') |
786 | 1568 | expected.append(dirname + '/3b.u1conflict.1') | 1623 | expected.append(new_dirname + '/3b.u1conflict.1') |
787 | 1569 | # ...on a directory with content | 1624 | # ...on a directory with content |
788 | 1570 | os.mkdir(dirname + '/3c.conflict') | 1625 | os.mkdir(dirname + '/3c.conflict') |
789 | 1571 | os.mkdir(dirname + '/3c.conflict/3c') | 1626 | os.mkdir(dirname + '/3c.conflict/3c') |
790 | 1572 | os.mkdir(dirname + '/3c.u1conflict') | 1627 | os.mkdir(dirname + '/3c.u1conflict') |
791 | 1573 | os.mkdir(dirname + '/3c.u1conflict/3c2') | 1628 | os.mkdir(dirname + '/3c.u1conflict/3c2') |
794 | 1574 | expected.append(dirname + '/3c.u1conflict.1/3c') | 1629 | expected.append(new_dirname + '/3c.u1conflict.1/3c') |
795 | 1575 | expected.append(dirname + '/3c.u1conflict/3c2') | 1630 | expected.append(new_dirname + '/3c.u1conflict/3c2') |
796 | 1576 | # ...in a readonly directory | 1631 | # ...in a readonly directory |
797 | 1577 | os.mkdir(dirname + '/3d') | 1632 | os.mkdir(dirname + '/3d') |
798 | 1578 | os.mkdir(dirname + '/3d/3d.conflict') | 1633 | os.mkdir(dirname + '/3d/3d.conflict') |
799 | 1579 | os.mkdir(dirname + '/3d/3d.u1conflict') | 1634 | os.mkdir(dirname + '/3d/3d.u1conflict') |
800 | 1580 | os.mkdir(dirname + '/3d/3d.u1conflict/3d') | 1635 | os.mkdir(dirname + '/3d/3d.u1conflict/3d') |
801 | 1581 | os.chmod(dirname + '/3d', 0500) | 1636 | os.chmod(dirname + '/3d', 0500) |
804 | 1582 | expected.append(dirname + '/3d/3d.u1conflict/3d') | 1637 | expected.append(new_dirname + '/3d/3d.u1conflict/3d') |
805 | 1583 | expected.append(dirname + '/3d/3d.u1conflict.1') | 1638 | expected.append(new_dirname + '/3d/3d.u1conflict.1') |
806 | 1584 | # ...in a directory that is also a .conflict | 1639 | # ...in a directory that is also a .conflict |
807 | 1585 | os.mkdir(dirname + '/3e.conflict') | 1640 | os.mkdir(dirname + '/3e.conflict') |
808 | 1586 | os.mkdir(dirname + '/3e.conflict/3e.conflict') | 1641 | os.mkdir(dirname + '/3e.conflict/3e.conflict') |
809 | 1587 | os.mkdir(dirname + '/3e.conflict/3e.u1conflict') | 1642 | os.mkdir(dirname + '/3e.conflict/3e.u1conflict') |
810 | 1588 | os.mkdir(dirname + '/3e.conflict/3e.u1conflict/3e') | 1643 | os.mkdir(dirname + '/3e.conflict/3e.u1conflict/3e') |
813 | 1589 | expected.append(dirname + '/3e.u1conflict/3e.u1conflict/3e') | 1644 | expected.append(new_dirname + '/3e.u1conflict/3e.u1conflict/3e') |
814 | 1590 | expected.append(dirname + '/3e.u1conflict/3e.u1conflict.1') | 1645 | expected.append(new_dirname + '/3e.u1conflict/3e.u1conflict.1') |
815 | 1591 | 1646 | ||
816 | 1592 | # a numbered .conflict of which there already exists a .u1conflict... | 1647 | # a numbered .conflict of which there already exists a .u1conflict... |
817 | 1593 | # ...on a file | 1648 | # ...on a file |
818 | 1594 | open(dirname + '/4a.conflict.1', 'w').close() | 1649 | open(dirname + '/4a.conflict.1', 'w').close() |
819 | 1595 | open(dirname + '/4a.u1conflict.1', 'w').close() | 1650 | open(dirname + '/4a.u1conflict.1', 'w').close() |
822 | 1596 | expected.append(dirname + '/4a.u1conflict.1') | 1651 | expected.append(new_dirname + '/4a.u1conflict.1') |
823 | 1597 | expected.append(dirname + '/4a.u1conflict.2') | 1652 | expected.append(new_dirname + '/4a.u1conflict.2') |
824 | 1598 | # ...on an empty directory | 1653 | # ...on an empty directory |
825 | 1599 | os.mkdir(dirname + '/4b.conflict.2') | 1654 | os.mkdir(dirname + '/4b.conflict.2') |
826 | 1600 | os.mkdir(dirname + '/4b.u1conflict.2') | 1655 | os.mkdir(dirname + '/4b.u1conflict.2') |
829 | 1601 | expected.append(dirname + '/4b.u1conflict.2') | 1656 | expected.append(new_dirname + '/4b.u1conflict.2') |
830 | 1602 | expected.append(dirname + '/4b.u1conflict.3') | 1657 | expected.append(new_dirname + '/4b.u1conflict.3') |
831 | 1603 | # ...on a directory with content | 1658 | # ...on a directory with content |
832 | 1604 | os.mkdir(dirname + '/4c.conflict.3') | 1659 | os.mkdir(dirname + '/4c.conflict.3') |
833 | 1605 | os.mkdir(dirname + '/4c.conflict.3/4c') | 1660 | os.mkdir(dirname + '/4c.conflict.3/4c') |
834 | 1606 | os.mkdir(dirname + '/4c.u1conflict.3') | 1661 | os.mkdir(dirname + '/4c.u1conflict.3') |
837 | 1607 | expected.append(dirname + '/4c.u1conflict.4/4c') | 1662 | expected.append(new_dirname + '/4c.u1conflict.4/4c') |
838 | 1608 | expected.append(dirname + '/4c.u1conflict.3') | 1663 | expected.append(new_dirname + '/4c.u1conflict.3') |
839 | 1609 | # ...in a readonly directory | 1664 | # ...in a readonly directory |
840 | 1610 | os.mkdir(dirname + '/4d') | 1665 | os.mkdir(dirname + '/4d') |
841 | 1611 | os.mkdir(dirname + '/4d/4d.conflict.4') | 1666 | os.mkdir(dirname + '/4d/4d.conflict.4') |
842 | 1612 | os.mkdir(dirname + '/4d/4d.u1conflict.4') | 1667 | os.mkdir(dirname + '/4d/4d.u1conflict.4') |
843 | 1613 | os.chmod(dirname + '/4d', 0500) | 1668 | os.chmod(dirname + '/4d', 0500) |
846 | 1614 | expected.append(dirname + '/4d/4d.u1conflict.4') | 1669 | expected.append(new_dirname + '/4d/4d.u1conflict.4') |
847 | 1615 | expected.append(dirname + '/4d/4d.u1conflict.5') | 1670 | expected.append(new_dirname + '/4d/4d.u1conflict.5') |
848 | 1616 | # ...in a directory that is also a .conflict | 1671 | # ...in a directory that is also a .conflict |
849 | 1617 | os.mkdir(dirname + '/4e.conflict') | 1672 | os.mkdir(dirname + '/4e.conflict') |
850 | 1618 | os.mkdir(dirname + '/4e.conflict/4e.conflict.5') | 1673 | os.mkdir(dirname + '/4e.conflict/4e.conflict.5') |
851 | 1619 | os.mkdir(dirname + '/4e.conflict/4e.u1conflict.5') | 1674 | os.mkdir(dirname + '/4e.conflict/4e.u1conflict.5') |
854 | 1620 | expected.append(dirname + '/4e.u1conflict/4e.u1conflict.5') | 1675 | expected.append(new_dirname + '/4e.u1conflict/4e.u1conflict.5') |
855 | 1621 | expected.append(dirname + '/4e.u1conflict/4e.u1conflict.6') | 1676 | expected.append(new_dirname + '/4e.u1conflict/4e.u1conflict.6') |
856 | 1622 | 1677 | ||
857 | 1623 | # a plain .partial... | 1678 | # a plain .partial... |
858 | 1624 | # ...of a file | 1679 | # ...of a file |
859 | 1625 | open(dirname + '/5a.partial', 'w').close() | 1680 | open(dirname + '/5a.partial', 'w').close() |
861 | 1626 | expected.append(dirname + '/.u1partial.5a') | 1681 | expected.append(new_dirname + '/.u1partial.5a') |
862 | 1627 | # ...of a directory | 1682 | # ...of a directory |
863 | 1628 | os.mkdir(dirname + '/5b') | 1683 | os.mkdir(dirname + '/5b') |
864 | 1629 | open(dirname + '/5b/.partial', 'w').close() | 1684 | open(dirname + '/5b/.partial', 'w').close() |
866 | 1630 | expected.append(dirname + '/5b/.u1partial') | 1685 | expected.append(new_dirname + '/5b/.u1partial') |
867 | 1631 | # ...of a readonly directory | 1686 | # ...of a readonly directory |
868 | 1632 | os.mkdir(dirname + '/5c') | 1687 | os.mkdir(dirname + '/5c') |
869 | 1633 | open(dirname + '/5c/.partial', 'w').close() | 1688 | open(dirname + '/5c/.partial', 'w').close() |
870 | 1634 | os.chmod(dirname + '/5c', 0500) | 1689 | os.chmod(dirname + '/5c', 0500) |
872 | 1635 | expected.append(dirname + '/5c/.u1partial') | 1690 | expected.append(new_dirname + '/5c/.u1partial') |
873 | 1636 | 1691 | ||
874 | 1637 | # a plain .partial of which there already exists a .u1partial... | 1692 | # a plain .partial of which there already exists a .u1partial... |
875 | 1638 | # ...of a file | 1693 | # ...of a file |
876 | 1639 | open(dirname + '/6a.partial', 'w').close() | 1694 | open(dirname + '/6a.partial', 'w').close() |
877 | 1640 | open(dirname + '/.u1partial.6a', 'w').close() | 1695 | open(dirname + '/.u1partial.6a', 'w').close() |
880 | 1641 | expected.append(dirname + '/.u1partial.6a') | 1696 | expected.append(new_dirname + '/.u1partial.6a') |
881 | 1642 | expected.append(dirname + '/.u1partial.6a.1') | 1697 | expected.append(new_dirname + '/.u1partial.6a.1') |
882 | 1643 | # ...of a directory | 1698 | # ...of a directory |
883 | 1644 | os.mkdir(dirname + '/6b') | 1699 | os.mkdir(dirname + '/6b') |
884 | 1645 | open(dirname + '/6b/.partial', 'w').close() | 1700 | open(dirname + '/6b/.partial', 'w').close() |
885 | 1646 | open(dirname + '/6b/.u1partial', 'w').close() | 1701 | open(dirname + '/6b/.u1partial', 'w').close() |
888 | 1647 | expected.append(dirname + '/6b/.u1partial') | 1702 | expected.append(new_dirname + '/6b/.u1partial') |
889 | 1648 | expected.append(dirname + '/6b/.u1partial.1') | 1703 | expected.append(new_dirname + '/6b/.u1partial.1') |
890 | 1649 | # ...of a readonly directory | 1704 | # ...of a readonly directory |
891 | 1650 | os.mkdir(dirname + '/6c') | 1705 | os.mkdir(dirname + '/6c') |
892 | 1651 | open(dirname + '/6c/.partial', 'w').close() | 1706 | open(dirname + '/6c/.partial', 'w').close() |
893 | 1652 | open(dirname + '/6c/.u1partial', 'w').close() | 1707 | open(dirname + '/6c/.u1partial', 'w').close() |
894 | 1653 | os.chmod(dirname + '/6c', 0500) | 1708 | os.chmod(dirname + '/6c', 0500) |
897 | 1654 | expected.append(dirname + '/6c/.u1partial') | 1709 | expected.append(new_dirname + '/6c/.u1partial') |
898 | 1655 | expected.append(dirname + '/6c/.u1partial.1') | 1710 | expected.append(new_dirname + '/6c/.u1partial.1') |
899 | 1656 | 1711 | ||
901 | 1657 | self.main = FakeMain(self.root_dir, self.shares_dir, | 1712 | self._set_permissions() |
902 | 1713 | self.main = FakeMain(self.new_root_dir, self.new_shares_dir, | ||
903 | 1658 | self.data_dir, self.partials_dir) | 1714 | self.data_dir, self.partials_dir) |
904 | 1659 | 1715 | ||
905 | 1660 | for path in expected: | 1716 | for path in expected: |
906 | 1661 | self.assertTrue(os.path.exists(path), 'missing ' + path) | 1717 | self.assertTrue(os.path.exists(path), 'missing ' + path) |
907 | 1718 | self.check_version() | ||
908 | 1662 | 1719 | ||
909 | 1663 | def test_missing_version_file_with_version_non_0(self): | 1720 | def test_missing_version_file_with_version_non_0(self): |
912 | 1664 | """ Test the upgrade from the first shelf layout version to v3 | 1721 | """Test the upgrade from the first shelf layout version |
913 | 1665 | while the metadata sould be in v3 format | 1722 | while the metadata sould be in v3 or greater format. |
914 | 1723 | |||
915 | 1666 | """ | 1724 | """ |
920 | 1667 | # ensure a clean data_dir | 1725 | self._build_layout_version_1() |
921 | 1668 | self.rmtree(self.data_dir) | 1726 | maybe_old_shelf = LegacyShareFileShelf(self.share_md_dir) |
918 | 1669 | vm_data_dir = os.path.join(self.data_dir, 'vm', 'shares') | ||
919 | 1670 | maybe_old_shelf = LegacyShareFileShelf(vm_data_dir) | ||
922 | 1671 | # add the root_uuid key | 1727 | # add the root_uuid key |
924 | 1672 | root_share = Share(path=self.root_dir) | 1728 | root_share = _Share(self.root_dir) |
925 | 1673 | root_share.access_level = 'Modify' | 1729 | root_share.access_level = 'Modify' |
926 | 1674 | maybe_old_shelf[''] = root_share | 1730 | maybe_old_shelf[''] = root_share |
927 | 1675 | for idx in range(1, 10): | 1731 | for idx in range(1, 10): |
930 | 1676 | maybe_old_shelf[str(uuid.uuid4())] = \ | 1732 | share_id = str(uuid.uuid4()) |
931 | 1677 | Share(path=os.path.join(self.shares_dir, str(idx))) | 1733 | maybe_old_shelf[share_id] = \ |
932 | 1734 | _Share(share_id=share_id, | ||
933 | 1735 | path=os.path.join(self.shares_dir, str(idx))) | ||
934 | 1678 | # ShareFileShelf.keys returns a generator | 1736 | # ShareFileShelf.keys returns a generator |
935 | 1679 | maybe_old_keys = [key for key in maybe_old_shelf.keys()] | 1737 | maybe_old_keys = [key for key in maybe_old_shelf.keys()] |
936 | 1680 | self.assertEquals(10, len(maybe_old_keys)) | 1738 | self.assertEquals(10, len(maybe_old_keys)) |
937 | 1739 | if self.md_version_None: | ||
938 | 1740 | self.set_md_version('') | ||
939 | 1681 | # we want to keep a refernece to main in order to shutdown | 1741 | # we want to keep a refernece to main in order to shutdown |
940 | 1682 | # pylint: disable-msg=W0201 | 1742 | # pylint: disable-msg=W0201 |
942 | 1683 | self.main = FakeMain(self.root_dir, self.shares_dir, | 1743 | self.main = FakeMain(self.new_root_dir, self.new_shares_dir, |
943 | 1684 | self.data_dir, self.partials_dir) | 1744 | self.data_dir, self.partials_dir) |
944 | 1685 | new_keys = [new_key for new_key in self.main.vm.shares.keys()] | 1745 | new_keys = [new_key for new_key in self.main.vm.shares.keys()] |
945 | 1686 | self.assertEquals(10, len(new_keys)) | 1746 | self.assertEquals(10, len(new_keys)) |
946 | @@ -1689,160 +1749,444 @@ | |||
947 | 1689 | # as we didn't actually upgrade the shelf, just the .version file | 1749 | # as we didn't actually upgrade the shelf, just the .version file |
948 | 1690 | # check the empty 0.bkp | 1750 | # check the empty 0.bkp |
949 | 1691 | # check the old data is still there (in the backup) | 1751 | # check the old data is still there (in the backup) |
951 | 1692 | backup_shelf = LegacyShareFileShelf(os.path.join(vm_data_dir, '0.bkp')) | 1752 | backup_shelf = LegacyShareFileShelf(os.path.join(self.vm_data_dir, '0.bkp')) |
952 | 1693 | backup_keys = [key for key in backup_shelf.keys()] | 1753 | backup_keys = [key for key in backup_shelf.keys()] |
953 | 1694 | self.assertEquals(0, len(backup_keys)) | 1754 | self.assertEquals(0, len(backup_keys)) |
954 | 1695 | self.check_version() | 1755 | self.check_version() |
955 | 1696 | 1756 | ||
968 | 1697 | def test_3_to_4(self): | 1757 | def test_upgrade_3(self): |
969 | 1698 | """upgrade from version 3 to 4""" | 1758 | """Test upgrade from version 3.""" |
970 | 1699 | vm_data_dir = os.path.join(self.data_dir, 'vm') | 1759 | self._build_layout_version_1() |
971 | 1700 | os.makedirs(vm_data_dir) | 1760 | self.set_md_version('3') |
972 | 1701 | with open(os.path.join(vm_data_dir, '.version'), 'w') as fd: | 1761 | # create a dir in the root |
973 | 1702 | fd.write('3') | 1762 | os.makedirs(os.path.join(self.root_dir, 'test_dir')) |
962 | 1703 | os.rmdir(self.shares_dir) | ||
963 | 1704 | # build the old layout | ||
964 | 1705 | old_root = os.path.join(self.root_dir, 'My Files') | ||
965 | 1706 | old_shares = os.path.join(self.root_dir, 'Shared With Me') | ||
966 | 1707 | os.makedirs(os.path.join(old_root, 'test_dir')) | ||
967 | 1708 | open(os.path.join(old_root, 'test_file'), 'w').close() | ||
974 | 1709 | # create a file in the root | 1763 | # create a file in the root |
975 | 1710 | open(os.path.join(self.root_dir, 'test_file'), 'w').close() | 1764 | open(os.path.join(self.root_dir, 'test_file'), 'w').close() |
977 | 1711 | share_path = os.path.join(old_shares, 'Bla from Foo') | 1765 | # create a file in the new root |
978 | 1766 | open(os.path.join(self.new_root_dir, 'test_file'), 'w').close() | ||
979 | 1767 | share_path = os.path.join(self.shares_dir, 'Bla from Foo') | ||
980 | 1712 | os.makedirs(share_path) | 1768 | os.makedirs(share_path) |
981 | 1713 | os.makedirs(os.path.join(share_path, 'test_dir')) | 1769 | os.makedirs(os.path.join(share_path, 'test_dir')) |
982 | 1714 | open(os.path.join(share_path, 'test_file'), 'w').close() | 1770 | open(os.path.join(share_path, 'test_file'), 'w').close() |
983 | 1715 | # fix permissions | 1771 | # fix permissions |
986 | 1716 | os.chmod(self.root_dir, 0555) | 1772 | self._set_permissions() |
987 | 1717 | os.chmod(old_shares, 0555) | 1773 | if self.md_version_None: |
988 | 1774 | self.set_md_version('') | ||
989 | 1718 | # migrate the data | 1775 | # migrate the data |
991 | 1719 | self.main = FakeMain(self.root_dir, self.shares_dir, | 1776 | self.main = FakeMain(self.new_root_dir, self.new_shares_dir, |
992 | 1720 | self.data_dir, self.partials_dir) | 1777 | self.data_dir, self.partials_dir) |
998 | 1721 | self.assertFalse(os.path.exists(old_root)) | 1778 | self.assertFalse(os.path.exists(self.root_dir)) |
999 | 1722 | self.assertTrue(os.path.exists(old_shares)) | 1779 | self.assertTrue(os.path.exists(self.shares_dir)) |
1000 | 1723 | self.assertTrue(os.path.islink(old_shares)) | 1780 | self.assertTrue(os.path.islink(self.shares_dir), self.shares_dir) |
1001 | 1724 | self.assertEquals(old_shares, self.main.shares_dir_link) | 1781 | self.assertEquals(self.shares_dir, self.main.shares_dir_link) |
1002 | 1725 | self.assertTrue(os.path.exists(os.path.join(self.root_dir, | 1782 | self.assertTrue(os.path.exists(os.path.join(self.new_root_dir, |
1003 | 1726 | 'test_dir'))) | 1783 | 'test_dir'))) |
1005 | 1727 | self.assertTrue(os.path.exists(os.path.join(self.root_dir, | 1784 | self.assertTrue(os.path.exists(os.path.join(self.new_root_dir, |
1006 | 1728 | 'test_file'))) | 1785 | 'test_file'))) |
1008 | 1729 | self.assertTrue(os.path.exists(os.path.join(self.root_dir, | 1786 | self.assertTrue(os.path.exists(os.path.join(self.new_root_dir, |
1009 | 1730 | 'test_file.u1conflict'))) | 1787 | 'test_file.u1conflict'))) |
1010 | 1731 | self.assertTrue(os.path.exists(share_path)) | 1788 | self.assertTrue(os.path.exists(share_path)) |
1011 | 1732 | self.assertTrue(os.path.exists(os.path.join(share_path, 'test_dir'))) | 1789 | self.assertTrue(os.path.exists(os.path.join(share_path, 'test_dir'))) |
1012 | 1733 | self.assertTrue(os.path.exists(os.path.join(share_path, 'test_file'))) | 1790 | self.assertTrue(os.path.exists(os.path.join(share_path, 'test_file'))) |
1013 | 1791 | self.check_version() | ||
1014 | 1734 | 1792 | ||
1022 | 1735 | def test_3_to_4_with_symlink_in_myfiles(self): | 1793 | def test_upgrade_3_with_symlink_in_myfiles(self): |
1023 | 1736 | """upgrade from version 3 to 4""" | 1794 | """Test upgrade from version 3 with symlink in 'My Files'.""" |
1024 | 1737 | vm_data_dir = os.path.join(self.data_dir, 'vm') | 1795 | self._build_layout_version_1() |
1025 | 1738 | os.makedirs(vm_data_dir) | 1796 | self.set_md_version('3') |
1019 | 1739 | with open(os.path.join(vm_data_dir, '.version'), 'w') as fd: | ||
1020 | 1740 | fd.write('3') | ||
1021 | 1741 | os.rmdir(self.shares_dir) | ||
1026 | 1742 | # build the old layout | 1797 | # build the old layout |
1031 | 1743 | old_root = os.path.join(self.root_dir, 'My Files') | 1798 | os.makedirs(os.path.join(self.root_dir, 'test_dir')) |
1032 | 1744 | old_shares = os.path.join(self.root_dir, 'Shared With Me') | 1799 | open(os.path.join(self.root_dir, 'test_file'), 'w').close() |
1029 | 1745 | os.makedirs(os.path.join(old_root, 'test_dir')) | ||
1030 | 1746 | open(os.path.join(old_root, 'test_file'), 'w').close() | ||
1033 | 1747 | # create a file in the root | 1800 | # create a file in the root |
1036 | 1748 | open(os.path.join(self.root_dir, 'test_file'), 'w').close() | 1801 | open(os.path.join(self.new_root_dir, 'test_file'), 'w').close() |
1037 | 1749 | share_path = os.path.join(old_shares, 'Bla from Foo') | 1802 | share_path = os.path.join(self.shares_dir, 'Bla from Foo') |
1038 | 1750 | os.makedirs(share_path) | 1803 | os.makedirs(share_path) |
1039 | 1751 | os.makedirs(os.path.join(share_path, 'test_dir')) | 1804 | os.makedirs(os.path.join(share_path, 'test_dir')) |
1040 | 1752 | open(os.path.join(share_path, 'test_file'), 'w').close() | 1805 | open(os.path.join(share_path, 'test_file'), 'w').close() |
1041 | 1753 | # create the Shared with Me symlink in My Files | 1806 | # create the Shared with Me symlink in My Files |
1043 | 1754 | os.symlink(old_shares, os.path.join(old_root, 'Shared With Me')) | 1807 | os.symlink(self.shares_dir, os.path.join(self.root_dir, |
1044 | 1808 | "Shared With Me")) | ||
1045 | 1755 | # fix permissions | 1809 | # fix permissions |
1048 | 1756 | os.chmod(self.root_dir, 0555) | 1810 | self._set_permissions() |
1049 | 1757 | os.chmod(old_shares, 0555) | 1811 | if self.md_version_None: |
1050 | 1812 | self.set_md_version('') | ||
1051 | 1758 | # migrate the data | 1813 | # migrate the data |
1054 | 1759 | self.shares_dir = os.path.join(self.tmpdir, 'shares') | 1814 | self.main = FakeMain(self.new_root_dir, self.new_shares_dir, |
1053 | 1760 | self.main = FakeMain(self.root_dir, self.shares_dir, | ||
1055 | 1761 | self.data_dir, self.partials_dir) | 1815 | self.data_dir, self.partials_dir) |
1061 | 1762 | self.assertFalse(os.path.exists(old_root)) | 1816 | self.assertFalse(os.path.exists(self.root_dir)) |
1062 | 1763 | self.assertTrue(os.path.exists(old_shares)) | 1817 | self.assertTrue(os.path.exists(self.shares_dir)) |
1063 | 1764 | self.assertTrue(os.path.islink(old_shares)) | 1818 | self.assertTrue(os.path.islink(self.shares_dir)) |
1064 | 1765 | self.assertEquals(old_shares, self.main.shares_dir_link) | 1819 | self.assertEquals(self.shares_dir, self.main.shares_dir_link) |
1065 | 1766 | self.assertTrue(os.path.exists(os.path.join(self.root_dir, | 1820 | self.assertTrue(os.path.exists(os.path.join(self.new_root_dir, |
1066 | 1767 | 'test_dir'))) | 1821 | 'test_dir'))) |
1068 | 1768 | self.assertTrue(os.path.exists(os.path.join(self.root_dir, | 1822 | self.assertTrue(os.path.exists(os.path.join(self.new_root_dir, |
1069 | 1769 | 'test_file'))) | 1823 | 'test_file'))) |
1071 | 1770 | self.assertTrue(os.path.exists(os.path.join(self.root_dir, | 1824 | self.assertTrue(os.path.exists(os.path.join(self.new_root_dir, |
1072 | 1771 | 'test_file.u1conflict'))) | 1825 | 'test_file.u1conflict'))) |
1073 | 1772 | self.assertTrue(os.path.exists(share_path)) | 1826 | self.assertTrue(os.path.exists(share_path)) |
1074 | 1773 | self.assertTrue(os.path.exists(os.path.join(share_path, 'test_dir'))) | 1827 | self.assertTrue(os.path.exists(os.path.join(share_path, 'test_dir'))) |
1075 | 1774 | self.assertTrue(os.path.exists(os.path.join(share_path, 'test_file'))) | 1828 | self.assertTrue(os.path.exists(os.path.join(share_path, 'test_file'))) |
1076 | 1775 | self.assertEquals(self.main.shares_dir, | 1829 | self.assertEquals(self.main.shares_dir, |
1077 | 1776 | os.readlink(self.main.shares_dir_link)) | 1830 | os.readlink(self.main.shares_dir_link)) |
1088 | 1777 | 1831 | self.check_version() | |
1089 | 1778 | def test_None_to_4(self): | 1832 | |
1090 | 1779 | """upgrade from version None to 4 (possibly a clean start)""" | 1833 | |
1091 | 1780 | VolumeManager.METADATA_VERSION = '4' | 1834 | class MetadataNewLayoutTests(MetadataTestCase): |
1092 | 1781 | vm_data_dir = os.path.join(self.data_dir, 'vm') | 1835 | """Test for 'new' layout and metadata upgrade.""" |
1093 | 1782 | version_file = os.path.join(vm_data_dir, '.version') | 1836 | |
1094 | 1783 | if os.path.exists(version_file): | 1837 | def setUp(self): |
1095 | 1784 | os.remove(version_file) | 1838 | MetadataTestCase.setUp(self) |
1096 | 1785 | os.rmdir(self.shares_dir) | 1839 | self.share_md_dir = os.path.join(self.vm_data_dir, 'shares') |
1097 | 1786 | os.rmdir(self.root_dir) | 1840 | self.shared_md_dir = os.path.join(self.vm_data_dir, 'shared') |
1098 | 1841 | self.home_dir = os.path.join(self.tmpdir, 'home', 'ubuntuonehacker') | ||
1099 | 1842 | self.u1_dir = os.path.join(self.home_dir, os.path.split(self.u1_dir)[1]) | ||
1100 | 1843 | self.root_dir = self.u1_dir | ||
1101 | 1844 | self.shares_dir = os.path.join(self.tmpdir, 'shares') | ||
1102 | 1845 | self.shares_dir_link = os.path.join(self.u1_dir, 'Shared With Me') | ||
1103 | 1846 | |||
1104 | 1847 | def _build_layout_version_4(self): | ||
1105 | 1848 | """Build the directory structure to mimic md v.4/5.""" | ||
1106 | 1849 | os.makedirs(self.share_md_dir) | ||
1107 | 1850 | os.makedirs(self.shared_md_dir) | ||
1108 | 1851 | os.makedirs(self.root_dir) | ||
1109 | 1852 | os.makedirs(self.shares_dir) | ||
1110 | 1853 | os.symlink(self.shares_dir, self.shares_dir_link) | ||
1111 | 1854 | |||
1112 | 1855 | def _fix_permissions(self): | ||
1113 | 1856 | """Fix shares dir permissions, making it read-only.""" | ||
1114 | 1857 | os.chmod(self.shares_dir, 0500) | ||
1115 | 1858 | |||
1116 | 1859 | def test_upgrade_None_to_last(self): | ||
1117 | 1860 | """Upgrade from version 'None' (possibly a clean start).""" | ||
1118 | 1787 | old_root = os.path.join(self.root_dir, 'My Files') | 1861 | old_root = os.path.join(self.root_dir, 'My Files') |
1119 | 1788 | old_shares = os.path.join(self.root_dir, 'Shared With Me') | 1862 | old_shares = os.path.join(self.root_dir, 'Shared With Me') |
1120 | 1789 | # start and check that everything is ok | 1863 | # start and check that everything is ok |
1121 | 1790 | self.main = FakeMain(self.root_dir, self.shares_dir, | 1864 | self.main = FakeMain(self.root_dir, self.shares_dir, |
1122 | 1791 | self.data_dir, self.partials_dir) | 1865 | self.data_dir, self.partials_dir) |
1123 | 1792 | self.assertFalse(os.path.exists(old_root)) | 1866 | self.assertFalse(os.path.exists(old_root)) |
1124 | 1867 | self.assertTrue(os.path.exists(self.root_dir)) | ||
1125 | 1793 | self.assertTrue(os.path.exists(old_shares)) | 1868 | self.assertTrue(os.path.exists(old_shares)) |
1126 | 1794 | self.assertTrue(os.path.islink(old_shares)) | 1869 | self.assertTrue(os.path.islink(old_shares)) |
1127 | 1795 | self.assertEquals(old_shares, self.main.shares_dir_link) | 1870 | self.assertEquals(old_shares, self.main.shares_dir_link) |
1143 | 1796 | if os.path.exists(version_file): | 1871 | self.check_version() |
1144 | 1797 | with open(os.path.join(vm_data_dir, '.version'), 'r') as fd: | 1872 | |
1145 | 1798 | self.assertEquals('4', fd.read()) | 1873 | def test_upgrade_None_to_last_phantom_share_path(self): |
1146 | 1799 | else: | 1874 | """Upgrade from version 'None' (possibly a clean start) with a root |
1147 | 1800 | self.fail('missing .version file') | 1875 | with missing path. |
1148 | 1801 | 1876 | ||
1149 | 1802 | def test_None_to_4_phantom_share_path(self): | 1877 | """ |
1135 | 1803 | """upgrade from version None to 4 (possibly a clean start)""" | ||
1136 | 1804 | VolumeManager.METADATA_VERSION = '4' | ||
1137 | 1805 | vm_data_dir = os.path.join(self.data_dir, 'vm') | ||
1138 | 1806 | version_file = os.path.join(vm_data_dir, '.version') | ||
1139 | 1807 | if os.path.exists(version_file): | ||
1140 | 1808 | os.remove(version_file) | ||
1141 | 1809 | os.rmdir(self.shares_dir) | ||
1142 | 1810 | os.rmdir(self.root_dir) | ||
1150 | 1811 | old_root = os.path.join(self.root_dir, 'My Files') | 1878 | old_root = os.path.join(self.root_dir, 'My Files') |
1151 | 1812 | old_shares = os.path.join(self.root_dir, 'Shared With Me') | 1879 | old_shares = os.path.join(self.root_dir, 'Shared With Me') |
1152 | 1813 | # start and check that everything is ok | ||
1153 | 1814 | self.main = FakeMain(self.root_dir, self.shares_dir, | 1880 | self.main = FakeMain(self.root_dir, self.shares_dir, |
1154 | 1815 | self.data_dir, self.partials_dir) | 1881 | self.data_dir, self.partials_dir) |
1156 | 1816 | root = self.main.vm.shares[''] | 1882 | self.main.shutdown() |
1157 | 1883 | self.rmtree(self.vm_data_dir) | ||
1158 | 1884 | os.makedirs(self.vm_data_dir) | ||
1159 | 1885 | self.set_md_version('') | ||
1160 | 1886 | shares = LegacyShareFileShelf(self.share_md_dir) | ||
1161 | 1887 | root_share = _Share(self.root_dir) | ||
1162 | 1888 | root_share.access_level = 'Modify' | ||
1163 | 1817 | # set None to the share path | 1889 | # set None to the share path |
1169 | 1818 | root.path = None | 1890 | root_share.path = None |
1170 | 1819 | self.main.vm.shares['test'] = root | 1891 | shares[''] = root_share |
1171 | 1820 | if os.path.exists(version_file): | 1892 | |
1172 | 1821 | os.remove(version_file) | 1893 | if self.md_version_None: |
1173 | 1822 | self.main.shutdown() | 1894 | self.set_md_version('') |
1174 | 1823 | # check that it's all OK | 1895 | # check that it's all OK |
1175 | 1824 | self.main = FakeMain(self.root_dir, self.shares_dir, | 1896 | self.main = FakeMain(self.root_dir, self.shares_dir, |
1176 | 1825 | self.data_dir, self.partials_dir) | 1897 | self.data_dir, self.partials_dir) |
1177 | 1826 | self.assertFalse(os.path.exists(old_root)) | 1898 | self.assertFalse(os.path.exists(old_root)) |
1179 | 1827 | self.assertTrue(os.path.exists(old_shares)) | 1899 | self.assertTrue(os.path.exists(self.root_dir)) |
1180 | 1900 | self.assertTrue(os.path.exists(self.shares_dir)) | ||
1181 | 1828 | self.assertTrue(os.path.islink(old_shares)) | 1901 | self.assertTrue(os.path.islink(old_shares)) |
1182 | 1829 | self.assertEquals(old_shares, self.main.shares_dir_link) | 1902 | self.assertEquals(old_shares, self.main.shares_dir_link) |
1198 | 1830 | if os.path.exists(version_file): | 1903 | self.check_version() |
1199 | 1831 | with open(os.path.join(vm_data_dir, '.version'), 'r') as fd: | 1904 | |
1200 | 1832 | self.assertEquals('4', fd.read()) | 1905 | def test_upgrade_4(self): |
1201 | 1833 | else: | 1906 | """Test migration from 4 to 5 (broken symlink in the root).""" |
1202 | 1834 | self.fail('missing .version file') | 1907 | self._build_layout_version_4() |
1203 | 1835 | 1908 | self.set_md_version('4') | |
1204 | 1836 | def test_4_to_5(self): | 1909 | # break the symlink |
1205 | 1837 | """test migration from 4 to 5 (broken symlink in the root)""" | 1910 | if os.path.exists(self.shares_dir_link): |
1206 | 1838 | vm_data_dir = os.path.join(self.data_dir, 'vm') | 1911 | os.unlink(self.shares_dir_link) |
1207 | 1839 | os.makedirs(vm_data_dir) | 1912 | os.symlink(self.shares_dir_link, self.shares_dir_link) |
1208 | 1840 | with open(os.path.join(vm_data_dir, '.version'), 'w') as fd: | 1913 | |
1209 | 1841 | fd.write('4') | 1914 | if self.md_version_None: |
1210 | 1842 | # build the new layout with a broken symlink | 1915 | self.set_md_version('') |
1196 | 1843 | shares_link = os.path.join(self.root_dir, 'Shared With Me') | ||
1197 | 1844 | os.symlink(shares_link, shares_link) | ||
1211 | 1845 | self.main = FakeMain(self.root_dir, self.shares_dir, | 1916 | self.main = FakeMain(self.root_dir, self.shares_dir, |
1212 | 1846 | self.data_dir, self.partials_dir) | 1917 | self.data_dir, self.partials_dir) |
1213 | 1847 | self.assertEquals(self.main.shares_dir, | 1918 | self.assertEquals(self.main.shares_dir, |
1214 | 1848 | os.readlink(self.main.shares_dir_link)) | 1919 | os.readlink(self.main.shares_dir_link)) |
1215 | 1920 | self.check_version() | ||
1216 | 1921 | |||
1217 | 1922 | def test_upgrade_5(self): | ||
1218 | 1923 | """Test the migration from version 5.""" | ||
1219 | 1924 | # build a fake version 5 state | ||
1220 | 1925 | self._build_layout_version_4() | ||
1221 | 1926 | self.set_md_version('5') | ||
1222 | 1927 | # create some old shares and shared metadata | ||
1223 | 1928 | legacy_shares = LegacyShareFileShelf(self.share_md_dir) | ||
1224 | 1929 | root_share = _Share(path=self.root_dir, share_id='', | ||
1225 | 1930 | access_level='Modify') | ||
1226 | 1931 | legacy_shares[''] = root_share | ||
1227 | 1932 | for idx, name in enumerate(['share'] * 1000): | ||
1228 | 1933 | sid = str(uuid.uuid4()) | ||
1229 | 1934 | share_name = name + '_' + str(idx) | ||
1230 | 1935 | share = _Share(path=os.path.join(self.shares_dir, share_name), | ||
1231 | 1936 | share_id=sid, name=share_name, | ||
1232 | 1937 | node_id=str(uuid.uuid4()), | ||
1233 | 1938 | other_username='username'+str(idx), | ||
1234 | 1939 | other_visible_name='visible name ' + str(idx)) | ||
1235 | 1940 | if idx % 2: | ||
1236 | 1941 | share.access_level = 'Modify' | ||
1237 | 1942 | else: | ||
1238 | 1943 | share.access_level = 'View' | ||
1239 | 1944 | legacy_shares[sid] = share | ||
1240 | 1945 | |||
1241 | 1946 | # create shared shares | ||
1242 | 1947 | legacy_shared = LegacyShareFileShelf(self.shared_md_dir) | ||
1243 | 1948 | for idx, name in enumerate(['dir'] * 5): | ||
1244 | 1949 | sid = str(uuid.uuid4()) | ||
1245 | 1950 | share_name = name + '_' + str(idx) | ||
1246 | 1951 | share = _Share(path=os.path.join(self.root_dir, share_name), | ||
1247 | 1952 | share_id=sid, node_id=str(uuid.uuid4()), | ||
1248 | 1953 | name=share_name, other_username='hola', | ||
1249 | 1954 | other_visible_name='hola') | ||
1250 | 1955 | if idx % 2: | ||
1251 | 1956 | share.access_level = 'Modify' | ||
1252 | 1957 | else: | ||
1253 | 1958 | share.access_level = 'View' | ||
1254 | 1959 | legacy_shared[sid] = share | ||
1255 | 1960 | |||
1256 | 1961 | # keep a copy of the current shares and shared metadata to check | ||
1257 | 1962 | # the upgrade went ok | ||
1258 | 1963 | legacy_shares = dict(legacy_shares.items()) | ||
1259 | 1964 | legacy_shared = dict(legacy_shared.items()) | ||
1260 | 1965 | |||
1261 | 1966 | if self.md_version_None: | ||
1262 | 1967 | self.set_md_version('') | ||
1263 | 1968 | # upgrade it! | ||
1264 | 1969 | self.main = FakeMain(self.root_dir, self.shares_dir, | ||
1265 | 1970 | self.data_dir, self.partials_dir) | ||
1266 | 1971 | vm = self.main.vm | ||
1267 | 1972 | def compare_share(share, old_share): | ||
1268 | 1973 | """Compare two shares, new and old""" | ||
1269 | 1974 | self.assertEquals(share.volume_id, old_share.id) | ||
1270 | 1975 | self.assertEquals(share.path, old_share.path) | ||
1271 | 1976 | self.assertEquals(share.node_id, old_share.subtree) | ||
1272 | 1977 | if not isinstance(share, Root): | ||
1273 | 1978 | self.assertEquals(share.name, old_share.name) | ||
1274 | 1979 | self.assertEquals(share.other_username, old_share.other_username) | ||
1275 | 1980 | self.assertEquals(share.other_visible_name, old_share.other_visible_name) | ||
1276 | 1981 | self.assertEquals(share.access_level, old_share.access_level) | ||
1277 | 1982 | |||
1278 | 1983 | for sid in vm.shares: | ||
1279 | 1984 | old_share = legacy_shares[sid] | ||
1280 | 1985 | share = vm.shares[sid] | ||
1281 | 1986 | self.assertTrue(isinstance(share, Share) or isinstance(share, Root)) | ||
1282 | 1987 | compare_share(share, old_share) | ||
1283 | 1988 | |||
1284 | 1989 | for sid in vm.shared: | ||
1285 | 1990 | old_share = legacy_shared[sid] | ||
1286 | 1991 | share = vm.shared[sid] | ||
1287 | 1992 | self.assertTrue(isinstance(share, Shared)) | ||
1288 | 1993 | compare_share(share, old_share) | ||
1289 | 1994 | |||
1290 | 1995 | def test_upgrade_5_with_udfs(self): | ||
1291 | 1996 | """Test the migration from version 5 with old UDFs.""" | ||
1292 | 1997 | # build a fake version 5 state | ||
1293 | 1998 | self._build_layout_version_4() | ||
1294 | 1999 | self.set_md_version('5') | ||
1295 | 2000 | self.udfs_md_dir = os.path.join(self.vm_data_dir, 'udfs') | ||
1296 | 2001 | # create some old shares and shared metadata | ||
1297 | 2002 | legacy_shares = LegacyShareFileShelf(self.share_md_dir) | ||
1298 | 2003 | root_share = _Share(path=self.root_dir, share_id='', | ||
1299 | 2004 | access_level='Modify') | ||
1300 | 2005 | legacy_shares[''] = root_share | ||
1301 | 2006 | for idx, name in enumerate(['share'] * 1000): | ||
1302 | 2007 | sid = str(uuid.uuid4()) | ||
1303 | 2008 | share_name = name + '_' + str(idx) | ||
1304 | 2009 | share = _Share(path=os.path.join(self.shares_dir, share_name), | ||
1305 | 2010 | share_id=sid, name=share_name, | ||
1306 | 2011 | node_id=str(uuid.uuid4()), | ||
1307 | 2012 | other_username='username'+str(idx), | ||
1308 | 2013 | other_visible_name='visible name ' + str(idx)) | ||
1309 | 2014 | if idx % 2: | ||
1310 | 2015 | share.access_level = 'Modify' | ||
1311 | 2016 | else: | ||
1312 | 2017 | share.access_level = 'View' | ||
1313 | 2018 | legacy_shares[sid] = share | ||
1314 | 2019 | |||
1315 | 2020 | # create shared shares | ||
1316 | 2021 | legacy_shared = LegacyShareFileShelf(self.shared_md_dir) | ||
1317 | 2022 | for idx, name in enumerate(['dir'] * 5): | ||
1318 | 2023 | sid = str(uuid.uuid4()) | ||
1319 | 2024 | share_name = name + '_' + str(idx) | ||
1320 | 2025 | share = _Share(path=os.path.join(self.root_dir, share_name), | ||
1321 | 2026 | share_id=sid, node_id=str(uuid.uuid4()), | ||
1322 | 2027 | name=share_name, other_username='hola', | ||
1323 | 2028 | other_visible_name='hola') | ||
1324 | 2029 | if idx % 2: | ||
1325 | 2030 | share.access_level = 'Modify' | ||
1326 | 2031 | else: | ||
1327 | 2032 | share.access_level = 'View' | ||
1328 | 2033 | legacy_shared[sid] = share | ||
1329 | 2034 | |||
1330 | 2035 | # create some udfs | ||
1331 | 2036 | legacy_udfs = LegacyShareFileShelf(self.udfs_md_dir) | ||
1332 | 2037 | for idx, name in enumerate(['dir'] * 5): | ||
1333 | 2038 | udf_id = str(uuid.uuid4()) | ||
1334 | 2039 | udf_name = name + '_' + str(idx) | ||
1335 | 2040 | udf = _UDF(udf_id, str(uuid.uuid4()), '~/' + udf_name, | ||
1336 | 2041 | os.path.join(self.home_dir, udf_name)) | ||
1337 | 2042 | if idx % 2: | ||
1338 | 2043 | udf.subscribed = True | ||
1339 | 2044 | else: | ||
1340 | 2045 | udf.subscribed = False | ||
1341 | 2046 | legacy_udfs[sid] = udf | ||
1342 | 2047 | |||
1343 | 2048 | # keep a copy of the current shares and shared metadata to check | ||
1344 | 2049 | # the upgrade went ok | ||
1345 | 2050 | legacy_shares = dict(legacy_shares.items()) | ||
1346 | 2051 | legacy_shared = dict(legacy_shared.items()) | ||
1347 | 2052 | legacy_udfs = dict(legacy_udfs.items()) | ||
1348 | 2053 | |||
1349 | 2054 | if self.md_version_None: | ||
1350 | 2055 | self.set_md_version('') | ||
1351 | 2056 | # upgrade it! | ||
1352 | 2057 | self.main = FakeMain(self.root_dir, self.shares_dir, | ||
1353 | 2058 | self.data_dir, self.partials_dir) | ||
1354 | 2059 | vm = self.main.vm | ||
1355 | 2060 | def compare_share(share, old_share): | ||
1356 | 2061 | """Compare two shares, new and old""" | ||
1357 | 2062 | self.assertEquals(share.volume_id, old_share.id) | ||
1358 | 2063 | self.assertEquals(share.path, old_share.path) | ||
1359 | 2064 | self.assertEquals(share.node_id, old_share.subtree) | ||
1360 | 2065 | if not isinstance(share, Root): | ||
1361 | 2066 | self.assertEquals(share.name, old_share.name) | ||
1362 | 2067 | self.assertEquals(share.other_username, old_share.other_username) | ||
1363 | 2068 | self.assertEquals(share.other_visible_name, old_share.other_visible_name) | ||
1364 | 2069 | self.assertEquals(share.access_level, old_share.access_level) | ||
1365 | 2070 | |||
1366 | 2071 | for sid in vm.shares: | ||
1367 | 2072 | old_share = legacy_shares[sid] | ||
1368 | 2073 | share = vm.shares[sid] | ||
1369 | 2074 | self.assertTrue(isinstance(share, Share) or isinstance(share, Root)) | ||
1370 | 2075 | compare_share(share, old_share) | ||
1371 | 2076 | |||
1372 | 2077 | for sid in vm.shared: | ||
1373 | 2078 | old_share = legacy_shared[sid] | ||
1374 | 2079 | share = vm.shared[sid] | ||
1375 | 2080 | self.assertTrue(isinstance(share, Shared)) | ||
1376 | 2081 | compare_share(share, old_share) | ||
1377 | 2082 | |||
1378 | 2083 | for udf_id in vm.udfs: | ||
1379 | 2084 | old_udf = legacy_udfs[udf_id] | ||
1380 | 2085 | udf = vm.udfs[udf_id] | ||
1381 | 2086 | self.assertTrue(isinstance(udf, UDF)) | ||
1382 | 2087 | self.assertEquals(udf.volume_id, old_udf.id) | ||
1383 | 2088 | self.assertEquals(udf.path, old_udf.path) | ||
1384 | 2089 | self.assertEquals(udf.node_id, old_udf.node_id) | ||
1385 | 2090 | self.assertEquals(udf.suggested_path, old_udf.suggested_path) | ||
1386 | 2091 | self.assertEquals(udf.subscribed, old_udf.subscribed) | ||
1387 | 2092 | |||
1388 | 2093 | |||
1389 | 2094 | class BrokenOldMDVersionUpgradeTests(MetadataOldLayoutTests): | ||
1390 | 2095 | """MetadataOldLayoutTests with broken .version file.""" | ||
1391 | 2096 | md_version_None = True | ||
1392 | 2097 | |||
1393 | 2098 | |||
1394 | 2099 | class BrokenNewMDVersionUpgradeTests(MetadataNewLayoutTests): | ||
1395 | 2100 | """MetadataNewLayoutTests with broken .version file.""" | ||
1396 | 2101 | md_version_None = True | ||
1397 | 2102 | |||
1398 | 2103 | |||
1399 | 2104 | class MetadataUpgraderTests(MetadataTestCase): | ||
1400 | 2105 | """MetadataUpgrader tests.""" | ||
1401 | 2106 | |||
1402 | 2107 | def setUp(self): | ||
1403 | 2108 | """Create the MetadataUpgrader instance.""" | ||
1404 | 2109 | MetadataTestCase.setUp(self) | ||
1405 | 2110 | self.share_md_dir = os.path.join(self.vm_data_dir, 'shares') | ||
1406 | 2111 | self.shared_md_dir = os.path.join(self.vm_data_dir, 'shared') | ||
1407 | 2112 | self.udfs_md_dir = os.path.join(self.vm_data_dir, 'udfs') | ||
1408 | 2113 | self.home_dir = os.path.join(self.tmpdir, 'home', 'ubuntuonehacker') | ||
1409 | 2114 | self.u1_dir = os.path.join(self.home_dir, os.path.split(self.u1_dir)[1]) | ||
1410 | 2115 | self.root_dir = self.u1_dir | ||
1411 | 2116 | self.shares_dir = os.path.join(self.tmpdir, 'shares') | ||
1412 | 2117 | self.shares_dir_link = os.path.join(self.u1_dir, 'Shared With Me') | ||
1413 | 2118 | for path in [self.share_md_dir, self.shared_md_dir, | ||
1414 | 2119 | self.root_dir, self.shares_dir]: | ||
1415 | 2120 | if not os.path.exists(path): | ||
1416 | 2121 | os.makedirs(path) | ||
1417 | 2122 | os.symlink(self.shares_dir, self.shares_dir_link) | ||
1418 | 2123 | self.old_get_md_version = MetadataUpgrader._get_md_version | ||
1419 | 2124 | MetadataUpgrader._get_md_version = lambda _: None | ||
1420 | 2125 | self.md_upgrader = MetadataUpgrader(self.vm_data_dir, self.share_md_dir, | ||
1421 | 2126 | self.shared_md_dir, | ||
1422 | 2127 | self.udfs_md_dir, self.root_dir, | ||
1423 | 2128 | self.shares_dir, | ||
1424 | 2129 | self.shares_dir_link) | ||
1425 | 2130 | def tearDown(self): | ||
1426 | 2131 | """Restorre _get_md_version""" | ||
1427 | 2132 | MetadataUpgrader._get_md_version = self.old_get_md_version | ||
1428 | 2133 | MetadataTestCase.tearDown(self) | ||
1429 | 2134 | |||
1430 | 2135 | def test_guess_metadata_version_None(self): | ||
1431 | 2136 | """Test _guess_metadata_version method for pre-version.""" | ||
1432 | 2137 | # fake a version None layout | ||
1433 | 2138 | if os.path.exists(self.version_file): | ||
1434 | 2139 | os.unlink(self.version_file) | ||
1435 | 2140 | for path in [self.share_md_dir, self.shared_md_dir, | ||
1436 | 2141 | self.root_dir, self.shares_dir]: | ||
1437 | 2142 | if os.path.exists(path): | ||
1438 | 2143 | self.rmtree(path) | ||
1439 | 2144 | os.makedirs(os.path.join(self.root_dir, 'My Files')) | ||
1440 | 2145 | shares_dir = os.path.join(self.root_dir, 'Shared With Me') | ||
1441 | 2146 | os.makedirs(shares_dir) | ||
1442 | 2147 | os.chmod(self.root_dir, 0500) | ||
1443 | 2148 | os.chmod(shares_dir, 0500) | ||
1444 | 2149 | version = self.md_upgrader._guess_metadata_version() | ||
1445 | 2150 | self.assertEquals(None, version) | ||
1446 | 2151 | |||
1447 | 2152 | def test_guess_metadata_version_1_or_2(self): | ||
1448 | 2153 | """Test _guess_metadata_version method for version 1 or 2.""" | ||
1449 | 2154 | # fake a version 1 layout | ||
1450 | 2155 | if os.path.exists(self.version_file): | ||
1451 | 2156 | os.unlink(self.version_file) | ||
1452 | 2157 | self.rmtree(self.root_dir) | ||
1453 | 2158 | os.makedirs(os.path.join(self.root_dir, 'My Files')) | ||
1454 | 2159 | shares_dir = os.path.join(self.root_dir, 'Shared With Me') | ||
1455 | 2160 | os.makedirs(shares_dir) | ||
1456 | 2161 | os.chmod(self.root_dir, 0500) | ||
1457 | 2162 | os.chmod(shares_dir, 0500) | ||
1458 | 2163 | self.rmtree(self.shares_dir) | ||
1459 | 2164 | version = self.md_upgrader._guess_metadata_version() | ||
1460 | 2165 | self.assertIn(version, ['1', '2']) | ||
1461 | 2166 | |||
1462 | 2167 | def test_guess_metadata_version_4(self): | ||
1463 | 2168 | """Test _guess_metadata_version method for version 4.""" | ||
1464 | 2169 | # fake a version 4 layout | ||
1465 | 2170 | if os.path.exists(self.version_file): | ||
1466 | 2171 | os.unlink(self.version_file) | ||
1467 | 2172 | os.unlink(self.shares_dir_link) | ||
1468 | 2173 | os.symlink(self.shares_dir_link, self.shares_dir_link) | ||
1469 | 2174 | version = self.md_upgrader._guess_metadata_version() | ||
1470 | 2175 | self.assertEquals(version, '4') | ||
1471 | 2176 | |||
1472 | 2177 | def test_guess_metadata_version_5(self): | ||
1473 | 2178 | """Test _guess_metadata_version method for version 5.""" | ||
1474 | 2179 | # fake a version 5 layout and metadata | ||
1475 | 2180 | shelf = LegacyShareFileShelf(self.share_md_dir) | ||
1476 | 2181 | shelf['foobar'] = _Share(path='/foo/bar', share_id='foobar') | ||
1477 | 2182 | version = self.md_upgrader._guess_metadata_version() | ||
1478 | 2183 | self.assertEquals(version, '5') | ||
1479 | 2184 | |||
1480 | 2185 | def test_guess_metadata_version_6(self): | ||
1481 | 2186 | """Test _guess_metadata_version method for version 6.""" | ||
1482 | 2187 | # fake a version 6 layout and metadata | ||
1483 | 2188 | shelf = VMFileShelf(self.share_md_dir) | ||
1484 | 2189 | shelf['foobar'] = Share(path='/foo/bar', volume_id='foobar') | ||
1485 | 2190 | version = self.md_upgrader._guess_metadata_version() | ||
1486 | 2191 | self.assertEquals(version, '6') | ||
1487 | 2192 | |||
1488 | 1849 | 2193 | ||
1489 | === modified file 'ubuntuone/syncdaemon/dbus_interface.py' | |||
1490 | --- ubuntuone/syncdaemon/dbus_interface.py 2010-01-26 14:32:54 +0000 | |||
1491 | +++ ubuntuone/syncdaemon/dbus_interface.py 2010-01-26 20:35:29 +0000 | |||
1492 | @@ -544,7 +544,9 @@ | |||
1493 | 544 | def handle_SV_SHARE_CHANGED(self, message, share): | 544 | def handle_SV_SHARE_CHANGED(self, message, share): |
1494 | 545 | """ handle SV_SHARE_CHANGED event, emit's ShareChanged signal. """ | 545 | """ handle SV_SHARE_CHANGED event, emit's ShareChanged signal. """ |
1495 | 546 | self.handle_default('SV_SHARE_CHANGED', message, share) | 546 | self.handle_default('SV_SHARE_CHANGED', message, share) |
1497 | 547 | self.dbus_iface.shares.emit_share_changed(message, share) | 547 | if message != 'deleted': |
1498 | 548 | # deleted shares are handled in VM | ||
1499 | 549 | self.dbus_iface.shares.emit_share_changed(message, share) | ||
1500 | 548 | 550 | ||
1501 | 549 | def handle_SV_FREE_SPACE(self, share_id, free_bytes): | 551 | def handle_SV_FREE_SPACE(self, share_id, free_bytes): |
1502 | 550 | """ handle SV_FREE_SPACE event, emit ShareChanged signal. """ | 552 | """ handle SV_FREE_SPACE event, emit ShareChanged signal. """ |
1503 | @@ -871,6 +873,8 @@ | |||
1504 | 871 | share_dict[unicode(k)] = '' | 873 | share_dict[unicode(k)] = '' |
1505 | 872 | elif k == 'path': | 874 | elif k == 'path': |
1506 | 873 | share_dict[unicode(k)] = v.decode('utf-8') | 875 | share_dict[unicode(k)] = v.decode('utf-8') |
1507 | 876 | elif k == 'accepted': | ||
1508 | 877 | share_dict[unicode(k)] = self.bool_str(v) | ||
1509 | 874 | else: | 878 | else: |
1510 | 875 | share_dict[unicode(k)] = unicode(v) | 879 | share_dict[unicode(k)] = unicode(v) |
1511 | 876 | return share_dict | 880 | return share_dict |
1512 | @@ -949,7 +953,7 @@ | |||
1513 | 949 | 953 | ||
1514 | 950 | def emit_share_answer_response(self, share_id, answer, error=None): | 954 | def emit_share_answer_response(self, share_id, answer, error=None): |
1515 | 951 | """ emits ShareCreated signal """ | 955 | """ emits ShareCreated signal """ |
1517 | 952 | answer_info = dict(share_id=share_id, answer=answer) | 956 | answer_info = dict(volume_id=share_id, answer=answer) |
1518 | 953 | if error: | 957 | if error: |
1519 | 954 | answer_info['error'] = error | 958 | answer_info['error'] = error |
1520 | 955 | self.ShareAnswerResponse(answer_info) | 959 | self.ShareAnswerResponse(answer_info) |
1521 | 956 | 960 | ||
1522 | === modified file 'ubuntuone/syncdaemon/event_queue.py' | |||
1523 | --- ubuntuone/syncdaemon/event_queue.py 2010-01-26 15:54:29 +0000 | |||
1524 | +++ ubuntuone/syncdaemon/event_queue.py 2010-01-26 20:35:29 +0000 | |||
1525 | @@ -159,7 +159,7 @@ | |||
1526 | 159 | } | 159 | } |
1527 | 160 | 160 | ||
1528 | 161 | # these are the events that will listen from inotify | 161 | # these are the events that will listen from inotify |
1530 | 162 | INOTIFY_EVENTS = ( | 162 | INOTIFY_EVENTS_GENERAL = ( |
1531 | 163 | evtcodes.IN_OPEN | | 163 | evtcodes.IN_OPEN | |
1532 | 164 | evtcodes.IN_CLOSE_NOWRITE | | 164 | evtcodes.IN_CLOSE_NOWRITE | |
1533 | 165 | evtcodes.IN_CLOSE_WRITE | | 165 | evtcodes.IN_CLOSE_WRITE | |
1534 | @@ -169,6 +169,12 @@ | |||
1535 | 169 | evtcodes.IN_MOVED_TO | | 169 | evtcodes.IN_MOVED_TO | |
1536 | 170 | evtcodes.IN_MOVE_SELF | 170 | evtcodes.IN_MOVE_SELF |
1537 | 171 | ) | 171 | ) |
1538 | 172 | INOTIFY_EVENTS_ANCESTORS = ( | ||
1539 | 173 | evtcodes.IN_DELETE | | ||
1540 | 174 | evtcodes.IN_MOVED_FROM | | ||
1541 | 175 | evtcodes.IN_MOVED_TO | | ||
1542 | 176 | evtcodes.IN_MOVE_SELF | ||
1543 | 177 | ) | ||
1544 | 172 | 178 | ||
1545 | 173 | DEFAULT_HANDLER = "handle_default" # receives (event_name, *args, **kwargs) | 179 | DEFAULT_HANDLER = "handle_default" # receives (event_name, *args, **kwargs) |
1546 | 174 | 180 | ||
1547 | @@ -201,14 +207,58 @@ | |||
1548 | 201 | return True | 207 | return True |
1549 | 202 | 208 | ||
1550 | 203 | 209 | ||
1553 | 204 | class _INotifyProcessor(pyinotify.ProcessEvent): | 210 | class _AncestorsINotifyProcessor(pyinotify.ProcessEvent): |
1554 | 205 | """Helper class that is called from inpotify when an event happens. | 211 | """inotify's processor when an event happens on an UDFs ancestor.""" |
1555 | 212 | def __init__(self, eq): | ||
1556 | 213 | self.log = logging.getLogger('ubuntuone.SyncDaemon.AncestorsINotProc') | ||
1557 | 214 | self.eq = eq | ||
1558 | 215 | |||
1559 | 216 | def _get_udf(self, path): | ||
1560 | 217 | """Get the udf for a specific path. | ||
1561 | 218 | |||
1562 | 219 | It can return None in case the UDF was deleted in the meantime. | ||
1563 | 220 | """ | ||
1564 | 221 | for udf in self.eq.fs.vm.udfs.itervalues(): | ||
1565 | 222 | parent = os.path.dirname(udf.path) + os.path.sep | ||
1566 | 223 | if parent.startswith(path + os.path.sep): | ||
1567 | 224 | return udf | ||
1568 | 225 | return None | ||
1569 | 226 | |||
1570 | 227 | def process_IN_MOVE_SELF(self, event): | ||
1571 | 228 | """Don't do anything here. | ||
1572 | 229 | |||
1573 | 230 | We just turned this event on because pyinotify does some | ||
1574 | 231 | path-fixing in its internal processing when this happens. | ||
1575 | 232 | """ | ||
1576 | 233 | process_IN_MOVED_TO = process_IN_MOVE_SELF | ||
1577 | 234 | |||
1578 | 235 | def process_IN_MOVED_FROM(self, event): | ||
1579 | 236 | """Getting it out or renaming means unsuscribe.""" | ||
1580 | 237 | if event.mask & evtcodes.IN_ISDIR: | ||
1581 | 238 | udf = self._get_udf(event.path) | ||
1582 | 239 | if udf is not None: | ||
1583 | 240 | self.log.info("Got MOVED_FROM on path %r, unsubscribing " | ||
1584 | 241 | "udf %s", event.path, udf) | ||
1585 | 242 | self.eq.fs.vm.unsubscribe_udf(udf.volume_id) | ||
1586 | 243 | |||
1587 | 244 | def process_IN_DELETE(self, event): | ||
1588 | 245 | """Check to see if the UDF was deleted.""" | ||
1589 | 246 | if event.mask & evtcodes.IN_ISDIR: | ||
1590 | 247 | udf = self._get_udf(event.path) | ||
1591 | 248 | if udf is not None and udf.path == event.pathname: | ||
1592 | 249 | self.log.info("Got DELETE on path %r, deleting udf %s", | ||
1593 | 250 | event.path, udf) | ||
1594 | 251 | self.eq.fs.vm.delete_volume(udf.volume_id) | ||
1595 | 252 | |||
1596 | 253 | |||
1597 | 254 | class _GeneralINotifyProcessor(pyinotify.ProcessEvent): | ||
1598 | 255 | """inotify's processor when a general event happens. | ||
1599 | 206 | 256 | ||
1600 | 207 | This class also catchs the MOVEs events, and synthetises a new | 257 | This class also catchs the MOVEs events, and synthetises a new |
1601 | 208 | FS_(DIR|FILE)_MOVE event when possible. | 258 | FS_(DIR|FILE)_MOVE event when possible. |
1602 | 209 | """ | 259 | """ |
1603 | 210 | def __init__(self, eq): | 260 | def __init__(self, eq): |
1605 | 211 | self.log = logging.getLogger('ubuntuone.SyncDaemon.INotifyProcessor') | 261 | self.log = logging.getLogger('ubuntuone.SyncDaemon.GeneralINotProc') |
1606 | 212 | self.eq = eq | 262 | self.eq = eq |
1607 | 213 | self.held_event = None | 263 | self.held_event = None |
1608 | 214 | self.timer = None | 264 | self.timer = None |
1609 | @@ -216,16 +266,6 @@ | |||
1610 | 216 | self.frozen_evts = False | 266 | self.frozen_evts = False |
1611 | 217 | self._to_mute = MuteFilter() | 267 | self._to_mute = MuteFilter() |
1612 | 218 | 268 | ||
1613 | 219 | def _is_udf_ancestor(self, path): | ||
1614 | 220 | """Decide if path is an UDF ancestor or not.""" | ||
1615 | 221 | result = None | ||
1616 | 222 | for udf in self.eq.fs.vm.udfs.itervalues(): | ||
1617 | 223 | parent = os.path.dirname(udf.path) + os.path.sep | ||
1618 | 224 | if parent.startswith(path + os.path.sep): | ||
1619 | 225 | return udf | ||
1620 | 226 | |||
1621 | 227 | return result | ||
1622 | 228 | |||
1623 | 229 | def add_to_mute_filter(self, event, *paths): | 269 | def add_to_mute_filter(self, event, *paths): |
1624 | 230 | """Add an event and path(s) to the mute filter.""" | 270 | """Add an event and path(s) to the mute filter.""" |
1625 | 231 | # all events have one path except the MOVEs | 271 | # all events have one path except the MOVEs |
1626 | @@ -261,14 +301,12 @@ | |||
1627 | 261 | 301 | ||
1628 | 262 | def process_IN_OPEN(self, event): | 302 | def process_IN_OPEN(self, event): |
1629 | 263 | """Filter IN_OPEN to make it happen only in files.""" | 303 | """Filter IN_OPEN to make it happen only in files.""" |
1632 | 264 | if not (event.mask & evtcodes.IN_ISDIR) and \ | 304 | if not (event.mask & evtcodes.IN_ISDIR): |
1631 | 265 | not self._is_udf_ancestor(event.path): | ||
1633 | 266 | self.push_event(event) | 305 | self.push_event(event) |
1634 | 267 | 306 | ||
1635 | 268 | def process_IN_CLOSE_NOWRITE(self, event): | 307 | def process_IN_CLOSE_NOWRITE(self, event): |
1636 | 269 | """Filter IN_CLOSE_NOWRITE to make it happen only in files.""" | 308 | """Filter IN_CLOSE_NOWRITE to make it happen only in files.""" |
1639 | 270 | if not (event.mask & evtcodes.IN_ISDIR) and \ | 309 | if not (event.mask & evtcodes.IN_ISDIR): |
1638 | 271 | not self._is_udf_ancestor(event.path): | ||
1640 | 272 | self.push_event(event) | 310 | self.push_event(event) |
1641 | 273 | 311 | ||
1642 | 274 | def process_IN_MOVE_SELF(self, event): | 312 | def process_IN_MOVE_SELF(self, event): |
1643 | @@ -281,11 +319,6 @@ | |||
1644 | 281 | 319 | ||
1645 | 282 | def process_IN_MOVED_FROM(self, event): | 320 | def process_IN_MOVED_FROM(self, event): |
1646 | 283 | """Capture the MOVED_FROM to maybe syntethize FILE_MOVED.""" | 321 | """Capture the MOVED_FROM to maybe syntethize FILE_MOVED.""" |
1647 | 284 | udf = self._is_udf_ancestor(event.path) | ||
1648 | 285 | if udf is not None: | ||
1649 | 286 | self.eq.fs.vm.unsubscribe_udf(udf.volume_id) | ||
1650 | 287 | return | ||
1651 | 288 | |||
1652 | 289 | if self.held_event is not None: | 322 | if self.held_event is not None: |
1653 | 290 | self.release_held_event() | 323 | self.release_held_event() |
1654 | 291 | 324 | ||
1655 | @@ -317,9 +350,6 @@ | |||
1656 | 317 | 350 | ||
1657 | 318 | def process_IN_MOVED_TO(self, event): | 351 | def process_IN_MOVED_TO(self, event): |
1658 | 319 | """Capture the MOVED_TO to maybe syntethize FILE_MOVED.""" | 352 | """Capture the MOVED_TO to maybe syntethize FILE_MOVED.""" |
1659 | 320 | if self._is_udf_ancestor(event.path): | ||
1660 | 321 | return | ||
1661 | 322 | |||
1662 | 323 | if self.held_event is not None: | 353 | if self.held_event is not None: |
1663 | 324 | if event.cookie == self.held_event.cookie: | 354 | if event.cookie == self.held_event.cookie: |
1664 | 325 | try: | 355 | try: |
1665 | @@ -381,16 +411,6 @@ | |||
1666 | 381 | 411 | ||
1667 | 382 | def process_default(self, event): | 412 | def process_default(self, event): |
1668 | 383 | """Push the event into the EventQueue.""" | 413 | """Push the event into the EventQueue.""" |
1669 | 384 | udf = self._is_udf_ancestor(event.path) | ||
1670 | 385 | if udf is not None: | ||
1671 | 386 | # if event is the deletion of the UDF per se, | ||
1672 | 387 | # call delete_volume on VolumeManager for that UDF. | ||
1673 | 388 | ename = NAME_TRANSLATIONS.get(event.mask, None) | ||
1674 | 389 | is_dir_delete = ename is not None and ename == 'FS_DIR_DELETE' | ||
1675 | 390 | if udf.path == event.pathname and is_dir_delete: | ||
1676 | 391 | self.eq.fs.vm.delete_volume(udf.volume_id) | ||
1677 | 392 | return | ||
1678 | 393 | |||
1679 | 394 | if self.held_event is not None: | 414 | if self.held_event is not None: |
1680 | 395 | self.release_held_event() | 415 | self.release_held_event() |
1681 | 396 | self.push_event(event) | 416 | self.push_event(event) |
1682 | @@ -482,13 +502,23 @@ | |||
1683 | 482 | 502 | ||
1684 | 483 | self.log = logging.getLogger('ubuntuone.SyncDaemon.EQ') | 503 | self.log = logging.getLogger('ubuntuone.SyncDaemon.EQ') |
1685 | 484 | self.fs = fs | 504 | self.fs = fs |
1693 | 485 | # hook inotify | 505 | |
1694 | 486 | self._inotify_reader = None | 506 | # general inotify |
1695 | 487 | self._inotify_wm = wm = pyinotify.WatchManager() | 507 | self._inotify_general_wm = wm = pyinotify.WatchManager() |
1696 | 488 | self._processor = _INotifyProcessor(self) | 508 | self._processor = _GeneralINotifyProcessor(self) |
1697 | 489 | self._inotify_notifier = pyinotify.Notifier(wm, self._processor) | 509 | self._inotify_notifier_gral = pyinotify.Notifier(wm, self._processor) |
1698 | 490 | self._hook_inotify_to_twisted(wm, self._inotify_notifier) | 510 | self._inotify_reader_gral = self._hook_inotify_to_twisted( |
1699 | 491 | self._watchs = {} | 511 | wm, self._inotify_notifier_gral) |
1700 | 512 | self._general_watchs = {} | ||
1701 | 513 | |||
1702 | 514 | # ancestors inotify | ||
1703 | 515 | self._inotify_ancestors_wm = wm = pyinotify.WatchManager() | ||
1704 | 516 | antr_processor = _AncestorsINotifyProcessor(self) | ||
1705 | 517 | self._inotify_notifier_antr = pyinotify.Notifier(wm, antr_processor) | ||
1706 | 518 | self._inotify_reader_antr = self._hook_inotify_to_twisted( | ||
1707 | 519 | wm, self._inotify_notifier_antr) | ||
1708 | 520 | self._ancestors_watchs = {} | ||
1709 | 521 | |||
1710 | 492 | self.dispatching = False | 522 | self.dispatching = False |
1711 | 493 | self.dispatch_queue = Queue() | 523 | self.dispatch_queue = Queue() |
1712 | 494 | self.empty_event_queue_callbacks = set() | 524 | self.empty_event_queue_callbacks = set() |
1713 | @@ -526,34 +556,64 @@ | |||
1714 | 526 | notifier.process_events() | 556 | notifier.process_events() |
1715 | 527 | 557 | ||
1716 | 528 | reader = MyReader() | 558 | reader = MyReader() |
1717 | 529 | self._inotify_reader = reader | ||
1718 | 530 | reactor.addReader(reader) | 559 | reactor.addReader(reader) |
1719 | 560 | return reader | ||
1720 | 531 | 561 | ||
1721 | 532 | def shutdown(self): | 562 | def shutdown(self): |
1722 | 533 | """Prepares the EQ to be closed.""" | 563 | """Prepares the EQ to be closed.""" |
1725 | 534 | self._inotify_notifier.stop() | 564 | self._inotify_notifier_gral.stop() |
1726 | 535 | reactor.removeReader(self._inotify_reader) | 565 | self._inotify_notifier_antr.stop() |
1727 | 566 | reactor.removeReader(self._inotify_reader_gral) | ||
1728 | 567 | reactor.removeReader(self._inotify_reader_antr) | ||
1729 | 536 | 568 | ||
1730 | 537 | def inotify_rm_watch(self, dirpath): | 569 | def inotify_rm_watch(self, dirpath): |
1731 | 538 | """Remove watch from a dir.""" | 570 | """Remove watch from a dir.""" |
1735 | 539 | try: | 571 | if dirpath in self._general_watchs: |
1736 | 540 | wd = self._watchs[dirpath] | 572 | w_dict = self._general_watchs |
1737 | 541 | except KeyError: | 573 | w_manager = self._inotify_general_wm |
1738 | 574 | elif dirpath in self._ancestors_watchs: | ||
1739 | 575 | w_dict = self._ancestors_watchs | ||
1740 | 576 | w_manager = self._inotify_ancestors_wm | ||
1741 | 577 | else: | ||
1742 | 542 | raise ValueError("The path %r is not watched right now!" % dirpath) | 578 | raise ValueError("The path %r is not watched right now!" % dirpath) |
1744 | 543 | result = self._inotify_wm.rm_watch(wd) | 579 | |
1745 | 580 | wd = w_dict[dirpath] | ||
1746 | 581 | result = w_manager.rm_watch(wd) | ||
1747 | 544 | if not result[wd]: | 582 | if not result[wd]: |
1748 | 545 | raise RuntimeError("The path %r couldn't be removed!" % dirpath) | 583 | raise RuntimeError("The path %r couldn't be removed!" % dirpath) |
1750 | 546 | del self._watchs[dirpath] | 584 | del w_dict[dirpath] |
1751 | 547 | 585 | ||
1752 | 548 | def inotify_add_watch(self, dirpath): | 586 | def inotify_add_watch(self, dirpath): |
1753 | 549 | """Add watch to a dir.""" | 587 | """Add watch to a dir.""" |
1757 | 550 | self.log.debug("Adding inotify watch to %r", dirpath) | 588 | # see where to add it |
1758 | 551 | result = self._inotify_wm.add_watch(dirpath, INOTIFY_EVENTS) | 589 | if self._is_udf_ancestor(dirpath): |
1759 | 552 | self._watchs[dirpath] = result[dirpath] | 590 | w_type = "ancestors" |
1760 | 591 | w_manager = self._inotify_ancestors_wm | ||
1761 | 592 | w_dict = self._ancestors_watchs | ||
1762 | 593 | events = INOTIFY_EVENTS_ANCESTORS | ||
1763 | 594 | else: | ||
1764 | 595 | w_type = "general" | ||
1765 | 596 | w_manager = self._inotify_general_wm | ||
1766 | 597 | w_dict = self._general_watchs | ||
1767 | 598 | events = INOTIFY_EVENTS_GENERAL | ||
1768 | 599 | |||
1769 | 600 | # add the watch! | ||
1770 | 601 | self.log.debug("Adding %s inotify watch to %r", w_type, dirpath) | ||
1771 | 602 | result = w_manager.add_watch(dirpath, events) | ||
1772 | 603 | w_dict[dirpath] = result[dirpath] | ||
1773 | 553 | 604 | ||
1774 | 554 | def inotify_has_watch(self, dirpath): | 605 | def inotify_has_watch(self, dirpath): |
1775 | 555 | """Check if a dirpath is watched.""" | 606 | """Check if a dirpath is watched.""" |
1777 | 556 | return dirpath in self._watchs | 607 | return (dirpath in self._general_watchs or |
1778 | 608 | dirpath in self._ancestors_watchs) | ||
1779 | 609 | |||
1780 | 610 | def _is_udf_ancestor(self, path): | ||
1781 | 611 | """Decide if path is an UDF ancestor or not.""" | ||
1782 | 612 | for udf in self.fs.vm.udfs.itervalues(): | ||
1783 | 613 | parent = os.path.dirname(udf.path) + os.path.sep | ||
1784 | 614 | if parent.startswith(path + os.path.sep): | ||
1785 | 615 | return True | ||
1786 | 616 | return False | ||
1787 | 557 | 617 | ||
1788 | 558 | def unsubscribe(self, obj): | 618 | def unsubscribe(self, obj): |
1789 | 559 | """Removes the callback object from the listener queue. | 619 | """Removes the callback object from the listener queue. |
1790 | 560 | 620 | ||
1791 | === modified file 'ubuntuone/syncdaemon/tools.py' | |||
1792 | --- ubuntuone/syncdaemon/tools.py 2010-01-25 14:58:45 +0000 | |||
1793 | +++ ubuntuone/syncdaemon/tools.py 2010-01-26 20:35:29 +0000 | |||
1794 | @@ -298,7 +298,7 @@ | |||
1795 | 298 | self.log.debug('accept_share(%s)', share_id) | 298 | self.log.debug('accept_share(%s)', share_id) |
1796 | 299 | shares_client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME) | 299 | shares_client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME) |
1797 | 300 | d = self.wait_for_signal('ShareAnswerResponse', | 300 | d = self.wait_for_signal('ShareAnswerResponse', |
1799 | 301 | lambda info: info['share_id']==share_id) | 301 | lambda info: info['volume_id']==share_id) |
1800 | 302 | shares_client.call_method('accept_share', share_id, | 302 | shares_client.call_method('accept_share', share_id, |
1801 | 303 | reply_handler=lambda _: None, | 303 | reply_handler=lambda _: None, |
1802 | 304 | error_handler=d.errback) | 304 | error_handler=d.errback) |
1803 | @@ -309,7 +309,7 @@ | |||
1804 | 309 | self.log.debug('reject_share(%s)', share_id) | 309 | self.log.debug('reject_share(%s)', share_id) |
1805 | 310 | shares_client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME) | 310 | shares_client = DBusClient(self.bus, '/shares', DBUS_IFACE_SHARES_NAME) |
1806 | 311 | d = self.wait_for_signal('ShareAnswerResponse', | 311 | d = self.wait_for_signal('ShareAnswerResponse', |
1808 | 312 | lambda info: info['share_id']==share_id) | 312 | lambda info: info['volume_id']==share_id) |
1809 | 313 | shares_client.call_method('reject_share', share_id, | 313 | shares_client.call_method('reject_share', share_id, |
1810 | 314 | reply_handler=lambda _: None, | 314 | reply_handler=lambda _: None, |
1811 | 315 | error_handler=d.errback) | 315 | error_handler=d.errback) |
1812 | @@ -601,8 +601,8 @@ | |||
1813 | 601 | for share in shares: | 601 | for share in shares: |
1814 | 602 | msg_template = ' id=%s name=%s accepted=%s ' + \ | 602 | msg_template = ' id=%s name=%s accepted=%s ' + \ |
1815 | 603 | 'access_level=%s to=%s path=%s\n' | 603 | 'access_level=%s to=%s path=%s\n' |
1818 | 604 | out.write(msg_template % (share['id'], share['name'], | 604 | out.write(msg_template % (share['volume_id'], share['name'], |
1819 | 605 | share['accepted'], share['access_level'], | 605 | bool(share['accepted']), share['access_level'], |
1820 | 606 | share['other_username'], | 606 | share['other_username'], |
1821 | 607 | share['path'])) | 607 | share['path'])) |
1822 | 608 | 608 | ||
1823 | @@ -615,7 +615,7 @@ | |||
1824 | 615 | out.write("Folder list:\n") | 615 | out.write("Folder list:\n") |
1825 | 616 | for folder in folders: | 616 | for folder in folders: |
1826 | 617 | msg_template = ' id=%s subscribed=%s path=%s\n' | 617 | msg_template = ' id=%s subscribed=%s path=%s\n' |
1828 | 618 | out.write(msg_template % (folder['id'], folder['subscribed'], | 618 | out.write(msg_template % (folder['volume_id'], folder['subscribed'], |
1829 | 619 | folder['path'])) | 619 | folder['path'])) |
1830 | 620 | 620 | ||
1831 | 621 | 621 | ||
1832 | @@ -636,7 +636,7 @@ | |||
1833 | 636 | out.write("Shares list:\n") | 636 | out.write("Shares list:\n") |
1834 | 637 | for share in shares: | 637 | for share in shares: |
1835 | 638 | out.write(' id=%s name=%s accepted=%s access_level=%s from=%s\n' % \ | 638 | out.write(' id=%s name=%s accepted=%s access_level=%s from=%s\n' % \ |
1837 | 639 | (share['id'], share['name'], share['accepted'], | 639 | (share['volume_id'], share['name'], bool(share['accepted']), |
1838 | 640 | share['access_level'], share['other_username'])) | 640 | share['access_level'], share['other_username'])) |
1839 | 641 | 641 | ||
1840 | 642 | 642 | ||
1841 | 643 | 643 | ||
1842 | === modified file 'ubuntuone/syncdaemon/volume_manager.py' | |||
1843 | --- ubuntuone/syncdaemon/volume_manager.py 2010-01-26 19:40:05 +0000 | |||
1844 | +++ ubuntuone/syncdaemon/volume_manager.py 2010-01-26 20:35:29 +0000 | |||
1845 | @@ -41,10 +41,10 @@ | |||
1846 | 41 | from twisted.internet import defer | 41 | from twisted.internet import defer |
1847 | 42 | 42 | ||
1848 | 43 | 43 | ||
1850 | 44 | class Share(object): | 44 | class _Share(object): |
1851 | 45 | """Represents a share or mount point""" | 45 | """Represents a share or mount point""" |
1852 | 46 | 46 | ||
1854 | 47 | def __init__(self, volume_id=request.ROOT, node_id=None, path=None, | 47 | def __init__(self, share_id=request.ROOT, node_id=None, path=None, |
1855 | 48 | name=None, access_level='View', accepted=False, | 48 | name=None, access_level='View', accepted=False, |
1856 | 49 | other_username=None, other_visible_name=None): | 49 | other_username=None, other_visible_name=None): |
1857 | 50 | """ Creates the instance. | 50 | """ Creates the instance. |
1858 | @@ -55,7 +55,7 @@ | |||
1859 | 55 | self.path = None | 55 | self.path = None |
1860 | 56 | else: | 56 | else: |
1861 | 57 | self.path = os.path.normpath(path) | 57 | self.path = os.path.normpath(path) |
1863 | 58 | self.id = str(volume_id) | 58 | self.id = str(share_id) |
1864 | 59 | self.access_level = access_level | 59 | self.access_level = access_level |
1865 | 60 | self.accepted = accepted | 60 | self.accepted = accepted |
1866 | 61 | self.name = name | 61 | self.name = name |
1867 | @@ -64,16 +64,77 @@ | |||
1868 | 64 | self.subtree = node_id | 64 | self.subtree = node_id |
1869 | 65 | self.free_bytes = None | 65 | self.free_bytes = None |
1870 | 66 | 66 | ||
1871 | 67 | |||
1872 | 68 | class _UDF(object): | ||
1873 | 69 | """A representation of a User Defined Folder.""" | ||
1874 | 70 | |||
1875 | 71 | def __init__(self, udf_id, node_id, suggested_path, | ||
1876 | 72 | path, subscribed=True): | ||
1877 | 73 | """Create the UDF, subscribed by default""" | ||
1878 | 74 | # id and node_id should be str or None | ||
1879 | 75 | assert isinstance(udf_id, basestring) or udf_id is None | ||
1880 | 76 | assert isinstance(node_id, basestring) or node_id is None | ||
1881 | 77 | self.id = udf_id | ||
1882 | 78 | self.node_id = node_id | ||
1883 | 79 | self.suggested_path = suggested_path | ||
1884 | 80 | self.path = path | ||
1885 | 81 | self.subscribed = subscribed | ||
1886 | 82 | |||
1887 | 83 | |||
1888 | 84 | class Volume(object): | ||
1889 | 85 | """A generic volume.""" | ||
1890 | 86 | |||
1891 | 87 | def __init__(self, volume_id, node_id): | ||
1892 | 88 | """Create the volume.""" | ||
1893 | 89 | # id and node_id should be str or None | ||
1894 | 90 | assert isinstance(volume_id, basestring) or volume_id is None | ||
1895 | 91 | assert isinstance(node_id, basestring) or node_id is None | ||
1896 | 92 | self.volume_id = volume_id | ||
1897 | 93 | self.node_id = node_id | ||
1898 | 94 | |||
1899 | 95 | @property | ||
1900 | 96 | def id(self): | ||
1901 | 97 | return self.volume_id | ||
1902 | 98 | |||
1903 | 99 | def can_write(self): | ||
1904 | 100 | raise NotImplementedError('Subclass responsability') | ||
1905 | 101 | |||
1906 | 102 | def __eq__(self, other): | ||
1907 | 103 | result = (self.id == other.id and | ||
1908 | 104 | self.node_id == other.node_id) | ||
1909 | 105 | return result | ||
1910 | 106 | |||
1911 | 107 | |||
1912 | 108 | class Share(Volume): | ||
1913 | 109 | """A volume representing a Share.""" | ||
1914 | 110 | |||
1915 | 111 | def __init__(self, volume_id=None, node_id=None, path=None, name=None, | ||
1916 | 112 | other_username=None, other_visible_name=None, accepted=False, | ||
1917 | 113 | access_level='View', free_bytes=None): | ||
1918 | 114 | """Create the share.""" | ||
1919 | 115 | super(Share, self).__init__(volume_id, node_id) | ||
1920 | 116 | self.__dict__['type'] = 'Share' | ||
1921 | 117 | if path is None: | ||
1922 | 118 | self.path = None | ||
1923 | 119 | else: | ||
1924 | 120 | self.path = os.path.normpath(path) | ||
1925 | 121 | self.name = name | ||
1926 | 122 | self.other_username = other_username | ||
1927 | 123 | self.other_visible_name = other_visible_name | ||
1928 | 124 | self.accepted = accepted | ||
1929 | 125 | self.access_level = access_level | ||
1930 | 126 | self.free_bytes = free_bytes | ||
1931 | 127 | |||
1932 | 67 | @classmethod | 128 | @classmethod |
1933 | 68 | def from_response(cls, share_response, path): | 129 | def from_response(cls, share_response, path): |
1934 | 69 | """ Creates a Share instance from a ShareResponse. | 130 | """ Creates a Share instance from a ShareResponse. |
1935 | 70 | 131 | ||
1936 | 71 | The received path should be 'bytes' | 132 | The received path should be 'bytes' |
1937 | 72 | """ | 133 | """ |
1942 | 73 | share = cls(str(share_response.id), share_response.subtree, path, | 134 | share = cls(str(share_response.id), str(share_response.subtree), |
1943 | 74 | share_response.name, share_response.access_level, | 135 | path, share_response.name, share_response.other_username, |
1944 | 75 | share_response.accepted, share_response.other_username, | 136 | share_response.other_visible_name, |
1945 | 76 | share_response.other_visible_name) | 137 | share_response.accepted, share_response.access_level) |
1946 | 77 | return share | 138 | return share |
1947 | 78 | 139 | ||
1948 | 79 | @classmethod | 140 | @classmethod |
1949 | @@ -82,12 +143,12 @@ | |||
1950 | 82 | 143 | ||
1951 | 83 | The received path should be 'bytes' | 144 | The received path should be 'bytes' |
1952 | 84 | """ | 145 | """ |
1956 | 85 | share = cls(path=path, volume_id=str(share_notify.share_id), | 146 | share = cls(volume_id=str(share_notify.share_id), |
1957 | 86 | name=share_notify.share_name, | 147 | node_id=str(share_notify.subtree), |
1958 | 87 | access_level=share_notify.access_level, | 148 | path=path, name=share_notify.share_name, |
1959 | 88 | other_username=share_notify.from_username, | 149 | other_username=share_notify.from_username, |
1960 | 89 | other_visible_name=share_notify.from_visible_name, | 150 | other_visible_name=share_notify.from_visible_name, |
1962 | 90 | node_id=share_notify.subtree) | 151 | access_level=share_notify.access_level) |
1963 | 91 | return share | 152 | return share |
1964 | 92 | 153 | ||
1965 | 93 | @classmethod | 154 | @classmethod |
1966 | @@ -97,13 +158,11 @@ | |||
1967 | 97 | The received path should be 'bytes' | 158 | The received path should be 'bytes' |
1968 | 98 | 159 | ||
1969 | 99 | """ | 160 | """ |
1977 | 100 | share = cls(volume_id=str(share_volume.volume_id), path=path, | 161 | share = cls(str(share_volume.volume_id), str(share_volume.node_id), |
1978 | 101 | name=share_volume.share_name, | 162 | path, share_volume.share_name, |
1979 | 102 | access_level=share_volume.access_level, | 163 | share_volume.other_username, |
1980 | 103 | other_username=share_volume.other_username, | 164 | share_volume.other_visible_name, share_volume.accepted, |
1981 | 104 | other_visible_name=share_volume.other_visible_name, | 165 | share_volume.access_level) |
1975 | 105 | node_id=str(share_volume.node_id), | ||
1976 | 106 | accepted=share_volume.accepted) | ||
1982 | 107 | return share | 166 | return share |
1983 | 108 | 167 | ||
1984 | 109 | def can_write(self): | 168 | def can_write(self): |
1985 | @@ -114,35 +173,64 @@ | |||
1986 | 114 | 173 | ||
1987 | 115 | @property | 174 | @property |
1988 | 116 | def active(self): | 175 | def active(self): |
1990 | 117 | """Returns True if the Share is accepted.""" | 176 | """Return True if this Share is accepted.""" |
1991 | 118 | return self.accepted | 177 | return self.accepted |
1992 | 119 | 178 | ||
2009 | 120 | # node_id property | 179 | def __eq__(self, other): |
2010 | 121 | def _set_node_id(self, node_id): | 180 | result = (super(Share, self).__eq__(other) and |
2011 | 122 | self.subtree = node_id | 181 | self.path == other.path and |
2012 | 123 | node_id = property(lambda self: self.subtree, _set_node_id) | 182 | self.name == other.name and |
2013 | 124 | 183 | self.other_username == other.other_username and | |
2014 | 125 | # volume_id property | 184 | self.other_visible_name == other.other_visible_name and |
2015 | 126 | def _set_volume_id(self, volume_id): | 185 | self.accepted == other.accepted and |
2016 | 127 | self.id = volume_id | 186 | self.access_level == other.access_level) |
2017 | 128 | volume_id = property(lambda self: self.id, _set_volume_id) | 187 | return result |
2018 | 129 | 188 | ||
2019 | 130 | 189 | ||
2020 | 131 | class UDF(object): | 190 | class Shared(Share): |
2021 | 132 | """A representation of a User Defined Folder.""" | 191 | |
2022 | 133 | 192 | def __init__(self, *args, **kwargs): | |
2023 | 134 | def __init__(self, volume_id, node_id, suggested_path, | 193 | super(Shared, self).__init__(*args, **kwargs) |
2024 | 135 | path, subscribed=True): | 194 | self.__dict__['type'] = 'Shared' |
2025 | 195 | |||
2026 | 196 | |||
2027 | 197 | class Root(Volume): | ||
2028 | 198 | """A volume representing the root.""" | ||
2029 | 199 | |||
2030 | 200 | def __init__(self, volume_id=None, node_id=None, path=None): | ||
2031 | 201 | """Create the Root.""" | ||
2032 | 202 | super(Root, self).__init__(volume_id, node_id) | ||
2033 | 203 | self.__dict__['type'] = 'Root' | ||
2034 | 204 | self.path = path | ||
2035 | 205 | |||
2036 | 206 | def __eq__(self, other): | ||
2037 | 207 | result = (super(Root, self).__eq__(other) and | ||
2038 | 208 | self.path == other.path) | ||
2039 | 209 | return result | ||
2040 | 210 | |||
2041 | 211 | def can_write(self): | ||
2042 | 212 | return True | ||
2043 | 213 | |||
2044 | 214 | def is_active(self): | ||
2045 | 215 | return True | ||
2046 | 216 | |||
2047 | 217 | |||
2048 | 218 | class UDF(Volume): | ||
2049 | 219 | """A volume representing a User Defined Folder.""" | ||
2050 | 220 | |||
2051 | 221 | def __init__(self, volume_id=None, node_id=None, | ||
2052 | 222 | suggested_path=None, path=None, subscribed=True): | ||
2053 | 136 | """Create the UDF, subscribed by default""" | 223 | """Create the UDF, subscribed by default""" |
2058 | 137 | # id and node_id should be str or None | 224 | super(UDF, self).__init__(volume_id, node_id) |
2059 | 138 | assert isinstance(volume_id, basestring) or volume_id is None | 225 | self.__dict__['type'] = 'UDF' |
2056 | 139 | assert isinstance(node_id, basestring) or node_id is None | ||
2057 | 140 | self.id = volume_id | ||
2060 | 141 | self.node_id = node_id | 226 | self.node_id = node_id |
2061 | 142 | self.suggested_path = suggested_path | 227 | self.suggested_path = suggested_path |
2062 | 143 | self.path = path | 228 | self.path = path |
2063 | 144 | self.subscribed = subscribed | 229 | self.subscribed = subscribed |
2064 | 145 | 230 | ||
2065 | 231 | def __repr__(self): | ||
2066 | 232 | return "<UDF id %r, real path %r>" % (self.id, self.path) | ||
2067 | 233 | |||
2068 | 146 | @property | 234 | @property |
2069 | 147 | def ancestors(self): | 235 | def ancestors(self): |
2070 | 148 | """Calculate all the ancestors for this UDF's path.""" | 236 | """Calculate all the ancestors for this UDF's path.""" |
2071 | @@ -161,6 +249,11 @@ | |||
2072 | 161 | """We always can write in a UDF.""" | 249 | """We always can write in a UDF.""" |
2073 | 162 | return True | 250 | return True |
2074 | 163 | 251 | ||
2075 | 252 | @property | ||
2076 | 253 | def active(self): | ||
2077 | 254 | """Returns True if the UDF is subscribed.""" | ||
2078 | 255 | return self.subscribed | ||
2079 | 256 | |||
2080 | 164 | @classmethod | 257 | @classmethod |
2081 | 165 | def from_udf_volume(cls, udf_volume, path): | 258 | def from_udf_volume(cls, udf_volume, path): |
2082 | 166 | """Creates a UDF instance from a volumes.UDFVolume. | 259 | """Creates a UDF instance from a volumes.UDFVolume. |
2083 | @@ -171,21 +264,18 @@ | |||
2084 | 171 | return cls(str(udf_volume.volume_id), str(udf_volume.node_id), | 264 | return cls(str(udf_volume.volume_id), str(udf_volume.node_id), |
2085 | 172 | udf_volume.suggested_path, path) | 265 | udf_volume.suggested_path, path) |
2086 | 173 | 266 | ||
2096 | 174 | @property | 267 | def __eq__(self, other): |
2097 | 175 | def active(self): | 268 | result = (super(UDF, self).__eq__(other) and |
2098 | 176 | """Returns True if the UDF is subscribed.""" | 269 | self.suggested_path == other.suggested_path and |
2099 | 177 | return self.subscribed | 270 | self.path == other.path and |
2100 | 178 | 271 | self.subscribed == other.subscribed) | |
2101 | 179 | # volume_id property | 272 | return result |
2093 | 180 | def _set_volume_id(self, volume_id): | ||
2094 | 181 | self.id = volume_id | ||
2095 | 182 | volume_id = property(lambda self: self.id, _set_volume_id) | ||
2102 | 183 | 273 | ||
2103 | 184 | 274 | ||
2104 | 185 | class VolumeManager(object): | 275 | class VolumeManager(object): |
2105 | 186 | """Manages shares and mount points.""" | 276 | """Manages shares and mount points.""" |
2106 | 187 | 277 | ||
2108 | 188 | METADATA_VERSION = '5' | 278 | METADATA_VERSION = '6' |
2109 | 189 | 279 | ||
2110 | 190 | def __init__(self, main): | 280 | def __init__(self, main): |
2111 | 191 | """Create the instance and populate the shares/d attributes | 281 | """Create the instance and populate the shares/d attributes |
2112 | @@ -199,8 +289,9 @@ | |||
2113 | 199 | self._udfs_dir = os.path.join(self._data_dir, 'udfs') | 289 | self._udfs_dir = os.path.join(self._data_dir, 'udfs') |
2114 | 200 | 290 | ||
2115 | 201 | md_upgrader = MetadataUpgrader(self._data_dir, self._shares_dir, | 291 | md_upgrader = MetadataUpgrader(self._data_dir, self._shares_dir, |
2118 | 202 | self._shared_dir, self.m.root_dir, | 292 | self._shared_dir, self._udfs_dir, |
2119 | 203 | self.m.shares_dir, self.m.shares_dir_link) | 293 | self.m.root_dir, self.m.shares_dir, |
2120 | 294 | self.m.shares_dir_link) | ||
2121 | 204 | md_upgrader.upgrade_metadata() | 295 | md_upgrader.upgrade_metadata() |
2122 | 205 | 296 | ||
2123 | 206 | # build the dir layout | 297 | # build the dir layout |
2124 | @@ -233,7 +324,7 @@ | |||
2125 | 233 | self.shared = VMFileShelf(self._shared_dir) | 324 | self.shared = VMFileShelf(self._shared_dir) |
2126 | 234 | self.udfs = VMFileShelf(self._udfs_dir) | 325 | self.udfs = VMFileShelf(self._udfs_dir) |
2127 | 235 | if self.shares.get(request.ROOT) is None: | 326 | if self.shares.get(request.ROOT) is None: |
2129 | 236 | self.root = Share(self.m.root_dir) | 327 | self.root = Root(path=self.m.root_dir) |
2130 | 237 | else: | 328 | else: |
2131 | 238 | self.root = self.shares[request.ROOT] | 329 | self.root = self.shares[request.ROOT] |
2132 | 239 | self.root.access_level = 'Modify' | 330 | self.root.access_level = 'Modify' |
2133 | @@ -356,7 +447,7 @@ | |||
2134 | 356 | self.log.warning("we got a share with 'from_me' direction," | 447 | self.log.warning("we got a share with 'from_me' direction," |
2135 | 357 | " but don't have the node_id in the metadata yet") | 448 | " but don't have the node_id in the metadata yet") |
2136 | 358 | path = None | 449 | path = None |
2138 | 359 | share = Share.from_response(a_share, path) | 450 | share = Shared.from_response(a_share, path) |
2139 | 360 | shared.append(share.volume_id) | 451 | shared.append(share.volume_id) |
2140 | 361 | self.add_shared(share) | 452 | self.add_shared(share) |
2141 | 362 | self._cleanup_volumes(shares, shared) | 453 | self._cleanup_volumes(shares, shared) |
2142 | @@ -583,7 +674,7 @@ | |||
2143 | 583 | mdobj = self.m.fs.get_by_path(path) | 674 | mdobj = self.m.fs.get_by_path(path) |
2144 | 584 | mdid = mdobj.mdid | 675 | mdid = mdobj.mdid |
2145 | 585 | marker = MDMarker(mdid) | 676 | marker = MDMarker(mdid) |
2147 | 586 | share = Share(path=self.m.fs.get_abspath("", mdobj.path), | 677 | share = Shared(path=self.m.fs.get_abspath("", mdobj.path), |
2148 | 587 | volume_id=marker, | 678 | volume_id=marker, |
2149 | 588 | name=name, access_level=access_level, | 679 | name=name, access_level=access_level, |
2150 | 589 | other_username=username, other_visible_name=None, | 680 | other_username=username, other_visible_name=None, |
2151 | @@ -748,17 +839,18 @@ | |||
2152 | 748 | udf = self.udfs[udf_id] | 839 | udf = self.udfs[udf_id] |
2153 | 749 | except KeyError: | 840 | except KeyError: |
2154 | 750 | push_error("DOES_NOT_EXIST") | 841 | push_error("DOES_NOT_EXIST") |
2155 | 751 | udf.subscribed = True | ||
2156 | 752 | self.udfs[udf_id] = udf | ||
2157 | 753 | try: | ||
2158 | 754 | d = self._scan_udf(udf) | ||
2159 | 755 | except KeyError, e: | ||
2160 | 756 | push_error("METADATA_DOES_NOT_EXIST") | ||
2161 | 757 | else: | 842 | else: |
2166 | 758 | d.addCallbacks( | 843 | udf.subscribed = True |
2167 | 759 | lambda _: self.m.event_q.push('VM_UDF_SUBSCRIBED', udf), | 844 | self.udfs[udf_id] = udf |
2168 | 760 | lambda f: push_error(f.getErrorMessage())) | 845 | try: |
2169 | 761 | return d | 846 | d = self._scan_udf(udf) |
2170 | 847 | except KeyError, e: | ||
2171 | 848 | push_error("METADATA_DOES_NOT_EXIST") | ||
2172 | 849 | else: | ||
2173 | 850 | d.addCallbacks( | ||
2174 | 851 | lambda _: self.m.event_q.push('VM_UDF_SUBSCRIBED', udf), | ||
2175 | 852 | lambda f: push_error(f.getErrorMessage())) | ||
2176 | 853 | return d | ||
2177 | 762 | 854 | ||
2178 | 763 | def _scan_udf(self, udf): | 855 | def _scan_udf(self, udf): |
2179 | 764 | """Local and server rescan of a UDF.""" | 856 | """Local and server rescan of a UDF.""" |
2180 | @@ -844,7 +936,7 @@ | |||
2181 | 844 | class MetadataUpgrader(object): | 936 | class MetadataUpgrader(object): |
2182 | 845 | """A class that loads old metadata and migrate it.""" | 937 | """A class that loads old metadata and migrate it.""" |
2183 | 846 | 938 | ||
2185 | 847 | def __init__(self, data_dir, shares_md_dir, shared_md_dir, | 939 | def __init__(self, data_dir, shares_md_dir, shared_md_dir, udfs_md_dir, |
2186 | 848 | root_dir, shares_dir, shares_dir_link): | 940 | root_dir, shares_dir, shares_dir_link): |
2187 | 849 | """Creates the instance""" | 941 | """Creates the instance""" |
2188 | 850 | self.log = logging.getLogger('ubuntuone.SyncDaemon.VM.MD') | 942 | self.log = logging.getLogger('ubuntuone.SyncDaemon.VM.MD') |
2189 | @@ -852,6 +944,7 @@ | |||
2190 | 852 | self._shares_dir = shares_dir | 944 | self._shares_dir = shares_dir |
2191 | 853 | self._shares_md_dir = shares_md_dir | 945 | self._shares_md_dir = shares_md_dir |
2192 | 854 | self._shared_md_dir = shared_md_dir | 946 | self._shared_md_dir = shared_md_dir |
2193 | 947 | self._udfs_md_dir = udfs_md_dir | ||
2194 | 855 | self._root_dir = root_dir | 948 | self._root_dir = root_dir |
2195 | 856 | self._shares_dir_link = shares_dir_link | 949 | self._shares_dir_link = shares_dir_link |
2196 | 857 | self._version_file = os.path.join(self._data_dir, '.version') | 950 | self._version_file = os.path.join(self._data_dir, '.version') |
2197 | @@ -878,8 +971,58 @@ | |||
2198 | 878 | if not md_version: | 971 | if not md_version: |
2199 | 879 | # we don't have a version of the metadata but a .version file? | 972 | # we don't have a version of the metadata but a .version file? |
2200 | 880 | # assume it's None and do an upgrade from version 0 | 973 | # assume it's None and do an upgrade from version 0 |
2203 | 881 | md_version = None | 974 | md_version = self._guess_metadata_version() |
2204 | 882 | else: | 975 | else: |
2205 | 976 | md_version = self._guess_metadata_version() | ||
2206 | 977 | self.log.debug('metadata version: %s', md_version) | ||
2207 | 978 | return md_version | ||
2208 | 979 | |||
2209 | 980 | def _guess_metadata_version(self): | ||
2210 | 981 | """Try to guess the metadata version based on current metadata | ||
2211 | 982 | and layout, fallbacks to md_version = None if can't guess it. | ||
2212 | 983 | |||
2213 | 984 | """ | ||
2214 | 985 | #md_version = None | ||
2215 | 986 | if os.path.exists(self._shares_md_dir) \ | ||
2216 | 987 | and os.path.exists(self._shared_md_dir): | ||
2217 | 988 | # we have shares and shared dirs | ||
2218 | 989 | # md_version >= 1 | ||
2219 | 990 | old_root_dir = os.path.join(self._root_dir, 'My Files') | ||
2220 | 991 | old_share_dir = os.path.join(self._root_dir, 'Shared With Me') | ||
2221 | 992 | if os.path.exists(old_share_dir) and os.path.exists(old_root_dir) \ | ||
2222 | 993 | and not os.path.islink(old_share_dir): | ||
2223 | 994 | # md >= 1 and <= 3 | ||
2224 | 995 | # we have a My Files dir, 'Shared With Me' isn't a | ||
2225 | 996 | # symlink and ~/.local/share/ubuntuone/shares doesn't | ||
2226 | 997 | # exists. | ||
2227 | 998 | # md_version <= 3, set it to 2 as it will migrate | ||
2228 | 999 | # .conflict to .u1conflict, and we don't need to upgrade | ||
2229 | 1000 | # from version 1 any more as the LegacyShareFileShelf | ||
2230 | 1001 | # takes care of that. | ||
2231 | 1002 | md_version = '2' | ||
2232 | 1003 | else: | ||
2233 | 1004 | try: | ||
2234 | 1005 | target = os.readlink(self._shares_dir_link) | ||
2235 | 1006 | except OSError: | ||
2236 | 1007 | target = None | ||
2237 | 1008 | if os.path.islink(self._shares_dir_link) \ | ||
2238 | 1009 | and os.path.normpath(target) == self._shares_dir_link: | ||
2239 | 1010 | # broken symlink, md_version = 4 | ||
2240 | 1011 | md_version = '4' | ||
2241 | 1012 | else: | ||
2242 | 1013 | # md_version >= 5 | ||
2243 | 1014 | shelf = LegacyShareFileShelf(self._shares_md_dir) | ||
2244 | 1015 | # check a pickled value to check if it's in version | ||
2245 | 1016 | # 5 or 6 | ||
2246 | 1017 | for key in shelf: | ||
2247 | 1018 | share = shelf[key] | ||
2248 | 1019 | if isinstance(share, _Share): | ||
2249 | 1020 | md_version = '5' | ||
2250 | 1021 | else: | ||
2251 | 1022 | md_version = '6' | ||
2252 | 1023 | break | ||
2253 | 1024 | else: | ||
2254 | 1025 | # this is metadata 'None' | ||
2255 | 883 | md_version = None | 1026 | md_version = None |
2256 | 884 | return md_version | 1027 | return md_version |
2257 | 885 | 1028 | ||
2258 | @@ -902,9 +1045,6 @@ | |||
2259 | 902 | if dir != os.path.basename(backup): | 1045 | if dir != os.path.basename(backup): |
2260 | 903 | shutil.move(os.path.join(dirname, dir), | 1046 | shutil.move(os.path.join(dirname, dir), |
2261 | 904 | os.path.join(backup, dir)) | 1047 | os.path.join(backup, dir)) |
2262 | 905 | # add the old module FQN to sys.modules in order to load the metadata | ||
2263 | 906 | sys.modules['canonical.ubuntuone.storage.syncdaemon.volume_manager'] = \ | ||
2264 | 907 | sys.modules['ubuntuone.syncdaemon.volume_manager'] | ||
2265 | 908 | # regenerate the shelf using the new layout using the backup as src | 1048 | # regenerate the shelf using the new layout using the backup as src |
2266 | 909 | old_shelf = LegacyShareFileShelf(backup) | 1049 | old_shelf = LegacyShareFileShelf(backup) |
2267 | 910 | if not os.path.exists(self._shares_dir): | 1050 | if not os.path.exists(self._shares_dir): |
2268 | @@ -912,9 +1052,7 @@ | |||
2269 | 912 | new_shelf = LegacyShareFileShelf(self._shares_md_dir) | 1052 | new_shelf = LegacyShareFileShelf(self._shares_md_dir) |
2270 | 913 | for key in old_shelf.keys(): | 1053 | for key in old_shelf.keys(): |
2271 | 914 | new_shelf[key] = old_shelf[key] | 1054 | new_shelf[key] = old_shelf[key] |
2275 | 915 | # undo the change to sys.modules | 1055 | # now upgrade to metadata 2 |
2273 | 916 | del sys.modules['canonical.ubuntuone.storage.syncdaemon.volume_manager'] | ||
2274 | 917 | # now upgrade to metadata 3 | ||
2276 | 918 | self._upgrade_metadata_2(md_version) | 1056 | self._upgrade_metadata_2(md_version) |
2277 | 919 | 1057 | ||
2278 | 920 | def _upgrade_metadata_1(self, md_version): | 1058 | def _upgrade_metadata_1(self, md_version): |
2279 | @@ -946,7 +1084,6 @@ | |||
2280 | 946 | for names in filenames, dirnames: | 1084 | for names in filenames, dirnames: |
2281 | 947 | self._upgrade_names(dirpath, names) | 1085 | self._upgrade_names(dirpath, names) |
2282 | 948 | self._upgrade_metadata_3(md_version) | 1086 | self._upgrade_metadata_3(md_version) |
2283 | 949 | self.update_metadata_version() | ||
2284 | 950 | 1087 | ||
2285 | 951 | def _upgrade_names(self, dirpath, names): | 1088 | def _upgrade_names(self, dirpath, names): |
2286 | 952 | """ | 1089 | """ |
2287 | @@ -997,6 +1134,14 @@ | |||
2288 | 997 | old_root_dir = os.path.join(self._root_dir, 'My Files') | 1134 | old_root_dir = os.path.join(self._root_dir, 'My Files') |
2289 | 998 | # change permissions | 1135 | # change permissions |
2290 | 999 | os.chmod(self._root_dir, 0775) | 1136 | os.chmod(self._root_dir, 0775) |
2291 | 1137 | |||
2292 | 1138 | def move(src, dst): | ||
2293 | 1139 | """Move a file/dir taking care if it's read-only.""" | ||
2294 | 1140 | prev_mode = stat.S_IMODE(os.stat(src).st_mode) | ||
2295 | 1141 | os.chmod(src, 0755) | ||
2296 | 1142 | shutil.move(src, dst) | ||
2297 | 1143 | os.chmod(dst, prev_mode) | ||
2298 | 1144 | |||
2299 | 1000 | # update the path's in metadata and move the folder | 1145 | # update the path's in metadata and move the folder |
2300 | 1001 | if os.path.exists(old_share_dir) and not os.path.islink(old_share_dir): | 1146 | if os.path.exists(old_share_dir) and not os.path.islink(old_share_dir): |
2301 | 1002 | os.chmod(old_share_dir, 0775) | 1147 | os.chmod(old_share_dir, 0775) |
2302 | @@ -1004,14 +1149,23 @@ | |||
2303 | 1004 | os.makedirs(os.path.dirname(self._shares_dir)) | 1149 | os.makedirs(os.path.dirname(self._shares_dir)) |
2304 | 1005 | self.log.debug('moving shares dir from: %r to %r', | 1150 | self.log.debug('moving shares dir from: %r to %r', |
2305 | 1006 | old_share_dir, self._shares_dir) | 1151 | old_share_dir, self._shares_dir) |
2307 | 1007 | shutil.move(old_share_dir, self._shares_dir) | 1152 | for path in os.listdir(old_share_dir): |
2308 | 1153 | src = os.path.join(old_share_dir, path) | ||
2309 | 1154 | dst = os.path.join(self._shares_dir, path) | ||
2310 | 1155 | move(src, dst) | ||
2311 | 1156 | os.rmdir(old_share_dir) | ||
2312 | 1157 | |||
2313 | 1008 | # update the shares metadata | 1158 | # update the shares metadata |
2314 | 1009 | shares = LegacyShareFileShelf(self._shares_md_dir) | 1159 | shares = LegacyShareFileShelf(self._shares_md_dir) |
2315 | 1010 | for key in shares.keys(): | 1160 | for key in shares.keys(): |
2316 | 1011 | share = shares[key] | 1161 | share = shares[key] |
2317 | 1012 | if share.path is not None: | 1162 | if share.path is not None: |
2320 | 1013 | share.path = share.path.replace(old_share_dir, | 1163 | if share.path == old_root_dir: |
2321 | 1014 | self._shares_dir) | 1164 | share.path = share.path.replace(old_root_dir, |
2322 | 1165 | self._root_dir) | ||
2323 | 1166 | else: | ||
2324 | 1167 | share.path = share.path.replace(old_share_dir, | ||
2325 | 1168 | self._shares_dir) | ||
2326 | 1015 | shares[key] = share | 1169 | shares[key] = share |
2327 | 1016 | 1170 | ||
2328 | 1017 | shared = LegacyShareFileShelf(self._shared_md_dir) | 1171 | shared = LegacyShareFileShelf(self._shared_md_dir) |
2329 | @@ -1021,7 +1175,7 @@ | |||
2330 | 1021 | share.path = share.path.replace(old_root_dir, self._root_dir) | 1175 | share.path = share.path.replace(old_root_dir, self._root_dir) |
2331 | 1022 | shared[key] = share | 1176 | shared[key] = share |
2332 | 1023 | # move the My Files contents, taking care of dir/files with the same | 1177 | # move the My Files contents, taking care of dir/files with the same |
2334 | 1024 | # in the new root | 1178 | # name in the new root |
2335 | 1025 | if os.path.exists(old_root_dir): | 1179 | if os.path.exists(old_root_dir): |
2336 | 1026 | self.log.debug('moving My Files contents to the root') | 1180 | self.log.debug('moving My Files contents to the root') |
2337 | 1027 | # make My Files rw | 1181 | # make My Files rw |
2338 | @@ -1038,10 +1192,11 @@ | |||
2339 | 1038 | os.remove(old_path) | 1192 | os.remove(old_path) |
2340 | 1039 | else: | 1193 | else: |
2341 | 1040 | self.log.debug('moving %r to %r', old_path, new_path) | 1194 | self.log.debug('moving %r to %r', old_path, new_path) |
2343 | 1041 | shutil.move(old_path, new_path) | 1195 | move(old_path, new_path) |
2344 | 1042 | self.log.debug('removing old root: %r', old_root_dir) | 1196 | self.log.debug('removing old root: %r', old_root_dir) |
2345 | 1043 | os.rmdir(old_root_dir) | 1197 | os.rmdir(old_root_dir) |
2346 | 1044 | 1198 | ||
2347 | 1199 | # fix broken symlink (md_version 4) | ||
2348 | 1045 | self._upgrade_metadata_4(md_version) | 1200 | self._upgrade_metadata_4(md_version) |
2349 | 1046 | 1201 | ||
2350 | 1047 | def _upgrade_metadata_4(self, md_version): | 1202 | def _upgrade_metadata_4(self, md_version): |
2351 | @@ -1056,9 +1211,61 @@ | |||
2352 | 1056 | self.log.debug('removing broken shares symlink: %r -> %r', | 1211 | self.log.debug('removing broken shares symlink: %r -> %r', |
2353 | 1057 | self._shares_dir_link, target) | 1212 | self._shares_dir_link, target) |
2354 | 1058 | os.remove(self._shares_dir_link) | 1213 | os.remove(self._shares_dir_link) |
2355 | 1214 | self._upgrade_metadata_5(md_version) | ||
2356 | 1059 | 1215 | ||
2357 | 1216 | def _upgrade_metadata_5(self, md_version): | ||
2358 | 1217 | """ | ||
2359 | 1218 | Upgrade to version 6 (plain dict storage) | ||
2360 | 1219 | """ | ||
2361 | 1220 | self.log.debug('upgrading from metadata 5') | ||
2362 | 1221 | # upgrade shares | ||
2363 | 1222 | old_shares = LegacyShareFileShelf(self._shares_md_dir) | ||
2364 | 1223 | shares = VMFileShelf(self._shares_md_dir) | ||
2365 | 1224 | for key in old_shares.keys(): | ||
2366 | 1225 | share = old_shares[key] | ||
2367 | 1226 | shares[key] = self._upgrade_share_to_volume(share) | ||
2368 | 1227 | # upgrade shared folders | ||
2369 | 1228 | old_shared = LegacyShareFileShelf(self._shared_md_dir) | ||
2370 | 1229 | shared = VMFileShelf(self._shared_md_dir) | ||
2371 | 1230 | for key in shared.keys(): | ||
2372 | 1231 | share = old_shared[key] | ||
2373 | 1232 | shared[key] = self._upgrade_share_to_volume(share, shared=True) | ||
2374 | 1233 | # upgrade the udfs | ||
2375 | 1234 | old_udfs = LegacyShareFileShelf(self._udfs_md_dir) | ||
2376 | 1235 | udfs = VMFileShelf(self._udfs_md_dir) | ||
2377 | 1236 | for key in old_udfs.keys(): | ||
2378 | 1237 | udf = old_udfs[key] | ||
2379 | 1238 | udfs[key] = UDF(udf.id, udf.node_id, udf.suggested_path, | ||
2380 | 1239 | udf.path, udf.subscribed) | ||
2381 | 1060 | self.update_metadata_version() | 1240 | self.update_metadata_version() |
2382 | 1061 | 1241 | ||
2383 | 1242 | def _upgrade_share_to_volume(self, share, shared=False): | ||
2384 | 1243 | """Upgrade from _Share to new Volume hierarchy.""" | ||
2385 | 1244 | def upgrade_share_dict(share): | ||
2386 | 1245 | """Upgrade share __dict__ to be compatible with the | ||
2387 | 1246 | new Share.__init__. | ||
2388 | 1247 | |||
2389 | 1248 | """ | ||
2390 | 1249 | if 'subtree' in share.__dict__: | ||
2391 | 1250 | share.node_id = share.__dict__.pop('subtree') | ||
2392 | 1251 | if 'id' in share.__dict__: | ||
2393 | 1252 | share.volume_id = share.__dict__.pop('id') | ||
2394 | 1253 | if 'free_bytes' in share.__dict__: | ||
2395 | 1254 | free_bytes = share.__dict__.pop('free_bytes') | ||
2396 | 1255 | else: | ||
2397 | 1256 | free_bytes = None | ||
2398 | 1257 | return share | ||
2399 | 1258 | # handle the root special case | ||
2400 | 1259 | if share.path == self._root_dir or share.id == '': | ||
2401 | 1260 | r = Root(share.id, share.subtree, share.path) | ||
2402 | 1261 | return r | ||
2403 | 1262 | else: | ||
2404 | 1263 | share = upgrade_share_dict(share) | ||
2405 | 1264 | if shared: | ||
2406 | 1265 | return Shared(**share.__dict__) | ||
2407 | 1266 | else: | ||
2408 | 1267 | return Share(**share.__dict__) | ||
2409 | 1268 | |||
2410 | 1062 | def update_metadata_version(self): | 1269 | def update_metadata_version(self): |
2411 | 1063 | """write the version of the metadata""" | 1270 | """write the version of the metadata""" |
2412 | 1064 | if not os.path.exists(os.path.dirname(self._version_file)): | 1271 | if not os.path.exists(os.path.dirname(self._version_file)): |
2413 | @@ -1082,8 +1289,13 @@ | |||
2414 | 1082 | class VMFileShelf(file_shelf.FileShelf): | 1289 | class VMFileShelf(file_shelf.FileShelf): |
2415 | 1083 | """ Custom file shelf that allow request.ROOT as key, it's replaced | 1290 | """ Custom file shelf that allow request.ROOT as key, it's replaced |
2416 | 1084 | by the string: root_node_id. | 1291 | by the string: root_node_id. |
2417 | 1292 | |||
2418 | 1085 | """ | 1293 | """ |
2419 | 1086 | 1294 | ||
2420 | 1295 | TYPE = 'type' | ||
2421 | 1296 | classes = dict((sub.__name__, sub) for sub in \ | ||
2422 | 1297 | Volume.__subclasses__() + Share.__subclasses__()) | ||
2423 | 1298 | |||
2424 | 1087 | def __init__(self, *args, **kwargs): | 1299 | def __init__(self, *args, **kwargs): |
2425 | 1088 | """ Create the instance. """ | 1300 | """ Create the instance. """ |
2426 | 1089 | super(VMFileShelf, self).__init__(*args, **kwargs) | 1301 | super(VMFileShelf, self).__init__(*args, **kwargs) |
2427 | @@ -1103,6 +1315,22 @@ | |||
2428 | 1103 | else: | 1315 | else: |
2429 | 1104 | yield key | 1316 | yield key |
2430 | 1105 | 1317 | ||
2431 | 1318 | def _unpickle(self, fd): | ||
2432 | 1319 | """Unpickle a dict and build the class instance specified in | ||
2433 | 1320 | value['type']. | ||
2434 | 1321 | """ | ||
2435 | 1322 | value = cPickle.load(fd) | ||
2436 | 1323 | class_name = value[self.TYPE] | ||
2437 | 1324 | clazz = self.classes[class_name] | ||
2438 | 1325 | obj = clazz.__new__(clazz) | ||
2439 | 1326 | obj.__dict__.update(value) | ||
2440 | 1327 | return obj | ||
2441 | 1328 | |||
2442 | 1329 | def _pickle(self, value, fd, protocol): | ||
2443 | 1330 | """Pickle value in fd using protocol.""" | ||
2444 | 1331 | cPickle.dump(value.__dict__, fd, protocol=protocol) | ||
2445 | 1332 | |||
2446 | 1333 | |||
2447 | 1106 | class LegacyShareFileShelf(VMFileShelf): | 1334 | class LegacyShareFileShelf(VMFileShelf): |
2448 | 1107 | """A FileShelf capable of replacing pickled classes | 1335 | """A FileShelf capable of replacing pickled classes |
2449 | 1108 | with a different class. | 1336 | with a different class. |
2450 | @@ -1112,11 +1340,12 @@ | |||
2451 | 1112 | """ | 1340 | """ |
2452 | 1113 | 1341 | ||
2453 | 1114 | upgrade_map = { | 1342 | upgrade_map = { |
2454 | 1343 | ('ubuntuone.syncdaemon.volume_manager', 'UDF'):_UDF, | ||
2455 | 1344 | ('ubuntuone.syncdaemon.volume_manager', 'Share'):_Share, | ||
2456 | 1115 | ('canonical.ubuntuone.storage.syncdaemon.volume_manager', | 1345 | ('canonical.ubuntuone.storage.syncdaemon.volume_manager', |
2458 | 1116 | 'Share'):Share | 1346 | 'Share'):_Share |
2459 | 1117 | } | 1347 | } |
2460 | 1118 | 1348 | ||
2461 | 1119 | |||
2462 | 1120 | def _find_global(self, module, name): | 1349 | def _find_global(self, module, name): |
2463 | 1121 | """Returns the class object for (module, name) or None.""" | 1350 | """Returns the class object for (module, name) or None.""" |
2464 | 1122 | # handle our 'migration types' | 1351 | # handle our 'migration types' |
This branch is the last of the VM refactor series:
- implement new Volume hierarchy in VolumeManager
- implenment VMFileShelf to pickle VM metadata as dict
- add metadata migration to new version
- refactor md migration tests:
- fix a few bugs found (thanks to better tests) in previous metadata migration functions
- update tools.py and dbus_interface.py
- update tools, dbus and vm tests