lib/beaker/ssh_connection.rb
# Wait for the ssh connection to fail, returns true on connection failure and false otherwise
# @param [Hash{Symbol=>String}] options Options hash to control method conditionals
# @option options [Boolean] :pty Should we request a terminal when attempting
#                                to send a command over this connection?
# @option options [String] :stdin Any input to be sent along with the command
# @param [IO] stdout_callback An IO stream to send connection stdout to, defaults to nil
# @param [IO] stderr_callback An IO stream to send connection stderr to, defaults to nil
# @return [Boolean] true if connection failed, false otherwise
Wait for the ssh connection to fail, returns true on connection failure and false otherwise
Wait for the ssh connection to fail returns true on connection failure and false otherwise
def wait_for_connection_failure options = {}, stdout_callback = nil, stderr_callback = stdout_callback
      try = 1
      last_wait = 2
      wait = 3
      command = 'echo echo' 
      while try < 11
        result = Result.new(@hostname, command)
        begin
          @logger.notify "Waiting for connection failure on #{@hostname} (attempt #{try}, try again in #{wait} second(s))"
          @logger.debug("\n#{@hostname} #{Time.new.strftime('%H:%M:%S')}$ #{command}")
          @ssh.open_channel do |channel|
            request_terminal_for( channel, command ) if options[:pty]
            channel.exec(command) do |terminal, success|
              raise Net::SSH::Exception.new("FAILED: to execute command on a new channel on #{@hostname}") unless success
              register_stdout_for terminal, result, stdout_callback
              register_stderr_for terminal, result, stderr_callback
              register_exit_code_for terminal, result
              process_stdin_for( terminal, options[:stdin] ) if options[:stdin]
             end
           end
           loop_tries = 0
           @ssh.loop { loop_tries += 1 ; loop_tries < 4 }
        rescue *RETRYABLE_EXCEPTIONS => e
          @logger.debug "Connection on #{@hostname} failed as expected (#{e.class.name} - #{e.message})"
          close 
          return true
        end
        slept = 0
        stdout_callback.call("sleep #{wait} second(s): ")
        while slept < wait
          sleep slept
          stdout_callback.call('.')
          slept += 1
        end
        stdout_callback.call("\n")
        (last_wait, wait) = wait, last_wait + wait
        try += 1
      end
      false
    end
def wait_for_connection_failure options = { } , stdout_callback = nil , stderr_callback = stdout_callback try = 1 last_wait = 2 wait = 3 command = 'echo echo' while try < 11 result = Result . new ( @hostname , command ) begin @logger . notify "Waiting for connection failure on #{@hostname} (attempt #{try}, try again in #{wait} second(s))" @logger . debug ( "\n#{@hostname} #{Time.new.strftime('%H:%M:%S')}$ #{command}" ) @ssh . open_channel do | channel | request_terminal_for ( channel , command ) if options [ :pty ] channel . exec ( command ) do | terminal , success | raise Net :: SSH :: Exception . new ( "FAILED: to execute command on a new channel on #{@hostname}" ) unless success register_stdout_for terminal , result , stdout_callback register_stderr_for terminal , result , stderr_callback register_exit_code_for terminal , result process_stdin_for ( terminal , options [ :stdin ] ) if options [ :stdin ] end end loop_tries = 0 @ssh . loop { loop_tries += 1 ; loop_tries < 4 } rescue * RETRYABLE_EXCEPTIONS => e @logger . debug "Connection on #{@hostname} failed as expected (#{e.class.name} - #{e.message})" close return true end slept = 0 stdout_callback . call ( "sleep #{wait} second(s): " ) while slept < wait sleep slept stdout_callback . call ( '.' ) slept += 1 end stdout_callback . call ( "\n" ) ( last_wait , wait ) = wait , last_wait + wait try += 1 end false end
Wait for the ssh connection to fail, returns true on connection failure and false otherwise
Wait for the ssh connection to fail returns true on connection failure and false otherwise
#can be run on all platforms (I'm looking at you, windows) #loop is actually loop_forever, so let it try 3 times and then quit instead of endless blocking #this connection is bad, shut it down
true if connection failed, false otherwise
true if connection failed false otherwise
Boolean
options
:stdin Any input to be sent along with the command
: stdin Any input to be sent along with the command
stdout_callback
<not_specific>
stderr_callback
<not_specific>
<not_specific>
stderr_callback An IO stream to send connection stderr to, defaults to nil
stderr_callback An IO stream to send connection stderr to defaults to nil
nil