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

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 1144
Merged at revision: 1142
Proposed branch: lp:~nataliabidart/ubuntuone-client/run-upload-run-stable-2-0
Merge into: lp:ubuntuone-client/stable-2-0
Diff against target: 946 lines (+165/-87)
14 files modified
tests/platform/linux/eventlog/test_zglog.py (+3/-2)
tests/platform/linux/test_dbus.py (+2/-1)
tests/platform/linux/test_messaging.py (+1/-9)
tests/platform/linux/test_notification.py (+1/-9)
tests/platform/linux/test_unity.py (+3/-0)
tests/platform/linux/test_vm.py (+6/-2)
tests/platform/test_interaction_interfaces.py (+18/-8)
tests/status/test_aggregator.py (+20/-2)
tests/syncdaemon/test_action_queue.py (+58/-13)
tests/syncdaemon/test_logger.py (+11/-0)
tests/syncdaemon/test_pathlockingtree.py (+8/-0)
tests/syncdaemon/test_states.py (+16/-5)
tests/syncdaemon/test_status_listener.py (+2/-1)
ubuntuone/syncdaemon/action_queue.py (+16/-35)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-client/run-upload-run-stable-2-0
Reviewer Review Type Date Requested Status
Facundo Batista (community) Approve
Joshua Hoover (community) tested Approve
Review via email: mp+81475@code.launchpad.net

Commit message

- Make the Upload process do not close the tempfile until is finished
  (LP: #872924).
- Reset the tempfile on every Upload _run() (LP: #884959).

To post a comment you must log in.
1144. By Natalia Bidart

All tests green, now for sure.

Revision history for this message
Joshua Hoover (joshuahoover) wrote :

Tested and passed using test case in bug #872924

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

Like it!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/platform/linux/eventlog/test_zglog.py'
--- tests/platform/linux/eventlog/test_zglog.py 2011-06-15 21:14:06 +0000
+++ tests/platform/linux/eventlog/test_zglog.py 2011-11-07 18:03:24 +0000
@@ -25,7 +25,7 @@
2525
26from distutils.spawn import find_executable26from distutils.spawn import find_executable
2727
28from twisted.internet.defer import Deferred28from twisted.internet.defer import Deferred, inlineCallbacks
29from zeitgeist.client import ZeitgeistClient29from zeitgeist.client import ZeitgeistClient
30from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation30from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation
3131
@@ -92,8 +92,9 @@
92class ZeitgeistTestCase(DBusTwistedTestCase):92class ZeitgeistTestCase(DBusTwistedTestCase):
93 """Tests for the zeitgeist logging module."""93 """Tests for the zeitgeist logging module."""
9494
95 @inlineCallbacks
95 def setUp(self):96 def setUp(self):
96 super(ZeitgeistTestCase, self).setUp()97 yield super(ZeitgeistTestCase, self).setUp()
97 zgdaemon = find_executable("zeitgeist-daemon")98 zgdaemon = find_executable("zeitgeist-daemon")
98 if not zgdaemon:99 if not zgdaemon:
99 raise NotFoundError("zeitgeist-daemon was not found.")100 raise NotFoundError("zeitgeist-daemon was not found.")
100101
=== modified file 'tests/platform/linux/test_dbus.py'
--- tests/platform/linux/test_dbus.py 2011-08-03 20:20:02 +0000
+++ tests/platform/linux/test_dbus.py 2011-11-07 18:03:24 +0000
@@ -2909,9 +2909,10 @@
2909 self._old_home = os.environ['HOME']2909 self._old_home = os.environ['HOME']
2910 os.environ['HOME'] = self.home_dir2910 os.environ['HOME'] = self.home_dir
29112911
2912 @defer.inlineCallbacks
2912 def tearDown(self):2913 def tearDown(self):
2913 os.environ['HOME'] = self._old_home2914 os.environ['HOME'] = self._old_home
2914 return DBusTwistedTestCase.tearDown(self)2915 yield super(FolderTests, self).tearDown()
29152916
2916 def _create_udf(self, id, node_id, suggested_path, subscribed=True):2917 def _create_udf(self, id, node_id, suggested_path, subscribed=True):
2917 """Create an UDF and returns it and the volume."""2918 """Create an UDF and returns it and the volume."""
29182919
=== modified file 'tests/platform/linux/test_messaging.py'
--- tests/platform/linux/test_messaging.py 2011-03-29 22:47:53 +0000
+++ tests/platform/linux/test_messaging.py 2011-11-07 18:03:24 +0000
@@ -22,8 +22,7 @@
22"""22"""
2323
2424
25from mocker import Mocker, ANY25from mocker import ANY, MockerTestCase as TestCase
26from twisted.trial.unittest import TestCase
2726
28from ubuntuone.platform.linux.messaging import Messaging, _server_callback27from ubuntuone.platform.linux.messaging import Messaging, _server_callback
2928
@@ -42,13 +41,6 @@
42class MessagingTestCase(TestCase):41class MessagingTestCase(TestCase):
43 """Test the Messaging API."""42 """Test the Messaging API."""
4443
45 def setUp(self):
46 self.mocker = Mocker()
47
48 def tearDown(self):
49 self.mocker.restore()
50 self.mocker.verify()
51
52 # pylint: disable=R091344 # pylint: disable=R0913
53 def _show_message_setup(self, message_time=None, message_count=None,45 def _show_message_setup(self, message_time=None, message_count=None,
54 icon=None, update_count=None, real_callback=False):46 icon=None, update_count=None, real_callback=False):
5547
=== modified file 'tests/platform/linux/test_notification.py'
--- tests/platform/linux/test_notification.py 2011-03-03 23:29:37 +0000
+++ tests/platform/linux/test_notification.py 2011-11-07 18:03:24 +0000
@@ -22,8 +22,7 @@
22"""22"""
2323
2424
25from mocker import Mocker25from mocker import MockerTestCase as TestCase
26from twisted.trial.unittest import TestCase
2726
28from ubuntuone.platform.linux.notification import Notification, ICON_NAME27from ubuntuone.platform.linux.notification import Notification, ICON_NAME
2928
@@ -45,13 +44,6 @@
45class NotificationTestCase(TestCase):44class NotificationTestCase(TestCase):
46 """Test the Messaging API."""45 """Test the Messaging API."""
4746
48 def setUp(self):
49 self.mocker = Mocker()
50
51 def tearDown(self):
52 self.mocker.restore()
53 self.mocker.verify()
54
55 def test_send_notification(self):47 def test_send_notification(self):
56 """On notification, pynotify receives the proper calls."""48 """On notification, pynotify receives the proper calls."""
57 mock_notify = self.mocker.replace("pynotify")49 mock_notify = self.mocker.replace("pynotify")
5850
=== modified file 'tests/platform/linux/test_unity.py'
--- tests/platform/linux/test_unity.py 2011-07-06 20:41:33 +0000
+++ tests/platform/linux/test_unity.py 2011-11-07 18:03:24 +0000
@@ -18,6 +18,7 @@
1818
19"""Tests for the liblauncher interface."""19"""Tests for the liblauncher interface."""
2020
21from twisted.internet import defer
21from twisted.trial.unittest import TestCase22from twisted.trial.unittest import TestCase
2223
23from ubuntuone.platform.linux import launcher24from ubuntuone.platform.linux import launcher
@@ -55,8 +56,10 @@
5556
56 skip = None if launcher.use_libunity else "libunity not installed."57 skip = None if launcher.use_libunity else "libunity not installed."
5758
59 @defer.inlineCallbacks
58 def setUp(self):60 def setUp(self):
59 """Initialize this test instance."""61 """Initialize this test instance."""
62 yield super(LauncherTestCase, self).setUp()
60 self.patch(launcher.Unity, "LauncherEntry", FakeLauncherEntry)63 self.patch(launcher.Unity, "LauncherEntry", FakeLauncherEntry)
61 self.launcher = launcher.UbuntuOneLauncher()64 self.launcher = launcher.UbuntuOneLauncher()
6265
6366
=== modified file 'tests/platform/linux/test_vm.py'
--- tests/platform/linux/test_vm.py 2011-07-27 20:10:33 +0000
+++ tests/platform/linux/test_vm.py 2011-11-07 18:03:24 +0000
@@ -19,6 +19,8 @@
19import os19import os
20import uuid20import uuid
2121
22from twisted.internet import defer
23
22from contrib.testing.testcase import FakeMain, environ24from contrib.testing.testcase import FakeMain, environ
23from tests.syncdaemon.test_vm import MetadataTestCase, BaseVolumeManagerTests25from tests.syncdaemon.test_vm import MetadataTestCase, BaseVolumeManagerTests
24from ubuntuone.storageprotocol import request26from ubuntuone.storageprotocol import request
@@ -44,8 +46,9 @@
44class MetadataOldLayoutTests(MetadataTestCase):46class MetadataOldLayoutTests(MetadataTestCase):
45 """Tests for 'old' layouts and metadata upgrade"""47 """Tests for 'old' layouts and metadata upgrade"""
4648
49 @defer.inlineCallbacks
47 def setUp(self):50 def setUp(self):
48 MetadataTestCase.setUp(self)51 yield super(MetadataOldLayoutTests, self).setUp()
49 self.root_dir = os.path.join(self.u1_dir, 'My Files')52 self.root_dir = os.path.join(self.u1_dir, 'My Files')
50 self.shares_dir = os.path.join(self.u1_dir, 'Shared With Me')53 self.shares_dir = os.path.join(self.u1_dir, 'Shared With Me')
51 self.new_root_dir = self.u1_dir54 self.new_root_dir = self.u1_dir
@@ -451,8 +454,9 @@
451class MetadataNewLayoutTests(MetadataTestCase):454class MetadataNewLayoutTests(MetadataTestCase):
452 """Test for 'new' layout and metadata upgrade."""455 """Test for 'new' layout and metadata upgrade."""
453456
457 @defer.inlineCallbacks
454 def setUp(self):458 def setUp(self):
455 MetadataTestCase.setUp(self)459 yield super(MetadataNewLayoutTests, self).setUp()
456 self.share_md_dir = os.path.join(self.vm_data_dir, 'shares')460 self.share_md_dir = os.path.join(self.vm_data_dir, 'shares')
457 self.shared_md_dir = os.path.join(self.vm_data_dir, 'shared')461 self.shared_md_dir = os.path.join(self.vm_data_dir, 'shared')
458 self.home_dir = os.path.join(self.tmpdir, 'home', 'ubuntuonehacker')462 self.home_dir = os.path.join(self.tmpdir, 'home', 'ubuntuonehacker')
459463
=== modified file 'tests/platform/test_interaction_interfaces.py'
--- tests/platform/test_interaction_interfaces.py 2011-07-27 14:26:36 +0000
+++ tests/platform/test_interaction_interfaces.py 2011-11-07 18:03:24 +0000
@@ -18,15 +18,18 @@
18"""Test that the interaction_interfaces are correctly called."""18"""Test that the interaction_interfaces are correctly called."""
1919
20from mocker import MockerTestCase, MATCH20from mocker import MockerTestCase, MATCH
21from twisted.internet import defer
22
21from tests.platform import IPCTestCase23from tests.platform import IPCTestCase
2224
2325
24class TestStatusIPC(MockerTestCase, IPCTestCase):26class TestStatusIPC(MockerTestCase, IPCTestCase):
25 """Ensure that calls are correctly fowarded."""27 """Ensure that calls are correctly fowarded."""
2628
29 @defer.inlineCallbacks
27 def setUp(self):30 def setUp(self):
28 """Set up tests."""31 """Set up tests."""
29 super(TestStatusIPC, self).setUp()32 yield super(TestStatusIPC, self).setUp()
30 self.syncdaemon_status = self.mocker.mock()33 self.syncdaemon_status = self.mocker.mock()
31 self.status.syncdaemon_status = self.syncdaemon_status34 self.status.syncdaemon_status = self.syncdaemon_status
3235
@@ -82,9 +85,10 @@
82class TestEventsIPC(MockerTestCase, IPCTestCase):85class TestEventsIPC(MockerTestCase, IPCTestCase):
83 """Ensure that calls are correctly fowarded."""86 """Ensure that calls are correctly fowarded."""
8487
88 @defer.inlineCallbacks
85 def setUp(self):89 def setUp(self):
86 """Set up tests."""90 """Set up tests."""
87 super(TestEventsIPC, self).setUp()91 yield super(TestEventsIPC, self).setUp()
88 self.events_mock = self.mocker.mock()92 self.events_mock = self.mocker.mock()
89 self.events.events = self.events_mock93 self.events.events = self.events_mock
9094
@@ -100,9 +104,10 @@
100class TestSyncDaemonIPC(MockerTestCase, IPCTestCase):104class TestSyncDaemonIPC(MockerTestCase, IPCTestCase):
101 """Ensure that calls are correctly fowarded."""105 """Ensure that calls are correctly fowarded."""
102106
107 @defer.inlineCallbacks
103 def setUp(self):108 def setUp(self):
104 """Set up tests."""109 """Set up tests."""
105 super(TestSyncDaemonIPC, self).setUp()110 yield super(TestSyncDaemonIPC, self).setUp()
106 self.service = self.mocker.mock()111 self.service = self.mocker.mock()
107 self.sync.service = self.service112 self.sync.service = self.service
108113
@@ -174,9 +179,10 @@
174class TestFileSystemIPC(MockerTestCase, IPCTestCase):179class TestFileSystemIPC(MockerTestCase, IPCTestCase):
175 """Ensure that calls are correctly fowarded."""180 """Ensure that calls are correctly fowarded."""
176181
182 @defer.inlineCallbacks
177 def setUp(self):183 def setUp(self):
178 """Set up tests."""184 """Set up tests."""
179 super(TestFileSystemIPC, self).setUp()185 yield super(TestFileSystemIPC, self).setUp()
180 self.syncdaemon_filesystem = self.mocker.mock()186 self.syncdaemon_filesystem = self.mocker.mock()
181 self.fs.syncdaemon_filesystem = self.syncdaemon_filesystem187 self.fs.syncdaemon_filesystem = self.syncdaemon_filesystem
182188
@@ -221,9 +227,10 @@
221class TestSharesIPC(MockerTestCase, IPCTestCase):227class TestSharesIPC(MockerTestCase, IPCTestCase):
222 """Ensure that calls are correctly fowarded."""228 """Ensure that calls are correctly fowarded."""
223229
230 @defer.inlineCallbacks
224 def setUp(self):231 def setUp(self):
225 """Set up tests."""232 """Set up tests."""
226 super(TestSharesIPC, self).setUp()233 yield super(TestSharesIPC, self).setUp()
227 self.syncdaemon_shares = self.mocker.mock()234 self.syncdaemon_shares = self.mocker.mock()
228 self.shares.syncdaemon_shares = self.syncdaemon_shares235 self.shares.syncdaemon_shares = self.syncdaemon_shares
229236
@@ -316,9 +323,10 @@
316class TestConfigIPC(MockerTestCase, IPCTestCase):323class TestConfigIPC(MockerTestCase, IPCTestCase):
317 """Ensure that calls are correctly fowarded."""324 """Ensure that calls are correctly fowarded."""
318325
326 @defer.inlineCallbacks
319 def setUp(self):327 def setUp(self):
320 """Set up tests."""328 """Set up tests."""
321 super(TestConfigIPC, self).setUp()329 yield super(TestConfigIPC, self).setUp()
322 self.syncdaemon_config = self.mocker.mock()330 self.syncdaemon_config = self.mocker.mock()
323 self.config.syncdaemon_config = self.syncdaemon_config331 self.config.syncdaemon_config = self.syncdaemon_config
324332
@@ -467,9 +475,10 @@
467class TestFoldersIPC(MockerTestCase, IPCTestCase):475class TestFoldersIPC(MockerTestCase, IPCTestCase):
468 """Ensure that calls are correctly fowarded."""476 """Ensure that calls are correctly fowarded."""
469477
478 @defer.inlineCallbacks
470 def setUp(self):479 def setUp(self):
471 """Set up tests."""480 """Set up tests."""
472 super(TestFoldersIPC, self).setUp()481 yield super(TestFoldersIPC, self).setUp()
473 self.syncdaemon_folders = self.mocker.mock()482 self.syncdaemon_folders = self.mocker.mock()
474 self.folders.syncdaemon_folders = self.syncdaemon_folders483 self.folders.syncdaemon_folders = self.syncdaemon_folders
475484
@@ -528,9 +537,10 @@
528class TestPublicFilesIPC(MockerTestCase, IPCTestCase):537class TestPublicFilesIPC(MockerTestCase, IPCTestCase):
529 """Ensure that calls are correctly fowarded."""538 """Ensure that calls are correctly fowarded."""
530539
540 @defer.inlineCallbacks
531 def setUp(self):541 def setUp(self):
532 """Set up tests."""542 """Set up tests."""
533 super(TestPublicFilesIPC, self).setUp()543 yield super(TestPublicFilesIPC, self).setUp()
534 self.syncdaemon_public_files = self.mocker.mock()544 self.syncdaemon_public_files = self.mocker.mock()
535 self.public_files.syncdaemon_public_files =\545 self.public_files.syncdaemon_public_files =\
536 self.syncdaemon_public_files546 self.syncdaemon_public_files
537547
=== modified file 'tests/status/test_aggregator.py'
--- tests/status/test_aggregator.py 2011-07-27 13:27:22 +0000
+++ tests/status/test_aggregator.py 2011-11-07 18:03:24 +0000
@@ -50,8 +50,10 @@
5050
51 TIMEOUT = 3.051 TIMEOUT = 3.0
5252
53 @defer.inlineCallbacks
53 def setUp(self):54 def setUp(self):
54 """Initialize this test instance."""55 """Initialize this test instance."""
56 yield super(TimerTestCase, self).setUp()
55 self.clock = PatchedClock()57 self.clock = PatchedClock()
56 self.timer = aggregator.Timer(delay=3.0, clock=self.clock)58 self.timer = aggregator.Timer(delay=3.0, clock=self.clock)
5759
@@ -101,8 +103,10 @@
101103
102 DELAY = 0.5104 DELAY = 0.5
103105
106 @defer.inlineCallbacks
104 def setUp(self):107 def setUp(self):
105 """Initialize this test instance."""108 """Initialize this test instance."""
109 yield super(DeadlineTimerTestCase, self).setUp()
106 self.clock = PatchedClock()110 self.clock = PatchedClock()
107 self.timer = aggregator.DeadlineTimer(delay=0.5, timeout=3.0,111 self.timer = aggregator.DeadlineTimer(delay=0.5, timeout=3.0,
108 clock=self.clock)112 clock=self.clock)
@@ -242,8 +246,10 @@
242class ToggleableNotificationTestCase(TestCase):246class ToggleableNotificationTestCase(TestCase):
243 """Test the ToggleableNotification class."""247 """Test the ToggleableNotification class."""
244248
249 @defer.inlineCallbacks
245 def setUp(self):250 def setUp(self):
246 """Initialize this test instance."""251 """Initialize this test instance."""
252 yield super(ToggleableNotificationTestCase, self).setUp()
247 self.patch(aggregator, "Notification", FakeNotification)253 self.patch(aggregator, "Notification", FakeNotification)
248 self.notification_switch = aggregator.NotificationSwitch()254 self.notification_switch = aggregator.NotificationSwitch()
249 self.toggleable = self.notification_switch.get_notification()255 self.toggleable = self.notification_switch.get_notification()
@@ -282,8 +288,10 @@
282class NotificationSwitchTestCase(TestCase):288class NotificationSwitchTestCase(TestCase):
283 """Test the NotificationSwitch class."""289 """Test the NotificationSwitch class."""
284290
291 @defer.inlineCallbacks
285 def setUp(self):292 def setUp(self):
286 """Initialize this test instance."""293 """Initialize this test instance."""
294 yield super(NotificationSwitchTestCase, self).setUp()
287 self.notification_switch = aggregator.NotificationSwitch()295 self.notification_switch = aggregator.NotificationSwitch()
288296
289 def test_get_notification(self):297 def test_get_notification(self):
@@ -306,8 +314,10 @@
306class FileDiscoveryBubbleTestCase(TestCase):314class FileDiscoveryBubbleTestCase(TestCase):
307 """Test the FileDiscoveryBubble class."""315 """Test the FileDiscoveryBubble class."""
308316
317 @defer.inlineCallbacks
309 def setUp(self):318 def setUp(self):
310 """Initialize this test instance."""319 """Initialize this test instance."""
320 yield super(FileDiscoveryBubbleTestCase, self).setUp()
311 self.patch(aggregator, "ToggleableNotification",321 self.patch(aggregator, "ToggleableNotification",
312 FakeNotificationSingleton())322 FakeNotificationSingleton())
313 self.clock = PatchedClock()323 self.clock = PatchedClock()
@@ -487,8 +497,10 @@
487class FinalBubbleTestCase(TestCase):497class FinalBubbleTestCase(TestCase):
488 """Test for the final status notification bubble."""498 """Test for the final status notification bubble."""
489499
500 @defer.inlineCallbacks
490 def setUp(self):501 def setUp(self):
491 """Initialize this test instance."""502 """Initialize this test instance."""
503 yield super(FinalBubbleTestCase, self).setUp()
492 self.patch(aggregator, "ToggleableNotification",504 self.patch(aggregator, "ToggleableNotification",
493 FakeNotificationSingleton())505 FakeNotificationSingleton())
494 self.clock = PatchedClock()506 self.clock = PatchedClock()
@@ -542,8 +554,10 @@
542class ProgressBarTestCase(TestCase):554class ProgressBarTestCase(TestCase):
543 """Tests for the progress bar."""555 """Tests for the progress bar."""
544556
557 @defer.inlineCallbacks
545 def setUp(self):558 def setUp(self):
546 """Initialize this test instance."""559 """Initialize this test instance."""
560 yield super(ProgressBarTestCase, self).setUp()
547 self.patch(aggregator, "UbuntuOneLauncher", FakeLauncher)561 self.patch(aggregator, "UbuntuOneLauncher", FakeLauncher)
548 self.patch(aggregator.session, "Inhibitor", FakeInhibitor)562 self.patch(aggregator.session, "Inhibitor", FakeInhibitor)
549 self.clock = PatchedClock()563 self.clock = PatchedClock()
@@ -737,10 +751,10 @@
737 self.files_uploading.remove(command)751 self.files_uploading.remove(command)
738 self.queued_commands.discard(command)752 self.queued_commands.discard(command)
739753
740 def progress_made(self, share_id, node_id, n_bytes_written, deflated_size):754 def progress_made(self, share_id, node_id, n_bytes, deflated_size):
741 """Progress made on up- or download."""755 """Progress made on up- or download."""
742 self.progress_events.append(756 self.progress_events.append(
743 (share_id, node_id, n_bytes_written, deflated_size))757 (share_id, node_id, n_bytes, deflated_size))
744758
745 def connection_made(self):759 def connection_made(self):
746 """The client made the connection to the server."""760 """The client made the connection to the server."""
@@ -1033,8 +1047,10 @@
1033 CLASS_KWARGS = {}1047 CLASS_KWARGS = {}
1034 status = None1048 status = None
10351049
1050 @defer.inlineCallbacks
1036 def setUp(self):1051 def setUp(self):
1037 """Initialize this test instance."""1052 """Initialize this test instance."""
1053 yield super(StatusEventTestCase, self).setUp()
1038 if type(self) == StatusEventTestCase:1054 if type(self) == StatusEventTestCase:
1039 self.assertRaises(AssertionError, self.CLASS, **self.CLASS_KWARGS)1055 self.assertRaises(AssertionError, self.CLASS, **self.CLASS_KWARGS)
1040 else:1056 else:
@@ -1177,8 +1193,10 @@
1177class StatusAggregatorTestCase(TestCase):1193class StatusAggregatorTestCase(TestCase):
1178 """Test the backend of the status aggregator."""1194 """Test the backend of the status aggregator."""
11791195
1196 @defer.inlineCallbacks
1180 def setUp(self):1197 def setUp(self):
1181 """Initialize this test instance."""1198 """Initialize this test instance."""
1199 yield super(StatusAggregatorTestCase, self).setUp()
1182 self.patch(aggregator, "FileDiscoveryBubble",1200 self.patch(aggregator, "FileDiscoveryBubble",
1183 FakeFileDiscoveryBubble)1201 FakeFileDiscoveryBubble)
1184 self.patch(aggregator, "FinalStatusBubble",1202 self.patch(aggregator, "FinalStatusBubble",
11851203
=== modified file 'tests/syncdaemon/test_action_queue.py'
--- tests/syncdaemon/test_action_queue.py 2011-09-08 21:29:37 +0000
+++ tests/syncdaemon/test_action_queue.py 2011-11-07 18:03:24 +0000
@@ -104,11 +104,19 @@
104 return self.check(logger.NOTE, *msgs)104 return self.check(logger.NOTE, *msgs)
105105
106106
107class FakeMagicHash(object):
108 """Fake magic hash."""
109 _magic_hash = '666'
110
111
107class FakeTempFile(object):112class FakeTempFile(object):
108 """Fake temporary file."""113 """Fake temporary file."""
114
109 def __init__(self, tmpdir):115 def __init__(self, tmpdir):
116 self.closed = 0 # be able to count how may close calls we had
110 self.name = os.path.join(tmpdir, 'remove-me.zip')117 self.name = os.path.join(tmpdir, 'remove-me.zip')
111 open_file(self.name, 'w').close()118 open_file(self.name, 'w').close()
119 self.close = lambda: setattr(self, 'closed', self.closed + 1)
112120
113121
114class FakeCommand(object):122class FakeCommand(object):
@@ -181,7 +189,7 @@
181189
182class FakeRequest(object):190class FakeRequest(object):
183 """Fake Request."""191 """Fake Request."""
184 def __init__(self):192 def __init__(self, *a, **k):
185 self.deferred = defer.succeed(True)193 self.deferred = defer.succeed(True)
186 self.cancelled = False194 self.cancelled = False
187195
@@ -442,8 +450,10 @@
442class TestRequestQueue(TwistedTestCase):450class TestRequestQueue(TwistedTestCase):
443 """Tests for the RequestQueue."""451 """Tests for the RequestQueue."""
444452
453 @defer.inlineCallbacks
445 def setUp(self):454 def setUp(self):
446 """Set up."""455 """Set up."""
456 yield super(TestRequestQueue, self).setUp()
447457
448 class FakeAQ(object):458 class FakeAQ(object):
449 """Fake AQ."""459 """Fake AQ."""
@@ -765,8 +775,10 @@
765class TestDeferredMap(TwistedTestCase):775class TestDeferredMap(TwistedTestCase):
766 """Test the deferred map."""776 """Test the deferred map."""
767777
778 @defer.inlineCallbacks
768 def setUp(self):779 def setUp(self):
769 """Set up."""780 """Set up."""
781 yield super(TestDeferredMap, self).setUp()
770 self.dm = DeferredMap()782 self.dm = DeferredMap()
771783
772 def test_one_get_returns_stored_deferred(self):784 def test_one_get_returns_stored_deferred(self):
@@ -853,8 +865,10 @@
853class TestZipQueue(TwistedTestCase):865class TestZipQueue(TwistedTestCase):
854 """Test the zipping queue."""866 """Test the zipping queue."""
855867
868 @defer.inlineCallbacks
856 def setUp(self):869 def setUp(self):
857 """Set up."""870 """Set up."""
871 yield super(TestZipQueue, self).setUp()
858 self.zq = ZipQueue()872 self.zq = ZipQueue()
859873
860 @defer.inlineCallbacks874 @defer.inlineCallbacks
@@ -3053,9 +3067,7 @@
3053 def test_fileobj_in_run(self):3067 def test_fileobj_in_run(self):
3054 """Create it first time, reset after that."""3068 """Create it first time, reset after that."""
3055 # don't use the real protocol3069 # don't use the real protocol
3056 obj = Mocker().mock()3070 self.action_queue.client.get_content_request = FakeRequest
3057 obj.deferred
3058 self.action_queue.client.get_content_request = lambda *a, **k: obj
30593071
3060 class FakeFileObjFactory(object):3072 class FakeFileObjFactory(object):
3061 """Fake class to check behaviour."""3073 """Fake class to check behaviour."""
@@ -3099,10 +3111,6 @@
3099 """Init."""3111 """Init."""
3100 yield super(UploadUnconnectedTestCase, self).setUp()3112 yield super(UploadUnconnectedTestCase, self).setUp()
31013113
3102 class FakeMagicHash(object):
3103 """Fake magic hash."""
3104 _magic_hash = '666'
3105
3106 self.rq = request_queue = RequestQueue(action_queue=self.action_queue)3114 self.rq = request_queue = RequestQueue(action_queue=self.action_queue)
3107 self.command = Upload(request_queue, share_id='a_share_id',3115 self.command = Upload(request_queue, share_id='a_share_id',
3108 node_id='a_node_id', previous_hash='prev_hash',3116 node_id='a_node_id', previous_hash='prev_hash',
@@ -3116,6 +3124,7 @@
3116 def test_upload_progress_wrapper_setup(self):3124 def test_upload_progress_wrapper_setup(self):
3117 """Test the setting up of the progress wrapper in ._run()."""3125 """Test the setting up of the progress wrapper in ._run()."""
3118 self.command.action_queue.connect_in_progress = False3126 self.command.action_queue.connect_in_progress = False
3127 self.command.tempfile = StringIO()
3119 self.command._run()3128 self.command._run()
31203129
3121 self.assertEqual(len(self.client.called), 1)3130 self.assertEqual(len(self.client.called), 1)
@@ -3306,16 +3315,29 @@
3306 events = [('AQ_UPLOAD_ERROR', kwargs)]3315 events = [('AQ_UPLOAD_ERROR', kwargs)]
3307 self.assertEqual(events, self.command.action_queue.event_queue.events)3316 self.assertEqual(events, self.command.action_queue.event_queue.events)
33083317
3309 def test_handle_failure_removes_temp_file(self):3318 def test_finish_closes_temp_file(self):
3310 """Test temp file is removed on failure."""3319 """Test temp file is closed when the command finishes."""
3320 self.command.tempfile = FakeTempFile(self.tmpdir)
3321 assert self.command.tempfile.closed == 0
3322
3323 self.command.finish()
3324 self.assertEqual(1, self.command.tempfile.closed)
3325
3326 def test_finish_removes_temp_file(self):
3327 """Test temp file is removed when the command finishes."""
3311 self.command.tempfile = FakeTempFile(self.tmpdir)3328 self.command.tempfile = FakeTempFile(self.tmpdir)
3312 assert path_exists(self.command.tempfile.name)3329 assert path_exists(self.command.tempfile.name)
33133330
3314 msg = 'Something went wrong'3331 self.command.finish()
3315 failure = Failure(DefaultException(msg))
3316 self.command.handle_failure(failure=failure)
3317 self.assertFalse(path_exists(self.command.tempfile.name))3332 self.assertFalse(path_exists(self.command.tempfile.name))
33183333
3334 def test_finish_handles_temp_file_none(self):
3335 """Test temp file can be None when calling finish."""
3336 self.command.tempfile = None
3337
3338 self.command.finish()
3339 self.assertEqual(self.command.tempfile, None) # nothing changed
3340
3319 def test_retryable_failure_push_quota_exceeded_if_that_error(self):3341 def test_retryable_failure_push_quota_exceeded_if_that_error(self):
3320 """Test SYS_QUOTA_EXCEEDED is pushed on QuotaExceededError."""3342 """Test SYS_QUOTA_EXCEEDED is pushed on QuotaExceededError."""
3321 protocol_msg = protocol_pb2.Message()3343 protocol_msg = protocol_pb2.Message()
@@ -3641,6 +3663,18 @@
3641 tempfile = NamedTemporaryFile()3663 tempfile = NamedTemporaryFile()
3642 self.assertEqual(tempfile.mode, 'w+b')3664 self.assertEqual(tempfile.mode, 'w+b')
36433665
3666 def test_fileobj_in_run(self):
3667 """Create it first time, reset after that."""
3668 # don't use the real protocol or magic hash
3669 self.action_queue.client.put_content_request = FakeRequest
3670 self.command.magic_hash = FakeMagicHash()
3671
3672 called = []
3673 self.command.tempfile = StringIO()
3674 self.command.tempfile.seek = lambda *a: called.extend(a)
3675 self.command._run()
3676 self.assertEqual(called, [0])
3677
36443678
3645class CreateShareTestCase(ConnectedBaseTestCase):3679class CreateShareTestCase(ConnectedBaseTestCase):
3646 """Test for CreateShare ActionQueueCommand."""3680 """Test for CreateShare ActionQueueCommand."""
@@ -4919,8 +4953,10 @@
4919class ActionQueueProtocolTests(TwistedTestCase):4953class ActionQueueProtocolTests(TwistedTestCase):
4920 """Test the ACQ class."""4954 """Test the ACQ class."""
49214955
4956 @defer.inlineCallbacks
4922 def setUp(self):4957 def setUp(self):
4923 """Set up."""4958 """Set up."""
4959 yield super(ActionQueueProtocolTests, self).setUp()
4924 # create an AQP and put a factory to it4960 # create an AQP and put a factory to it
4925 self.aqp = ActionQueueProtocol()4961 self.aqp = ActionQueueProtocol()
4926 obj = Mocker().mock()4962 obj = Mocker().mock()
@@ -4932,8 +4968,10 @@
4932 self.handler.setLevel(logging.DEBUG)4968 self.handler.setLevel(logging.DEBUG)
4933 self.aqp.log.addHandler(self.handler)4969 self.aqp.log.addHandler(self.handler)
49344970
4971 @defer.inlineCallbacks
4935 def tearDown(self):4972 def tearDown(self):
4936 """Tear down."""4973 """Tear down."""
4974 yield super(ActionQueueProtocolTests, self).tearDown()
4937 self.aqp.log.removeHandler(self.handler)4975 self.aqp.log.removeHandler(self.handler)
4938 if self.aqp.ping_manager is not None:4976 if self.aqp.ping_manager is not None:
4939 self.aqp.ping_manager.stop()4977 self.aqp.ping_manager.stop()
@@ -5541,8 +5579,10 @@
5541class ConditionsLockerTests(TwistedTestCase):5579class ConditionsLockerTests(TwistedTestCase):
5542 """Test the ConditionsLocker."""5580 """Test the ConditionsLocker."""
55435581
5582 @defer.inlineCallbacks
5544 def setUp(self):5583 def setUp(self):
5545 """Set up."""5584 """Set up."""
5585 yield super(ConditionsLockerTests, self).setUp()
5546 self.cl = ConditionsLocker()5586 self.cl = ConditionsLocker()
55475587
5548 def test_get_locking_deferred_returns_deferred(self):5588 def test_get_locking_deferred_returns_deferred(self):
@@ -5664,8 +5704,11 @@
5664class PingManagerTestCase(TwistedTestCase):5704class PingManagerTestCase(TwistedTestCase):
5665 """Test the Ping manager."""5705 """Test the Ping manager."""
56665706
5707 @defer.inlineCallbacks
5667 def setUp(self):5708 def setUp(self):
5668 """Set up."""5709 """Set up."""
5710 yield super(PingManagerTestCase, self).setUp()
5711
5669 class FakeActionQueueProtocol(object):5712 class FakeActionQueueProtocol(object):
5670 """Fake object for the tests."""5713 """Fake object for the tests."""
5671 log = logging.getLogger("ubuntuone.SyncDaemon.ActionQueue")5714 log = logging.getLogger("ubuntuone.SyncDaemon.ActionQueue")
@@ -5677,8 +5720,10 @@
5677 self.fake_aqp.log.addHandler(self.handler)5720 self.fake_aqp.log.addHandler(self.handler)
5678 self.pm = PingManager(self.fake_aqp)5721 self.pm = PingManager(self.fake_aqp)
56795722
5723 @defer.inlineCallbacks
5680 def tearDown(self):5724 def tearDown(self):
5681 """Tear down."""5725 """Tear down."""
5726 yield super(PingManagerTestCase, self).tearDown()
5682 self.fake_aqp.log.removeHandler(self.handler)5727 self.fake_aqp.log.removeHandler(self.handler)
5683 self.pm.stop()5728 self.pm.stop()
56845729
56855730
=== modified file 'tests/syncdaemon/test_logger.py'
--- tests/syncdaemon/test_logger.py 2011-08-10 12:01:01 +0000
+++ tests/syncdaemon/test_logger.py 2011-11-07 18:03:24 +0000
@@ -20,6 +20,7 @@
2020
21import logging21import logging
2222
23from twisted.internet import defer
23from twisted.trial import unittest24from twisted.trial import unittest
2425
25from ubuntuone.devtools.handlers import MementoHandler26from ubuntuone.devtools.handlers import MementoHandler
@@ -39,15 +40,19 @@
39class DebugCaptureTest(unittest.TestCase):40class DebugCaptureTest(unittest.TestCase):
40 """Tests for DebugCapture context manager."""41 """Tests for DebugCapture context manager."""
4142
43 @defer.inlineCallbacks
42 def setUp(self):44 def setUp(self):
43 """Setup the logger and the handler"""45 """Setup the logger and the handler"""
46 yield super(DebugCaptureTest, self).setUp()
44 self.handler = MementoHandler()47 self.handler = MementoHandler()
45 self.logger = logging.getLogger(self.__class__.__name__)48 self.logger = logging.getLogger(self.__class__.__name__)
46 self.logger.addHandler(self.handler)49 self.logger.addHandler(self.handler)
47 self.logger.setLevel(logging.DEBUG)50 self.logger.setLevel(logging.DEBUG)
4851
52 @defer.inlineCallbacks
49 def tearDown(self):53 def tearDown(self):
50 """close the handler and restore the logger (Logger's are global)"""54 """close the handler and restore the logger (Logger's are global)"""
55 yield super(DebugCaptureTest, self).tearDown()
51 self.handler.close()56 self.handler.close()
52 self.logger.removeHandler(self.handler)57 self.logger.removeHandler(self.handler)
53 self.logger.setLevel(logging.DEBUG)58 self.logger.setLevel(logging.DEBUG)
@@ -222,8 +227,10 @@
222class FilterTests(unittest.TestCase):227class FilterTests(unittest.TestCase):
223 """Tests log filters"""228 """Tests log filters"""
224229
230 @defer.inlineCallbacks
225 def setUp(self):231 def setUp(self):
226 """Setup the logger and the handler"""232 """Setup the logger and the handler"""
233 yield super(FilterTests, self).setUp()
227 self.handler = MementoHandler()234 self.handler = MementoHandler()
228 self.handler.setLevel(logging.DEBUG)235 self.handler.setLevel(logging.DEBUG)
229 root_logger.addHandler(self.handler)236 root_logger.addHandler(self.handler)
@@ -253,15 +260,19 @@
253class MultiFilterTest(unittest.TestCase):260class MultiFilterTest(unittest.TestCase):
254 """Tests for logger.MultiFilter"""261 """Tests for logger.MultiFilter"""
255262
263 @defer.inlineCallbacks
256 def setUp(self):264 def setUp(self):
257 """Setup the logger and the handler"""265 """Setup the logger and the handler"""
266 yield super(MultiFilterTest, self).setUp()
258 self.handler = MementoHandler()267 self.handler = MementoHandler()
259 self.logger = logging.getLogger(self.__class__.__name__)268 self.logger = logging.getLogger(self.__class__.__name__)
260 self.logger.addHandler(self.handler)269 self.logger.addHandler(self.handler)
261 self.logger.setLevel(logging.DEBUG)270 self.logger.setLevel(logging.DEBUG)
262271
272 @defer.inlineCallbacks
263 def tearDown(self):273 def tearDown(self):
264 """close the handler and restore the logger (Logger's are global)"""274 """close the handler and restore the logger (Logger's are global)"""
275 yield super(MultiFilterTest, self).tearDown()
265 self.handler.close()276 self.handler.close()
266 self.logger.removeHandler(self.handler)277 self.logger.removeHandler(self.handler)
267 self.logger.setLevel(logging.DEBUG)278 self.logger.setLevel(logging.DEBUG)
268279
=== modified file 'tests/syncdaemon/test_pathlockingtree.py'
--- tests/syncdaemon/test_pathlockingtree.py 2011-01-20 21:27:24 +0000
+++ tests/syncdaemon/test_pathlockingtree.py 2011-11-07 18:03:24 +0000
@@ -29,8 +29,10 @@
29class InternalDeferredTests(TwistedTestCase):29class InternalDeferredTests(TwistedTestCase):
30 """Test the internal deferreds handling functionality."""30 """Test the internal deferreds handling functionality."""
3131
32 @defer.inlineCallbacks
32 def setUp(self):33 def setUp(self):
33 """Set up."""34 """Set up."""
35 yield super(InternalDeferredTests, self).setUp()
34 self.plt = PathLockingTree()36 self.plt = PathLockingTree()
3537
36 def test_single_element_old(self):38 def test_single_element_old(self):
@@ -217,8 +219,10 @@
217class LockingTests(TwistedTestCase):219class LockingTests(TwistedTestCase):
218 """Test the locking between elements."""220 """Test the locking between elements."""
219221
222 @defer.inlineCallbacks
220 def setUp(self):223 def setUp(self):
221 """Set up."""224 """Set up."""
225 yield super(LockingTests, self).setUp()
222 self.plt = PathLockingTree()226 self.plt = PathLockingTree()
223227
224 @defer.inlineCallbacks228 @defer.inlineCallbacks
@@ -417,8 +421,10 @@
417class CleaningTests(TwistedTestCase):421class CleaningTests(TwistedTestCase):
418 """Test that the releases clean the tree."""422 """Test that the releases clean the tree."""
419423
424 @defer.inlineCallbacks
420 def setUp(self):425 def setUp(self):
421 """Set up."""426 """Set up."""
427 yield super(CleaningTests, self).setUp()
422 self.plt = PathLockingTree()428 self.plt = PathLockingTree()
423429
424 @defer.inlineCallbacks430 @defer.inlineCallbacks
@@ -547,8 +553,10 @@
547class LoggingTests(TwistedTestCase):553class LoggingTests(TwistedTestCase):
548 """Test the logging."""554 """Test the logging."""
549555
556 @defer.inlineCallbacks
550 def setUp(self):557 def setUp(self):
551 """Set up."""558 """Set up."""
559 yield super(LoggingTests, self).setUp()
552 self.plt = PathLockingTree()560 self.plt = PathLockingTree()
553561
554 self.handler = MementoHandler()562 self.handler = MementoHandler()
555563
=== modified file 'tests/syncdaemon/test_states.py'
--- tests/syncdaemon/test_states.py 2011-01-18 20:25:54 +0000
+++ tests/syncdaemon/test_states.py 2011-11-07 18:03:24 +0000
@@ -107,7 +107,9 @@
107class Base(TwistedTestCase):107class Base(TwistedTestCase):
108 """Base class for state tests."""108 """Base class for state tests."""
109109
110 @defer.inlineCallbacks
110 def setUp(self):111 def setUp(self):
112 yield super(Base, self).setUp()
111 # create fake classes113 # create fake classes
112 self.eq = FakeEventQueue()114 self.eq = FakeEventQueue()
113 self.aq = FakeActionQueue()115 self.aq = FakeActionQueue()
@@ -157,15 +159,18 @@
157 reactor.callLater(.1, check, 0)159 reactor.callLater(.1, check, 0)
158 return d160 return d
159161
162 @defer.inlineCallbacks
160 def tearDown(self):163 def tearDown(self):
164 yield super(Base, self).tearDown()
161 self.sm.connection.shutdown()165 self.sm.connection.shutdown()
162166
163167
164class QueueBase(Base):168class QueueBase(Base):
165 """Basic setup for QueueManager."""169 """Basic setup for QueueManager."""
166170
171 @defer.inlineCallbacks
167 def setUp(self):172 def setUp(self):
168 Base.setUp(self)173 yield super(QueueBase, self).setUp()
169 self.sm.state = StateManager.QUEUE_MANAGER174 self.sm.state = StateManager.QUEUE_MANAGER
170175
171176
@@ -223,8 +228,9 @@
223class TestConnectionManager(Base):228class TestConnectionManager(Base):
224 """Test the "internal network" transitions."""229 """Test the "internal network" transitions."""
225230
231 @defer.inlineCallbacks
226 def setUp(self):232 def setUp(self):
227 Base.setUp(self)233 yield super(TestConnectionManager, self).setUp()
228234
229 # put SM on some state that does not generate further235 # put SM on some state that does not generate further
230 # transition-related efforts for this CM236 # transition-related efforts for this CM
@@ -341,8 +347,9 @@
341class TestConnectionManagerTimings(Base):347class TestConnectionManagerTimings(Base):
342 """Times handled by ConnectionManager."""348 """Times handled by ConnectionManager."""
343349
350 @defer.inlineCallbacks
344 def setUp(self):351 def setUp(self):
345 Base.setUp(self)352 yield super(TestConnectionManagerTimings, self).setUp()
346353
347 # set timeout values to really low, to make tests run quicker354 # set timeout values to really low, to make tests run quicker
348 self.sm.connection.handshake_timeout = 0355 self.sm.connection.handshake_timeout = 0
@@ -843,8 +850,10 @@
843class TestStateManagerPassToNetworkManager(Base):850class TestStateManagerPassToNetworkManager(Base):
844 """All network events should go to NetworkManager."""851 """All network events should go to NetworkManager."""
845852
853 @defer.inlineCallbacks
846 def setUp(self):854 def setUp(self):
847 Base.setUp(self)855 yield super(TestStateManagerPassToNetworkManager,
856 self).setUp()
848857
849 # put a function in the middle to log calls858 # put a function in the middle to log calls
850 self.called_events = []859 self.called_events = []
@@ -893,8 +902,10 @@
893class TestStateManagerPassToQueueManager(Base):902class TestStateManagerPassToQueueManager(Base):
894 """All queue events should go to QueueManager."""903 """All queue events should go to QueueManager."""
895904
905 @defer.inlineCallbacks
896 def setUp(self):906 def setUp(self):
897 Base.setUp(self)907 yield super(TestStateManagerPassToQueueManager,
908 self).setUp()
898909
899 # put a function in the middle to log calls910 # put a function in the middle to log calls
900 self.called_events = []911 self.called_events = []
901912
=== modified file 'tests/syncdaemon/test_status_listener.py'
--- tests/syncdaemon/test_status_listener.py 2011-08-05 15:50:52 +0000
+++ tests/syncdaemon/test_status_listener.py 2011-11-07 18:03:24 +0000
@@ -96,9 +96,10 @@
96class StatusListenerTestCase(FakeMainTestCase):96class StatusListenerTestCase(FakeMainTestCase):
97 """Tests for StatusListener."""97 """Tests for StatusListener."""
9898
99 @defer.inlineCallbacks
99 def setUp(self):100 def setUp(self):
100 """Initialize this instance."""101 """Initialize this instance."""
101 super(StatusListenerTestCase, self).setUp()102 yield super(StatusListenerTestCase, self).setUp()
102 self.status_frontend = FakeStatusFrontend()103 self.status_frontend = FakeStatusFrontend()
103 self.listener = status_listener.StatusListener(self.fs, self.vm,104 self.listener = status_listener.StatusListener(self.fs, self.vm,
104 self.status_frontend)105 self.status_frontend)
105106
=== modified file 'ubuntuone/syncdaemon/action_queue.py'
--- ubuntuone/syncdaemon/action_queue.py 2011-09-08 21:41:00 +0000
+++ ubuntuone/syncdaemon/action_queue.py 2011-11-07 18:03:24 +0000
@@ -37,7 +37,7 @@
37import zlib37import zlib
3838
39from collections import deque, defaultdict39from collections import deque, defaultdict
40from functools import wraps, partial40from functools import partial
41from urllib import urlencode41from urllib import urlencode
42from urllib2 import urlopen, Request, HTTPError42from urllib2 import urlopen, Request, HTTPError
43from urlparse import urljoin43from urlparse import urljoin
@@ -72,18 +72,7 @@
72EREGEX = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"72EREGEX = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"
7373
74# progress threshold to emit a download/upload progress event: 64Kb74# progress threshold to emit a download/upload progress event: 64Kb
75TRANSFER_PROGRESS_THRESHOLD = 64*1024*102475TRANSFER_PROGRESS_THRESHOLD = 64 * 1024 * 1024
76
77def passit(func):
78 """Pass the value on for the next deferred, while calling func with it."""
79
80 @wraps(func)
81 def wrapper(a):
82 """Do it."""
83 func(a)
84 return a
85
86 return wrapper
8776
8877
89class DeferredInterrupted(Exception):78class DeferredInterrupted(Exception):
@@ -116,7 +105,6 @@
116 self.errback(DeferredInterrupted())105 self.errback(DeferredInterrupted())
117106
118107
119
120class PathLockingTree(object):108class PathLockingTree(object):
121 """Tree that stores deferreds in the nodes."""109 """Tree that stores deferreds in the nodes."""
122110
@@ -214,7 +202,6 @@
214 node, element = branch.pop()202 node, element = branch.pop()
215 del node['children_nodes'][element]203 del node['children_nodes'][element]
216204
217
218 # finally, log and release the deferred205 # finally, log and release the deferred
219 logger.debug("pathlock releasing %s; remaining: %d", elements,206 logger.debug("pathlock releasing %s; remaining: %d", elements,
220 self.count)207 self.count)
@@ -250,8 +237,8 @@
250 return ('start - processMessage: id: %s, type: %s',237 return ('start - processMessage: id: %s, type: %s',
251 message.id, message.type)238 message.id, message.type)
252 elif message.type == protocol_pb2.Message.PUT_CONTENT:239 elif message.type == protocol_pb2.Message.PUT_CONTENT:
253 lines = [ line for line in str(message).split("\n")240 lines = [line for line in str(message).split("\n")
254 if not line.strip().startswith("magic_hash:") ]241 if not line.strip().startswith("magic_hash:")]
255 return ('start - processMessage: %s',242 return ('start - processMessage: %s',
256 " ".join(lines))243 " ".join(lines))
257 else:244 else:
@@ -461,12 +448,8 @@
461 magic_hasher.update(data)448 magic_hasher.update(data)
462 upload.deflated_size = f.tell()449 upload.deflated_size = f.tell()
463450
464 # keep the file open, but reset its position
465 # to zero, ready to be read later
466 f.seek(0)
467
468 upload.magic_hash = magic_hasher.content_hash()451 upload.magic_hash = magic_hasher.content_hash()
469 except Exception, e: # pylint: disable-msg=W0703452 except Exception, e: # pylint: disable-msg=W0703
470 failed = True453 failed = True
471 reactor.callFromThread(deferred.errback, e)454 reactor.callFromThread(deferred.errback, e)
472 finally:455 finally:
@@ -705,10 +688,10 @@
705 self.token = None688 self.token = None
706 self.consumer = None689 self.consumer = None
707690
708 self.client = None # an instance of self.protocol691 self.client = None # an instance of self.protocol
709692
710 # is a twisted.internet.tcp/ssl.Connector instance693 # is a twisted.internet.tcp/ssl.Connector instance
711 self.connector = None # created on reactor.connectTCP/SSL694 self.connector = None # created on reactor.connectTCP/SSL
712 # we need to track down if a connection is in progress695 # we need to track down if a connection is in progress
713 # to avoid double connections696 # to avoid double connections
714 self.connect_in_progress = False697 self.connect_in_progress = False
@@ -1029,8 +1012,8 @@
1029 @defer.inlineCallbacks1012 @defer.inlineCallbacks
1030 def authenticate(self):1013 def authenticate(self):
1031 """Authenticate against the server using stored credentials."""1014 """Authenticate against the server using stored credentials."""
1032 metadata = {'version':clientdefs.VERSION,1015 metadata = {'version': clientdefs.VERSION,
1033 'platform':platform}1016 'platform': platform}
1034 authenticate_d = self._send_request_and_handle_errors(1017 authenticate_d = self._send_request_and_handle_errors(
1035 request=self.client.oauth_authenticate,1018 request=self.client.oauth_authenticate,
1036 request_error=protocol_errors.AuthenticationFailedError,1019 request_error=protocol_errors.AuthenticationFailedError,
@@ -2078,7 +2061,6 @@
2078 self.log = mklog(logger, 'GetDeltaFromScratch', self.volume_id, None)2061 self.log = mklog(logger, 'GetDeltaFromScratch', self.volume_id, None)
20792062
20802063
2081
2082class ChangePublicAccess(ActionQueueCommand):2064class ChangePublicAccess(ActionQueueCommand):
2083 """Change the public access of a file."""2065 """Change the public access of a file."""
20842066
@@ -2498,6 +2480,11 @@
24982480
2499 def finish(self):2481 def finish(self):
2500 """Release the semaphore if already acquired."""2482 """Release the semaphore if already acquired."""
2483 if self.tempfile is not None:
2484 # clean the temporary file
2485 self.tempfile.close()
2486 remove_file(self.tempfile.name)
2487
2501 if self.tx_semaphore is not None:2488 if self.tx_semaphore is not None:
2502 self.tx_semaphore = self.tx_semaphore.release()2489 self.tx_semaphore = self.tx_semaphore.release()
2503 self.log.debug('semaphore released')2490 self.log.debug('semaphore released')
@@ -2509,7 +2496,7 @@
2509 share_id=self.share_id,2496 share_id=self.share_id,
2510 node_id=self.node_id,2497 node_id=self.node_id,
2511 hash=self.hash)2498 hash=self.hash)
25122499 self.tempfile.seek(0)
2513 f = UploadProgressWrapper(self.tempfile, self)2500 f = UploadProgressWrapper(self.tempfile, self)
25142501
2515 # access here the magic hash value, don't log anywhere, and2502 # access here the magic hash value, don't log anywhere, and
@@ -2521,9 +2508,7 @@
2521 upload_id=self.upload_id, upload_id_cb=self._upload_id_cb,2508 upload_id=self.upload_id, upload_id_cb=self._upload_id_cb,
2522 magic_hash=magic_hash)2509 magic_hash=magic_hash)
2523 self.upload_req = req2510 self.upload_req = req
2524 d = req.deferred2511 return req.deferred
2525 d.addBoth(passit(lambda _: self.tempfile.close()))
2526 return d
25272512
2528 def _upload_id_cb(self, upload_id):2513 def _upload_id_cb(self, upload_id):
2529 """Handle the received upload_id, save it in the metadata."""2514 """Handle the received upload_id, save it in the metadata."""
@@ -2545,9 +2530,6 @@
25452530
2546 def handle_success(self, request):2531 def handle_success(self, request):
2547 """It worked! Push the event."""2532 """It worked! Push the event."""
2548 # remove the temporary file
2549 remove_file(self.tempfile.name)
2550
2551 # send the event2533 # send the event
2552 d = dict(share_id=self.share_id, node_id=self.node_id, hash=self.hash,2534 d = dict(share_id=self.share_id, node_id=self.node_id, hash=self.hash,
2553 new_generation=request.new_generation)2535 new_generation=request.new_generation)
@@ -2563,7 +2545,6 @@
25632545
2564 def handle_failure(self, failure):2546 def handle_failure(self, failure):
2565 """It didn't work! Push the event."""2547 """It didn't work! Push the event."""
2566 remove_file(self.tempfile.name)
2567 self.action_queue.event_queue.push('AQ_UPLOAD_ERROR',2548 self.action_queue.event_queue.push('AQ_UPLOAD_ERROR',
2568 error=failure.getErrorMessage(),2549 error=failure.getErrorMessage(),
2569 share_id=self.share_id,2550 share_id=self.share_id,

Subscribers

People subscribed via source and target branches