Merge lp:~mikemc/ubuntuone-client/find-proxy-tunnel-fix-1083832 into lp:ubuntuone-client

Proposed by Mike McCracken
Status: Merged
Approved by: Mike McCracken
Approved revision: 1359
Merged at revision: 1362
Proposed branch: lp:~mikemc/ubuntuone-client/find-proxy-tunnel-fix-1083832
Merge into: lp:ubuntuone-client
Diff against target: 206 lines (+37/-61)
5 files modified
tests/syncdaemon/test_tunnel_runner.py (+2/-20)
ubuntuone/platform/constants.py (+0/-5)
ubuntuone/proxy/tunnel_client.py (+7/-1)
ubuntuone/syncdaemon/tunnel_runner.py (+6/-28)
ubuntuone/syncdaemon/utils.py (+22/-7)
To merge this branch: bzr merge lp:~mikemc/ubuntuone-client/find-proxy-tunnel-fix-1083832
Reviewer Review Type Date Requested Status
Brian Curtin (community) Approve
Michał Karnicki (community) Approve
dobey (community) Approve
Review via email: mp+136593@code.launchpad.net

Commit message

- Use dirspec to find proxy tunnel exe, adding support for frozen osx. (LP: #1083832)

Description of the change

- Use dirspec to find proxy tunnel exe, adding support for frozen osx. (LP: #1083832)

Removed tests of old code that checks e.g. getting windows binary when frozen - dirspec tests cover those cases.

Tests pass on linux, and tests relevant to changes here pass on windows and darwin.

Tested IRL on darwin:
- start local squid, set system proxy settings to use it
- frozen app starts proxy-tunnel
- CONNECT to u1 servers shows up in squid access.log

Partially tested IRL on windows:
- starting control panel from source still correctly starts proxy-tunnel.

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

+ print "IN START_PROCESS: tunnel_cmd is %r" % tunnel_cmd # MMCC DEBUG, 11/26 11:37:

review: Needs Fixing
Revision history for this message
Mike McCracken (mikemc) wrote :

Whoops, forgot to push the rev that removed those. Sorry about that.

Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
Michał Karnicki (karni) wrote :

Looks good :)

review: Approve
Revision history for this message
Brian Curtin (brian.curtin) wrote :

Cool.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/syncdaemon/test_tunnel_runner.py'
2--- tests/syncdaemon/test_tunnel_runner.py 2012-04-09 20:08:42 +0000
3+++ tests/syncdaemon/test_tunnel_runner.py 2012-11-29 20:57:21 +0000
4@@ -28,9 +28,6 @@
5 # files in the program, then also delete it here.
6 """Tests for the proxy tunnel runner."""
7
8-import os
9-import sys
10-
11 from twisted.internet import defer, error, reactor, task
12 from twisted.trial.unittest import TestCase
13
14@@ -63,7 +60,8 @@
15 @defer.inlineCallbacks
16 def test_executable_not_found(self):
17 """The executable is not found anywhere."""
18- self.patch(tunnel_runner, "TUNNEL_EXECUTABLE", "this_does_not_exist")
19+ self.patch(tunnel_runner, "get_tunnel_bin_cmd",
20+ lambda *args, **kwargs: ["this_does_not_exist"])
21 tr = tunnel_runner.TunnelRunner(FAKE_HOST, FAKE_PORT)
22 client = yield tr.get_client()
23 self.assertEqual(client, reactor)
24@@ -185,19 +183,3 @@
25 client = yield self.tr.get_client()
26 self.assertEqual(client.tunnel_port, FAKE_PORT)
27 self.assertEqual(client.cookie, FAKE_COOKIE)
28-
29- def test_frozen_path(self):
30- """Ensure the path is correct if sys is frozen."""
31- sys.frozen = "Yes"
32- self.addCleanup(delattr, sys, "frozen")
33- self.assertEqual(os.path.dirname(self.tr.get_process_path()),
34- os.path.dirname(sys.executable))
35-
36- def test_start_process_win_devel(self):
37- """Test the windows devel case."""
38- fake_python = r"c:\python99\python.exe"
39- self.patch(sys, "platform", "win98")
40- self.patch(tunnel_runner.procutils, "which", lambda _: [fake_python])
41- tunnel_runner.TunnelRunner("fs-1.one.ubuntu.com", 443)
42- args, kwargs = self.spawned[1]
43- self.assertEqual(args[1], fake_python)
44
45=== modified file 'ubuntuone/platform/constants.py'
46--- ubuntuone/platform/constants.py 2012-04-09 20:07:05 +0000
47+++ ubuntuone/platform/constants.py 2012-11-29 20:57:21 +0000
48@@ -33,12 +33,7 @@
49
50 import sys
51
52-TUNNEL_EXECUTABLE = "ubuntuone-proxy-tunnel"
53-
54 if sys.platform == "win32":
55 HASHQUEUE_DELAY = 3.0
56- if getattr(sys, "frozen", None) is not None:
57- # Only use the .exe suffix in windows+frozen
58- TUNNEL_EXECUTABLE += ".exe"
59 else:
60 HASHQUEUE_DELAY = 0.5
61
62=== modified file 'ubuntuone/proxy/tunnel_client.py'
63--- ubuntuone/proxy/tunnel_client.py 2012-06-01 04:11:49 +0000
64+++ ubuntuone/proxy/tunnel_client.py 2012-11-29 20:57:21 +0000
65@@ -42,7 +42,8 @@
66
67 METHOD_LINE = "CONNECT %s:%d HTTP/1.0" + CRLF
68 LOCALHOST = "127.0.0.1"
69-logger = logging.getLogger("ubuntuone.Proxy.TunnelClient")
70+
71+logger = logging.getLogger("ubuntuone.SyncDaemon.TunnelClient")
72
73
74 class TunnelClientProtocol(BaseTunnelProtocol):
75@@ -166,6 +167,7 @@
76 def finish_timeout(self):
77 """Stop the timer from firing."""
78 if self.timer and self.timer.active():
79+ logger.debug("canceling timer before connection timeout")
80 self.timer.cancel()
81
82 def processExited(self, status):
83@@ -173,6 +175,7 @@
84 self.finish_timeout()
85 logger.info("Tunnel process exit status %r.", status)
86 if not self.client_d.called:
87+ logger.debug("Tunnel process exited before TunnelClient created. Falling back to reactor")
88 self.client_d.callback(reactor)
89
90 def outReceived(self, data):
91@@ -192,3 +195,6 @@
92 logger.info("Tunnel process listening on port %r.", self.port)
93 client = TunnelClient(LOCALHOST, self.port, self.cookie)
94 self.client_d.callback(client)
95+
96+ def errReceived(self, data):
97+ logger.debug("Got stderr from tunnel process: %r", data)
98
99=== modified file 'ubuntuone/syncdaemon/tunnel_runner.py'
100--- ubuntuone/syncdaemon/tunnel_runner.py 2012-04-09 20:08:42 +0000
101+++ ubuntuone/syncdaemon/tunnel_runner.py 2012-11-29 20:57:21 +0000
102@@ -29,14 +29,11 @@
103 """Run the tunnel process and start a client, with a reactor as a fallback."""
104
105 import logging
106-import sys
107-
108-from os import path
109
110 from twisted.internet import defer, reactor
111-from twisted.python import procutils
112
113-from ubuntuone.platform.constants import TUNNEL_EXECUTABLE
114+from ubuntuone.clientdefs import LIBEXECDIR
115+from ubuntuone.syncdaemon.utils import get_tunnel_bin_cmd
116
117 logger = logging.getLogger("ubuntuone.SyncDaemon.TunnelRunner")
118
119@@ -61,12 +58,10 @@
120 """Start the tunnel process."""
121 from ubuntuone.proxy.tunnel_client import TunnelProcessProtocol
122 protocol = TunnelProcessProtocol(self.client_d)
123- process_path = self.get_process_path()
124- args = [process_path, host, str(port)]
125- if sys.platform.startswith("win") and not process_path.endswith("exe"):
126- python_exe = procutils.which("python.exe")
127- if python_exe:
128- args.insert(0, python_exe[0])
129+ tunnel_cmd = get_tunnel_bin_cmd(extra_fallbacks=[LIBEXECDIR])
130+
131+ args = tunnel_cmd + [host, str(port)]
132+
133 self.process_transport = reactor.spawnProcess(protocol, args[0],
134 env=None, args=args)
135 reactor.addSystemEventTrigger("before", "shutdown", self.stop)
136@@ -77,23 +72,6 @@
137 if self.process_transport.pid is not None:
138 self.process_transport.signalProcess("KILL")
139
140- def get_process_path(self):
141- """Get the path to the tunnel process."""
142- # In a frozen setting, all binaries are in the same path
143- if getattr(sys, "frozen", None) is not None:
144- return path.join(path.dirname(
145- path.abspath(sys.executable)), TUNNEL_EXECUTABLE)
146-
147- # This works when we are running from sources
148- filename = path.join(path.dirname(__file__), "..", "..", "bin",
149- TUNNEL_EXECUTABLE)
150- if path.isfile(filename):
151- return filename
152-
153- # Use the configured LIBEXECDIR
154- from ubuntuone.clientdefs import LIBEXECDIR
155- return path.join(LIBEXECDIR, TUNNEL_EXECUTABLE)
156-
157 def get_client(self):
158 """A deferred with the reactor or a tunnel client."""
159
160
161=== modified file 'ubuntuone/syncdaemon/utils.py'
162--- ubuntuone/syncdaemon/utils.py 2012-10-15 22:05:57 +0000
163+++ ubuntuone/syncdaemon/utils.py 2012-11-29 20:57:21 +0000
164@@ -35,16 +35,20 @@
165
166 from dirspec.utils import get_program_path
167
168-DARWIN_APP_NAMES = {'ubuntuone-syncdaemon': 'UbuntuOne Syncdaemon.app'}
169-
170-
171-def get_sd_bin_cmd():
172- """Get cmd + args to launch syncdaemon executable."""
173+SYNCDAEMON_EXECUTABLE = 'ubuntuone-syncdaemon'
174+TUNNEL_EXECUTABLE = 'ubuntuone-proxy-tunnel'
175+
176+DARWIN_APP_NAMES = {SYNCDAEMON_EXECUTABLE: 'UbuntuOne Syncdaemon.app',
177+ TUNNEL_EXECUTABLE: 'UbuntuOne Proxy Tunnel.app'}
178+
179+
180+def _get_bin_cmd(exe_name, extra_fallbacks=[]):
181+ """Get cmd+args to launch 'exe_name'."""
182 syncdaemon_dir = os.path.dirname(__file__)
183 ubuntuone_dir = os.path.dirname(syncdaemon_dir)
184 tree_dir = os.path.dirname(ubuntuone_dir)
185- fallback_dirs = [os.path.join(tree_dir, 'bin')]
186- path = get_program_path('ubuntuone-syncdaemon',
187+ fallback_dirs = [os.path.join(tree_dir, 'bin')] + extra_fallbacks
188+ path = get_program_path(exe_name,
189 fallback_dirs=fallback_dirs,
190 app_names=DARWIN_APP_NAMES)
191 cmd_args = [path]
192@@ -58,3 +62,14 @@
193 cmd_args.insert(0, procutils.which("python.exe")[0])
194
195 return cmd_args
196+
197+
198+def get_sd_bin_cmd():
199+ """Get cmd + args to launch syncdaemon executable."""
200+ return _get_bin_cmd(SYNCDAEMON_EXECUTABLE)
201+
202+
203+def get_tunnel_bin_cmd(extra_fallbacks):
204+ """Get cmd + args to launch proxy tunnel."""
205+ return _get_bin_cmd(TUNNEL_EXECUTABLE,
206+ extra_fallbacks=extra_fallbacks)

Subscribers

People subscribed via source and target branches