Merge lp:~facundo/magicicada-client/connect-multi-server into lp:magicicada-client
- connect-multi-server
- Merge into trunk
Proposed by
Facundo Batista
Status: | Merged |
---|---|
Approved by: | Natalia Bidart |
Approved revision: | 1437 |
Merged at revision: | 1435 |
Proposed branch: | lp:~facundo/magicicada-client/connect-multi-server |
Merge into: | lp:magicicada-client |
Prerequisite: | lp:~facundo/magicicada-client/remove-web |
Diff against target: |
592 lines (+217/-102) 9 files modified
bin/ubuntuone-syncdaemon (+2/-3) data/syncdaemon.conf (+5/-14) ubuntuone/syncdaemon/action_queue.py (+18/-57) ubuntuone/syncdaemon/config.py (+38/-0) ubuntuone/syncdaemon/main.py (+4/-8) ubuntuone/syncdaemon/states.py (+2/-5) ubuntuone/syncdaemon/tests/test_action_queue.py (+78/-13) ubuntuone/syncdaemon/tests/test_config.py (+68/-0) ubuntuone/syncdaemon/tests/test_main.py (+2/-2) |
To merge this branch: | bzr merge lp:~facundo/magicicada-client/connect-multi-server |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Natalia Bidart | Approve | ||
Review via email: mp+316913@code.launchpad.net |
Commit message
Allow in the config multiple servers to connect.
These possible multiple servers travel in one simple object, not a miriad of parameters to ActionQueue, which will use them to try to connect. It first tries the first one, on connection error tries the second, and so on until the list ends, and starts again with the first one.
For a quick retry on different servers, I lowered the initial delay to reconnect to 200ms.
Description of the change
To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) : | # |
- 1437. By Facundo Batista
-
Better explanation in the .conf
Revision history for this message
Facundo Batista (facundo) wrote : | # |
Revision history for this message
Natalia Bidart (nataliabidart) wrote : | # |
Looks good, thanks!
review:
Approve
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 2015-09-29 21:05:26 +0000 |
3 | +++ bin/ubuntuone-syncdaemon 2017-02-22 16:49:18 +0000 |
4 | @@ -1,6 +1,7 @@ |
5 | #!/usr/bin/python |
6 | # |
7 | # Copyright 2009-2015 Canonical Ltd. |
8 | +# Copyright 2017 Chicharreros (https://launchpad.net/~chicharreros) |
9 | # |
10 | # This program is free software: you can redistribute it and/or modify it |
11 | # under the terms of the GNU General Public License version 3, as published |
12 | @@ -218,9 +219,7 @@ |
13 | monitor_class = yield get_filemonitor_class(options.fs_monitor) |
14 | |
15 | main = Main(options.root_dir, options.shares_dir, options.data_dir, |
16 | - partials_dir, host=options.host, port=int(options.port), |
17 | - dns_srv=options.dns_srv, ssl=True, |
18 | - disable_ssl_verify=options.disable_ssl_verify, |
19 | + partials_dir, options.server, |
20 | mark_interval=options.mark_interval, |
21 | broadcast_events=options.send_events_over_dbus, |
22 | handshake_timeout=options.handshake_timeout, |
23 | |
24 | === modified file 'data/syncdaemon.conf' |
25 | --- data/syncdaemon.conf 2016-09-17 01:06:23 +0000 |
26 | +++ data/syncdaemon.conf 2017-02-22 16:49:18 +0000 |
27 | @@ -1,18 +1,9 @@ |
28 | [__main__] |
29 | -host.default = fs-1.one.ubuntu.com |
30 | -host.help = The server address |
31 | - |
32 | -dns_srv.default = _https._tcp.fs.one.ubuntu.com |
33 | -dns_srv.help = The DNS SRV record |
34 | - |
35 | -disable_ssl_verify.default = False |
36 | -disable_ssl_verify.action = store_true |
37 | -disable_ssl_verify.parser = bool |
38 | -disable_ssl_verify.help = Disable SSL certificate verification in a test environment. |
39 | - |
40 | -port.default = 443 |
41 | -port.parser = int |
42 | -port.help = The port on which to connect to the server |
43 | +server.default = localhost:443 |
44 | +server.parser = connection |
45 | +server.help = The info to connect to the server: a comma-separated |
46 | + list of HOST:PORT or HOST:PORT:SSL_MODE (SSL_MODE |
47 | + options: 'plain', 'ssl', 'ssl_noverify', defaults to 'ssl') |
48 | |
49 | files_sync_enabled.default = True |
50 | files_sync_enabled.action = store_true |
51 | |
52 | === modified file 'ubuntuone/syncdaemon/action_queue.py' |
53 | --- ubuntuone/syncdaemon/action_queue.py 2017-01-07 14:01:39 +0000 |
54 | +++ ubuntuone/syncdaemon/action_queue.py 2017-02-22 16:49:18 +0000 |
55 | @@ -30,9 +30,9 @@ |
56 | """Queue and execute operations on the server.""" |
57 | |
58 | import inspect |
59 | +import itertools |
60 | import logging |
61 | import os |
62 | -import random |
63 | import tempfile |
64 | import traceback |
65 | import zlib |
66 | @@ -45,7 +45,6 @@ |
67 | from zope.interface import implements |
68 | from twisted.internet import reactor, defer, task |
69 | from twisted.internet import error as twisted_errors |
70 | -from twisted.names import client as dns_client |
71 | from twisted.python.failure import Failure, DefaultException |
72 | |
73 | from ubuntuone import clientdefs |
74 | @@ -756,8 +755,7 @@ |
75 | implements(IActionQueue) |
76 | protocol = ActionQueueProtocol |
77 | |
78 | - def __init__(self, event_queue, main, host, port, dns_srv, |
79 | - use_ssl=False, disable_ssl_verify=False, |
80 | + def __init__(self, event_queue, main, connection_info, |
81 | read_limit=None, write_limit=None, throttling_enabled=False, |
82 | connection_timeout=30): |
83 | ThrottlingStorageClientFactory.__init__( |
84 | @@ -765,11 +763,8 @@ |
85 | throttling_enabled=throttling_enabled) |
86 | self.event_queue = event_queue |
87 | self.main = main |
88 | - self.host = host |
89 | - self.port = port |
90 | - self.dns_srv = dns_srv |
91 | - self.use_ssl = use_ssl |
92 | - self.disable_ssl_verify = disable_ssl_verify |
93 | + self.connection_info = itertools.cycle(connection_info) |
94 | + |
95 | self.connection_timeout = connection_timeout |
96 | self.credentials = {} |
97 | |
98 | @@ -787,7 +782,6 @@ |
99 | self.zip_queue = ZipQueue() |
100 | self.conditions_locker = ConditionsLocker() |
101 | self.disk_queue = offload_queue.OffloadQueue() |
102 | - self.tunnel_runner = tunnel_runner.TunnelRunner(self.host, self.port) |
103 | |
104 | self.estimated_free_space = {} |
105 | event_queue.subscribe(self) |
106 | @@ -862,53 +856,22 @@ |
107 | self.event_queue.push('SV_VOLUME_NEW_GENERATION', |
108 | volume_id=volume_id, generation=generation) |
109 | |
110 | - def _lookup_srv(self): |
111 | - """Do the SRV lookup. |
112 | - |
113 | - Return a deferred whose callback is going to be called with |
114 | - (host, port). If we can't do the lookup, the default host, port |
115 | - is used. |
116 | - |
117 | - """ |
118 | - |
119 | - def on_lookup_ok(results): |
120 | - """Get a random host from the SRV result.""" |
121 | - logger.debug('SRV lookup done, choosing a server.') |
122 | - records, auth, add = results |
123 | - if not records: |
124 | - raise ValueError('No available records.') |
125 | - # pick a random server |
126 | - record = random.choice(records) |
127 | - logger.debug('Using record: %r', record) |
128 | - if record.payload: |
129 | - return record.payload.target.name, record.payload.port |
130 | - else: |
131 | - logger.info('Empty SRV record, fallback to %r:%r', |
132 | - self.host, self.port) |
133 | - return self.host, self.port |
134 | - |
135 | - def on_lookup_error(failure): |
136 | - """Return the default host/post on a DNS SRV lookup failure.""" |
137 | - logger.info("SRV lookup error, fallback to %r:%r \n%s", |
138 | - self.host, self.port, failure.getTraceback()) |
139 | - return self.host, self.port |
140 | - |
141 | - if self.dns_srv: |
142 | - # lookup the DNS SRV records |
143 | - d = dns_client.lookupService(self.dns_srv, timeout=[3, 2]) |
144 | - d.addCallback(on_lookup_ok) |
145 | - d.addErrback(on_lookup_error) |
146 | - return d |
147 | - else: |
148 | - return defer.succeed((self.host, self.port)) |
149 | + def _get_tunnel_runner(self, host, port): |
150 | + """Build the tunnel runner.""" |
151 | + return tunnel_runner.TunnelRunner(host, port) |
152 | |
153 | @defer.inlineCallbacks |
154 | - def _make_connection(self, result): |
155 | + def _make_connection(self): |
156 | """Do the real connect call.""" |
157 | - host, port = result |
158 | - ssl_context = get_ssl_context(self.disable_ssl_verify, host) |
159 | - client = yield self.tunnel_runner.get_client() |
160 | - if self.use_ssl: |
161 | + connection_info = self.connection_info.next() |
162 | + logger.info("Attempting connection to %s", connection_info) |
163 | + host = connection_info['host'] |
164 | + port = connection_info['port'] |
165 | + tunnelrunner = self._get_tunnel_runner(host, port) |
166 | + client = yield tunnelrunner.get_client() |
167 | + if connection_info['use_ssl']: |
168 | + ssl_context = get_ssl_context( |
169 | + connection_info['disable_ssl_verify'], host) |
170 | self.connector = client.connectSSL( |
171 | host, port, factory=self, contextFactory=ssl_context, |
172 | timeout=self.connection_timeout) |
173 | @@ -925,9 +888,7 @@ |
174 | return |
175 | |
176 | self.connect_in_progress = True |
177 | - d = self._lookup_srv() |
178 | - # DNS lookup always succeeds, proceed to actually connect |
179 | - d.addCallback(self._make_connection) |
180 | + self._make_connection() |
181 | |
182 | def buildProtocol(self, addr): |
183 | """Build the client and store it. Connect callbacks.""" |
184 | |
185 | === modified file 'ubuntuone/syncdaemon/config.py' |
186 | --- ubuntuone/syncdaemon/config.py 2016-09-17 01:06:23 +0000 |
187 | +++ ubuntuone/syncdaemon/config.py 2017-02-22 16:49:18 +0000 |
188 | @@ -1,6 +1,7 @@ |
189 | # ubuntuone.syncdaemon.config - SyncDaemon config utilities |
190 | # |
191 | # Copyright 2009-2012 Canonical Ltd. |
192 | +# Copyright 2017 Chicharreros (https://launchpad.net/~chicharreros) |
193 | # |
194 | # This program is free software: you can redistribute it and/or modify it |
195 | # under the terms of the GNU General Public License version 3, as published |
196 | @@ -128,6 +129,42 @@ |
197 | return result |
198 | |
199 | |
200 | +def server_connection_parser(value): |
201 | + """Parser for the server connection info.""" |
202 | + results = [] |
203 | + for item in value.split(","): |
204 | + ci_parts = item.split(':') |
205 | + if len(ci_parts) == 2: |
206 | + host, port = ci_parts |
207 | + mode = 'ssl' # default |
208 | + elif len(ci_parts) == 3: |
209 | + host, port, mode = ci_parts |
210 | + else: |
211 | + raise ValueError( |
212 | + "--server info must be HOST:PORT or HOST:PORT:SSL_MODE") |
213 | + |
214 | + if mode == 'plain': |
215 | + use_ssl = False |
216 | + disable_ssl_verify = False |
217 | + elif mode == 'ssl': |
218 | + use_ssl = True |
219 | + disable_ssl_verify = False |
220 | + elif mode == 'ssl_noverify': |
221 | + use_ssl = True |
222 | + disable_ssl_verify = True |
223 | + else: |
224 | + raise ValueError( |
225 | + "--server form (HOST:PORT:SSL_MODE) accepts the following" |
226 | + "SSL_MODE options only: 'plain', 'ssl', 'ssl_noverify'") |
227 | + results.append({ |
228 | + 'host': host, |
229 | + 'port': int(port), |
230 | + 'use_ssl': use_ssl, |
231 | + 'disable_ssl_verify': disable_ssl_verify, |
232 | + }) |
233 | + return results |
234 | + |
235 | + |
236 | def log_level_parser(value): |
237 | """Parser for "logging" module log levels. |
238 | |
239 | @@ -157,6 +194,7 @@ |
240 | ('xdg_cache', xdg_cache_dir_parser), |
241 | ('xdg_data', xdg_data_dir_parser), |
242 | ('log_level', log_level_parser), |
243 | + ('connection', server_connection_parser), |
244 | ('throttling_limit', throttling_limit_parser)] |
245 | |
246 | |
247 | |
248 | === modified file 'ubuntuone/syncdaemon/main.py' |
249 | --- ubuntuone/syncdaemon/main.py 2016-09-17 01:06:23 +0000 |
250 | +++ ubuntuone/syncdaemon/main.py 2017-02-22 16:49:18 +0000 |
251 | @@ -1,7 +1,7 @@ |
252 | # -*- coding: utf-8 -*- |
253 | # |
254 | # Copyright 2009-2015 Canonical Ltd. |
255 | -# Copyright 2015-2016 Chicharreros (https://launchpad.net/~chicharreros) |
256 | +# Copyright 2015-2017 Chicharreros (https://launchpad.net/~chicharreros) |
257 | # |
258 | # This program is free software: you can redistribute it and/or modify it |
259 | # under the terms of the GNU General Public License version 3, as published |
260 | @@ -83,10 +83,8 @@ |
261 | """The one who executes the syncdaemon.""" |
262 | |
263 | def __init__(self, root_dir, shares_dir, data_dir, partials_dir, |
264 | - host='fs-1.one.ubuntu.com', port=443, dns_srv=None, ssl=True, |
265 | - disable_ssl_verify=False, |
266 | - mark_interval=120, broadcast_events=False, |
267 | - handshake_timeout=30, |
268 | + connection_info, mark_interval=120, |
269 | + broadcast_events=False, handshake_timeout=30, |
270 | shares_symlink_name='Shared With Me', |
271 | read_limit=None, write_limit=None, throttling_enabled=False, |
272 | ignore_files=None, auth_credentials=None, |
273 | @@ -125,9 +123,7 @@ |
274 | |
275 | # we don't have the auth tokens yet, we 'll get them later |
276 | self.action_q = action_queue.ActionQueue(self.event_q, self, |
277 | - host, port, |
278 | - dns_srv, ssl, |
279 | - disable_ssl_verify, |
280 | + connection_info, |
281 | read_limit, write_limit, |
282 | throttling_enabled) |
283 | self.hash_q = hash_queue.HashQueue(self.event_q) |
284 | |
285 | === modified file 'ubuntuone/syncdaemon/states.py' |
286 | --- ubuntuone/syncdaemon/states.py 2015-09-19 23:15:50 +0000 |
287 | +++ ubuntuone/syncdaemon/states.py 2017-02-22 16:49:18 +0000 |
288 | @@ -1,8 +1,5 @@ |
289 | -# ubuntuone.syncdaemon.states.py - States! |
290 | -# |
291 | -# Author: Facundo Batista <facundo@canonical.com> |
292 | -# |
293 | # Copyright 2010-2012 Canonical Ltd. |
294 | +# Copyright 2017 Chicharreros (https://launchpad.net/~chicharreros) |
295 | # |
296 | # This program is free software: you can redistribute it and/or modify it |
297 | # under the terms of the GNU General Public License version 3, as published |
298 | @@ -63,7 +60,7 @@ |
299 | self.sm = state_manager |
300 | self.eq = state_manager.main.event_q |
301 | self.handshake_timeout = handshake_timeout |
302 | - self.waiting_timeout = 1 |
303 | + self.waiting_timeout = .2 |
304 | self.state = self.NU_NN |
305 | self.working = True |
306 | |
307 | |
308 | === modified file 'ubuntuone/syncdaemon/tests/test_action_queue.py' |
309 | --- ubuntuone/syncdaemon/tests/test_action_queue.py 2017-01-07 14:01:39 +0000 |
310 | +++ ubuntuone/syncdaemon/tests/test_action_queue.py 2017-02-22 16:49:18 +0000 |
311 | @@ -1,7 +1,7 @@ |
312 | # -*- coding: utf-8 -*- |
313 | # |
314 | # Copyright 2009-2015 Canonical Ltd. |
315 | -# Copyright 2016-2017 Chicharreros |
316 | +# Copyright 2016-2017 Chicharreros (https://launchpad.net/~chicharreros) |
317 | # |
318 | # This program is free software: you can redistribute it and/or modify it |
319 | # under the terms of the GNU General Public License version 3, as published |
320 | @@ -33,6 +33,7 @@ |
321 | |
322 | import collections |
323 | import inspect |
324 | +import itertools |
325 | import logging |
326 | import operator |
327 | import os |
328 | @@ -237,9 +238,11 @@ |
329 | class SavingConnectionTunnelRunner(object): |
330 | """A fake proxy.tunnel_client.TunnelRunner.""" |
331 | |
332 | - def __init__(self, *args): |
333 | + def __init__(self, host, port): |
334 | """Fake a proxy tunnel.""" |
335 | self.client = FakeTunnelClient() |
336 | + self.host = host |
337 | + self.port = port |
338 | |
339 | def get_client(self): |
340 | """Always return the reactor.""" |
341 | @@ -287,7 +290,8 @@ |
342 | |
343 | # set up FakeMain to use the testing AQ, the port will be decided later |
344 | self.patch(FakeMain, '_fake_AQ_class', TestActionQueue) |
345 | - self.patch(FakeMain, '_fake_AQ_params', ('127.0.0.1', 0, False)) |
346 | + connection_info = [dict(host='127.0.0.1', port=0, use_ssl=False)] |
347 | + self.patch(FakeMain, '_fake_AQ_params', (connection_info,)) |
348 | self.patch(offload_queue, "OffloadQueue", FakeOffloadQueue) |
349 | |
350 | self.main = FakeMain(root_dir=self.root, shares_dir=self.shares, |
351 | @@ -1130,12 +1134,23 @@ |
352 | class FactoryBaseTestCase(BasicTestCase): |
353 | """Helper for by-pass Twisted.""" |
354 | |
355 | + def _patch_connection_info(self, **attrvalues): |
356 | + """Helper to patch the ActionQueue connection_info. |
357 | + |
358 | + This assumes there is only one item in the connection_info, which |
359 | + is the case for the tests. |
360 | + """ |
361 | + connection_info = self.action_queue.connection_info.next() |
362 | + for attr, value in attrvalues.items(): |
363 | + connection_info[attr] = value |
364 | + self.action_queue.connection_info = itertools.cycle([connection_info]) |
365 | + |
366 | def _start_sample_webserver(self): |
367 | """Start a web server serving content at its root""" |
368 | # start listening on `decide yourself` port, and fix AQ with it |
369 | website = server.Site(None) |
370 | webport = reactor.listenTCP(0, website) |
371 | - self.action_queue.port = webport.getHost().port |
372 | + self._patch_connection_info(port=webport.getHost().port) |
373 | |
374 | server_transport_deferred = defer.Deferred() |
375 | transport_class = webport.transport |
376 | @@ -1356,8 +1371,9 @@ |
377 | |
378 | def test_connection_started_logging(self): |
379 | """Test that the connection started logs connector info, not AQ's.""" |
380 | - assert self.action_queue.host == '127.0.0.1' |
381 | - assert self.action_queue.port == 0 |
382 | + connection_info = self.action_queue.connection_info.next() |
383 | + assert connection_info['host'] == '127.0.0.1' |
384 | + assert connection_info['port'] == 0 |
385 | |
386 | class FakeConnector(object): |
387 | """Fake connector.""" |
388 | @@ -1368,26 +1384,70 @@ |
389 | self.assertTrue(self.handler.check_info("Connection started", |
390 | "host 1.2.3.4", "port 4321")) |
391 | |
392 | + @defer.inlineCallbacks |
393 | + def test_connection_info_rotation(self): |
394 | + """It tries to connect to different servers.""" |
395 | + |
396 | + multiple_conn = [ |
397 | + {'host': 'host1', 'port': 'port1', 'use_ssl': False}, |
398 | + {'host': 'host2', 'port': 'port2', 'use_ssl': False}, |
399 | + ] |
400 | + self.action_queue.connection_info = itertools.cycle(multiple_conn) |
401 | + |
402 | + self.tunnel_runner = None |
403 | + |
404 | + def mitm(*args): |
405 | + tunnel_runner = SavingConnectionTunnelRunner(*args) |
406 | + self.tunnel_runner = tunnel_runner |
407 | + return tunnel_runner |
408 | + |
409 | + self.action_queue._get_tunnel_runner = mitm |
410 | + |
411 | + yield self.action_queue._make_connection() |
412 | + self.assertEqual(self.tunnel_runner.host, 'host1') |
413 | + self.assertEqual(self.tunnel_runner.port, 'port1') |
414 | + |
415 | + yield self.action_queue._make_connection() |
416 | + self.assertEqual(self.tunnel_runner.host, 'host2') |
417 | + self.assertEqual(self.tunnel_runner.port, 'port2') |
418 | + |
419 | + yield self.action_queue._make_connection() |
420 | + self.assertEqual(self.tunnel_runner.host, 'host1') |
421 | + self.assertEqual(self.tunnel_runner.port, 'port1') |
422 | + |
423 | |
424 | class TunnelRunnerTestCase(FactoryBaseTestCase): |
425 | """Tests for the tunnel runner.""" |
426 | |
427 | tunnel_runner_class = SavingConnectionTunnelRunner |
428 | |
429 | + def setUp(self): |
430 | + result = super(TunnelRunnerTestCase, self).setUp() |
431 | + self.tunnel_runner = None |
432 | + orig_get_tunnel_runner = self.action_queue._get_tunnel_runner |
433 | + |
434 | + def mitm(*args): |
435 | + tunnel_runner = orig_get_tunnel_runner(*args) |
436 | + self.tunnel_runner = tunnel_runner |
437 | + return tunnel_runner |
438 | + |
439 | + self.action_queue._get_tunnel_runner = mitm |
440 | + return result |
441 | + |
442 | @defer.inlineCallbacks |
443 | def test_make_connection_uses_tunnelrunner_non_ssl(self): |
444 | """Check that _make_connection uses TunnelRunner.""" |
445 | - self.action_queue.use_ssl = False |
446 | - yield self.action_queue._make_connection(("127.0.0.1", 1234)) |
447 | - self.assertTrue(self.action_queue.tunnel_runner.client.tcp_connected, |
448 | + self._patch_connection_info(use_ssl=False) |
449 | + yield self.action_queue._make_connection() |
450 | + self.assertTrue(self.tunnel_runner.client.tcp_connected, |
451 | "connectTCP is called on the client.") |
452 | |
453 | @defer.inlineCallbacks |
454 | def test_make_connection_uses_tunnelrunner_ssl(self): |
455 | """Check that _make_connection uses TunnelRunner.""" |
456 | - self.action_queue.use_ssl = True |
457 | - yield self.action_queue._make_connection(("127.0.0.1", 1234)) |
458 | - self.assertTrue(self.action_queue.tunnel_runner.client.ssl_connected, |
459 | + self._patch_connection_info(use_ssl=True, disable_ssl_verify=False) |
460 | + yield self.action_queue._make_connection() |
461 | + self.assertTrue(self.tunnel_runner.client.ssl_connected, |
462 | "connectSSL is called on the client.") |
463 | |
464 | |
465 | @@ -1400,13 +1460,18 @@ |
466 | def test_context_request_passes_host(self): |
467 | """The context is requested passing the host.""" |
468 | fake_host = "fake_host" |
469 | + fake_disable_ssl_verify = False |
470 | |
471 | def fake_get_ssl_context(disable_ssl_verify, host): |
472 | """The host is used to call get_ssl_context.""" |
473 | + self.assertEqual(disable_ssl_verify, fake_disable_ssl_verify) |
474 | self.assertEqual(host, fake_host) |
475 | |
476 | self.patch(action_queue, "get_ssl_context", fake_get_ssl_context) |
477 | - yield self.action_queue._make_connection((fake_host, 1234)) |
478 | + self._patch_connection_info( |
479 | + host=fake_host, use_ssl=True, |
480 | + disable_ssl_verify=fake_disable_ssl_verify) |
481 | + yield self.action_queue._make_connection() |
482 | |
483 | |
484 | class ConnectedBaseTestCase(FactoryBaseTestCase): |
485 | |
486 | === modified file 'ubuntuone/syncdaemon/tests/test_config.py' |
487 | --- ubuntuone/syncdaemon/tests/test_config.py 2016-09-17 01:06:23 +0000 |
488 | +++ ubuntuone/syncdaemon/tests/test_config.py 2017-02-22 16:49:18 +0000 |
489 | @@ -1,6 +1,7 @@ |
490 | # encoding: utf-8 |
491 | # |
492 | # Copyright 2009-2012 Canonical Ltd. |
493 | +# Copyright 2017 Chicharreros (https://launchpad.net/~chicharreros) |
494 | # |
495 | # This program is free software: you can redistribute it and/or modify it |
496 | # under the terms of the GNU General Public License version 3, as published |
497 | @@ -494,6 +495,73 @@ |
498 | self.assertEqual(logging.DEBUG, parser(bad_value)) |
499 | self.assertEqual(logging.DEBUG, parser(invalid_value)) |
500 | |
501 | + def test_serverconnection_simple_defaultmode(self): |
502 | + results = config.server_connection_parser('test.host:666') |
503 | + self.assertEqual(results, [{ |
504 | + 'host': 'test.host', |
505 | + 'port': 666, |
506 | + 'use_ssl': True, |
507 | + 'disable_ssl_verify': False, |
508 | + }]) |
509 | + |
510 | + def test_serverconnection_simple_plain(self): |
511 | + results = config.server_connection_parser('test.host:666:plain') |
512 | + self.assertEqual(results, [{ |
513 | + 'host': 'test.host', |
514 | + 'port': 666, |
515 | + 'use_ssl': False, |
516 | + 'disable_ssl_verify': False, |
517 | + }]) |
518 | + |
519 | + def test_serverconnection_simple_ssl(self): |
520 | + results = config.server_connection_parser('test.host:666:ssl') |
521 | + self.assertEqual(results, [{ |
522 | + 'host': 'test.host', |
523 | + 'port': 666, |
524 | + 'use_ssl': True, |
525 | + 'disable_ssl_verify': False, |
526 | + }]) |
527 | + |
528 | + def test_serverconnection_simple_noverify(self): |
529 | + results = config.server_connection_parser('test.host:666:ssl_noverify') |
530 | + self.assertEqual(results, [{ |
531 | + 'host': 'test.host', |
532 | + 'port': 666, |
533 | + 'use_ssl': True, |
534 | + 'disable_ssl_verify': True, |
535 | + }]) |
536 | + |
537 | + def test_serverconnection_simple_bad_mode(self): |
538 | + self.assertRaises( |
539 | + ValueError, config.server_connection_parser, 'host:666:badmode') |
540 | + |
541 | + def test_serverconnection_simple_too_many_parts(self): |
542 | + self.assertRaises( |
543 | + ValueError, config.server_connection_parser, 'host:666:plain:what') |
544 | + |
545 | + def test_serverconnection_simple_too_few_parts(self): |
546 | + self.assertRaises( |
547 | + ValueError, config.server_connection_parser, 'test.host') |
548 | + |
549 | + def test_serverconnection_simple_port_not_numeric(self): |
550 | + self.assertRaises( |
551 | + ValueError, config.server_connection_parser, 'test.host:port') |
552 | + |
553 | + def test_serverconnection_multiple(self): |
554 | + results = config.server_connection_parser( |
555 | + 'test.host1:666:plain,host2.com:447') |
556 | + self.assertEqual(results, [{ |
557 | + 'host': 'test.host1', |
558 | + 'port': 666, |
559 | + 'use_ssl': False, |
560 | + 'disable_ssl_verify': False, |
561 | + }, { |
562 | + 'host': 'host2.com', |
563 | + 'port': 447, |
564 | + 'use_ssl': True, |
565 | + 'disable_ssl_verify': False, |
566 | + }]) |
567 | + |
568 | |
569 | class XdgHomeParsersTests(BaseTwistedTestCase): |
570 | """Tests for our custom xdg parsers.""" |
571 | |
572 | === modified file 'ubuntuone/syncdaemon/tests/test_main.py' |
573 | --- ubuntuone/syncdaemon/tests/test_main.py 2016-09-17 14:29:53 +0000 |
574 | +++ ubuntuone/syncdaemon/tests/test_main.py 2017-02-22 16:49:18 +0000 |
575 | @@ -1,6 +1,7 @@ |
576 | # -*- coding: utf-8 -*- |
577 | # |
578 | # Copyright 2009-2015 Canonical Ltd. |
579 | +# Copyright 2016-2017 Chicharreros (https://launchpad.net/~chicharreros) |
580 | # |
581 | # This program is free software: you can redistribute it and/or modify it |
582 | # under the terms of the GNU General Public License version 3, as published |
583 | @@ -96,8 +97,7 @@ |
584 | shares_dir=self.shares, |
585 | data_dir=self.data, |
586 | partials_dir=self.partials_dir, |
587 | - host='localhost', port=0, |
588 | - dns_srv=False, ssl=False, |
589 | + connection_info='localhost:0:plain', |
590 | mark_interval=60, |
591 | handshake_timeout=2, |
592 | auth_credentials=FAKED_CREDENTIALS, |
Comments addressed