Skip to content

Commit

Permalink
Upgrade Sauce Connect to r21
Browse files Browse the repository at this point in the history
  • Loading branch information
epall committed Dec 16, 2010
1 parent c0c9f31 commit 5454938
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.2
0.12.3
69 changes: 39 additions & 30 deletions support/sauce_connect
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
from __future__ import with_statement

# TODO:
# * ?? Use "-o StrictHostKeyChecking no"
# * Move to REST API v1
# * windows: SSH link healthcheck (PuTTY session file hack?)
# * Daemonizing
# * issue: windows: no os.fork()
# * issue: unix: null file descriptors causes Expect script to fail
# * Renew tunnel lease (backend not implemented)
# * Check tunnel machine ports are open (backend not implemented)
#

import os
import sys
Expand Down Expand Up @@ -39,7 +37,7 @@ except ImportError:
import simplejson as json # Python 2.5 dependency

NAME = "sauce_connect"
RELEASE = 20
RELEASE = 21
DISPLAY_VERSION = "%s release %s" % (NAME, RELEASE)
PRODUCT_NAME = u"Sauce Connect"
VERSIONS_URL = "http://saucelabs.com/versions.json"
Expand Down Expand Up @@ -352,11 +350,13 @@ class ReverseSSHError(Exception):

class ReverseSSH(object):

def __init__(self, tunnel, host, ports, tunnel_ports, debug=False):
def __init__(self, tunnel, host, ports, tunnel_ports,
use_ssh_config=False, debug=False):
self.tunnel = tunnel
self.host = host
self.ports = ports
self.tunnel_ports = tunnel_ports
self.use_ssh_config = use_ssh_config
self.debug = debug

self.proc = None
Expand All @@ -375,12 +375,8 @@ class ReverseSSH(object):
ssh_config_file = os.path.join(os.environ['HOME'], ".ssh", "config")
if os.path.exists(ssh_config_file):
logger.debug("Found %s" % ssh_config_file)

ssh_known_hosts = os.path.join(os.environ['HOME'], ".ssh", "known_hosts")
if os.path.exists(ssh_known_hosts):
if not os.path.isfile(ssh_known_hosts) or os.path.islink(ssh_known_hosts):
logger.debug("SSH known_hosts file (%s) is not a regular file "
% ssh_known_hosts)
if self.use_ssh_config:
logger.warn("Using local SSH config")

@property
def _dash_Rs(self):
Expand All @@ -390,27 +386,25 @@ class ReverseSSH(object):
return dash_Rs

def get_plink_command(self):
"""Return the Windows SSH command."""
verbosity = "-v" if self.debug else ""
return ("plink\plink %s -l %s -pw %s -N %s %s"
% (verbosity, self.tunnel.user, self.tunnel.password,
self._dash_Rs, self.tunnel.host))

def get_expect_script(self):
"""Return the Unix SSH command."""
wait = "wait"
if is_openbsd: # using 'wait;' hangs the script on OpenBSD
wait = "wait -nowait;sleep 1" # hack

verbosity = "-v" if self.debug else "-q"
config_file = "" if self.use_ssh_config else "-F /dev/null"
host_ip = socket.gethostbyname(self.tunnel.host)
script = (
"spawn ssh-keygen %s -R %s;%s;"
% (verbosity, self.tunnel.host, wait) +
"spawn ssh-keygen %s -R %s;%s;" % (verbosity, host_ip, wait) +
"spawn ssh %s -p 22 -l %s -o ServerAliveInterval=%s -N %s %s;"
% (verbosity, self.tunnel.user, HEALTH_CHECK_INTERVAL,
self._dash_Rs, self.tunnel.host) +
'expect \\"Are you sure you want to continue connecting'
' (yes/no)?\\";send yes\\r;'
"spawn ssh %s %s -p 22 -l %s -o ServerAliveInterval=%s -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -N %s %s;"
% (verbosity, config_file, self.tunnel.user,
HEALTH_CHECK_INTERVAL, self._dash_Rs, self.tunnel.host) +
"expect *password:;send -- %s\\r;" % self.tunnel.password +
"expect -timeout -1 timeout")
return script
Expand Down Expand Up @@ -539,7 +533,7 @@ def peace_out(tunnel=None, returncode=0, atexit=False):
logger.info("\ Exiting /")
raise SystemExit(returncode)
else:
logger.debug("--- fin ---")
logger.debug("-- fin --")


def setup_signal_handler(tunnel, options):
Expand Down Expand Up @@ -632,15 +626,15 @@ def check_domains(domains):
sys.stderr.write(
"Error: Domain contains illegal character '/' in it.\n")
print " Did you use a URL instead of just the domain?\n"
print "Examples: -d example.com -d '*.example.com' -d cdn.example.org"
print "Examples: -d example.com -d '*.example.com' -d another.site"
print
raise SystemExit(1)

# no numerical addresses
if all(map(lambda c: c.isdigit() or c == '.', dom)):
sys.stderr.write("Error: Domain must be a hostname not an IP\n")
print
print "Examples: -d example.com -d '*.example.com' -d cdn.example.org"
print "Examples: -d example.com -d '*.example.com' -d another.site"
print
raise SystemExit(1)

Expand All @@ -650,7 +644,16 @@ def check_domains(domains):
sys.stderr.write(
"Error: Domain requires a TLD of 2 characters or more\n")
print
print "Example: -d example.tld -d '*.example.tld' -d cdn.example.tld"
print "Example: -d example.tld -d '*.example.tld' -d another.tld"
print
raise SystemExit(1)

# *.com will break uploading to S3
if dom == "*.com":
sys.stderr.write(
"Error: Matching *.com will break videos and logs. Use a hostname.\n")
print
print "Example: -d example.com -d *.example.com"
print
raise SystemExit(1)

Expand Down Expand Up @@ -709,16 +712,20 @@ Performance tip:
og.add_option("--readyfile",
help="Path of the file to drop when the tunnel is ready "
"for tests to run. By default, no file is dropped.")
og.add_option("--use-ssh-config", action="store_true", default=False,
help="Use the local SSH config. WARNING: Turning this on "
"may break the script!")
og.add_option("--rest-url", default="https://saucelabs.com/rest",
help=optparse.SUPPRESS_HELP)
og.add_option("--allow-unclean-exit", action="store_true", default=False,
help=optparse.SUPPRESS_HELP)
op.add_option_group(og)

og = optparse.OptionGroup(op, "Script debugging options")
og.add_option("--rest-url", default="https://saucelabs.com/rest",
help="[%default]")
og.add_option("--debug-ssh", action="store_true", default=False)
og.add_option("--debug-ssh", action="store_true", default=False,
help="Log SSH output.")
og.add_option("--latency-log", type=int, default=LATENCY_LOG,
help="Threshold above which latency (ms) will be "
"logged. [%default]")
og.add_option("--allow-unclean-exit", action="store_true", default=False)
help="Threshold for logging latency (ms) [%default]")
op.add_option_group(og)

(options, args) = op.parse_args()
Expand Down Expand Up @@ -872,8 +879,10 @@ def run(options, dependency_versions=None):
logger.info("** Please contact help@saucelabs.com")
peace_out(tunnel, returncode=1) # exits

ssh = ReverseSSH(tunnel, options.host, options.ports, options.tunnel_ports,
options.debug_ssh)
ssh = ReverseSSH(tunnel=tunnel, host=options.host,
ports=options.ports, tunnel_ports=options.tunnel_ports,
use_ssh_config=options.use_ssh_config,
debug=options.debug_ssh)
try:
ssh.run(options.readyfile)
except (ReverseSSHError, TunnelMachineError), e:
Expand Down

0 comments on commit 5454938

Please sign in to comment.