Merge lp:~facundo/ubuntuone-client/simple-auth into lp:ubuntuone-client
- simple-auth
- Merge into trunk
Proposed by
Facundo Batista
Status: | Superseded |
---|---|
Proposed branch: | lp:~facundo/ubuntuone-client/simple-auth |
Merge into: | lp:ubuntuone-client |
Diff against target: |
1298 lines (+178/-256) 9 files modified
bin/ubuntuone-syncdaemon (+15/-13) contrib/testing/testcase.py (+5/-8) data/syncdaemon.conf (+2/-2) tests/syncdaemon/test_action_queue.py (+68/-73) tests/syncdaemon/test_interaction_interfaces.py (+25/-54) tests/syncdaemon/test_main.py (+2/-2) ubuntuone/syncdaemon/action_queue.py (+42/-68) ubuntuone/syncdaemon/interaction_interfaces.py (+11/-28) ubuntuone/syncdaemon/main.py (+8/-8) |
To merge this branch: | bzr merge lp:~facundo/ubuntuone-client/simple-auth |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Roberto Alsina (community) | Approve | ||
Review via email: mp+259441@code.launchpad.net |
This proposal has been superseded by a proposal from 2015-05-20.
Commit message
Simple authentication.
Description of the change
Simple authentication.
To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) : | # |
review:
Approve
Unmerged revisions
- 1406. By Facundo Batista
-
Simple authentication.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'bin/ubuntuone-syncdaemon' | |||
2 | --- bin/ubuntuone-syncdaemon 2013-01-28 17:43:24 +0000 | |||
3 | +++ bin/ubuntuone-syncdaemon 2015-05-18 21:26:35 +0000 | |||
4 | @@ -1,6 +1,6 @@ | |||
5 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/python |
6 | 2 | # | 2 | # |
8 | 3 | # Copyright 2009-2013 Canonical Ltd. | 3 | # Copyright 2009-2015 Canonical Ltd. |
9 | 4 | # | 4 | # |
10 | 5 | # This program is free software: you can redistribute it and/or modify it | 5 | # This program is free software: you can redistribute it and/or modify it |
11 | 6 | # under the terms of the GNU General Public License version 3, as published | 6 | # under the terms of the GNU General Public License version 3, as published |
12 | @@ -88,7 +88,7 @@ | |||
13 | 88 | 88 | ||
14 | 89 | 89 | ||
15 | 90 | def main(argv): | 90 | def main(argv): |
17 | 91 | """ client entry point. """ | 91 | """Client entry point.""" |
18 | 92 | args = argv[1:] | 92 | args = argv[1:] |
19 | 93 | usage = "Usage: %prog [config file] [extra config files] [options] " | 93 | usage = "Usage: %prog [config file] [extra config files] [options] " |
20 | 94 | configs = [] | 94 | configs = [] |
21 | @@ -97,7 +97,7 @@ | |||
22 | 97 | if len(configs) == 0: | 97 | if len(configs) == 0: |
23 | 98 | configs.extend(get_config_files()) | 98 | configs.extend(get_config_files()) |
24 | 99 | (parser, options, argv) = config.configglue(file(configs[0]), *configs[1:], | 99 | (parser, options, argv) = config.configglue(file(configs[0]), *configs[1:], |
26 | 100 | args=args, usage=usage) | 100 | args=args, usage=usage) |
27 | 101 | d = async_main(parser, options, argv) | 101 | d = async_main(parser, options, argv) |
28 | 102 | d.addErrback(check_death) | 102 | d.addErrback(check_death) |
29 | 103 | d.addErrback(logger.root_logger.exception) | 103 | d.addErrback(logger.root_logger.exception) |
30 | @@ -202,16 +202,17 @@ | |||
31 | 202 | assert isinstance(options.shares_dir, str) | 202 | assert isinstance(options.shares_dir, str) |
32 | 203 | assert isinstance(options.data_dir, str) | 203 | assert isinstance(options.data_dir, str) |
33 | 204 | 204 | ||
40 | 205 | # check if we have oauth credentials | 205 | # check if we have auth credentials |
41 | 206 | oauth_credentials = None | 206 | auth_credentials = None |
42 | 207 | if options.oauth: | 207 | if options.auth: |
43 | 208 | values = options.oauth.split(':') | 208 | values = options.auth.split(':') |
44 | 209 | if len(values) == 4 or len(values) == 2: | 209 | if len(values) == 2: |
45 | 210 | oauth_credentials = values | 210 | auth_credentials = dict(zip(('username', 'password'), values)) |
46 | 211 | else: | 211 | else: |
50 | 212 | msg = "--oauth requires a key and secret together in the form " \ | 212 | parser.error( |
51 | 213 | "[CONSUMER_KEY:CONSUMER_SECRET:]KEY:SECRET" | 213 | "--auth requires a username and password together " |
52 | 214 | parser.error(msg) | 214 | "in the form USERNAME:PASSWORD" |
53 | 215 | ) | ||
54 | 215 | 216 | ||
55 | 216 | # check which file monitor to use | 217 | # check which file monitor to use |
56 | 217 | monitor_class = yield get_filemonitor_class(options.fs_monitor) | 218 | monitor_class = yield get_filemonitor_class(options.fs_monitor) |
57 | @@ -228,12 +229,13 @@ | |||
58 | 228 | write_limit=options.bandwidth_throttling_write_limit, | 229 | write_limit=options.bandwidth_throttling_write_limit, |
59 | 229 | throttling_enabled=options.bandwidth_throttling_on, | 230 | throttling_enabled=options.bandwidth_throttling_on, |
60 | 230 | ignore_files=options.ignore, | 231 | ignore_files=options.ignore, |
62 | 231 | oauth_credentials=oauth_credentials, | 232 | auth_credentials=auth_credentials, |
63 | 232 | monitor_class=monitor_class) | 233 | monitor_class=monitor_class) |
64 | 233 | 234 | ||
65 | 234 | # override the reactor default signal handlers in order to | 235 | # override the reactor default signal handlers in order to |
66 | 235 | # shutdown properly | 236 | # shutdown properly |
67 | 236 | atexit.register(reactor.callFromThread, main.quit) | 237 | atexit.register(reactor.callFromThread, main.quit) |
68 | 238 | |||
69 | 237 | def install_handlers(): | 239 | def install_handlers(): |
70 | 238 | """ install our custom signal handler. """ | 240 | """ install our custom signal handler. """ |
71 | 239 | def handler(signum, frame): | 241 | def handler(signum, frame): |
72 | 240 | 242 | ||
73 | === modified file 'contrib/testing/testcase.py' | |||
74 | --- contrib/testing/testcase.py 2013-02-20 22:41:12 +0000 | |||
75 | +++ contrib/testing/testcase.py 2015-05-18 21:26:35 +0000 | |||
76 | @@ -1,6 +1,6 @@ | |||
77 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
78 | 2 | # | 2 | # |
80 | 3 | # Copyright 2009-2012 Canonical Ltd. | 3 | # Copyright 2009-2015 Canonical Ltd. |
81 | 4 | # | 4 | # |
82 | 5 | # This program is free software: you can redistribute it and/or modify it | 5 | # This program is free software: you can redistribute it and/or modify it |
83 | 6 | # under the terms of the GNU General Public License version 3, as published | 6 | # under the terms of the GNU General Public License version 3, as published |
84 | @@ -73,11 +73,8 @@ | |||
85 | 73 | 73 | ||
86 | 74 | logger.init() | 74 | logger.init() |
87 | 75 | 75 | ||
93 | 76 | FAKED_CREDENTIALS = {'consumer_key': 'faked_consumer_key', | 76 | FAKED_CREDENTIALS = {'username': 'test_username', |
94 | 77 | 'consumer_secret': 'faked_consumer_secret', | 77 | 'password': 'test_password'} |
90 | 78 | 'token': 'faked_token', | ||
91 | 79 | 'token_secret': 'faked_token_secret', | ||
92 | 80 | 'token_name': 'Test me please'} | ||
95 | 81 | 78 | ||
96 | 82 | 79 | ||
97 | 83 | @contextlib.contextmanager | 80 | @contextlib.contextmanager |
98 | @@ -425,7 +422,7 @@ | |||
99 | 425 | 422 | ||
100 | 426 | # use the config from the branch | 423 | # use the config from the branch |
101 | 427 | new_get_config_files = lambda: [os.path.join(os.environ['ROOTDIR'], | 424 | new_get_config_files = lambda: [os.path.join(os.environ['ROOTDIR'], |
103 | 428 | 'data', 'syncdaemon.conf')] | 425 | 'data', 'syncdaemon.conf')] |
104 | 429 | self.patch(config, 'get_config_files', new_get_config_files) | 426 | self.patch(config, 'get_config_files', new_get_config_files) |
105 | 430 | 427 | ||
106 | 431 | # fake a very basic config file with sane defaults for the tests | 428 | # fake a very basic config file with sane defaults for the tests |
107 | @@ -724,4 +721,4 @@ | |||
108 | 724 | 721 | ||
109 | 725 | skip_if_darwin_missing_fs_event = \ | 722 | skip_if_darwin_missing_fs_event = \ |
110 | 726 | skipIfOS('darwin', 'Fails due to missing/out of order FS events, ' | 723 | skipIfOS('darwin', 'Fails due to missing/out of order FS events, ' |
112 | 727 | 'see bug #820598.') | 724 | 'see bug #820598.') |
113 | 728 | 725 | ||
114 | === modified file 'data/syncdaemon.conf' | |||
115 | --- data/syncdaemon.conf 2012-10-23 20:54:03 +0000 | |||
116 | +++ data/syncdaemon.conf 2015-05-18 21:26:35 +0000 | |||
117 | @@ -31,8 +31,8 @@ | |||
118 | 31 | data_dir.parser = xdg_data | 31 | data_dir.parser = xdg_data |
119 | 32 | data_dir.help = Use the specified directory to store the metadata | 32 | data_dir.help = Use the specified directory to store the metadata |
120 | 33 | 33 | ||
123 | 34 | oauth.help = Explicitly provide OAuth credentials. You can either provide the 4 values (consumer key and secret, plus the key and secret), or just the last two (key and secret). | 34 | auth.help = Explicitly provide Auth credentials (username and password) |
124 | 35 | oauth.metavar = [CONSUMER_KEY:CONSUMER_SECRET:]KEY:SECRET | 35 | auth.metavar = USERNAME:PASSWORD |
125 | 36 | 36 | ||
126 | 37 | debug.default = False | 37 | debug.default = False |
127 | 38 | debug.action = store_true | 38 | debug.action = store_true |
128 | 39 | 39 | ||
129 | === modified file 'tests/syncdaemon/test_action_queue.py' | |||
130 | --- tests/syncdaemon/test_action_queue.py 2013-02-04 21:33:35 +0000 | |||
131 | +++ tests/syncdaemon/test_action_queue.py 2015-05-18 21:26:35 +0000 | |||
132 | @@ -1,6 +1,6 @@ | |||
133 | 1 | #-*- coding: utf-8 -*- | 1 | #-*- coding: utf-8 -*- |
134 | 2 | # | 2 | # |
136 | 3 | # Copyright 2009-2012 Canonical Ltd. | 3 | # Copyright 2009-2015 Canonical Ltd. |
137 | 4 | # | 4 | # |
138 | 5 | # This program is free software: you can redistribute it and/or modify it | 5 | # This program is free software: you can redistribute it and/or modify it |
139 | 6 | # under the terms of the GNU General Public License version 3, as published | 6 | # under the terms of the GNU General Public License version 3, as published |
140 | @@ -45,7 +45,6 @@ | |||
141 | 45 | import OpenSSL.SSL | 45 | import OpenSSL.SSL |
142 | 46 | 46 | ||
143 | 47 | from mocker import Mocker, MockerTestCase, ANY, expect | 47 | from mocker import Mocker, MockerTestCase, ANY, expect |
144 | 48 | from oauthlib.oauth1 import Client | ||
145 | 49 | from twisted.internet import defer, reactor | 48 | from twisted.internet import defer, reactor |
146 | 50 | from twisted.internet import error as twisted_error | 49 | from twisted.internet import error as twisted_error |
147 | 51 | from twisted.python.failure import DefaultException, Failure | 50 | from twisted.python.failure import DefaultException, Failure |
148 | @@ -263,7 +262,7 @@ | |||
149 | 263 | events = [x[0] for x in self.factory.event_queue.events] | 262 | events = [x[0] for x in self.factory.event_queue.events] |
150 | 264 | assert 'SYS_CONNECTION_MADE' in events | 263 | assert 'SYS_CONNECTION_MADE' in events |
151 | 265 | 264 | ||
153 | 266 | self.factory.event_queue.events = [] # reset events | 265 | self.factory.event_queue.events = [] # reset events |
154 | 267 | if hasattr(self, 'testing_deferred'): | 266 | if hasattr(self, 'testing_deferred'): |
155 | 268 | self.testing_deferred.callback(True) | 267 | self.testing_deferred.callback(True) |
156 | 269 | 268 | ||
157 | @@ -324,10 +323,8 @@ | |||
158 | 324 | 323 | ||
159 | 325 | def user_connect(self): | 324 | def user_connect(self): |
160 | 326 | """User requested to connect to server.""" | 325 | """User requested to connect to server.""" |
165 | 327 | token = {'token': 'bla', 'token_secret': 'ble', | 326 | auth_info = dict(username='test_username', password='test_password') |
166 | 328 | 'consumer_key': 'foo', 'consumer_secret': 'bar'} | 327 | self.action_queue.event_queue.push('SYS_USER_CONNECT', access_token=auth_info) |
163 | 329 | self.action_queue.event_queue.push('SYS_USER_CONNECT', | ||
164 | 330 | access_token=token) | ||
167 | 331 | 328 | ||
168 | 332 | 329 | ||
169 | 333 | class BasicTests(BasicTestCase): | 330 | class BasicTests(BasicTestCase): |
170 | @@ -1228,6 +1225,7 @@ | |||
171 | 1228 | orig = self.action_queue.client.connectionLost | 1225 | orig = self.action_queue.client.connectionLost |
172 | 1229 | 1226 | ||
173 | 1230 | d = defer.Deferred() | 1227 | d = defer.Deferred() |
174 | 1228 | |||
175 | 1231 | def faked_connectionLost(reason): | 1229 | def faked_connectionLost(reason): |
176 | 1232 | """Receive connection lost and fire tearDown.""" | 1230 | """Receive connection lost and fire tearDown.""" |
177 | 1233 | orig(reason) | 1231 | orig(reason) |
178 | @@ -1262,7 +1260,8 @@ | |||
179 | 1262 | yield self._connect_factory() | 1260 | yield self._connect_factory() |
180 | 1263 | 1261 | ||
181 | 1264 | assert self.action_queue.connector is not None | 1262 | assert self.action_queue.connector is not None |
183 | 1265 | assert self.action_queue.connect_in_progress == True | 1263 | assert self.action_queue.connect_in_progress |
184 | 1264 | |||
185 | 1266 | # double connect, it returns None instead of a Deferred | 1265 | # double connect, it returns None instead of a Deferred |
186 | 1267 | result = self.action_queue.connect() | 1266 | result = self.action_queue.connect() |
187 | 1268 | self.assertTrue(result is None, 'not connecting again') | 1267 | self.assertTrue(result is None, 'not connecting again') |
188 | @@ -1274,7 +1273,7 @@ | |||
189 | 1274 | """self.action_queue.connector.disconnect was called.""" | 1273 | """self.action_queue.connector.disconnect was called.""" |
190 | 1275 | yield self._connect_factory() | 1274 | yield self._connect_factory() |
191 | 1276 | 1275 | ||
193 | 1277 | self.action_queue.event_queue.events = [] # cleanup events | 1276 | self.action_queue.event_queue.events = [] # cleanup events |
194 | 1278 | assert self.action_queue.connector.state == 'connected' | 1277 | assert self.action_queue.connector.state == 'connected' |
195 | 1279 | self.action_queue.disconnect() | 1278 | self.action_queue.disconnect() |
196 | 1280 | 1279 | ||
197 | @@ -1297,6 +1296,7 @@ | |||
198 | 1297 | orig = self.action_queue.clientConnectionFailed | 1296 | orig = self.action_queue.clientConnectionFailed |
199 | 1298 | 1297 | ||
200 | 1299 | d = defer.Deferred() | 1298 | d = defer.Deferred() |
201 | 1299 | |||
202 | 1300 | def faked_clientConnectionFailed(connector, reason): | 1300 | def faked_clientConnectionFailed(connector, reason): |
203 | 1301 | """Receive connection failed and check.""" | 1301 | """Receive connection failed and check.""" |
204 | 1302 | orig(connector, reason) | 1302 | orig(connector, reason) |
205 | @@ -1331,6 +1331,7 @@ | |||
206 | 1331 | orig = self.action_queue.clientConnectionLost | 1331 | orig = self.action_queue.clientConnectionLost |
207 | 1332 | 1332 | ||
208 | 1333 | d = defer.Deferred() | 1333 | d = defer.Deferred() |
209 | 1334 | |||
210 | 1334 | def faked_clientConnectionLost(connector, reason): | 1335 | def faked_clientConnectionLost(connector, reason): |
211 | 1335 | """Receive connection lost and check.""" | 1336 | """Receive connection lost and check.""" |
212 | 1336 | orig(connector, reason) | 1337 | orig(connector, reason) |
213 | @@ -1502,14 +1503,14 @@ | |||
214 | 1502 | volume = FakedVolume() | 1503 | volume = FakedVolume() |
215 | 1503 | self.action_queue._volume_created_callback(volume) | 1504 | self.action_queue._volume_created_callback(volume) |
216 | 1504 | self.assertEqual([('SV_VOLUME_CREATED', {'volume': volume})], | 1505 | self.assertEqual([('SV_VOLUME_CREATED', {'volume': volume})], |
218 | 1505 | self.action_queue.event_queue.events) | 1506 | self.action_queue.event_queue.events) |
219 | 1506 | 1507 | ||
220 | 1507 | def test_volume_deleted_push_event(self): | 1508 | def test_volume_deleted_push_event(self): |
221 | 1508 | """Volume deleted callback push proper event.""" | 1509 | """Volume deleted callback push proper event.""" |
222 | 1509 | volume_id = VOLUME | 1510 | volume_id = VOLUME |
223 | 1510 | self.action_queue._volume_deleted_callback(volume_id) | 1511 | self.action_queue._volume_deleted_callback(volume_id) |
224 | 1511 | self.assertEqual([('SV_VOLUME_DELETED', {'volume_id': volume_id})], | 1512 | self.assertEqual([('SV_VOLUME_DELETED', {'volume_id': volume_id})], |
226 | 1512 | self.action_queue.event_queue.events) | 1513 | self.action_queue.event_queue.events) |
227 | 1513 | 1514 | ||
228 | 1514 | def test_volume_new_generation_push_event_root(self): | 1515 | def test_volume_new_generation_push_event_root(self): |
229 | 1515 | """Volume New Generation callback push proper event with root.""" | 1516 | """Volume New Generation callback push proper event with root.""" |
230 | @@ -1540,7 +1541,7 @@ | |||
231 | 1540 | self.assertEqual(('volume',), EVENTS['SV_VOLUME_CREATED']) | 1541 | self.assertEqual(('volume',), EVENTS['SV_VOLUME_CREATED']) |
232 | 1541 | self.assertEqual(('volume_id',), EVENTS['SV_VOLUME_DELETED']) | 1542 | self.assertEqual(('volume_id',), EVENTS['SV_VOLUME_DELETED']) |
233 | 1542 | self.assertEqual(('volume_id', 'node_id', 'marker'), | 1543 | self.assertEqual(('volume_id', 'node_id', 'marker'), |
235 | 1543 | EVENTS['AQ_CREATE_UDF_OK']) | 1544 | EVENTS['AQ_CREATE_UDF_OK']) |
236 | 1544 | self.assertEqual(('error', 'marker'), EVENTS['AQ_CREATE_UDF_ERROR']) | 1545 | self.assertEqual(('error', 'marker'), EVENTS['AQ_CREATE_UDF_ERROR']) |
237 | 1545 | self.assertEqual(('volumes',), EVENTS['AQ_LIST_VOLUMES']) | 1546 | self.assertEqual(('volumes',), EVENTS['AQ_LIST_VOLUMES']) |
238 | 1546 | self.assertEqual(('error',), EVENTS['AQ_LIST_VOLUMES_ERROR']) | 1547 | self.assertEqual(('error',), EVENTS['AQ_LIST_VOLUMES_ERROR']) |
239 | @@ -1845,7 +1846,7 @@ | |||
240 | 1845 | called = [] | 1846 | called = [] |
241 | 1846 | self.cmd.run = lambda: defer.succeed(True) | 1847 | self.cmd.run = lambda: defer.succeed(True) |
242 | 1847 | self.cmd._acquire_pathlock = lambda: defer.succeed( | 1848 | self.cmd._acquire_pathlock = lambda: defer.succeed( |
244 | 1848 | lambda: called.append(True)) | 1849 | lambda: called.append(True)) |
245 | 1849 | 1850 | ||
246 | 1850 | self.cmd.go() | 1851 | self.cmd.go() |
247 | 1851 | self.assertTrue(called) | 1852 | self.assertTrue(called) |
248 | @@ -1856,7 +1857,7 @@ | |||
249 | 1856 | called = [] | 1857 | called = [] |
250 | 1857 | self.cmd.run = lambda: defer.fail(ValueError("error message")) | 1858 | self.cmd.run = lambda: defer.fail(ValueError("error message")) |
251 | 1858 | self.cmd._acquire_pathlock = lambda: defer.succeed( | 1859 | self.cmd._acquire_pathlock = lambda: defer.succeed( |
253 | 1859 | lambda: called.append(True)) | 1860 | lambda: called.append(True)) |
254 | 1860 | 1861 | ||
255 | 1861 | yield self.cmd.go() | 1862 | yield self.cmd.go() |
256 | 1862 | self.assertTrue(called) | 1863 | self.assertTrue(called) |
257 | @@ -2146,7 +2147,7 @@ | |||
258 | 2146 | def test_finish_running(self): | 2147 | def test_finish_running(self): |
259 | 2147 | """Set running to False when finish.""" | 2148 | """Set running to False when finish.""" |
260 | 2148 | self.cmd.running = True | 2149 | self.cmd.running = True |
262 | 2149 | self.rq.unqueue = lambda c: None # don't do anything | 2150 | self.rq.unqueue = lambda c: None # don't do anything |
263 | 2150 | self.cmd.finish() | 2151 | self.cmd.finish() |
264 | 2151 | self.assertFalse(self.cmd.running) | 2152 | self.assertFalse(self.cmd.running) |
265 | 2152 | 2153 | ||
266 | @@ -2192,7 +2193,7 @@ | |||
267 | 2192 | 2193 | ||
268 | 2193 | def test_cancel_releases_conditions(self): | 2194 | def test_cancel_releases_conditions(self): |
269 | 2194 | """Cancel calls the conditions locker for the command.""" | 2195 | """Cancel calls the conditions locker for the command.""" |
271 | 2195 | self.cmd.finish = lambda: None # don't try to unqueue! | 2196 | self.cmd.finish = lambda: None # don't try to unqueue! |
272 | 2196 | d = self.action_queue.conditions_locker.get_lock(self.cmd) | 2197 | d = self.action_queue.conditions_locker.get_lock(self.cmd) |
273 | 2197 | self.cmd.cancel() | 2198 | self.cmd.cancel() |
274 | 2198 | self.assertTrue(d.called) | 2199 | self.assertTrue(d.called) |
275 | @@ -2300,7 +2301,7 @@ | |||
276 | 2300 | failure = Failure(DefaultException(msg)) | 2301 | failure = Failure(DefaultException(msg)) |
277 | 2301 | self.command.handle_failure(failure=failure) | 2302 | self.command.handle_failure(failure=failure) |
278 | 2302 | events = [('AQ_CREATE_UDF_ERROR', | 2303 | events = [('AQ_CREATE_UDF_ERROR', |
280 | 2303 | {'error': msg, 'marker': self.marker})] | 2304 | {'error': msg, 'marker': self.marker})] |
281 | 2304 | self.assertEqual(events, self.command.action_queue.event_queue.events) | 2305 | self.assertEqual(events, self.command.action_queue.event_queue.events) |
282 | 2305 | 2306 | ||
283 | 2306 | def test_path_locking(self): | 2307 | def test_path_locking(self): |
284 | @@ -2714,8 +2715,8 @@ | |||
285 | 2714 | node_id = uuid.uuid4() | 2715 | node_id = uuid.uuid4() |
286 | 2715 | nodekey = '%s' % (base64.urlsafe_b64encode(node_id.bytes).strip("=")) | 2716 | nodekey = '%s' % (base64.urlsafe_b64encode(node_id.bytes).strip("=")) |
287 | 2716 | node_id_2 = uuid.uuid4() | 2717 | node_id_2 = uuid.uuid4() |
290 | 2717 | nodekey_2 = '%s' % (base64.urlsafe_b64encode( | 2718 | nodekey_2 = '%s' % ( |
291 | 2718 | node_id_2.bytes).strip("=")) | 2719 | base64.urlsafe_b64encode(node_id_2.bytes).strip("=")) |
292 | 2719 | volume_id = uuid.uuid4() | 2720 | volume_id = uuid.uuid4() |
293 | 2720 | 2721 | ||
294 | 2721 | def check_webcall(request_iri, method=None): | 2722 | def check_webcall(request_iri, method=None): |
295 | @@ -2743,10 +2744,10 @@ | |||
296 | 2743 | 2744 | ||
297 | 2744 | def test_handle_success_push_event(self): | 2745 | def test_handle_success_push_event(self): |
298 | 2745 | """Test AQ_PUBLIC_FILES_LIST_OK is pushed on success.""" | 2746 | """Test AQ_PUBLIC_FILES_LIST_OK is pushed on success.""" |
300 | 2746 | response = [{'node_id': uuid.uuid4(), 'volume_id':None, | 2747 | response = [{'node_id': uuid.uuid4(), 'volume_id': None, |
301 | 2747 | 'public_url': 'http://example.com'}] | 2748 | 'public_url': 'http://example.com'}] |
302 | 2748 | self.command.handle_success(success=response) | 2749 | self.command.handle_success(success=response) |
304 | 2749 | event = ('AQ_PUBLIC_FILES_LIST_OK', {'public_files': response,}) | 2750 | event = ('AQ_PUBLIC_FILES_LIST_OK', {'public_files': response}) |
305 | 2750 | self.assertIn(event, self.command.action_queue.event_queue.events) | 2751 | self.assertIn(event, self.command.action_queue.event_queue.events) |
306 | 2751 | 2752 | ||
307 | 2752 | def test_handle_failure_push_event(self): | 2753 | def test_handle_failure_push_event(self): |
308 | @@ -2789,8 +2790,8 @@ | |||
309 | 2789 | self.test_path = os.path.join(self.root, 'file') | 2790 | self.test_path = os.path.join(self.root, 'file') |
310 | 2790 | self.mdid = self.main.fs.create(self.test_path, '') | 2791 | self.mdid = self.main.fs.create(self.test_path, '') |
311 | 2791 | self.command = Download(request_queue, share_id='a_share_id', | 2792 | self.command = Download(request_queue, share_id='a_share_id', |
314 | 2792 | node_id='a_node_id', server_hash='server_hash', | 2793 | node_id='a_node_id', server_hash='server_hash', |
315 | 2793 | mdid=self.mdid) | 2794 | mdid=self.mdid) |
316 | 2794 | self.command.make_logger() | 2795 | self.command.make_logger() |
317 | 2795 | 2796 | ||
318 | 2796 | def test_progress_information_setup(self): | 2797 | def test_progress_information_setup(self): |
319 | @@ -2861,7 +2862,7 @@ | |||
320 | 2861 | self.assertEqual(self.command.n_bytes_read, 0) | 2862 | self.assertEqual(self.command.n_bytes_read, 0) |
321 | 2862 | self.assertEqual(self.command.n_bytes_read_last, 0) | 2863 | self.assertEqual(self.command.n_bytes_read_last, 0) |
322 | 2863 | self.command.node_attr_cb( | 2864 | self.command.node_attr_cb( |
324 | 2864 | deflated_size = TRANSFER_PROGRESS_THRESHOLD * 2) | 2865 | deflated_size=TRANSFER_PROGRESS_THRESHOLD * 2) |
325 | 2865 | 2866 | ||
326 | 2866 | self.command.downloaded_cb('x' * 5) | 2867 | self.command.downloaded_cb('x' * 5) |
327 | 2867 | events = self.command.action_queue.event_queue.events | 2868 | events = self.command.action_queue.event_queue.events |
328 | @@ -3085,7 +3086,7 @@ | |||
329 | 3085 | lambda n, s: FakeFileObj()) | 3086 | lambda n, s: FakeFileObj()) |
330 | 3086 | test_path = os.path.join(self.root, 'foo', 'bar') | 3087 | test_path = os.path.join(self.root, 'foo', 'bar') |
331 | 3087 | mdid = self.main.fs.create(test_path, '') | 3088 | mdid = self.main.fs.create(test_path, '') |
333 | 3088 | cmd = Download(self.rq, 'a_share_id','a_node_id', 'server_hash', | 3089 | cmd = Download(self.rq, 'a_share_id', 'a_node_id', 'server_hash', |
334 | 3089 | mdid) | 3090 | mdid) |
335 | 3090 | 3091 | ||
336 | 3091 | # first run, it is just instantiated | 3092 | # first run, it is just instantiated |
337 | @@ -3178,7 +3179,7 @@ | |||
338 | 3178 | 3179 | ||
339 | 3179 | def test_reset(self): | 3180 | def test_reset(self): |
340 | 3180 | """Reset the values at start.""" | 3181 | """Reset the values at start.""" |
342 | 3181 | f = StringIO("x" * 10 + "y" * 5) | 3182 | f = StringIO("x" * 10 + "y" * 5) |
343 | 3182 | cmd = FakeCommand() | 3183 | cmd = FakeCommand() |
344 | 3183 | 3184 | ||
345 | 3184 | # first time | 3185 | # first time |
346 | @@ -3206,7 +3207,7 @@ | |||
347 | 3206 | """Count how many times it was called.""" | 3207 | """Count how many times it was called.""" |
348 | 3207 | innerself._progress_hook_called += 1 | 3208 | innerself._progress_hook_called += 1 |
349 | 3208 | 3209 | ||
351 | 3209 | f = StringIO("x" * 10 + "y" * 5) | 3210 | f = StringIO("x" * 10 + "y" * 5) |
352 | 3210 | cmd = FakeCommand() | 3211 | cmd = FakeCommand() |
353 | 3211 | upw = UploadProgressWrapper(f, cmd) | 3212 | upw = UploadProgressWrapper(f, cmd) |
354 | 3212 | 3213 | ||
355 | @@ -3416,7 +3417,7 @@ | |||
356 | 3416 | self.command.progress_hook() | 3417 | self.command.progress_hook() |
357 | 3417 | kwargs = {'share_id': self.command.share_id, 'node_id': 'a_node_id', | 3418 | kwargs = {'share_id': self.command.share_id, 'node_id': 'a_node_id', |
358 | 3418 | 'deflated_size': 2*TRANSFER_PROGRESS_THRESHOLD, | 3419 | 'deflated_size': 2*TRANSFER_PROGRESS_THRESHOLD, |
360 | 3419 | 'n_bytes_written': 5+TRANSFER_PROGRESS_THRESHOLD } | 3420 | 'n_bytes_written': 5+TRANSFER_PROGRESS_THRESHOLD} |
361 | 3420 | events = [('AQ_UPLOAD_FILE_PROGRESS', kwargs)] | 3421 | events = [('AQ_UPLOAD_FILE_PROGRESS', kwargs)] |
362 | 3421 | self.assertEqual(events, self.command.action_queue.event_queue.events) | 3422 | self.assertEqual(events, self.command.action_queue.event_queue.events) |
363 | 3422 | self.assertEqual(self.command.n_bytes_written_last, | 3423 | self.assertEqual(self.command.n_bytes_written_last, |
364 | @@ -3747,8 +3748,8 @@ | |||
365 | 3747 | 3748 | ||
366 | 3748 | self.patch(CreateShare, "_create_share_http", check_create_http) | 3749 | self.patch(CreateShare, "_create_share_http", check_create_http) |
367 | 3749 | command = CreateShare(self.request_queue, 'node_id', | 3750 | command = CreateShare(self.request_queue, 'node_id', |
370 | 3750 | 'share_to@example.com', 'share_name', | 3751 | 'share_to@example.com', 'share_name', |
371 | 3751 | ACCESS_LEVEL_RW, 'marker', 'path') | 3752 | ACCESS_LEVEL_RW, 'marker', 'path') |
372 | 3752 | self.assertTrue(command.use_http, 'CreateShare should be in http mode') | 3753 | self.assertTrue(command.use_http, 'CreateShare should be in http mode') |
373 | 3753 | 3754 | ||
374 | 3754 | command._run() | 3755 | command._run() |
375 | @@ -3770,8 +3771,8 @@ | |||
376 | 3770 | 3771 | ||
377 | 3771 | self.patch(CreateShare, "_create_share_http", check_create_http) | 3772 | self.patch(CreateShare, "_create_share_http", check_create_http) |
378 | 3772 | command = CreateShare(self.request_queue, 'node_id', | 3773 | command = CreateShare(self.request_queue, 'node_id', |
381 | 3773 | 'share_to@example.com', 'share_name', | 3774 | 'share_to@example.com', 'share_name', |
382 | 3774 | ACCESS_LEVEL_RO, 'marker', 'path') | 3775 | ACCESS_LEVEL_RO, 'marker', 'path') |
383 | 3775 | self.assertTrue(command.use_http, 'CreateShare should be in http mode') | 3776 | self.assertTrue(command.use_http, 'CreateShare should be in http mode') |
384 | 3776 | command._run() | 3777 | command._run() |
385 | 3777 | node_id, user, name, read_only = yield d | 3778 | node_id, user, name, read_only = yield d |
386 | @@ -3804,7 +3805,7 @@ | |||
387 | 3804 | cmd.use_http = True | 3805 | cmd.use_http = True |
388 | 3805 | cmd.handle_success(mock_success) | 3806 | cmd.handle_success(mock_success) |
389 | 3806 | 3807 | ||
391 | 3807 | event_params = { 'marker': marker_id } | 3808 | event_params = {'marker': marker_id} |
392 | 3808 | events = [('AQ_SHARE_INVITATION_SENT', event_params)] | 3809 | events = [('AQ_SHARE_INVITATION_SENT', event_params)] |
393 | 3809 | self.assertEqual(events, cmd.action_queue.event_queue.events) | 3810 | self.assertEqual(events, cmd.action_queue.event_queue.events) |
394 | 3810 | 3811 | ||
395 | @@ -3856,6 +3857,7 @@ | |||
396 | 3856 | def test_run_calls_protocol(self): | 3857 | def test_run_calls_protocol(self): |
397 | 3857 | """Test protocol's delete_volume is called.""" | 3858 | """Test protocol's delete_volume is called.""" |
398 | 3858 | self.called = False | 3859 | self.called = False |
399 | 3860 | |||
400 | 3859 | def check(share_id): | 3861 | def check(share_id): |
401 | 3860 | """Take control over client's feature.""" | 3862 | """Take control over client's feature.""" |
402 | 3861 | self.called = True | 3863 | self.called = True |
403 | @@ -3888,6 +3890,7 @@ | |||
404 | 3888 | """Check the API of AQ.query_volumes.""" | 3890 | """Check the API of AQ.query_volumes.""" |
405 | 3889 | self.main.start() | 3891 | self.main.start() |
406 | 3890 | d = defer.Deferred() | 3892 | d = defer.Deferred() |
407 | 3893 | |||
408 | 3891 | def list_volumes(): | 3894 | def list_volumes(): |
409 | 3892 | """Fake list_volumes.""" | 3895 | """Fake list_volumes.""" |
410 | 3893 | result = DummyClass() | 3896 | result = DummyClass() |
411 | @@ -3897,6 +3900,7 @@ | |||
412 | 3897 | self.action_queue.client = DummyClass() | 3900 | self.action_queue.client = DummyClass() |
413 | 3898 | self.action_queue.client.list_volumes = list_volumes | 3901 | self.action_queue.client.list_volumes = list_volumes |
414 | 3899 | d = self.action_queue.query_volumes() | 3902 | d = self.action_queue.query_volumes() |
415 | 3903 | |||
416 | 3900 | def check(result): | 3904 | def check(result): |
417 | 3901 | self.assertIn('foo', result) | 3905 | self.assertIn('foo', result) |
418 | 3902 | self.assertIn('bar', result) | 3906 | self.assertIn('bar', result) |
419 | @@ -3923,7 +3927,7 @@ | |||
420 | 3923 | def test_have_sufficient_space_for_upload_if_no_free_space(self): | 3927 | def test_have_sufficient_space_for_upload_if_no_free_space(self): |
421 | 3924 | """Check have_sufficient_space_for_upload pushes SYS_QUOTA_EXCEEDED.""" | 3928 | """Check have_sufficient_space_for_upload pushes SYS_QUOTA_EXCEEDED.""" |
422 | 3925 | self.patch(self.action_queue.main.vm, 'get_free_space', | 3929 | self.patch(self.action_queue.main.vm, 'get_free_space', |
424 | 3926 | lambda share_id: 0) # no free space, always | 3930 | lambda share_id: 0) # no free space, always |
425 | 3927 | volume_id = 'test share' | 3931 | volume_id = 'test share' |
426 | 3928 | res = self.action_queue.have_sufficient_space_for_upload(volume_id, | 3932 | res = self.action_queue.have_sufficient_space_for_upload(volume_id, |
427 | 3929 | upload_size=1) | 3933 | upload_size=1) |
428 | @@ -3936,7 +3940,7 @@ | |||
429 | 3936 | def test_have_sufficient_space_for_upload_if_free_space(self): | 3940 | def test_have_sufficient_space_for_upload_if_free_space(self): |
430 | 3937 | """Check have_sufficient_space_for_upload doesn't push any event.""" | 3941 | """Check have_sufficient_space_for_upload doesn't push any event.""" |
431 | 3938 | self.patch(self.action_queue.main.vm, 'get_free_space', | 3942 | self.patch(self.action_queue.main.vm, 'get_free_space', |
433 | 3939 | lambda share_id: 1) # free space, always | 3943 | lambda share_id: 1) # free space, always |
434 | 3940 | res = self.action_queue.have_sufficient_space_for_upload(share_id=None, | 3944 | res = self.action_queue.have_sufficient_space_for_upload(share_id=None, |
435 | 3941 | upload_size=0) | 3945 | upload_size=0) |
436 | 3942 | self.assertEqual(res, True, "Must have enough space to upload.") | 3946 | self.assertEqual(res, True, "Must have enough space to upload.") |
437 | @@ -3957,20 +3961,10 @@ | |||
438 | 3957 | 3961 | ||
439 | 3958 | def test_handle_SYS_USER_CONNECT(self): | 3962 | def test_handle_SYS_USER_CONNECT(self): |
440 | 3959 | """handle_SYS_USER_CONNECT stores credentials.""" | 3963 | """handle_SYS_USER_CONNECT stores credentials.""" |
444 | 3960 | self.assertEqual(self.action_queue.token, None) | 3964 | self.assertEqual(self.action_queue.credentials, {}) |
442 | 3961 | self.assertEqual(self.action_queue.consumer, None) | ||
443 | 3962 | |||
445 | 3963 | self.user_connect() | 3965 | self.user_connect() |
456 | 3964 | 3966 | self.assertEqual(self.action_queue.credentials, | |
457 | 3965 | expected = Client('bla', 'ble', 'foo', 'bar') | 3967 | {'password': 'test_password', 'username': 'test_username'}) |
448 | 3966 | |||
449 | 3967 | self.assertEqual(self.action_queue.token.key, expected.client_key) | ||
450 | 3968 | self.assertEqual(self.action_queue.token.secret, | ||
451 | 3969 | expected.client_secret) | ||
452 | 3970 | self.assertEqual(self.action_queue.consumer.key, | ||
453 | 3971 | expected.resource_owner_key) | ||
454 | 3972 | self.assertEqual(self.action_queue.consumer.secret, | ||
455 | 3973 | expected.resource_owner_secret) | ||
458 | 3974 | 3968 | ||
459 | 3975 | 3969 | ||
460 | 3976 | class SpecificException(Exception): | 3970 | class SpecificException(Exception): |
461 | @@ -4036,7 +4030,7 @@ | |||
462 | 4036 | """_send_request_and_handle_errors is correct when no error.""" | 4030 | """_send_request_and_handle_errors is correct when no error.""" |
463 | 4037 | 4031 | ||
464 | 4038 | event = 'SYS_SPECIFIC_OK' | 4032 | event = 'SYS_SPECIFIC_OK' |
466 | 4039 | EVENTS[event] = () # add event to the global valid events list | 4033 | EVENTS[event] = () # add event to the global valid events list |
467 | 4040 | self.addCleanup(EVENTS.pop, event) | 4034 | self.addCleanup(EVENTS.pop, event) |
468 | 4041 | 4035 | ||
469 | 4042 | result = object() | 4036 | result = object() |
470 | @@ -4080,7 +4074,7 @@ | |||
471 | 4080 | """_send_request_and_handle_errors is correct when expected error.""" | 4074 | """_send_request_and_handle_errors is correct when expected error.""" |
472 | 4081 | 4075 | ||
473 | 4082 | event = 'SYS_SPECIFIC_ERROR' | 4076 | event = 'SYS_SPECIFIC_ERROR' |
475 | 4083 | EVENTS[event] = ('error',) # add event to the global valid events list | 4077 | EVENTS[event] = ('error',) # add event to the global valid events list |
476 | 4084 | self.addCleanup(EVENTS.pop, event) | 4078 | self.addCleanup(EVENTS.pop, event) |
477 | 4085 | 4079 | ||
478 | 4086 | exc = SpecificException('The request failed! please be happy.') | 4080 | exc = SpecificException('The request failed! please be happy.') |
479 | @@ -4268,7 +4262,7 @@ | |||
480 | 4268 | 4262 | ||
481 | 4269 | request = self.fail_please(exc) | 4263 | request = self.fail_please(exc) |
482 | 4270 | kwargs = dict(request=request, request_error=SpecificException, | 4264 | kwargs = dict(request=request, request_error=SpecificException, |
484 | 4271 | event_error='BAR', event_ok='FOO') | 4265 | event_error='BAR', event_ok='FOO') |
485 | 4272 | d = self.action_queue._send_request_and_handle_errors(**kwargs) | 4266 | d = self.action_queue._send_request_and_handle_errors(**kwargs) |
486 | 4273 | yield d | 4267 | yield d |
487 | 4274 | 4268 | ||
488 | @@ -4306,7 +4300,7 @@ | |||
489 | 4306 | """Change AQ's client while doing the request.""" | 4300 | """Change AQ's client while doing the request.""" |
490 | 4307 | self.action_queue.client = object() | 4301 | self.action_queue.client = object() |
491 | 4308 | 4302 | ||
493 | 4309 | self.action_queue.event_queue.events = [] # event cleanup | 4303 | self.action_queue.event_queue.events = [] # event cleanup |
494 | 4310 | kwargs = dict(request=change_client, request_error=SpecificException, | 4304 | kwargs = dict(request=change_client, request_error=SpecificException, |
495 | 4311 | event_error='BAR', event_ok='FOO') | 4305 | event_error='BAR', event_ok='FOO') |
496 | 4312 | d = self.action_queue._send_request_and_handle_errors(**kwargs) | 4306 | d = self.action_queue._send_request_and_handle_errors(**kwargs) |
497 | @@ -4345,7 +4339,7 @@ | |||
498 | 4345 | event = ('SYS_SET_CAPABILITIES_ERROR', {'error': msg}) | 4339 | event = ('SYS_SET_CAPABILITIES_ERROR', {'error': msg}) |
499 | 4346 | self.assertEqual(event, self.action_queue.event_queue.events[-1]) | 4340 | self.assertEqual(event, self.action_queue.event_queue.events[-1]) |
500 | 4347 | self.assertNotIn(('SYS_SET_CAPABILITIES_OK', {}), | 4341 | self.assertNotIn(('SYS_SET_CAPABILITIES_OK', {}), |
502 | 4348 | self.action_queue.event_queue.events) | 4342 | self.action_queue.event_queue.events) |
503 | 4349 | 4343 | ||
504 | 4350 | @defer.inlineCallbacks | 4344 | @defer.inlineCallbacks |
505 | 4351 | def test_set_capabilities_when_set_caps_not_accepted(self): | 4345 | def test_set_capabilities_when_set_caps_not_accepted(self): |
506 | @@ -4361,7 +4355,7 @@ | |||
507 | 4361 | event = ('SYS_SET_CAPABILITIES_ERROR', {'error': msg}) | 4355 | event = ('SYS_SET_CAPABILITIES_ERROR', {'error': msg}) |
508 | 4362 | self.assertEqual(event, self.action_queue.event_queue.events[-1]) | 4356 | self.assertEqual(event, self.action_queue.event_queue.events[-1]) |
509 | 4363 | self.assertNotIn(('SYS_SET_CAPABILITIES_OK', {}), | 4357 | self.assertNotIn(('SYS_SET_CAPABILITIES_OK', {}), |
511 | 4364 | self.action_queue.event_queue.events) | 4358 | self.action_queue.event_queue.events) |
512 | 4365 | 4359 | ||
513 | 4366 | @defer.inlineCallbacks | 4360 | @defer.inlineCallbacks |
514 | 4367 | def test_set_capabilities_when_client_is_none(self): | 4361 | def test_set_capabilities_when_client_is_none(self): |
515 | @@ -4374,7 +4368,7 @@ | |||
516 | 4374 | event = ('SYS_SET_CAPABILITIES_ERROR', {'error': msg}) | 4368 | event = ('SYS_SET_CAPABILITIES_ERROR', {'error': msg}) |
517 | 4375 | self.assertEqual(event, self.action_queue.event_queue.events[-1]) | 4369 | self.assertEqual(event, self.action_queue.event_queue.events[-1]) |
518 | 4376 | self.assertNotIn(('SYS_SET_CAPABILITIES_OK', {}), | 4370 | self.assertNotIn(('SYS_SET_CAPABILITIES_OK', {}), |
520 | 4377 | self.action_queue.event_queue.events) | 4371 | self.action_queue.event_queue.events) |
521 | 4378 | 4372 | ||
522 | 4379 | @defer.inlineCallbacks | 4373 | @defer.inlineCallbacks |
523 | 4380 | def test_set_capabilities_when_set_caps_is_accepted(self): | 4374 | def test_set_capabilities_when_set_caps_is_accepted(self): |
524 | @@ -4394,7 +4388,7 @@ | |||
525 | 4394 | request = client.Authenticate(self.action_queue.client, | 4388 | request = client.Authenticate(self.action_queue.client, |
526 | 4395 | {'dummy_token': 'credentials'}) | 4389 | {'dummy_token': 'credentials'}) |
527 | 4396 | request.session_id = str(uuid.uuid4()) | 4390 | request.session_id = str(uuid.uuid4()) |
529 | 4397 | self.action_queue.client.oauth_authenticate = \ | 4391 | self.action_queue.client.simple_authenticate = \ |
530 | 4398 | self.succeed_please(result=request) | 4392 | self.succeed_please(result=request) |
531 | 4399 | yield self.action_queue.authenticate() | 4393 | yield self.action_queue.authenticate() |
532 | 4400 | event = ('SYS_AUTH_OK', {}) | 4394 | event = ('SYS_AUTH_OK', {}) |
533 | @@ -4410,7 +4404,7 @@ | |||
534 | 4410 | msg.error.comment = 'This is a funny comment.' | 4404 | msg.error.comment = 'This is a funny comment.' |
535 | 4411 | exc = errors.AuthenticationFailedError(request=None, message=msg) | 4405 | exc = errors.AuthenticationFailedError(request=None, message=msg) |
536 | 4412 | 4406 | ||
538 | 4413 | self.action_queue.client.oauth_authenticate = self.fail_please(exc) | 4407 | self.action_queue.client.simple_authenticate = self.fail_please(exc) |
539 | 4414 | yield self.action_queue.authenticate() | 4408 | yield self.action_queue.authenticate() |
540 | 4415 | event = ('SYS_AUTH_ERROR', {'error': str(exc)}) | 4409 | event = ('SYS_AUTH_ERROR', {'error': str(exc)}) |
541 | 4416 | self.assertEqual(event, self.action_queue.event_queue.events[-1]) | 4410 | self.assertEqual(event, self.action_queue.event_queue.events[-1]) |
542 | @@ -4773,7 +4767,7 @@ | |||
543 | 4773 | self.patch(PathLockingTree, 'acquire', | 4767 | self.patch(PathLockingTree, 'acquire', |
544 | 4774 | lambda s, *a, **k: t.extend((a, k))) | 4768 | lambda s, *a, **k: t.extend((a, k))) |
545 | 4775 | cmd = Unlink(self.rq, VOLUME, 'parent_id', 'node_id', | 4769 | cmd = Unlink(self.rq, VOLUME, 'parent_id', 'node_id', |
547 | 4776 | os.path.join('foo','bar'), False) | 4770 | os.path.join('foo', 'bar'), False) |
548 | 4777 | cmd._acquire_pathlock() | 4771 | cmd._acquire_pathlock() |
549 | 4778 | self.assertEqual(t, [('foo', 'bar'), {'on_parent': True, | 4772 | self.assertEqual(t, [('foo', 'bar'), {'on_parent': True, |
550 | 4779 | 'on_children': True, | 4773 | 'on_children': True, |
551 | @@ -4799,7 +4793,7 @@ | |||
552 | 4799 | """Test AQ_MOVE_OK is pushed on success.""" | 4793 | """Test AQ_MOVE_OK is pushed on success.""" |
553 | 4800 | # create a request and fill it with succesful information | 4794 | # create a request and fill it with succesful information |
554 | 4801 | request = client.Move(self.action_queue.client, VOLUME, 'node', | 4795 | request = client.Move(self.action_queue.client, VOLUME, 'node', |
556 | 4802 | 'new_parent', 'new_name') | 4796 | 'new_parent', 'new_name') |
557 | 4803 | request.new_generation = 13 | 4797 | request.new_generation = 13 |
558 | 4804 | 4798 | ||
559 | 4805 | # create a command and trigger it success | 4799 | # create a command and trigger it success |
560 | @@ -4835,8 +4829,8 @@ | |||
561 | 4835 | os.path.join(os.path.sep, 'path', 'to')) | 4829 | os.path.join(os.path.sep, 'path', 'to')) |
562 | 4836 | cmd._acquire_pathlock() | 4830 | cmd._acquire_pathlock() |
563 | 4837 | should = [ | 4831 | should = [ |
566 | 4838 | ("", "path", "from"), {'on_parent': True, 'on_children': True, | 4832 | ("", "path", "from"), {'on_parent': True, |
567 | 4839 | 'logger': None}, | 4833 | 'on_children': True, 'logger': None}, |
568 | 4840 | ("", "path", "to"), {'on_parent': True, 'logger': None}, | 4834 | ("", "path", "to"), {'on_parent': True, 'logger': None}, |
569 | 4841 | ] | 4835 | ] |
570 | 4842 | self.assertEqual(t, should) | 4836 | self.assertEqual(t, should) |
571 | @@ -4930,7 +4924,7 @@ | |||
572 | 4930 | """Test that it returns the correct values.""" | 4924 | """Test that it returns the correct values.""" |
573 | 4931 | cmd = MakeFile(self.rq, VOLUME, 'parent', 'name', 'marker', self.mdid) | 4925 | cmd = MakeFile(self.rq, VOLUME, 'parent', 'name', 'marker', self.mdid) |
574 | 4932 | res = [getattr(cmd, x) for x in cmd.possible_markers] | 4926 | res = [getattr(cmd, x) for x in cmd.possible_markers] |
576 | 4933 | self.assertEqual(res, [ 'parent']) | 4927 | self.assertEqual(res, ['parent']) |
577 | 4934 | 4928 | ||
578 | 4935 | def test_path_locking(self): | 4929 | def test_path_locking(self): |
579 | 4936 | """Test that it acquires correctly the path lock.""" | 4930 | """Test that it acquires correctly the path lock.""" |
580 | @@ -5068,8 +5062,7 @@ | |||
581 | 5068 | request = client.Authenticate(self.action_queue.client, | 5062 | request = client.Authenticate(self.action_queue.client, |
582 | 5069 | {'dummy_token': 'credentials'}) | 5063 | {'dummy_token': 'credentials'}) |
583 | 5070 | request.session_id = str(uuid.uuid4()) | 5064 | request.session_id = str(uuid.uuid4()) |
586 | 5071 | self.action_queue.client.oauth_authenticate = \ | 5065 | self.action_queue.client.simple_authenticate = lambda *args: defer.succeed(request) |
585 | 5072 | lambda *args: defer.succeed(request) | ||
587 | 5073 | 5066 | ||
588 | 5074 | yield self.action_queue.authenticate() | 5067 | yield self.action_queue.authenticate() |
589 | 5075 | 5068 | ||
590 | @@ -5080,17 +5073,19 @@ | |||
591 | 5080 | def test_send_platform_and_version(self): | 5073 | def test_send_platform_and_version(self): |
592 | 5081 | """Test that platform and version is sent to the server.""" | 5074 | """Test that platform and version is sent to the server.""" |
593 | 5082 | called = [] | 5075 | called = [] |
595 | 5083 | def fake_oauth_authenticate(*args, **kwargs): | 5076 | |
596 | 5077 | def fake_authenticate(*args, **kwargs): | ||
597 | 5084 | called.append((args, kwargs)) | 5078 | called.append((args, kwargs)) |
598 | 5085 | request = client.Authenticate(self.action_queue.client, | 5079 | request = client.Authenticate(self.action_queue.client, |
599 | 5086 | {'dummy_token': 'credentials'}) | 5080 | {'dummy_token': 'credentials'}) |
600 | 5087 | request.session_id = str(uuid.uuid4()) | 5081 | request.session_id = str(uuid.uuid4()) |
601 | 5088 | return defer.succeed(request) | 5082 | return defer.succeed(request) |
603 | 5089 | self.action_queue.client.oauth_authenticate = fake_oauth_authenticate | 5083 | |
604 | 5084 | self.action_queue.client.simple_authenticate = fake_authenticate | ||
605 | 5090 | yield self.action_queue.authenticate() | 5085 | yield self.action_queue.authenticate() |
606 | 5091 | self.assertEqual(len(called), 1) | 5086 | self.assertEqual(len(called), 1) |
607 | 5092 | metadata = called[0][0][2] | 5087 | metadata = called[0][0][2] |
609 | 5093 | expected_metadata = {'platform':platform, 'version':clientdefs.VERSION} | 5088 | expected_metadata = {'platform': platform, 'version': clientdefs.VERSION} |
610 | 5094 | self.assertEqual(metadata, expected_metadata) | 5089 | self.assertEqual(metadata, expected_metadata) |
611 | 5095 | 5090 | ||
612 | 5096 | 5091 | ||
613 | @@ -5396,7 +5391,7 @@ | |||
614 | 5396 | """Retry the command immediately.""" | 5391 | """Retry the command immediately.""" |
615 | 5397 | finished = defer.Deferred() | 5392 | finished = defer.Deferred() |
616 | 5398 | called = [] | 5393 | called = [] |
618 | 5399 | exc = twisted_error.ConnectionDone() # retryable! | 5394 | exc = twisted_error.ConnectionDone() # retryable! |
619 | 5400 | run_deferreds = [defer.fail(Failure(exc)), defer.succeed('finish')] | 5395 | run_deferreds = [defer.fail(Failure(exc)), defer.succeed('finish')] |
620 | 5401 | self.cmd._run = lambda: called.append('run') or run_deferreds.pop(0) | 5396 | self.cmd._run = lambda: called.append('run') or run_deferreds.pop(0) |
621 | 5402 | self.cmd.handle_retryable = lambda f: called.append(f.value) | 5397 | self.cmd.handle_retryable = lambda f: called.append(f.value) |
622 | @@ -5429,7 +5424,7 @@ | |||
623 | 5429 | def f1(): | 5424 | def f1(): |
624 | 5430 | """Fail and make conditions not ok to run.""" | 5425 | """Fail and make conditions not ok to run.""" |
625 | 5431 | self.cmd.is_runnable = False | 5426 | self.cmd.is_runnable = False |
627 | 5432 | failure = Failure(twisted_error.ConnectionDone()) # retryable! | 5427 | failure = Failure(twisted_error.ConnectionDone()) # retryable! |
628 | 5433 | return defer.fail(failure) | 5428 | return defer.fail(failure) |
629 | 5434 | 5429 | ||
630 | 5435 | def f2(): | 5430 | def f2(): |
631 | @@ -5473,6 +5468,7 @@ | |||
632 | 5473 | 5468 | ||
633 | 5474 | # check cleanup | 5469 | # check cleanup |
634 | 5475 | self.cmd.cleanup = lambda: called.append(2) | 5470 | self.cmd.cleanup = lambda: called.append(2) |
635 | 5471 | |||
636 | 5476 | def fake_finish(): | 5472 | def fake_finish(): |
637 | 5477 | """Flag and call the real one.""" | 5473 | """Flag and call the real one.""" |
638 | 5478 | called.append(3) | 5474 | called.append(3) |
639 | @@ -5515,7 +5511,7 @@ | |||
640 | 5515 | self.cmd.is_runnable = False | 5511 | self.cmd.is_runnable = False |
641 | 5516 | released = [] | 5512 | released = [] |
642 | 5517 | self.cmd._acquire_pathlock = lambda: defer.succeed( | 5513 | self.cmd._acquire_pathlock = lambda: defer.succeed( |
644 | 5518 | lambda: released.append(True)) | 5514 | lambda: released.append(True)) |
645 | 5519 | 5515 | ||
646 | 5520 | # let the command go (will stuck because not runnable), and | 5516 | # let the command go (will stuck because not runnable), and |
647 | 5521 | # cancel in the middle | 5517 | # cancel in the middle |
648 | @@ -5532,7 +5528,7 @@ | |||
649 | 5532 | self.queue.stop() | 5528 | self.queue.stop() |
650 | 5533 | released = [] | 5529 | released = [] |
651 | 5534 | self.cmd._acquire_pathlock = lambda: defer.succeed( | 5530 | self.cmd._acquire_pathlock = lambda: defer.succeed( |
653 | 5535 | lambda: released.append(True)) | 5531 | lambda: released.append(True)) |
654 | 5536 | 5532 | ||
655 | 5537 | # let the command go (will stuck because not runnable), and | 5533 | # let the command go (will stuck because not runnable), and |
656 | 5538 | # cancel in the middle | 5534 | # cancel in the middle |
657 | @@ -5675,7 +5671,6 @@ | |||
658 | 5675 | intrdef.interrupt() | 5671 | intrdef.interrupt() |
659 | 5676 | self.assertFalse(intrdef.interrupted) | 5672 | self.assertFalse(intrdef.interrupted) |
660 | 5677 | 5673 | ||
661 | 5678 | |||
662 | 5679 | def test_interrupt_except(self): | 5674 | def test_interrupt_except(self): |
663 | 5680 | """Interrupt!""" | 5675 | """Interrupt!""" |
664 | 5681 | intrdef = InterruptibleDeferred(defer.Deferred()) | 5676 | intrdef = InterruptibleDeferred(defer.Deferred()) |
665 | @@ -5890,7 +5885,7 @@ | |||
666 | 5890 | # call and check all is started when the ping is done | 5885 | # call and check all is started when the ping is done |
667 | 5891 | self.pm._do_ping() | 5886 | self.pm._do_ping() |
668 | 5892 | self.assertTrue(self.pm._timeout_call.active()) | 5887 | self.assertTrue(self.pm._timeout_call.active()) |
670 | 5893 | self.handler.debug = True | 5888 | self.handler.debug = True |
671 | 5894 | self.assertTrue(self.handler.check(logger.TRACE, 'Sending ping')) | 5889 | self.assertTrue(self.handler.check(logger.TRACE, 'Sending ping')) |
672 | 5895 | 5890 | ||
673 | 5896 | # answer the ping, and check | 5891 | # answer the ping, and check |
674 | 5897 | 5892 | ||
675 | === modified file 'tests/syncdaemon/test_interaction_interfaces.py' | |||
676 | --- tests/syncdaemon/test_interaction_interfaces.py 2013-01-17 21:20:29 +0000 | |||
677 | +++ tests/syncdaemon/test_interaction_interfaces.py 2015-05-18 21:26:35 +0000 | |||
678 | @@ -1,6 +1,6 @@ | |||
679 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
680 | 2 | # | 2 | # |
682 | 3 | # Copyright 2011-2012 Canonical Ltd. | 3 | # Copyright 2011-2015 Canonical Ltd. |
683 | 4 | # | 4 | # |
684 | 5 | # This program is free software: you can redistribute it and/or modify it | 5 | # This program is free software: you can redistribute it and/or modify it |
685 | 6 | # under the terms of the GNU General Public License version 3, as published | 6 | # under the terms of the GNU General Public License version 3, as published |
686 | @@ -381,7 +381,7 @@ | |||
687 | 381 | other='', running='True') | 381 | other='', running='True') |
688 | 382 | self.assertEqual(result[2], ('FakeCommand', pl)) | 382 | self.assertEqual(result[2], ('FakeCommand', pl)) |
689 | 383 | 383 | ||
691 | 384 | self.handler.debug=True | 384 | self.handler.debug = True |
692 | 385 | self.assertTrue(self.handler.check_warning('deprecated')) | 385 | self.assertTrue(self.handler.check_warning('deprecated')) |
693 | 386 | 386 | ||
694 | 387 | def test_waiting_content(self): | 387 | def test_waiting_content(self): |
695 | @@ -579,7 +579,7 @@ | |||
696 | 579 | result = self.sd_obj.get_metadata_and_quick_tree_synced(expected_path) | 579 | result = self.sd_obj.get_metadata_and_quick_tree_synced(expected_path) |
697 | 580 | 580 | ||
698 | 581 | self.assertEqual(expected_path.decode('utf-8'), | 581 | self.assertEqual(expected_path.decode('utf-8'), |
700 | 582 | unicode(result['path'])) | 582 | unicode(result['path'])) |
701 | 583 | self.assertEqual(share.volume_id, result['share_id']) | 583 | self.assertEqual(share.volume_id, result['share_id']) |
702 | 584 | self.assertEqual(share.node_id, result['node_id']) | 584 | self.assertEqual(share.node_id, result['node_id']) |
703 | 585 | self.assertEqual('synced', result['quick_tree_synced']) | 585 | self.assertEqual('synced', result['quick_tree_synced']) |
704 | @@ -610,7 +610,7 @@ | |||
705 | 610 | self.assertNotIn(mdid3, dirty_mdids) | 610 | self.assertNotIn(mdid3, dirty_mdids) |
706 | 611 | # check that path de/encoding is done correctly | 611 | # check that path de/encoding is done correctly |
707 | 612 | self.assertEqual(repr(self.main.fs.get_by_mdid(mdid2).path), | 612 | self.assertEqual(repr(self.main.fs.get_by_mdid(mdid2).path), |
709 | 613 | repr(dirty_mdids[mdid2]['path'].encode('utf-8'))) | 613 | repr(dirty_mdids[mdid2]['path'].encode('utf-8'))) |
710 | 614 | 614 | ||
711 | 615 | 615 | ||
712 | 616 | class SyncdaemonSharesTestCase(BaseTestCase): | 616 | class SyncdaemonSharesTestCase(BaseTestCase): |
713 | @@ -758,7 +758,7 @@ | |||
714 | 758 | ACCESS_LEVEL_RO) | 758 | ACCESS_LEVEL_RO) |
715 | 759 | 759 | ||
716 | 760 | expected = [(a_dir, u, 'share_a_dir', ACCESS_LEVEL_RO) | 760 | expected = [(a_dir, u, 'share_a_dir', ACCESS_LEVEL_RO) |
718 | 761 | for u in usernames] | 761 | for u in usernames] |
719 | 762 | self.assertEqual(called, expected) | 762 | self.assertEqual(called, expected) |
720 | 763 | 763 | ||
721 | 764 | def test_refresh_shares(self): | 764 | def test_refresh_shares(self): |
722 | @@ -828,8 +828,8 @@ | |||
723 | 828 | self.main.fs.create(a_dir, "", is_dir=True) | 828 | self.main.fs.create(a_dir, "", is_dir=True) |
724 | 829 | self.main.fs.set_node_id(a_dir, "node_id") | 829 | self.main.fs.set_node_id(a_dir, "node_id") |
725 | 830 | share = Shared(path=a_dir, volume_id='shared_id', name=u'ñoño_shared', | 830 | share = Shared(path=a_dir, volume_id='shared_id', name=u'ñoño_shared', |
728 | 831 | access_level=ACCESS_LEVEL_RO, | 831 | access_level=ACCESS_LEVEL_RO, |
729 | 832 | other_username=u'test_username', node_id='node_id') | 832 | other_username=u'test_username', node_id='node_id') |
730 | 833 | yield self.main.vm.add_shared(share) | 833 | yield self.main.vm.add_shared(share) |
731 | 834 | 834 | ||
732 | 835 | result = self.sd_obj.get_shared() | 835 | result = self.sd_obj.get_shared() |
733 | @@ -1210,7 +1210,7 @@ | |||
734 | 1210 | self.addCleanup(self.event_q.unsubscribe, listener) | 1210 | self.addCleanup(self.event_q.unsubscribe, listener) |
735 | 1211 | 1211 | ||
736 | 1212 | event_name = 'FS_FILE_CREATE' | 1212 | event_name = 'FS_FILE_CREATE' |
738 | 1213 | args = {'path':'bar'} | 1213 | args = {'path': 'bar'} |
739 | 1214 | self.sd_obj.push_event(event_name, args) | 1214 | self.sd_obj.push_event(event_name, args) |
740 | 1215 | 1215 | ||
741 | 1216 | return d | 1216 | return d |
742 | @@ -1563,7 +1563,7 @@ | |||
743 | 1563 | def test_handle_AQ_ANSWER_SHARE_ERROR(self): | 1563 | def test_handle_AQ_ANSWER_SHARE_ERROR(self): |
744 | 1564 | """Test the handle_AQ_ANSWER_SHARE_ERROR method.""" | 1564 | """Test the handle_AQ_ANSWER_SHARE_ERROR method.""" |
745 | 1565 | share_id = 'share_id' | 1565 | share_id = 'share_id' |
747 | 1566 | answer='foo' | 1566 | answer = 'foo' |
748 | 1567 | error_msg = 'an error message' | 1567 | error_msg = 'an error message' |
749 | 1568 | d = defer.Deferred() | 1568 | d = defer.Deferred() |
750 | 1569 | self.patch(self.sd_obj.interface.shares, | 1569 | self.patch(self.sd_obj.interface.shares, |
751 | @@ -2204,7 +2204,7 @@ | |||
752 | 2204 | yield super(SyncdaemonServiceTestCase, self).setUp() | 2204 | yield super(SyncdaemonServiceTestCase, self).setUp() |
753 | 2205 | self.events = [] | 2205 | self.events = [] |
754 | 2206 | self.sd_obj.main.event_q.push = lambda name, **kw: \ | 2206 | self.sd_obj.main.event_q.push = lambda name, **kw: \ |
756 | 2207 | self.events.append((name, kw)) | 2207 | self.events.append((name, kw)) |
757 | 2208 | 2208 | ||
758 | 2209 | def test_disconnect(self): | 2209 | def test_disconnect(self): |
759 | 2210 | """Test the disconnect method.""" | 2210 | """Test the disconnect method.""" |
760 | @@ -2263,7 +2263,7 @@ | |||
761 | 2263 | """Test for rescan_from_scratch with a non-existing volume.""" | 2263 | """Test for rescan_from_scratch with a non-existing volume.""" |
762 | 2264 | volume_id = object() | 2264 | volume_id = object() |
763 | 2265 | self.assertRaises(ValueError, | 2265 | self.assertRaises(ValueError, |
765 | 2266 | self.sd_obj.rescan_from_scratch, volume_id) | 2266 | self.sd_obj.rescan_from_scratch, volume_id) |
766 | 2267 | 2267 | ||
767 | 2268 | def test_network_state_changed_with_connection(self): | 2268 | def test_network_state_changed_with_connection(self): |
768 | 2269 | """Test the network_state changed method with a connection.""" | 2269 | """Test the network_state changed method with a connection.""" |
769 | @@ -2348,7 +2348,7 @@ | |||
770 | 2348 | 2348 | ||
771 | 2349 | self.events = [] | 2349 | self.events = [] |
772 | 2350 | self.sd_obj.main.event_q.push = lambda name, **kw: \ | 2350 | self.sd_obj.main.event_q.push = lambda name, **kw: \ |
774 | 2351 | self.events.append((name, kw)) | 2351 | self.events.append((name, kw)) |
775 | 2352 | 2352 | ||
776 | 2353 | self.memento = MementoHandler() | 2353 | self.memento = MementoHandler() |
777 | 2354 | logger.addHandler(self.memento) | 2354 | logger.addHandler(self.memento) |
778 | @@ -2383,48 +2383,19 @@ | |||
779 | 2383 | d = self.sd_obj.connect(autoconnecting=self.autoconnecting) | 2383 | d = self.sd_obj.connect(autoconnecting=self.autoconnecting) |
780 | 2384 | yield self.assertFailure(d, Exception) | 2384 | yield self.assertFailure(d, Exception) |
781 | 2385 | 2385 | ||
824 | 2386 | def test_oauth_credentials_are_none_at_startup(self): | 2386 | def test_auth_credentials_are_none_at_startup(self): |
825 | 2387 | """If the oauth_credentials are not passed as param, they are None.""" | 2387 | """If the auth_credentials are not passed as param, they are None.""" |
826 | 2388 | self.assertTrue(self.sd_obj.oauth_credentials is None) | 2388 | self.assertTrue(self.sd_obj.auth_credentials is None) |
827 | 2389 | 2389 | ||
828 | 2390 | @defer.inlineCallbacks | 2390 | @defer.inlineCallbacks |
829 | 2391 | def test_oauth_credentials_are_used_to_connect(self): | 2391 | def test_auth_credentials_are_used_to_connect(self): |
830 | 2392 | """If present, the oauth_credentials are used to connect.""" | 2392 | """If present, the auth_credentials are used to connect.""" |
831 | 2393 | expected = {'consumer_key': 'ubuntuone', | 2393 | expected = {'username': 'test_username', |
832 | 2394 | 'consumer_secret': 'hammertime', | 2394 | 'password': 'test_password'} |
833 | 2395 | 'token': 'faked_token', | 2395 | self.sd_obj.auth_credentials = expected |
834 | 2396 | 'token_secret': 'faked_token_secret'} | 2396 | yield self.sd_obj.connect(autoconnecting=self.autoconnecting) |
835 | 2397 | self.sd_obj.oauth_credentials = (expected['token'], | 2397 | self.assertEqual(self.events, [('SYS_USER_CONNECT', |
836 | 2398 | expected['token_secret']) | 2398 | {'access_token': expected})]) |
795 | 2399 | yield self.sd_obj.connect(autoconnecting=self.autoconnecting) | ||
796 | 2400 | self.assertEqual(self.events, [('SYS_USER_CONNECT', | ||
797 | 2401 | {'access_token': expected})]) | ||
798 | 2402 | |||
799 | 2403 | @defer.inlineCallbacks | ||
800 | 2404 | def test_oauth_credentials_can_be_a_four_uple(self): | ||
801 | 2405 | """If present, the oauth_credentials are used to connect.""" | ||
802 | 2406 | expected = {'consumer_key': 'faked_consumer_key', | ||
803 | 2407 | 'consumer_secret': 'faked_consumer_secret', | ||
804 | 2408 | 'token': 'faked_token', | ||
805 | 2409 | 'token_secret': 'faked_token_secret'} | ||
806 | 2410 | self.sd_obj.oauth_credentials = (expected['consumer_key'], | ||
807 | 2411 | expected['consumer_secret'], | ||
808 | 2412 | expected['token'], | ||
809 | 2413 | expected['token_secret']) | ||
810 | 2414 | yield self.sd_obj.connect(autoconnecting=self.autoconnecting) | ||
811 | 2415 | self.assertEqual(self.events, [('SYS_USER_CONNECT', | ||
812 | 2416 | {'access_token': expected})]) | ||
813 | 2417 | |||
814 | 2418 | @defer.inlineCallbacks | ||
815 | 2419 | def test_log_warning_if_oauth_credentials_len_is_useless(self): | ||
816 | 2420 | """Log a warning and return if the oauth_credentials are useless.""" | ||
817 | 2421 | self.sd_obj.oauth_credentials = ('consumer_key', | ||
818 | 2422 | 'consumer_secret', | ||
819 | 2423 | 'token_secret') | ||
820 | 2424 | yield self.sd_obj.connect(autoconnecting=self.autoconnecting) | ||
821 | 2425 | self.assertEqual(self.events, []) | ||
822 | 2426 | msgs = (str(self.sd_obj.oauth_credentials), 'useless') | ||
823 | 2427 | self.assertTrue(self.memento.check_warning(*msgs)) | ||
837 | 2428 | 2399 | ||
838 | 2429 | 2400 | ||
839 | 2430 | class AutoconnectingTestCase(SyncdaemonServiceConnectTestCase): | 2401 | class AutoconnectingTestCase(SyncdaemonServiceConnectTestCase): |
840 | 2431 | 2402 | ||
841 | === modified file 'tests/syncdaemon/test_main.py' | |||
842 | --- tests/syncdaemon/test_main.py 2013-02-04 16:04:19 +0000 | |||
843 | +++ tests/syncdaemon/test_main.py 2015-05-18 21:26:35 +0000 | |||
844 | @@ -1,6 +1,6 @@ | |||
845 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
846 | 2 | # | 2 | # |
848 | 3 | # Copyright 2009-2012 Canonical Ltd. | 3 | # Copyright 2009-2015 Canonical Ltd. |
849 | 4 | # | 4 | # |
850 | 5 | # This program is free software: you can redistribute it and/or modify it | 5 | # This program is free software: you can redistribute it and/or modify it |
851 | 6 | # under the terms of the GNU General Public License version 3, as published | 6 | # under the terms of the GNU General Public License version 3, as published |
852 | @@ -102,7 +102,7 @@ | |||
853 | 102 | dns_srv=False, ssl=False, | 102 | dns_srv=False, ssl=False, |
854 | 103 | mark_interval=60, | 103 | mark_interval=60, |
855 | 104 | handshake_timeout=2, | 104 | handshake_timeout=2, |
857 | 105 | oauth_credentials=FAKED_CREDENTIALS, | 105 | auth_credentials=FAKED_CREDENTIALS, |
858 | 106 | monitor_class=FakeMonitor) | 106 | monitor_class=FakeMonitor) |
859 | 107 | 107 | ||
860 | 108 | def build_main(self, **kwargs): | 108 | def build_main(self, **kwargs): |
861 | 109 | 109 | ||
862 | === modified file 'ubuntuone/syncdaemon/action_queue.py' | |||
863 | --- ubuntuone/syncdaemon/action_queue.py 2013-02-04 21:33:35 +0000 | |||
864 | +++ ubuntuone/syncdaemon/action_queue.py 2015-05-18 21:26:35 +0000 | |||
865 | @@ -1,6 +1,6 @@ | |||
866 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
867 | 2 | # | 2 | # |
869 | 3 | # Copyright 2009-2012 Canonical Ltd. | 3 | # Copyright 2009-2015 Canonical Ltd. |
870 | 4 | # | 4 | # |
871 | 5 | # This program is free software: you can redistribute it and/or modify it | 5 | # This program is free software: you can redistribute it and/or modify it |
872 | 6 | # under the terms of the GNU General Public License version 3, as published | 6 | # under the terms of the GNU General Public License version 3, as published |
873 | @@ -53,7 +53,6 @@ | |||
874 | 53 | from twisted.names import client as dns_client | 53 | from twisted.names import client as dns_client |
875 | 54 | from twisted.python.failure import Failure, DefaultException | 54 | from twisted.python.failure import Failure, DefaultException |
876 | 55 | 55 | ||
877 | 56 | from oauthlib.oauth1 import Client | ||
878 | 57 | from ubuntu_sso.utils.webclient import txweb | 56 | from ubuntu_sso.utils.webclient import txweb |
879 | 58 | from ubuntuone import clientdefs | 57 | from ubuntuone import clientdefs |
880 | 59 | from ubuntuone.platform import platform, remove_file | 58 | from ubuntuone.platform import platform, remove_file |
881 | @@ -234,8 +233,8 @@ | |||
882 | 234 | del node['children_nodes'][element] | 233 | del node['children_nodes'][element] |
883 | 235 | 234 | ||
884 | 236 | # finally, log and release the deferred | 235 | # finally, log and release the deferred |
887 | 237 | logger.debug("pathlock releasing %s; remaining: %d", elements, | 236 | logger.debug("pathlock releasing %s; remaining: %d", |
888 | 238 | self.count) | 237 | elements, self.count) |
889 | 239 | deferred.callback(True) | 238 | deferred.callback(True) |
890 | 240 | 239 | ||
891 | 241 | def fix_path(self, from_elements, to_elements): | 240 | def fix_path(self, from_elements, to_elements): |
892 | @@ -308,7 +307,7 @@ | |||
893 | 308 | 307 | ||
894 | 309 | # fix the children deferreds after the movement | 308 | # fix the children deferreds after the movement |
895 | 310 | all_children_deferreds = (node_to_move['node_deferreds'] | | 309 | all_children_deferreds = (node_to_move['node_deferreds'] | |
897 | 311 | node_to_move['children_deferreds']) | 310 | node_to_move['children_deferreds']) |
898 | 312 | for node in branch[::-1]: | 311 | for node in branch[::-1]: |
899 | 313 | node['children_deferreds'] = set(all_children_deferreds) | 312 | node['children_deferreds'] = set(all_children_deferreds) |
900 | 314 | all_children_deferreds.update(node['node_deferreds']) | 313 | all_children_deferreds.update(node['node_deferreds']) |
901 | @@ -771,9 +770,9 @@ | |||
902 | 771 | use_ssl=False, disable_ssl_verify=False, | 770 | use_ssl=False, disable_ssl_verify=False, |
903 | 772 | read_limit=None, write_limit=None, throttling_enabled=False, | 771 | read_limit=None, write_limit=None, throttling_enabled=False, |
904 | 773 | connection_timeout=30): | 772 | connection_timeout=30): |
908 | 774 | ThrottlingStorageClientFactory.__init__(self, read_limit=read_limit, | 773 | ThrottlingStorageClientFactory.__init__( |
909 | 775 | write_limit=write_limit, | 774 | self, read_limit=read_limit, write_limit=write_limit, |
910 | 776 | throttling_enabled=throttling_enabled) | 775 | throttling_enabled=throttling_enabled) |
911 | 777 | self.event_queue = event_queue | 776 | self.event_queue = event_queue |
912 | 778 | self.main = main | 777 | self.main = main |
913 | 779 | self.host = host | 778 | self.host = host |
914 | @@ -782,10 +781,7 @@ | |||
915 | 782 | self.use_ssl = use_ssl | 781 | self.use_ssl = use_ssl |
916 | 783 | self.disable_ssl_verify = disable_ssl_verify | 782 | self.disable_ssl_verify = disable_ssl_verify |
917 | 784 | self.connection_timeout = connection_timeout | 783 | self.connection_timeout = connection_timeout |
922 | 785 | 784 | self.credentials = {} | |
919 | 786 | # credentials | ||
920 | 787 | self.oauth_client = None | ||
921 | 788 | self.credentials = None | ||
923 | 789 | 785 | ||
924 | 790 | self.client = None # an instance of self.protocol | 786 | self.client = None # an instance of self.protocol |
925 | 791 | 787 | ||
926 | @@ -809,9 +805,9 @@ | |||
927 | 809 | # data for the offloaded queue | 805 | # data for the offloaded queue |
928 | 810 | user_config = config.get_user_config() | 806 | user_config = config.get_user_config() |
929 | 811 | self.memory_pool_limit = user_config.get_memory_pool_limit() | 807 | self.memory_pool_limit = user_config.get_memory_pool_limit() |
933 | 812 | self.commands = dict((x, y) for x, y in globals().iteritems() | 808 | self.commands = dict( |
934 | 813 | if inspect.isclass(y) and | 809 | (x, y) for x, y in globals().iteritems() |
935 | 814 | issubclass(y, ActionQueueCommand)) | 810 | if inspect.isclass(y) and issubclass(y, ActionQueueCommand)) |
936 | 815 | 811 | ||
937 | 816 | def check_conditions(self): | 812 | def check_conditions(self): |
938 | 817 | """Check conditions in the locker, to release all the waiting ops.""" | 813 | """Check conditions in the locker, to release all the waiting ops.""" |
939 | @@ -830,31 +826,9 @@ | |||
940 | 830 | return enough | 826 | return enough |
941 | 831 | 827 | ||
942 | 832 | def handle_SYS_USER_CONNECT(self, access_token): | 828 | def handle_SYS_USER_CONNECT(self, access_token): |
968 | 833 | """Stow the access token away for later use.""" | 829 | """Stow the credentials for later use.""" |
969 | 834 | self.credentials = access_token | 830 | self.credentials = dict(username=access_token['username'], |
970 | 835 | self.oauth_client = Client(access_token['token'], | 831 | password=access_token['password']) |
946 | 836 | access_token['token_secret'], | ||
947 | 837 | access_token['consumer_key'], | ||
948 | 838 | access_token['consumer_secret']) | ||
949 | 839 | |||
950 | 840 | # For API backward compatibility. | ||
951 | 841 | @property | ||
952 | 842 | def token(self): | ||
953 | 843 | if self.oauth_client is None: | ||
954 | 844 | return None | ||
955 | 845 | class _Token: | ||
956 | 846 | key = self.oauth_client.client_key | ||
957 | 847 | secret = self.oauth_client.client_secret | ||
958 | 848 | return _Token() | ||
959 | 849 | |||
960 | 850 | @property | ||
961 | 851 | def consumer(self): | ||
962 | 852 | if self.oauth_client is None: | ||
963 | 853 | return None | ||
964 | 854 | class _Consumer: | ||
965 | 855 | key = self.oauth_client.resource_owner_key | ||
966 | 856 | secret = self.oauth_client.resource_owner_secret | ||
967 | 857 | return _Consumer() | ||
971 | 858 | 832 | ||
972 | 859 | def _cleanup_connection_state(self, *args): | 833 | def _cleanup_connection_state(self, *args): |
973 | 860 | """Reset connection state.""" | 834 | """Reset connection state.""" |
974 | @@ -939,13 +913,13 @@ | |||
975 | 939 | else: | 913 | else: |
976 | 940 | return defer.succeed((self.host, self.port)) | 914 | return defer.succeed((self.host, self.port)) |
977 | 941 | 915 | ||
978 | 942 | |||
979 | 943 | @defer.inlineCallbacks | 916 | @defer.inlineCallbacks |
980 | 944 | def webcall(self, iri, **kwargs): | 917 | def webcall(self, iri, **kwargs): |
981 | 945 | """Perform a web call to the api servers.""" | 918 | """Perform a web call to the api servers.""" |
982 | 946 | webclient = yield self.get_webclient(iri) | 919 | webclient = yield self.get_webclient(iri) |
985 | 947 | response = yield webclient.request(iri, | 920 | # FIXME: we need to review these requests after credentials change |
986 | 948 | oauth_credentials=self.credentials, **kwargs) | 921 | response = yield webclient.request( |
987 | 922 | iri, oauth_credentials=self.credentials, **kwargs) | ||
988 | 949 | defer.returnValue(response) | 923 | defer.returnValue(response) |
989 | 950 | 924 | ||
990 | 951 | @defer.inlineCallbacks | 925 | @defer.inlineCallbacks |
991 | @@ -967,12 +941,12 @@ | |||
992 | 967 | ssl_context = get_ssl_context(self.disable_ssl_verify, host) | 941 | ssl_context = get_ssl_context(self.disable_ssl_verify, host) |
993 | 968 | client = yield self.tunnel_runner.get_client() | 942 | client = yield self.tunnel_runner.get_client() |
994 | 969 | if self.use_ssl: | 943 | if self.use_ssl: |
998 | 970 | self.connector = client.connectSSL(host, port, factory=self, | 944 | self.connector = client.connectSSL( |
999 | 971 | contextFactory=ssl_context, | 945 | host, port, factory=self, contextFactory=ssl_context, |
1000 | 972 | timeout=self.connection_timeout) | 946 | timeout=self.connection_timeout) |
1001 | 973 | else: | 947 | else: |
1004 | 974 | self.connector = client.connectTCP(host, port, self, | 948 | self.connector = client.connectTCP( |
1005 | 975 | timeout=self.connection_timeout) | 949 | host, port, self, timeout=self.connection_timeout) |
1006 | 976 | 950 | ||
1007 | 977 | def connect(self): | 951 | def connect(self): |
1008 | 978 | """Start the circus going.""" | 952 | """Start the circus going.""" |
1009 | @@ -1004,7 +978,7 @@ | |||
1010 | 1004 | self.client.set_volume_created_callback(self._volume_created_callback) | 978 | self.client.set_volume_created_callback(self._volume_created_callback) |
1011 | 1005 | self.client.set_volume_deleted_callback(self._volume_deleted_callback) | 979 | self.client.set_volume_deleted_callback(self._volume_deleted_callback) |
1012 | 1006 | self.client.set_volume_new_generation_callback( | 980 | self.client.set_volume_new_generation_callback( |
1014 | 1007 | self._volume_new_generation_callback) | 981 | self._volume_new_generation_callback) |
1015 | 1008 | 982 | ||
1016 | 1009 | logger.info('Connection made.') | 983 | logger.info('Connection made.') |
1017 | 1010 | return self.client | 984 | return self.client |
1018 | @@ -1104,7 +1078,7 @@ | |||
1019 | 1104 | if failure is not None: | 1078 | if failure is not None: |
1020 | 1105 | if event is None: | 1079 | if event is None: |
1021 | 1106 | logger.info("The request '%s' failed with the error: %s", | 1080 | logger.info("The request '%s' failed with the error: %s", |
1023 | 1107 | req_name, failure) | 1081 | req_name, failure) |
1024 | 1108 | else: | 1082 | else: |
1025 | 1109 | logger.info("The request '%s' failed with the error: %s " | 1083 | logger.info("The request '%s' failed with the error: %s " |
1026 | 1110 | "and was handled with the event: %s", | 1084 | "and was handled with the event: %s", |
1027 | @@ -1162,12 +1136,13 @@ | |||
1028 | 1162 | """Authenticate against the server using stored credentials.""" | 1136 | """Authenticate against the server using stored credentials.""" |
1029 | 1163 | metadata = {'version': clientdefs.VERSION, | 1137 | metadata = {'version': clientdefs.VERSION, |
1030 | 1164 | 'platform': platform} | 1138 | 'platform': platform} |
1031 | 1139 | username = self.credentials.get('username') | ||
1032 | 1140 | password = self.credentials.get('password') | ||
1033 | 1165 | authenticate_d = self._send_request_and_handle_errors( | 1141 | authenticate_d = self._send_request_and_handle_errors( |
1035 | 1166 | request=self.client.oauth_authenticate, | 1142 | request=self.client.simple_authenticate, |
1036 | 1167 | request_error=protocol_errors.AuthenticationFailedError, | 1143 | request_error=protocol_errors.AuthenticationFailedError, |
1037 | 1168 | event_error='SYS_AUTH_ERROR', event_ok='SYS_AUTH_OK', | 1144 | event_error='SYS_AUTH_ERROR', event_ok='SYS_AUTH_OK', |
1040 | 1169 | # XXX: handle self.token is None or self.consumer is None? | 1145 | args=(username, password, metadata)) |
1039 | 1170 | args=(self.consumer, self.token, metadata)) | ||
1041 | 1171 | req = yield authenticate_d | 1146 | req = yield authenticate_d |
1042 | 1172 | 1147 | ||
1043 | 1173 | # req can be None if the auth failed, but it's handled by | 1148 | # req can be None if the auth failed, but it's handled by |
1044 | @@ -1380,7 +1355,7 @@ | |||
1045 | 1380 | """Create a logger for this object.""" | 1355 | """Create a logger for this object.""" |
1046 | 1381 | share_id = getattr(self, "share_id", UNKNOWN) | 1356 | share_id = getattr(self, "share_id", UNKNOWN) |
1047 | 1382 | node_id = getattr(self, "node_id", None) or \ | 1357 | node_id = getattr(self, "node_id", None) or \ |
1049 | 1383 | getattr(self, "marker", UNKNOWN) | 1358 | getattr(self, "marker", UNKNOWN) |
1050 | 1384 | self.log = mklog(logger, self.__class__.__name__, | 1359 | self.log = mklog(logger, self.__class__.__name__, |
1051 | 1385 | share_id, node_id, **self.to_dict()) | 1360 | share_id, node_id, **self.to_dict()) |
1052 | 1386 | 1361 | ||
1053 | @@ -1620,7 +1595,7 @@ | |||
1054 | 1620 | name = self.__class__.__name__ | 1595 | name = self.__class__.__name__ |
1055 | 1621 | if len(str_attrs) == 0: | 1596 | if len(str_attrs) == 0: |
1056 | 1622 | return name | 1597 | return name |
1058 | 1623 | attrs = [str(attr) + '=' + str(getattr(self, attr, None) or 'None') \ | 1598 | attrs = [str(attr) + '=' + str(getattr(self, attr, None) or 'None') |
1059 | 1624 | for attr in str_attrs] | 1599 | for attr in str_attrs] |
1060 | 1625 | return ''.join([name, '(', ', '.join([attr for attr in attrs]), ')']) | 1600 | return ''.join([name, '(', ', '.join([attr for attr in attrs]), ')']) |
1061 | 1626 | 1601 | ||
1062 | @@ -1668,8 +1643,8 @@ | |||
1063 | 1668 | """Acquire pathlock.""" | 1643 | """Acquire pathlock.""" |
1064 | 1669 | self.path = self._get_current_path(self.mdid) | 1644 | self.path = self._get_current_path(self.mdid) |
1065 | 1670 | pathlock = self.action_queue.pathlock | 1645 | pathlock = self.action_queue.pathlock |
1068 | 1671 | return pathlock.acquire(*self.path.split(os.path.sep), on_parent=True, | 1646 | return pathlock.acquire(*self.path.split(os.path.sep), |
1069 | 1672 | logger=self.log) | 1647 | on_parent=True, logger=self.log) |
1070 | 1673 | 1648 | ||
1071 | 1674 | 1649 | ||
1072 | 1675 | class MakeFile(MakeThing): | 1650 | class MakeFile(MakeThing): |
1073 | @@ -1955,9 +1930,9 @@ | |||
1074 | 1955 | """Do the actual running.""" | 1930 | """Do the actual running.""" |
1075 | 1956 | if self.use_http: | 1931 | if self.use_http: |
1076 | 1957 | # External user, do the HTTP REST method | 1932 | # External user, do the HTTP REST method |
1080 | 1958 | return self._create_share_http(self.node_id, self.share_to, | 1933 | return self._create_share_http( |
1081 | 1959 | self.name, | 1934 | self.node_id, self.share_to, self.name, |
1082 | 1960 | self.access_level != ACCESS_LEVEL_RW) | 1935 | self.access_level != ACCESS_LEVEL_RW) |
1083 | 1961 | else: | 1936 | else: |
1084 | 1962 | return self.action_queue.client.create_share(self.node_id, | 1937 | return self.action_queue.client.create_share(self.node_id, |
1085 | 1963 | self.share_to, | 1938 | self.share_to, |
1086 | @@ -2384,7 +2359,7 @@ | |||
1087 | 2384 | 'fileobj', 'gunzip', 'mdid', 'download_req', 'tx_semaphore', | 2359 | 'fileobj', 'gunzip', 'mdid', 'download_req', 'tx_semaphore', |
1088 | 2385 | 'deflated_size', 'n_bytes_read_last', 'n_bytes_read', 'path') | 2360 | 'deflated_size', 'n_bytes_read_last', 'n_bytes_read', 'path') |
1089 | 2386 | logged_attrs = ActionQueueCommand.logged_attrs + ( | 2361 | logged_attrs = ActionQueueCommand.logged_attrs + ( |
1091 | 2387 | 'share_id', 'node_id', 'server_hash', 'mdid', 'path') | 2362 | 'share_id', 'node_id', 'server_hash', 'mdid', 'path') |
1092 | 2388 | possible_markers = 'node_id', | 2363 | possible_markers = 'node_id', |
1093 | 2389 | 2364 | ||
1094 | 2390 | def __init__(self, request_queue, share_id, node_id, server_hash, mdid): | 2365 | def __init__(self, request_queue, share_id, node_id, server_hash, mdid): |
1095 | @@ -2553,10 +2528,10 @@ | |||
1096 | 2553 | 'n_bytes_written', 'upload_id', 'mdid', 'path') | 2528 | 'n_bytes_written', 'upload_id', 'mdid', 'path') |
1097 | 2554 | 2529 | ||
1098 | 2555 | logged_attrs = ActionQueueCommand.logged_attrs + ( | 2530 | logged_attrs = ActionQueueCommand.logged_attrs + ( |
1101 | 2556 | 'share_id', 'node_id', 'previous_hash', 'hash', 'crc32', | 2531 | 'share_id', 'node_id', 'previous_hash', 'hash', 'crc32', |
1102 | 2557 | 'size', 'upload_id', 'mdid', 'path') | 2532 | 'size', 'upload_id', 'mdid', 'path') |
1103 | 2558 | retryable_errors = ActionQueueCommand.retryable_errors + ( | 2533 | retryable_errors = ActionQueueCommand.retryable_errors + ( |
1105 | 2559 | protocol_errors.UploadInProgressError,) | 2534 | protocol_errors.UploadInProgressError,) |
1106 | 2560 | possible_markers = 'node_id', | 2535 | possible_markers = 'node_id', |
1107 | 2561 | 2536 | ||
1108 | 2562 | def __init__(self, request_queue, share_id, node_id, previous_hash, hash, | 2537 | def __init__(self, request_queue, share_id, node_id, previous_hash, hash, |
1109 | @@ -2591,7 +2566,7 @@ | |||
1110 | 2591 | return True | 2566 | return True |
1111 | 2592 | else: | 2567 | else: |
1112 | 2593 | return self.action_queue.have_sufficient_space_for_upload( | 2568 | return self.action_queue.have_sufficient_space_for_upload( |
1114 | 2594 | self.share_id, self.size) | 2569 | self.share_id, self.size) |
1115 | 2595 | 2570 | ||
1116 | 2596 | def _should_be_queued(self): | 2571 | def _should_be_queued(self): |
1117 | 2597 | """Queue but keeping uniqueness.""" | 2572 | """Queue but keeping uniqueness.""" |
1118 | @@ -2633,8 +2608,7 @@ | |||
1119 | 2633 | def cleanup(self): | 2608 | def cleanup(self): |
1120 | 2634 | """Cleanup: stop the producer.""" | 2609 | """Cleanup: stop the producer.""" |
1121 | 2635 | self.log.debug('cleanup') | 2610 | self.log.debug('cleanup') |
1124 | 2636 | if self.upload_req is not None and \ | 2611 | if self.upload_req is not None and self.upload_req.producer is not None: |
1123 | 2637 | self.upload_req.producer is not None: | ||
1125 | 2638 | self.log.debug('stopping the producer') | 2612 | self.log.debug('stopping the producer') |
1126 | 2639 | self.upload_req.producer.stopProducing() | 2613 | self.upload_req.producer.stopProducing() |
1127 | 2640 | 2614 | ||
1128 | @@ -2696,7 +2670,7 @@ | |||
1129 | 2696 | def progress_hook(self): | 2670 | def progress_hook(self): |
1130 | 2697 | """Send event if accumulated enough progress.""" | 2671 | """Send event if accumulated enough progress.""" |
1131 | 2698 | written_since_last = self.n_bytes_written - self.n_bytes_written_last | 2672 | written_since_last = self.n_bytes_written - self.n_bytes_written_last |
1133 | 2699 | if written_since_last >= TRANSFER_PROGRESS_THRESHOLD: | 2673 | if written_since_last >= TRANSFER_PROGRESS_THRESHOLD: |
1134 | 2700 | event_data = dict(share_id=self.share_id, node_id=self.node_id, | 2674 | event_data = dict(share_id=self.share_id, node_id=self.node_id, |
1135 | 2701 | n_bytes_written=self.n_bytes_written, | 2675 | n_bytes_written=self.n_bytes_written, |
1136 | 2702 | deflated_size=self.deflated_size) | 2676 | deflated_size=self.deflated_size) |
1137 | 2703 | 2677 | ||
1138 | === modified file 'ubuntuone/syncdaemon/interaction_interfaces.py' | |||
1139 | --- ubuntuone/syncdaemon/interaction_interfaces.py 2014-05-22 19:22:44 +0000 | |||
1140 | +++ ubuntuone/syncdaemon/interaction_interfaces.py 2015-05-18 21:26:35 +0000 | |||
1141 | @@ -1,6 +1,6 @@ | |||
1142 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
1143 | 2 | # | 2 | # |
1145 | 3 | # Copyright 2011-2012 Canonical Ltd. | 3 | # Copyright 2011-2015 Canonical Ltd. |
1146 | 4 | # | 4 | # |
1147 | 5 | # This program is free software: you can redistribute it and/or modify it | 5 | # This program is free software: you can redistribute it and/or modify it |
1148 | 6 | # under the terms of the GNU General Public License version 3, as published | 6 | # under the terms of the GNU General Public License version 3, as published |
1149 | @@ -38,7 +38,6 @@ | |||
1150 | 38 | """ | 38 | """ |
1151 | 39 | 39 | ||
1152 | 40 | import collections | 40 | import collections |
1153 | 41 | import datetime | ||
1154 | 42 | import logging | 41 | import logging |
1155 | 43 | import os | 42 | import os |
1156 | 44 | import uuid | 43 | import uuid |
1157 | @@ -846,7 +845,7 @@ | |||
1158 | 846 | 845 | ||
1159 | 847 | @log_call(logger.trace) | 846 | @log_call(logger.trace) |
1160 | 848 | def handle_AQ_UPLOAD_FILE_PROGRESS(self, share_id, node_id, | 847 | def handle_AQ_UPLOAD_FILE_PROGRESS(self, share_id, node_id, |
1162 | 849 | n_bytes_written, deflated_size): | 848 | n_bytes_written, deflated_size): |
1163 | 850 | """Handle AQ_UPLOAD_FILE_PROGRESS.""" | 849 | """Handle AQ_UPLOAD_FILE_PROGRESS.""" |
1164 | 851 | info = dict(n_bytes_written=str(n_bytes_written), | 850 | info = dict(n_bytes_written=str(n_bytes_written), |
1165 | 852 | deflated_size=str(deflated_size)) | 851 | deflated_size=str(deflated_size)) |
1166 | @@ -1052,7 +1051,7 @@ | |||
1167 | 1052 | else: | 1051 | else: |
1168 | 1053 | logger.error("Unable to handle VM_VOLUME_DELETE_ERROR (%r) " | 1052 | logger.error("Unable to handle VM_VOLUME_DELETE_ERROR (%r) " |
1169 | 1054 | "for volume_id=%r as it's not a Share or UDF", | 1053 | "for volume_id=%r as it's not a Share or UDF", |
1171 | 1055 | error, volume_id) | 1054 | error, volume_id) |
1172 | 1056 | 1055 | ||
1173 | 1057 | @log_call(logger.debug) | 1056 | @log_call(logger.debug) |
1174 | 1058 | def handle_VM_SHARE_CHANGED(self, share_id): | 1057 | def handle_VM_SHARE_CHANGED(self, share_id): |
1175 | @@ -1193,7 +1192,7 @@ | |||
1176 | 1193 | 1192 | ||
1177 | 1194 | self.send_events = send_events | 1193 | self.send_events = send_events |
1178 | 1195 | self.network_manager = NetworkManagerState( | 1194 | self.network_manager = NetworkManagerState( |
1180 | 1196 | result_cb=self.network_state_changed) | 1195 | result_cb=self.network_state_changed) |
1181 | 1197 | self.network_manager.find_online_state() | 1196 | self.network_manager.find_online_state() |
1182 | 1198 | 1197 | ||
1183 | 1199 | if interface is None: | 1198 | if interface is None: |
1184 | @@ -1209,7 +1208,7 @@ | |||
1185 | 1209 | self.all_events_sender = AllEventsSender(self.interface.events) | 1208 | self.all_events_sender = AllEventsSender(self.interface.events) |
1186 | 1210 | self.main.event_q.subscribe(self.all_events_sender) | 1209 | self.main.event_q.subscribe(self.all_events_sender) |
1187 | 1211 | 1210 | ||
1189 | 1212 | self.oauth_credentials = None | 1211 | self.auth_credentials = None |
1190 | 1213 | 1212 | ||
1191 | 1214 | def _create_children(self): | 1213 | def _create_children(self): |
1192 | 1215 | """Create the specific syncdaemon objects.""" | 1214 | """Create the specific syncdaemon objects.""" |
1193 | @@ -1246,31 +1245,13 @@ | |||
1194 | 1246 | The token is requested via com.ubuntuone.credentials service. If | 1245 | The token is requested via com.ubuntuone.credentials service. If |
1195 | 1247 | 'autoconnecting' is True, no UI window will be raised to prompt the user | 1246 | 'autoconnecting' is True, no UI window will be raised to prompt the user |
1196 | 1248 | for login/registration, only already existent credentials will be used. | 1247 | for login/registration, only already existent credentials will be used. |
1197 | 1249 | |||
1198 | 1250 | """ | 1248 | """ |
1218 | 1251 | # Avoid connecting after June 1. | 1249 | if self.auth_credentials is not None: |
1219 | 1252 | end_date = datetime.date(2014, 6, 1) | 1250 | logger.debug('connect: auth credentials were given by parameter.') |
1220 | 1253 | if datetime.date.today() >= end_date: | 1251 | token = self.auth_credentials |
1202 | 1254 | return | ||
1203 | 1255 | |||
1204 | 1256 | if self.oauth_credentials is not None: | ||
1205 | 1257 | logger.debug('connect: oauth credentials were given by parameter.') | ||
1206 | 1258 | ckey = csecret = key = secret = None | ||
1207 | 1259 | if len(self.oauth_credentials) == 4: | ||
1208 | 1260 | ckey, csecret, key, secret = self.oauth_credentials | ||
1209 | 1261 | elif len(self.oauth_credentials) == 2: | ||
1210 | 1262 | ckey, csecret = ('ubuntuone', 'hammertime') | ||
1211 | 1263 | key, secret = self.oauth_credentials | ||
1212 | 1264 | else: | ||
1213 | 1265 | msg = 'connect: oauth_credentials (%r) was set but is useless!' | ||
1214 | 1266 | logger.warning(msg, self.oauth_credentials) | ||
1215 | 1267 | return | ||
1216 | 1268 | token = {'consumer_key': ckey, 'consumer_secret': csecret, | ||
1217 | 1269 | 'token': key, 'token_secret': secret} | ||
1221 | 1270 | else: | 1252 | else: |
1222 | 1271 | try: | 1253 | try: |
1225 | 1272 | token = yield self._request_token( | 1254 | token = yield self._request_token(autoconnecting=autoconnecting) |
1224 | 1273 | autoconnecting=autoconnecting) | ||
1226 | 1274 | except Exception, e: | 1255 | except Exception, e: |
1227 | 1275 | logger.exception('failure while getting the token') | 1256 | logger.exception('failure while getting the token') |
1228 | 1276 | raise NoAccessToken(e) | 1257 | raise NoAccessToken(e) |
1229 | @@ -1282,6 +1263,8 @@ | |||
1230 | 1282 | 1263 | ||
1231 | 1283 | def _request_token(self, autoconnecting): | 1264 | def _request_token(self, autoconnecting): |
1232 | 1284 | """Request to SSO auth service to fetch the token.""" | 1265 | """Request to SSO auth service to fetch the token.""" |
1233 | 1266 | # FIXME: we need to unbind this from SSO, probably just | ||
1234 | 1267 | # get tokens from keyring | ||
1235 | 1285 | # call ubuntu sso | 1268 | # call ubuntu sso |
1236 | 1286 | management = credentials.CredentialsManagementTool() | 1269 | management = credentials.CredentialsManagementTool() |
1237 | 1287 | # return the deferred, since we are no longer using signals | 1270 | # return the deferred, since we are no longer using signals |
1238 | 1288 | 1271 | ||
1239 | === modified file 'ubuntuone/syncdaemon/main.py' | |||
1240 | --- ubuntuone/syncdaemon/main.py 2014-05-22 18:00:54 +0000 | |||
1241 | +++ ubuntuone/syncdaemon/main.py 2015-05-18 21:26:35 +0000 | |||
1242 | @@ -1,6 +1,6 @@ | |||
1243 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
1244 | 2 | # | 2 | # |
1246 | 3 | # Copyright 2009-2012 Canonical Ltd. | 3 | # Copyright 2009-2015 Canonical Ltd. |
1247 | 4 | # | 4 | # |
1248 | 5 | # This program is free software: you can redistribute it and/or modify it | 5 | # This program is free software: you can redistribute it and/or modify it |
1249 | 6 | # under the terms of the GNU General Public License version 3, as published | 6 | # under the terms of the GNU General Public License version 3, as published |
1250 | @@ -89,7 +89,7 @@ | |||
1251 | 89 | handshake_timeout=30, | 89 | handshake_timeout=30, |
1252 | 90 | shares_symlink_name='Shared With Me', | 90 | shares_symlink_name='Shared With Me', |
1253 | 91 | read_limit=None, write_limit=None, throttling_enabled=False, | 91 | read_limit=None, write_limit=None, throttling_enabled=False, |
1255 | 92 | ignore_files=None, oauth_credentials=None, | 92 | ignore_files=None, auth_credentials=None, |
1256 | 93 | monitor_class=None): | 93 | monitor_class=None): |
1257 | 94 | self.root_dir = root_dir | 94 | self.root_dir = root_dir |
1258 | 95 | self.shares_dir = shares_dir | 95 | self.shares_dir = shares_dir |
1259 | @@ -115,8 +115,8 @@ | |||
1260 | 115 | self.vm = volume_manager.VolumeManager(self) | 115 | self.vm = volume_manager.VolumeManager(self) |
1261 | 116 | self.fs = filesystem_manager.FileSystemManager( | 116 | self.fs = filesystem_manager.FileSystemManager( |
1262 | 117 | data_dir, partials_dir, self.vm, self.db) | 117 | data_dir, partials_dir, self.vm, self.db) |
1265 | 118 | self.event_q = event_queue.EventQueue(self.fs, ignore_files, | 118 | self.event_q = event_queue.EventQueue( |
1266 | 119 | monitor_class=monitor_class) | 119 | self.fs, ignore_files, monitor_class=monitor_class) |
1267 | 120 | self.fs.register_eq(self.event_q) | 120 | self.fs.register_eq(self.event_q) |
1268 | 121 | 121 | ||
1269 | 122 | # subscribe VM to EQ, to be unsubscribed in shutdown | 122 | # subscribe VM to EQ, to be unsubscribed in shutdown |
1270 | @@ -142,7 +142,7 @@ | |||
1271 | 142 | 142 | ||
1272 | 143 | self.external = SyncdaemonService(main=self, | 143 | self.external = SyncdaemonService(main=self, |
1273 | 144 | send_events=broadcast_events) | 144 | send_events=broadcast_events) |
1275 | 145 | self.external.oauth_credentials = oauth_credentials | 145 | self.external.auth_credentials = auth_credentials |
1276 | 146 | if user_config.get_autoconnect(): | 146 | if user_config.get_autoconnect(): |
1277 | 147 | self.external.connect(autoconnecting=True) | 147 | self.external.connect(autoconnecting=True) |
1278 | 148 | 148 | ||
1279 | @@ -154,8 +154,8 @@ | |||
1280 | 154 | 154 | ||
1281 | 155 | def start_status_listener(self): | 155 | def start_status_listener(self): |
1282 | 156 | """Start the status listener if it is configured to start.""" | 156 | """Start the status listener if it is configured to start.""" |
1285 | 157 | self.status_listener = status_listener.get_listener(self.fs, self.vm, | 157 | self.status_listener = status_listener.get_listener( |
1286 | 158 | self.external) | 158 | self.fs, self.vm, self.external) |
1287 | 159 | # subscribe to EQ, to be unsubscribed in shutdown | 159 | # subscribe to EQ, to be unsubscribed in shutdown |
1288 | 160 | if self.status_listener: | 160 | if self.status_listener: |
1289 | 161 | self.event_q.subscribe(self.status_listener) | 161 | self.event_q.subscribe(self.status_listener) |
1290 | @@ -302,7 +302,7 @@ | |||
1291 | 302 | def stop_the_press(failure): | 302 | def stop_the_press(failure): |
1292 | 303 | """Something went wrong in LR, can't continue.""" | 303 | """Something went wrong in LR, can't continue.""" |
1293 | 304 | self.logger.error("Local rescan finished with error: %s", | 304 | self.logger.error("Local rescan finished with error: %s", |
1295 | 305 | failure.getBriefTraceback()) | 305 | failure.getBriefTraceback()) |
1296 | 306 | self.event_q.push('SYS_UNKNOWN_ERROR') | 306 | self.event_q.push('SYS_UNKNOWN_ERROR') |
1297 | 307 | 307 | ||
1298 | 308 | d.addCallbacks(local_rescan_done, stop_the_press) | 308 | d.addCallbacks(local_rescan_done, stop_the_press) |