Merge lp:~facundo/ubuntuone-client/put_path_back into lp:ubuntuone-client

Proposed by Facundo Batista on 2012-10-17
Status: Merged
Approved by: Facundo Batista on 2012-10-17
Approved revision: 1344
Merged at revision: 1346
Proposed branch: lp:~facundo/ubuntuone-client/put_path_back
Merge into: lp:ubuntuone-client
Diff against target: 256 lines (+68/-21)
3 files modified
tests/platform/linux/eventlog/test_zg_listener.py (+2/-2)
tests/syncdaemon/test_action_queue.py (+60/-14)
ubuntuone/syncdaemon/action_queue.py (+6/-5)
To merge this branch: bzr merge lp:~facundo/ubuntuone-client/put_path_back
Reviewer Review Type Date Requested Status
Roberto Alsina (community) 2012-10-17 Approve on 2012-10-17
Review via email: mp+130142@code.launchpad.net

Commit Message

Put path back for some commands, and assure it's included in their info.

Description of the Change

Put path back for some commands, and assure it's included in their info.

In detail: put it back for MakeThing, and included it in the to_dict() result for Upload and Download.

This is needed to send the info with some signals (e.g.: SYS_QUEUE_ADDED) internally and externally through dbus.

Tests included.

To post a comment you must log in.
Roberto Alsina (ralsina) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/platform/linux/eventlog/test_zg_listener.py'
2--- tests/platform/linux/eventlog/test_zg_listener.py 2012-10-04 18:22:17 +0000
3+++ tests/platform/linux/eventlog/test_zg_listener.py 2012-10-17 15:11:22 +0000
4@@ -600,7 +600,7 @@
5
6 # create a command and trigger it success
7 cmd = MakeFile(self.rq, self.share_id, 'parent', filename,
8- 'marker', path)
9+ 'marker', self.mdid)
10 cmd.handle_success(request)
11
12 # create a request and fill it with succesful information
13@@ -658,7 +658,7 @@
14
15 # create a command and trigger it success
16 cmd = MakeDir(self.rq, self.share_id, 'parent',
17- dirname, 'marker', path)
18+ dirname, 'marker', self.mdid)
19 cmd.handle_success(request)
20
21 # check for successful event
22
23=== modified file 'tests/syncdaemon/test_action_queue.py'
24--- tests/syncdaemon/test_action_queue.py 2012-10-04 16:50:17 +0000
25+++ tests/syncdaemon/test_action_queue.py 2012-10-17 15:11:22 +0000
26@@ -3098,6 +3098,11 @@
27 expected = os.path.join('test_has_path', 'root', 'file')
28 self.assertIn(expected, self.command.path)
29
30+ def test_to_dict_info(self):
31+ """Some info should be in to_dict."""
32+ info = self.command.to_dict()
33+ self.assertEqual(info['path'], self.test_path)
34+
35
36 class UploadUnconnectedTestCase(FactoryBaseTestCase):
37 """Test for Upload ActionQueueCommand, no connection"""
38@@ -3705,6 +3710,11 @@
39 expected = os.path.join('test_has_path', 'root', 'foo', 'bar')
40 self.assertIn(expected, self.command.path)
41
42+ def test_to_dict_info(self):
43+ """Some info should be in to_dict."""
44+ info = self.command.to_dict()
45+ self.assertEqual(info['path'], self.test_path)
46+
47
48 class CreateShareTestCase(ConnectedBaseTestCase):
49 """Test for CreateShare ActionQueueCommand."""
50@@ -4757,6 +4767,12 @@
51 'on_children': True,
52 'logger': None}])
53
54+ def test_to_dict_info(self):
55+ """Some info should be in to_dict."""
56+ cmd = Unlink(self.rq, VOLUME, 'parent_id', 'node_id', 'path', False)
57+ info = cmd.to_dict()
58+ self.assertEqual(info['path'], 'path')
59+
60
61 class MoveTestCase(ConnectedBaseTestCase):
62 """Test for Move ActionQueueCommand."""
63@@ -4842,6 +4858,14 @@
64 merge_release[0]()
65 self.assertEqual(sorted(release_called), [1, 2])
66
67+ def test_to_dict_info(self):
68+ """Some info should be in to_dict."""
69+ cmd = Move(self.rq, VOLUME, 'node', 'o_parent', 'n_parent', 'n_name',
70+ 'path_from', 'path_to')
71+ info = cmd.to_dict()
72+ self.assertEqual(info['path_from'], 'path_from')
73+ self.assertEqual(info['path_to'], 'path_to')
74+
75
76 class MakeFileTestCase(ConnectedBaseTestCase):
77 """Test for MakeFile ActionQueueCommand."""
78@@ -4850,6 +4874,8 @@
79 def setUp(self):
80 """Init."""
81 yield super(MakeFileTestCase, self).setUp()
82+ self.test_path = os.path.join(self.root, 'foo', 'bar')
83+ self.mdid = self.main.fs.create(self.test_path, '')
84 self.rq = RequestQueue(action_queue=self.action_queue)
85
86 def test_handle_success_push_event(self):
87@@ -4861,7 +4887,7 @@
88 request.new_generation = 13
89
90 # create a command and trigger it success
91- cmd = MakeFile(self.rq, VOLUME, 'parent', 'name', 'marker', 'path')
92+ cmd = MakeFile(self.rq, VOLUME, 'parent', 'name', 'marker', self.mdid)
93 cmd.handle_success(request)
94
95 # check for successful event
96@@ -4879,7 +4905,7 @@
97 request.new_generation = 13
98
99 # create a command and trigger it fail
100- cmd = MakeFile(self.rq, VOLUME, 'parent', 'name', 'marker', 'path')
101+ cmd = MakeFile(self.rq, VOLUME, 'parent', 'name', 'marker', self.mdid)
102 failure = Failure(Exception('foo'))
103 cmd.handle_failure(failure)
104
105@@ -4890,7 +4916,7 @@
106
107 def test_possible_markers(self):
108 """Test that it returns the correct values."""
109- cmd = MakeFile(self.rq, VOLUME, 'parent', 'name', 'marker', 'path')
110+ cmd = MakeFile(self.rq, VOLUME, 'parent', 'name', 'marker', self.mdid)
111 res = [getattr(cmd, x) for x in cmd.possible_markers]
112 self.assertEqual(res, [ 'parent'])
113
114@@ -4899,14 +4925,23 @@
115 t = []
116 self.patch(PathLockingTree, 'acquire',
117 lambda s, *a, **k: t.extend((a, k)))
118- path = os.path.join(self.root, 'file')
119- mdid = self.main.fs.create(path, '')
120- cmd = MakeFile(self.rq, VOLUME, 'parent', 'name', 'marker', mdid)
121+ cmd = MakeFile(self.rq, VOLUME, 'parent', 'name', 'marker', self.mdid)
122 cmd._acquire_pathlock()
123- should = [tuple(path.split(os.path.sep)),
124+ should = [tuple(self.test_path.split(os.path.sep)),
125 {'on_parent': True, 'logger': None}]
126 self.assertEqual(t, should)
127
128+ def test_has_path_at_init(self):
129+ """MakeDir must has a path even at init."""
130+ cmd = MakeFile(self.rq, VOLUME, 'parent', 'name', 'marker', self.mdid)
131+ self.assertEqual(cmd.path, self.test_path)
132+
133+ def test_to_dict_info(self):
134+ """Some info should be in to_dict."""
135+ cmd = MakeFile(self.rq, VOLUME, 'parent', 'name', 'marker', self.mdid)
136+ info = cmd.to_dict()
137+ self.assertEqual(info['path'], self.test_path)
138+
139
140 class MakeDirTestCase(ConnectedBaseTestCase):
141 """Test for MakeDir ActionQueueCommand."""
142@@ -4915,6 +4950,8 @@
143 def setUp(self):
144 """Init."""
145 yield super(MakeDirTestCase, self).setUp()
146+ self.test_path = os.path.join(self.root, 'foo', 'bar')
147+ self.mdid = self.main.fs.create(self.test_path, '')
148 self.rq = RequestQueue(action_queue=self.action_queue)
149
150 def test_handle_success_push_event(self):
151@@ -4926,7 +4963,7 @@
152 request.new_generation = 13
153
154 # create a command and trigger it success
155- cmd = MakeDir(self.rq, VOLUME, 'parent', 'name', 'marker', 'path')
156+ cmd = MakeDir(self.rq, VOLUME, 'parent', 'name', 'marker', self.mdid)
157 cmd.handle_success(request)
158
159 # check for successful event
160@@ -4944,7 +4981,7 @@
161 request.new_generation = 13
162
163 # create a command and trigger it fail
164- cmd = MakeDir(self.rq, VOLUME, 'parent', 'name', 'marker', 'path')
165+ cmd = MakeDir(self.rq, VOLUME, 'parent', 'name', 'marker', self.mdid)
166 failure = Failure(Exception('foo'))
167 cmd.handle_failure(failure)
168
169@@ -4955,7 +4992,7 @@
170
171 def test_possible_markers(self):
172 """Test that it returns the correct values."""
173- cmd = MakeDir(self.rq, VOLUME, 'parent', 'name', 'marker', 'path')
174+ cmd = MakeDir(self.rq, VOLUME, 'parent', 'name', 'marker', self.mdid)
175 res = [getattr(cmd, x) for x in cmd.possible_markers]
176 self.assertEqual(res, ['parent'])
177
178@@ -4964,14 +5001,23 @@
179 t = []
180 self.patch(PathLockingTree, 'acquire',
181 lambda s, *a, **k: t.extend((a, k)))
182- path = os.path.join(self.root, 'file')
183- mdid = self.main.fs.create(path, '')
184- cmd = MakeDir(self.rq, VOLUME, 'parent', 'name', 'marker', mdid)
185+ cmd = MakeDir(self.rq, VOLUME, 'parent', 'name', 'marker', self.mdid)
186 cmd._acquire_pathlock()
187- should = [tuple(path.split(os.path.sep)),
188+ should = [tuple(self.test_path.split(os.path.sep)),
189 {'on_parent': True, 'logger': None}]
190 self.assertEqual(t, should)
191
192+ def test_has_path_at_init(self):
193+ """MakeDir must has a path even at init."""
194+ cmd = MakeDir(self.rq, VOLUME, 'parent', 'name', 'marker', self.mdid)
195+ self.assertEqual(cmd.path, self.test_path)
196+
197+ def test_to_dict_info(self):
198+ """Some info should be in to_dict."""
199+ cmd = MakeDir(self.rq, VOLUME, 'parent', 'name', 'marker', self.mdid)
200+ info = cmd.to_dict()
201+ self.assertEqual(info['path'], self.test_path)
202+
203
204 class TestDeltaList(unittest.TestCase):
205 """Tests for DeltaList."""
206
207=== modified file 'ubuntuone/syncdaemon/action_queue.py'
208--- ubuntuone/syncdaemon/action_queue.py 2012-10-04 15:45:56 +0000
209+++ ubuntuone/syncdaemon/action_queue.py 2012-10-17 15:11:22 +0000
210@@ -1610,7 +1610,7 @@
211 class MakeThing(ActionQueueCommand):
212 """Base of MakeFile and MakeDir."""
213
214- __slots__ = ('share_id', 'parent_id', 'name', 'marker', 'mdid')
215+ __slots__ = ('share_id', 'parent_id', 'name', 'marker', 'mdid', 'path')
216 logged_attrs = ActionQueueCommand.logged_attrs + __slots__
217 possible_markers = 'parent_id',
218
219@@ -1623,6 +1623,7 @@
220 self.name = name.decode("utf-8")
221 self.marker = marker
222 self.mdid = mdid
223+ self.path = self._get_current_path(mdid)
224
225 def _run(self):
226 """Do the actual running."""
227@@ -1647,9 +1648,9 @@
228
229 def _acquire_pathlock(self):
230 """Acquire pathlock."""
231- curr_path = self._get_current_path(self.mdid)
232+ self.path = self._get_current_path(self.mdid)
233 pathlock = self.action_queue.pathlock
234- return pathlock.acquire(*curr_path.split(os.path.sep), on_parent=True,
235+ return pathlock.acquire(*self.path.split(os.path.sep), on_parent=True,
236 logger=self.log)
237
238
239@@ -2365,7 +2366,7 @@
240 'fileobj', 'gunzip', 'mdid', 'download_req', 'tx_semaphore',
241 'deflated_size', 'n_bytes_read_last', 'n_bytes_read', 'path')
242 logged_attrs = ActionQueueCommand.logged_attrs + (
243- 'share_id', 'node_id', 'server_hash', 'mdid')
244+ 'share_id', 'node_id', 'server_hash', 'mdid', 'path')
245 possible_markers = 'node_id',
246
247 def __init__(self, request_queue, share_id, node_id, server_hash, mdid):
248@@ -2535,7 +2536,7 @@
249
250 logged_attrs = ActionQueueCommand.logged_attrs + (
251 'share_id', 'node_id', 'previous_hash', 'hash', 'crc32',
252- 'size', 'upload_id', 'mdid')
253+ 'size', 'upload_id', 'mdid', 'path')
254 retryable_errors = ActionQueueCommand.retryable_errors + (
255 protocol_errors.UploadInProgressError,)
256 possible_markers = 'node_id',

Subscribers

People subscribed via source and target branches