Skip to content

Commit

Permalink
allow override of tcp and ssh timeout through environment variable VE…
Browse files Browse the repository at this point in the history
…EWEE_TIMEOUT. This allows for automated timeouts
  • Loading branch information
jedi4ever committed Apr 18, 2012
1 parent 3058d13 commit 739472f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
12 changes: 12 additions & 0 deletions Rakefile
Expand Up @@ -67,6 +67,9 @@ end
desc 'Autobuilds all templates and runs validation'
task :autotest do

# We overrule all timeouts for tcp and ssh
ENV['VEEWEE_TIMEOUT']='6'

ve=Veewee::Environment.new()
ve.templates.each do |name,template|
begin
Expand All @@ -81,6 +84,15 @@ task :autotest do
box.destroy
rescue Exception => ex
puts "AUTO: Template #{name} failed - #{ex}"
if box.running?
begin
screenshot="screenshot-auto-#{name}.png"
puts "AUTO: Taking snapshot #{screenshot}"
box.screenshot(screenshot)
rescue Veewee::Error => ex
puts "AUTO: Error taking screenshot"
end
end
end
end
end
11 changes: 6 additions & 5 deletions lib/veewee/provider/core/helper/ssh.rb
Expand Up @@ -25,16 +25,18 @@ def when_ssh_login_works(ip="127.0.0.1", options = { } , &block)
defaults={ :port => '22', :timeout => 20000 }

options=defaults.merge(options)
timeout = options[:timeout]
timeout=ENV['VEEWEE_TIMEOUT'] unless ENV['VEEWEE_TIMEOUT'].nil?

ui.info "Waiting for ssh login on #{ip} with user #{options[:user]} to sshd on port => #{options[:port]} to work, timeout=#{options[:timeout]} sec"
ui.info "Waiting for ssh login on #{ip} with user #{options[:user]} to sshd on port => #{options[:port]} to work, timeout=#{timeout} sec"

begin
Timeout::timeout(options[:timeout]) do
Timeout::timeout(timeout) do
connected=false
while !connected do
begin
env.ui.info ".",{:new_line => false , :prefix => false}
Net::SSH.start(ip, options[:user], { :port => options[:port] , :password => options[:password], :paranoid => false , :timeout => options[:timeout] }) do |ssh|
Net::SSH.start(ip, options[:user], { :port => options[:port] , :password => options[:password], :paranoid => false , :timeout => timeout }) do |ssh|

ui.info "\n", {:prefix => false}
block.call(ip);
Expand All @@ -46,8 +48,7 @@ def when_ssh_login_works(ip="127.0.0.1", options = { } , &block)
end
end
rescue Timeout::Error
ui.error "Ssh timeout #{options[:timeout]} sec has been reached."
raise Veewee::Error, "Ssh timeout #{options[:timeout]} sec has been reached."
raise Veewee::Error, "Ssh timeout #{timeout} sec has been reached."
end
ui.info ""
return false
Expand Down
6 changes: 4 additions & 2 deletions lib/veewee/provider/core/helper/tcp.rb
Expand Up @@ -52,9 +52,11 @@ def execute_when_tcp_available(ip="127.0.0.1", options = { } , &block)
defaults={ :port => 22, :timeout => 2 , :pollrate => 5}

options=defaults.merge(options)
timeout=options[:timeout]
timeout=ENV['VEEWEE_TIMEOUT'] unless ENV['VEEWEE_TIMEOUT'].nil?

begin
Timeout::timeout(options[:timeout]) do
Timeout::timeout(timeout) do
connected=false
while !connected do
begin
Expand All @@ -69,7 +71,7 @@ def execute_when_tcp_available(ip="127.0.0.1", options = { } , &block)
end
end
rescue Timeout::Error
raise 'timeout connecting to port'
raise "Timeout connecting to TCP port {options[:port]} exceeded #{timeout} secs."
end

return false
Expand Down

0 comments on commit 739472f

Please sign in to comment.