Merge lp:~nataliabidart/ubuntuone-client/run-upload-run into lp:ubuntuone-client

Proposed by Natalia Bidart
Status: Merged
Approved by: Roman Yepishev
Approved revision: 1156
Merged at revision: 1154
Proposed branch: lp:~nataliabidart/ubuntuone-client/run-upload-run
Merge into: lp:ubuntuone-client
Diff against target: 124 lines (+28/-25)
2 files modified
tests/syncdaemon/test_action_queue.py (+21/-5)
ubuntuone/syncdaemon/action_queue.py (+7/-20)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-client/run-upload-run
Reviewer Review Type Date Requested Status
Roman Yepishev (community) fieldtest Approve
Facundo Batista (community) Approve
Review via email: mp+80702@code.launchpad.net

Commit message

- Make the Upload process do not close the tempfile until is finished (LP: #872924).

To post a comment you must log in.
Revision history for this message
Facundo Batista (facundo) wrote :

Thanks!

review: Approve
1156. By Natalia Bidart

Merged trunk in.

Revision history for this message
Roman Yepishev (rye) wrote :

Looks good. No errors while disconnecting/reconnecting the network or SD.

review: Approve (fieldtest)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/syncdaemon/test_action_queue.py'
2--- tests/syncdaemon/test_action_queue.py 2011-10-27 11:39:43 +0000
3+++ tests/syncdaemon/test_action_queue.py 2011-10-28 19:48:24 +0000
4@@ -106,9 +106,12 @@
5
6 class FakeTempFile(object):
7 """Fake temporary file."""
8+
9 def __init__(self, tmpdir):
10+ self.closed = 0 # be able to count how may close calls we had
11 self.name = os.path.join(tmpdir, 'remove-me.zip')
12 open_file(self.name, 'w').close()
13+ self.close = lambda: setattr(self, 'closed', self.closed + 1)
14
15
16 class FakeCommand(object):
17@@ -3349,16 +3352,29 @@
18 events = [('AQ_UPLOAD_ERROR', kwargs)]
19 self.assertEqual(events, self.command.action_queue.event_queue.events)
20
21- def test_handle_failure_removes_temp_file(self):
22- """Test temp file is removed on failure."""
23+ def test_finish_closes_temp_file(self):
24+ """Test temp file is closed when the command finishes."""
25+ self.command.tempfile = FakeTempFile(self.tmpdir)
26+ assert self.command.tempfile.closed == 0
27+
28+ self.command.finish()
29+ self.assertEqual(1, self.command.tempfile.closed)
30+
31+ def test_finish_removes_temp_file(self):
32+ """Test temp file is removed when the command finishes."""
33 self.command.tempfile = FakeTempFile(self.tmpdir)
34 assert path_exists(self.command.tempfile.name)
35
36- msg = 'Something went wrong'
37- failure = Failure(DefaultException(msg))
38- self.command.handle_failure(failure=failure)
39+ self.command.finish()
40 self.assertFalse(path_exists(self.command.tempfile.name))
41
42+ def test_finish_handles_temp_file_none(self):
43+ """Test temp file can be None when calling finish."""
44+ self.command.tempfile = None
45+
46+ self.command.finish()
47+ self.assertEqual(self.command.tempfile, None) # nothing changed
48+
49 def test_retryable_failure_push_quota_exceeded_if_that_error(self):
50 """Test SYS_QUOTA_EXCEEDED is pushed on QuotaExceededError."""
51 protocol_msg = protocol_pb2.Message()
52
53=== modified file 'ubuntuone/syncdaemon/action_queue.py'
54--- ubuntuone/syncdaemon/action_queue.py 2011-10-14 20:02:23 +0000
55+++ ubuntuone/syncdaemon/action_queue.py 2011-10-28 19:48:24 +0000
56@@ -37,7 +37,7 @@
57 import zlib
58
59 from collections import deque, defaultdict
60-from functools import wraps, partial
61+from functools import partial
62 from urllib import urlencode
63 from urllib2 import urlopen, Request, HTTPError
64 from urlparse import urljoin
65@@ -77,18 +77,6 @@
66 TRANSFER_PROGRESS_THRESHOLD = 64 * 1024 * 1024
67
68
69-def passit(func):
70- """Pass the value on for the next deferred, while calling func with it."""
71-
72- @wraps(func)
73- def wrapper(a):
74- """Do it."""
75- func(a)
76- return a
77-
78- return wrapper
79-
80-
81 class DeferredInterrupted(Exception):
82 """To stop the run when pausing."""
83
84@@ -2497,6 +2485,11 @@
85
86 def finish(self):
87 """Release the semaphore if already acquired."""
88+ if self.tempfile is not None:
89+ # clean the temporary file
90+ self.tempfile.close()
91+ remove_file(self.tempfile.name)
92+
93 if self.tx_semaphore is not None:
94 self.tx_semaphore = self.tx_semaphore.release()
95 self.log.debug('semaphore released')
96@@ -2520,9 +2513,7 @@
97 upload_id=self.upload_id, upload_id_cb=self._upload_id_cb,
98 magic_hash=magic_hash)
99 self.upload_req = req
100- d = req.deferred
101- d.addBoth(passit(lambda _: self.tempfile.close()))
102- return d
103+ return req.deferred
104
105 def _upload_id_cb(self, upload_id):
106 """Handle the received upload_id, save it in the metadata."""
107@@ -2544,9 +2535,6 @@
108
109 def handle_success(self, request):
110 """It worked! Push the event."""
111- # remove the temporary file
112- remove_file(self.tempfile.name)
113-
114 # send the event
115 d = dict(share_id=self.share_id, node_id=self.node_id, hash=self.hash,
116 new_generation=request.new_generation)
117@@ -2562,7 +2550,6 @@
118
119 def handle_failure(self, failure):
120 """It didn't work! Push the event."""
121- remove_file(self.tempfile.name)
122 self.action_queue.event_queue.push('AQ_UPLOAD_ERROR',
123 error=failure.getErrorMessage(),
124 share_id=self.share_id,

Subscribers

People subscribed via source and target branches