Method: Beaker::SshConnection#wait_for_connection_failure
- Defined in:
- lib/beaker/ssh_connection.rb
#wait_for_connection_failure(options = {}, stdout_callback = nil, stderr_callback = stdout_callback) ⇒ Boolean
Wait for the ssh connection to fail, returns true on connection failure and false otherwise
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/beaker/ssh_connection.rb', line 151 def wait_for_connection_failure = {}, stdout_callback = nil, stderr_callback = stdout_callback try = 1 last_wait = 2 wait = 3 command = 'echo echo' #can be run on all platforms (I'm looking at you, windows) 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 [: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, [:stdin] ) if [:stdin] end end loop_tries = 0 #loop is actually loop_forever, so let it try 3 times and then quit instead of endless blocking @ssh.loop { loop_tries += 1 ; loop_tries < 4 } rescue *RETRYABLE_EXCEPTIONS => e @logger.debug "Connection on #{@hostname} failed as expected (#{e.class.name} - #{e.})" close #this connection is bad, shut it down 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 |