Merge lp:~alecu/ubuntuone-client/fix-broken-tunnel into lp:ubuntuone-client

Proposed by Alejandro J. Cura
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 1219
Merged at revision: 1221
Proposed branch: lp:~alecu/ubuntuone-client/fix-broken-tunnel
Merge into: lp:ubuntuone-client
Diff against target: 145 lines (+59/-4)
4 files modified
tests/proxy/test_tunnel_server.py (+33/-0)
tests/syncdaemon/test_tunnel_runner.py (+9/-0)
ubuntuone/proxy/tunnel_server.py (+10/-2)
ubuntuone/syncdaemon/tunnel_runner.py (+7/-2)
To merge this branch: bzr merge lp:~alecu/ubuntuone-client/fix-broken-tunnel
Reviewer Review Type Date Requested Status
Diego Sarmentero (community) Approve
Eric Casteleijn (community) Approve
Review via email: mp+100133@code.launchpad.net

Commit message

- Do not use the Qt Dbus mainloop on Windows (LP: #969150).
- Force using the system proxy on Windows (LP: #969157).

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) wrote :

+1

review: Approve
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/proxy/test_tunnel_server.py'
--- tests/proxy/test_tunnel_server.py 2012-03-24 00:10:25 +0000
+++ tests/proxy/test_tunnel_server.py 2012-03-30 12:59:21 +0000
@@ -549,6 +549,7 @@
549class FakeNetworkProxyFactoryClass(object):549class FakeNetworkProxyFactoryClass(object):
550 """A fake QNetworkProxyFactory."""550 """A fake QNetworkProxyFactory."""
551 last_query = None551 last_query = None
552 use_system = False
552553
553 def __init__(self, enabled):554 def __init__(self, enabled):
554 """Initialize this fake instance."""555 """Initialize this fake instance."""
@@ -561,6 +562,16 @@
561 """Return the proxy type configured."""562 """Return the proxy type configured."""
562 return self.proxy_type563 return self.proxy_type
563564
565 @classmethod
566 def setUseSystemConfiguration(cls, new_value):
567 """Save the system configuration requested."""
568 cls.use_system = new_value
569
570 @classmethod
571 def useSystemConfiguration(cls):
572 """Is the system configured for proxies?"""
573 return cls.use_system
574
564 def systemProxyForQuery(self, query):575 def systemProxyForQuery(self, query):
565 """A list of proxies, but only type() will be called on the first."""576 """A list of proxies, but only type() will be called on the first."""
566 return [self]577 return [self]
@@ -610,6 +621,7 @@
610 self.patch(tunnel_server, "QNetworkProxyFactory", fake_netproxfact)621 self.patch(tunnel_server, "QNetworkProxyFactory", fake_netproxfact)
611 self._assert_proxy_enabled("windows 1.0")622 self._assert_proxy_enabled("windows 1.0")
612 self.assertEqual(len(self.app_proxy), 0)623 self.assertEqual(len(self.app_proxy), 0)
624 self.assertTrue(fake_netproxfact.useSystemConfiguration())
613625
614 def test_platform_other_disabled(self):626 def test_platform_other_disabled(self):
615 """Tests for any other platform with proxies disabled."""627 """Tests for any other platform with proxies disabled."""
@@ -617,6 +629,7 @@
617 self.patch(tunnel_server, "QNetworkProxyFactory", fake_netproxfact)629 self.patch(tunnel_server, "QNetworkProxyFactory", fake_netproxfact)
618 self._assert_proxy_disabled("windows 1.0")630 self._assert_proxy_disabled("windows 1.0")
619 self.assertEqual(len(self.app_proxy), 0)631 self.assertEqual(len(self.app_proxy), 0)
632 self.assertTrue(fake_netproxfact.useSystemConfiguration())
620633
621634
622class FakeQCoreApp(object):635class FakeQCoreApp(object):
@@ -683,3 +696,23 @@
683 tunnel_server.main(["example.com", "443"])696 tunnel_server.main(["example.com", "443"])
684 self.assertIn("Proxy not enabled.", self.fake_stdout.getvalue())697 self.assertIn("Proxy not enabled.", self.fake_stdout.getvalue())
685 self.assertEqual(FakeQCoreApp.fake_instance, None)698 self.assertEqual(FakeQCoreApp.fake_instance, None)
699
700 def test_qtdbus_installed_on_linux(self):
701 """The QtDbus mainloop is installed."""
702 self.patch(tunnel_server.sys, "platform", "linux123")
703 installed = []
704 self.patch(tunnel_server, "install_qt_dbus",
705 lambda: installed.append(None))
706 self.proxies_enabled = True
707 tunnel_server.main(["example.com", "443"])
708 self.assertEqual(len(installed), 1)
709
710 def test_qtdbus_not_installed_on_windows(self):
711 """The QtDbus mainloop is installed."""
712 self.patch(tunnel_server.sys, "platform", "win98")
713 installed = []
714 self.patch(tunnel_server, "install_qt_dbus",
715 lambda: installed.append(None))
716 self.proxies_enabled = True
717 tunnel_server.main(["example.com", "443"])
718 self.assertEqual(len(installed), 0)
686719
=== modified file 'tests/syncdaemon/test_tunnel_runner.py'
--- tests/syncdaemon/test_tunnel_runner.py 2012-03-27 03:41:06 +0000
+++ tests/syncdaemon/test_tunnel_runner.py 2012-03-30 12:59:21 +0000
@@ -179,3 +179,12 @@
179 self.addCleanup(delattr, sys, "frozen")179 self.addCleanup(delattr, sys, "frozen")
180 self.assertEqual(os.path.dirname(self.tr.get_process_path()),180 self.assertEqual(os.path.dirname(self.tr.get_process_path()),
181 os.path.dirname(sys.executable))181 os.path.dirname(sys.executable))
182
183 def test_start_process_win_devel(self):
184 """Test the windows devel case."""
185 fake_python = r"c:\python99\python.exe"
186 self.patch(sys, "platform", "win98")
187 self.patch(tunnel_runner.procutils, "which", lambda _: [fake_python])
188 tunnel_runner.TunnelRunner("fs-1.one.ubuntu.com", 443)
189 args, kwargs = self.spawned[1]
190 self.assertEqual(args[1], fake_python)
182191
=== modified file 'ubuntuone/proxy/tunnel_server.py'
--- ubuntuone/proxy/tunnel_server.py 2012-03-24 00:10:25 +0000
+++ ubuntuone/proxy/tunnel_server.py 2012-03-30 12:59:21 +0000
@@ -353,19 +353,27 @@
353 logger.info("Proxy is disabled.")353 logger.info("Proxy is disabled.")
354 return enabled354 return enabled
355 else:355 else:
356 QNetworkProxyFactory.setUseSystemConfiguration(True)
356 query = QNetworkProxyQuery(host, port)357 query = QNetworkProxyQuery(host, port)
357 proxies = QNetworkProxyFactory.systemProxyForQuery(query)358 proxies = QNetworkProxyFactory.systemProxyForQuery(query)
358 return len(proxies) and proxies[0].type() != QNetworkProxy.DefaultProxy359 return len(proxies) and proxies[0].type() != QNetworkProxy.DefaultProxy
359360
360361
362def install_qt_dbus():
363 """Import and install the qt+dbus integration."""
364 from dbus.mainloop.qt import DBusQtMainLoop
365 DBusQtMainLoop(set_as_default=True)
366
367
361def main(argv):368def main(argv):
362 """The main function for the tunnel server."""369 """The main function for the tunnel server."""
363 if not check_proxy_enabled(*argv[1:]):370 if not check_proxy_enabled(*argv[1:]):
364 sys.stdout.write("Proxy not enabled.")371 sys.stdout.write("Proxy not enabled.")
365 sys.stdout.flush()372 sys.stdout.flush()
366 else:373 else:
367 from dbus.mainloop.qt import DBusQtMainLoop374 if sys.platform.startswith("linux"):
368 DBusQtMainLoop(set_as_default=True)375 install_qt_dbus()
376
369 app = QCoreApplication(argv)377 app = QCoreApplication(argv)
370 cookie = str(uuid.uuid4())378 cookie = str(uuid.uuid4())
371 tunnel_server = TunnelServer(cookie)379 tunnel_server = TunnelServer(cookie)
372380
=== modified file 'ubuntuone/syncdaemon/tunnel_runner.py'
--- ubuntuone/syncdaemon/tunnel_runner.py 2012-03-27 03:41:06 +0000
+++ ubuntuone/syncdaemon/tunnel_runner.py 2012-03-30 12:59:21 +0000
@@ -21,6 +21,7 @@
21from os import path21from os import path
2222
23from twisted.internet import defer, reactor23from twisted.internet import defer, reactor
24from twisted.python import procutils
2425
25from ubuntuone.platform.constants import TUNNEL_EXECUTABLE26from ubuntuone.platform.constants import TUNNEL_EXECUTABLE
2627
@@ -48,8 +49,12 @@
48 from ubuntuone.proxy.tunnel_client import TunnelProcessProtocol49 from ubuntuone.proxy.tunnel_client import TunnelProcessProtocol
49 protocol = TunnelProcessProtocol(self.client_d)50 protocol = TunnelProcessProtocol(self.client_d)
50 process_path = self.get_process_path()51 process_path = self.get_process_path()
51 args = [TUNNEL_EXECUTABLE, host, str(port)]52 args = [process_path, host, str(port)]
52 self.process_transport = reactor.spawnProcess(protocol, process_path,53 if sys.platform.startswith("win") and not process_path.endswith("exe"):
54 python_exe = procutils.which("python.exe")
55 if python_exe:
56 args.insert(0, python_exe[0])
57 self.process_transport = reactor.spawnProcess(protocol, args[0],
53 env=None, args=args)58 env=None, args=args)
54 reactor.addSystemEventTrigger("before", "shutdown", self.stop)59 reactor.addSystemEventTrigger("before", "shutdown", self.stop)
5560

Subscribers

People subscribed via source and target branches