Class: TasteTester::Tunnel
- Inherits:
-
Object
- Object
- TasteTester::Tunnel
- Defined in:
- lib/taste_tester/tunnel.rb
Overview
Thin ssh tunnel wrapper
Instance Attribute Summary collapse
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Class Method Summary collapse
Instance Method Summary collapse
- #cmd ⇒ Object
-
#initialize(host, server) ⇒ Tunnel
constructor
A new instance of Tunnel.
- #run ⇒ Object
Methods included from SSH::Util
#build_ssh_cmd, #error!, #ssh_base_cmd
Methods included from Logging
#formatter, formatterproc=, logger, #logger, use_log_formatter=, verbosity=
Constructor Details
#initialize(host, server) ⇒ Tunnel
Returns a new instance of Tunnel.
30 31 32 33 |
# File 'lib/taste_tester/tunnel.rb', line 30 def initialize(host, server) @host = host @server = server end |
Instance Attribute Details
#port ⇒ Object (readonly)
Returns the value of attribute port.
28 29 30 |
# File 'lib/taste_tester/tunnel.rb', line 28 def port @port end |
Class Method Details
.kill(name) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/taste_tester/tunnel.rb', line 62 def self.kill(name) ssh = TasteTester::SSH.new(name) # Since commands are &&'d together, and we're using &&, we need to # surround this in paryns, and make sure as a whole it evaluates # to true so it doesn't mess up other things... even though this is # the only thing we're currently executing in this SSH. if TasteTester::Config.windows_target cmd = <<~EOPS if (Test-Path "#{TasteTester::Config.}") { $x = cat "#{TasteTester::Config.}" if ($x -ne $null) { kill -Force $x 2>$null } } $LASTEXITCODE = 0 EOPS else cmd = "( [ -s #{TasteTester::Config.} ]" + ' && kill -9 -- ' + "-\$(cat #{TasteTester::Config.}) 2>/dev/null; " + ' true )' end ssh << cmd ssh.run! end |
Instance Method Details
#cmd ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/taste_tester/tunnel.rb', line 44 def cmd if TasteTester::Config.windows_target cmds = windows_tunnel_cmd else cmds = sane_os_tunnel_cmd end # As great as it would be to have ExitOnForwardFailure=yes, # we had multiple cases of tunnels dying # if -f and ExitOnForwardFailure are used together. # In most cases the first request from chef was "breaking" the tunnel, # in a way that port was still open, but subsequent requests were hanging. # This is reproducible and should be looked into. cmd = "#{ssh_base_cmd} -o ServerAliveInterval=10 " + "-o ServerAliveCountMax=6 -f -R #{@port}:localhost:#{@server.port} " build_ssh_cmd(cmd, [cmds]) end |
#run ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/taste_tester/tunnel.rb', line 35 def run @port = TasteTester::Config.tunnel_port logger.info("Setting up tunnel on port #{@port}") exec!(cmd, logger) rescue StandardError => e logger.error "Failed bringing up ssh tunnel: #{e}" error! end |