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
=== modified file 'tests/syncdaemon/test_tunnel_runner.py'
--- tests/syncdaemon/test_tunnel_runner.py 2012-04-09 20:08:42 +0000
+++ tests/syncdaemon/test_tunnel_runner.py 2012-11-29 20:57:21 +0000
@@ -28,9 +28,6 @@
28# files in the program, then also delete it here.28# files in the program, then also delete it here.
29"""Tests for the proxy tunnel runner."""29"""Tests for the proxy tunnel runner."""
3030
31import os
32import sys
33
34from twisted.internet import defer, error, reactor, task31from twisted.internet import defer, error, reactor, task
35from twisted.trial.unittest import TestCase32from twisted.trial.unittest import TestCase
3633
@@ -63,7 +60,8 @@
63 @defer.inlineCallbacks60 @defer.inlineCallbacks
64 def test_executable_not_found(self):61 def test_executable_not_found(self):
65 """The executable is not found anywhere."""62 """The executable is not found anywhere."""
66 self.patch(tunnel_runner, "TUNNEL_EXECUTABLE", "this_does_not_exist")63 self.patch(tunnel_runner, "get_tunnel_bin_cmd",
64 lambda *args, **kwargs: ["this_does_not_exist"])
67 tr = tunnel_runner.TunnelRunner(FAKE_HOST, FAKE_PORT)65 tr = tunnel_runner.TunnelRunner(FAKE_HOST, FAKE_PORT)
68 client = yield tr.get_client()66 client = yield tr.get_client()
69 self.assertEqual(client, reactor)67 self.assertEqual(client, reactor)
@@ -185,19 +183,3 @@
185 client = yield self.tr.get_client()183 client = yield self.tr.get_client()
186 self.assertEqual(client.tunnel_port, FAKE_PORT)184 self.assertEqual(client.tunnel_port, FAKE_PORT)
187 self.assertEqual(client.cookie, FAKE_COOKIE)185 self.assertEqual(client.cookie, FAKE_COOKIE)
188
189 def test_frozen_path(self):
190 """Ensure the path is correct if sys is frozen."""
191 sys.frozen = "Yes"
192 self.addCleanup(delattr, sys, "frozen")
193 self.assertEqual(os.path.dirname(self.tr.get_process_path()),
194 os.path.dirname(sys.executable))
195
196 def test_start_process_win_devel(self):
197 """Test the windows devel case."""
198 fake_python = r"c:\python99\python.exe"
199 self.patch(sys, "platform", "win98")
200 self.patch(tunnel_runner.procutils, "which", lambda _: [fake_python])
201 tunnel_runner.TunnelRunner("fs-1.one.ubuntu.com", 443)
202 args, kwargs = self.spawned[1]
203 self.assertEqual(args[1], fake_python)
204186
=== modified file 'ubuntuone/platform/constants.py'
--- ubuntuone/platform/constants.py 2012-04-09 20:07:05 +0000
+++ ubuntuone/platform/constants.py 2012-11-29 20:57:21 +0000
@@ -33,12 +33,7 @@
3333
34import sys34import sys
3535
36TUNNEL_EXECUTABLE = "ubuntuone-proxy-tunnel"
37
38if sys.platform == "win32":36if sys.platform == "win32":
39 HASHQUEUE_DELAY = 3.037 HASHQUEUE_DELAY = 3.0
40 if getattr(sys, "frozen", None) is not None:
41 # Only use the .exe suffix in windows+frozen
42 TUNNEL_EXECUTABLE += ".exe"
43else:38else:
44 HASHQUEUE_DELAY = 0.539 HASHQUEUE_DELAY = 0.5
4540
=== modified file 'ubuntuone/proxy/tunnel_client.py'
--- ubuntuone/proxy/tunnel_client.py 2012-06-01 04:11:49 +0000
+++ ubuntuone/proxy/tunnel_client.py 2012-11-29 20:57:21 +0000
@@ -42,7 +42,8 @@
4242
43METHOD_LINE = "CONNECT %s:%d HTTP/1.0" + CRLF43METHOD_LINE = "CONNECT %s:%d HTTP/1.0" + CRLF
44LOCALHOST = "127.0.0.1"44LOCALHOST = "127.0.0.1"
45logger = logging.getLogger("ubuntuone.Proxy.TunnelClient")45
46logger = logging.getLogger("ubuntuone.SyncDaemon.TunnelClient")
4647
4748
48class TunnelClientProtocol(BaseTunnelProtocol):49class TunnelClientProtocol(BaseTunnelProtocol):
@@ -166,6 +167,7 @@
166 def finish_timeout(self):167 def finish_timeout(self):
167 """Stop the timer from firing."""168 """Stop the timer from firing."""
168 if self.timer and self.timer.active():169 if self.timer and self.timer.active():
170 logger.debug("canceling timer before connection timeout")
169 self.timer.cancel()171 self.timer.cancel()
170172
171 def processExited(self, status):173 def processExited(self, status):
@@ -173,6 +175,7 @@
173 self.finish_timeout()175 self.finish_timeout()
174 logger.info("Tunnel process exit status %r.", status)176 logger.info("Tunnel process exit status %r.", status)
175 if not self.client_d.called:177 if not self.client_d.called:
178 logger.debug("Tunnel process exited before TunnelClient created. Falling back to reactor")
176 self.client_d.callback(reactor)179 self.client_d.callback(reactor)
177180
178 def outReceived(self, data):181 def outReceived(self, data):
@@ -192,3 +195,6 @@
192 logger.info("Tunnel process listening on port %r.", self.port)195 logger.info("Tunnel process listening on port %r.", self.port)
193 client = TunnelClient(LOCALHOST, self.port, self.cookie)196 client = TunnelClient(LOCALHOST, self.port, self.cookie)
194 self.client_d.callback(client)197 self.client_d.callback(client)
198
199 def errReceived(self, data):
200 logger.debug("Got stderr from tunnel process: %r", data)
195201
=== modified file 'ubuntuone/syncdaemon/tunnel_runner.py'
--- ubuntuone/syncdaemon/tunnel_runner.py 2012-04-09 20:08:42 +0000
+++ ubuntuone/syncdaemon/tunnel_runner.py 2012-11-29 20:57:21 +0000
@@ -29,14 +29,11 @@
29"""Run the tunnel process and start a client, with a reactor as a fallback."""29"""Run the tunnel process and start a client, with a reactor as a fallback."""
3030
31import logging31import logging
32import sys
33
34from os import path
3532
36from twisted.internet import defer, reactor33from twisted.internet import defer, reactor
37from twisted.python import procutils
3834
39from ubuntuone.platform.constants import TUNNEL_EXECUTABLE35from ubuntuone.clientdefs import LIBEXECDIR
36from ubuntuone.syncdaemon.utils import get_tunnel_bin_cmd
4037
41logger = logging.getLogger("ubuntuone.SyncDaemon.TunnelRunner")38logger = logging.getLogger("ubuntuone.SyncDaemon.TunnelRunner")
4239
@@ -61,12 +58,10 @@
61 """Start the tunnel process."""58 """Start the tunnel process."""
62 from ubuntuone.proxy.tunnel_client import TunnelProcessProtocol59 from ubuntuone.proxy.tunnel_client import TunnelProcessProtocol
63 protocol = TunnelProcessProtocol(self.client_d)60 protocol = TunnelProcessProtocol(self.client_d)
64 process_path = self.get_process_path()61 tunnel_cmd = get_tunnel_bin_cmd(extra_fallbacks=[LIBEXECDIR])
65 args = [process_path, host, str(port)]62
66 if sys.platform.startswith("win") and not process_path.endswith("exe"):63 args = tunnel_cmd + [host, str(port)]
67 python_exe = procutils.which("python.exe")64
68 if python_exe:
69 args.insert(0, python_exe[0])
70 self.process_transport = reactor.spawnProcess(protocol, args[0],65 self.process_transport = reactor.spawnProcess(protocol, args[0],
71 env=None, args=args)66 env=None, args=args)
72 reactor.addSystemEventTrigger("before", "shutdown", self.stop)67 reactor.addSystemEventTrigger("before", "shutdown", self.stop)
@@ -77,23 +72,6 @@
77 if self.process_transport.pid is not None:72 if self.process_transport.pid is not None:
78 self.process_transport.signalProcess("KILL")73 self.process_transport.signalProcess("KILL")
7974
80 def get_process_path(self):
81 """Get the path to the tunnel process."""
82 # In a frozen setting, all binaries are in the same path
83 if getattr(sys, "frozen", None) is not None:
84 return path.join(path.dirname(
85 path.abspath(sys.executable)), TUNNEL_EXECUTABLE)
86
87 # This works when we are running from sources
88 filename = path.join(path.dirname(__file__), "..", "..", "bin",
89 TUNNEL_EXECUTABLE)
90 if path.isfile(filename):
91 return filename
92
93 # Use the configured LIBEXECDIR
94 from ubuntuone.clientdefs import LIBEXECDIR
95 return path.join(LIBEXECDIR, TUNNEL_EXECUTABLE)
96
97 def get_client(self):75 def get_client(self):
98 """A deferred with the reactor or a tunnel client."""76 """A deferred with the reactor or a tunnel client."""
9977
10078
=== modified file 'ubuntuone/syncdaemon/utils.py'
--- ubuntuone/syncdaemon/utils.py 2012-10-15 22:05:57 +0000
+++ ubuntuone/syncdaemon/utils.py 2012-11-29 20:57:21 +0000
@@ -35,16 +35,20 @@
3535
36from dirspec.utils import get_program_path36from dirspec.utils import get_program_path
3737
38DARWIN_APP_NAMES = {'ubuntuone-syncdaemon': 'UbuntuOne Syncdaemon.app'}38SYNCDAEMON_EXECUTABLE = 'ubuntuone-syncdaemon'
3939TUNNEL_EXECUTABLE = 'ubuntuone-proxy-tunnel'
4040
41def get_sd_bin_cmd():41DARWIN_APP_NAMES = {SYNCDAEMON_EXECUTABLE: 'UbuntuOne Syncdaemon.app',
42 """Get cmd + args to launch syncdaemon executable."""42 TUNNEL_EXECUTABLE: 'UbuntuOne Proxy Tunnel.app'}
43
44
45def _get_bin_cmd(exe_name, extra_fallbacks=[]):
46 """Get cmd+args to launch 'exe_name'."""
43 syncdaemon_dir = os.path.dirname(__file__)47 syncdaemon_dir = os.path.dirname(__file__)
44 ubuntuone_dir = os.path.dirname(syncdaemon_dir)48 ubuntuone_dir = os.path.dirname(syncdaemon_dir)
45 tree_dir = os.path.dirname(ubuntuone_dir)49 tree_dir = os.path.dirname(ubuntuone_dir)
46 fallback_dirs = [os.path.join(tree_dir, 'bin')]50 fallback_dirs = [os.path.join(tree_dir, 'bin')] + extra_fallbacks
47 path = get_program_path('ubuntuone-syncdaemon',51 path = get_program_path(exe_name,
48 fallback_dirs=fallback_dirs,52 fallback_dirs=fallback_dirs,
49 app_names=DARWIN_APP_NAMES)53 app_names=DARWIN_APP_NAMES)
50 cmd_args = [path]54 cmd_args = [path]
@@ -58,3 +62,14 @@
58 cmd_args.insert(0, procutils.which("python.exe")[0])62 cmd_args.insert(0, procutils.which("python.exe")[0])
5963
60 return cmd_args64 return cmd_args
65
66
67def get_sd_bin_cmd():
68 """Get cmd + args to launch syncdaemon executable."""
69 return _get_bin_cmd(SYNCDAEMON_EXECUTABLE)
70
71
72def get_tunnel_bin_cmd(extra_fallbacks):
73 """Get cmd + args to launch proxy tunnel."""
74 return _get_bin_cmd(TUNNEL_EXECUTABLE,
75 extra_fallbacks=extra_fallbacks)

Subscribers

People subscribed via source and target branches