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
1=== modified file 'tests/proxy/test_tunnel_server.py'
2--- tests/proxy/test_tunnel_server.py 2012-03-24 00:10:25 +0000
3+++ tests/proxy/test_tunnel_server.py 2012-03-30 12:59:21 +0000
4@@ -549,6 +549,7 @@
5 class FakeNetworkProxyFactoryClass(object):
6 """A fake QNetworkProxyFactory."""
7 last_query = None
8+ use_system = False
9
10 def __init__(self, enabled):
11 """Initialize this fake instance."""
12@@ -561,6 +562,16 @@
13 """Return the proxy type configured."""
14 return self.proxy_type
15
16+ @classmethod
17+ def setUseSystemConfiguration(cls, new_value):
18+ """Save the system configuration requested."""
19+ cls.use_system = new_value
20+
21+ @classmethod
22+ def useSystemConfiguration(cls):
23+ """Is the system configured for proxies?"""
24+ return cls.use_system
25+
26 def systemProxyForQuery(self, query):
27 """A list of proxies, but only type() will be called on the first."""
28 return [self]
29@@ -610,6 +621,7 @@
30 self.patch(tunnel_server, "QNetworkProxyFactory", fake_netproxfact)
31 self._assert_proxy_enabled("windows 1.0")
32 self.assertEqual(len(self.app_proxy), 0)
33+ self.assertTrue(fake_netproxfact.useSystemConfiguration())
34
35 def test_platform_other_disabled(self):
36 """Tests for any other platform with proxies disabled."""
37@@ -617,6 +629,7 @@
38 self.patch(tunnel_server, "QNetworkProxyFactory", fake_netproxfact)
39 self._assert_proxy_disabled("windows 1.0")
40 self.assertEqual(len(self.app_proxy), 0)
41+ self.assertTrue(fake_netproxfact.useSystemConfiguration())
42
43
44 class FakeQCoreApp(object):
45@@ -683,3 +696,23 @@
46 tunnel_server.main(["example.com", "443"])
47 self.assertIn("Proxy not enabled.", self.fake_stdout.getvalue())
48 self.assertEqual(FakeQCoreApp.fake_instance, None)
49+
50+ def test_qtdbus_installed_on_linux(self):
51+ """The QtDbus mainloop is installed."""
52+ self.patch(tunnel_server.sys, "platform", "linux123")
53+ installed = []
54+ self.patch(tunnel_server, "install_qt_dbus",
55+ lambda: installed.append(None))
56+ self.proxies_enabled = True
57+ tunnel_server.main(["example.com", "443"])
58+ self.assertEqual(len(installed), 1)
59+
60+ def test_qtdbus_not_installed_on_windows(self):
61+ """The QtDbus mainloop is installed."""
62+ self.patch(tunnel_server.sys, "platform", "win98")
63+ installed = []
64+ self.patch(tunnel_server, "install_qt_dbus",
65+ lambda: installed.append(None))
66+ self.proxies_enabled = True
67+ tunnel_server.main(["example.com", "443"])
68+ self.assertEqual(len(installed), 0)
69
70=== modified file 'tests/syncdaemon/test_tunnel_runner.py'
71--- tests/syncdaemon/test_tunnel_runner.py 2012-03-27 03:41:06 +0000
72+++ tests/syncdaemon/test_tunnel_runner.py 2012-03-30 12:59:21 +0000
73@@ -179,3 +179,12 @@
74 self.addCleanup(delattr, sys, "frozen")
75 self.assertEqual(os.path.dirname(self.tr.get_process_path()),
76 os.path.dirname(sys.executable))
77+
78+ def test_start_process_win_devel(self):
79+ """Test the windows devel case."""
80+ fake_python = r"c:\python99\python.exe"
81+ self.patch(sys, "platform", "win98")
82+ self.patch(tunnel_runner.procutils, "which", lambda _: [fake_python])
83+ tunnel_runner.TunnelRunner("fs-1.one.ubuntu.com", 443)
84+ args, kwargs = self.spawned[1]
85+ self.assertEqual(args[1], fake_python)
86
87=== modified file 'ubuntuone/proxy/tunnel_server.py'
88--- ubuntuone/proxy/tunnel_server.py 2012-03-24 00:10:25 +0000
89+++ ubuntuone/proxy/tunnel_server.py 2012-03-30 12:59:21 +0000
90@@ -353,19 +353,27 @@
91 logger.info("Proxy is disabled.")
92 return enabled
93 else:
94+ QNetworkProxyFactory.setUseSystemConfiguration(True)
95 query = QNetworkProxyQuery(host, port)
96 proxies = QNetworkProxyFactory.systemProxyForQuery(query)
97 return len(proxies) and proxies[0].type() != QNetworkProxy.DefaultProxy
98
99
100+def install_qt_dbus():
101+ """Import and install the qt+dbus integration."""
102+ from dbus.mainloop.qt import DBusQtMainLoop
103+ DBusQtMainLoop(set_as_default=True)
104+
105+
106 def main(argv):
107 """The main function for the tunnel server."""
108 if not check_proxy_enabled(*argv[1:]):
109 sys.stdout.write("Proxy not enabled.")
110 sys.stdout.flush()
111 else:
112- from dbus.mainloop.qt import DBusQtMainLoop
113- DBusQtMainLoop(set_as_default=True)
114+ if sys.platform.startswith("linux"):
115+ install_qt_dbus()
116+
117 app = QCoreApplication(argv)
118 cookie = str(uuid.uuid4())
119 tunnel_server = TunnelServer(cookie)
120
121=== modified file 'ubuntuone/syncdaemon/tunnel_runner.py'
122--- ubuntuone/syncdaemon/tunnel_runner.py 2012-03-27 03:41:06 +0000
123+++ ubuntuone/syncdaemon/tunnel_runner.py 2012-03-30 12:59:21 +0000
124@@ -21,6 +21,7 @@
125 from os import path
126
127 from twisted.internet import defer, reactor
128+from twisted.python import procutils
129
130 from ubuntuone.platform.constants import TUNNEL_EXECUTABLE
131
132@@ -48,8 +49,12 @@
133 from ubuntuone.proxy.tunnel_client import TunnelProcessProtocol
134 protocol = TunnelProcessProtocol(self.client_d)
135 process_path = self.get_process_path()
136- args = [TUNNEL_EXECUTABLE, host, str(port)]
137- self.process_transport = reactor.spawnProcess(protocol, process_path,
138+ args = [process_path, host, str(port)]
139+ if sys.platform.startswith("win") and not process_path.endswith("exe"):
140+ python_exe = procutils.which("python.exe")
141+ if python_exe:
142+ args.insert(0, python_exe[0])
143+ self.process_transport = reactor.spawnProcess(protocol, args[0],
144 env=None, args=args)
145 reactor.addSystemEventTrigger("before", "shutdown", self.stop)
146

Subscribers

People subscribed via source and target branches