Waiting for a VM to boot maxes out (configurable # of times)

This commit is contained in:
Mitchell Hashimoto 2010-01-31 22:38:00 -08:00
parent 081c2a0483
commit 303cc90a12
4 changed files with 17 additions and 3 deletions

View File

@ -3,6 +3,7 @@
:pass: hobo
:host: localhost
:port: 2222
:max_tries: 10
:dotfile_name: .hobo

View File

@ -96,14 +96,21 @@ module Hobo
HOBO_LOGGER.info "Waiting for VM to boot..."
counter = 1
begin
sleep 5 unless ENV['HOBO_ENV'] == 'test'
HOBO_LOGGER.info "Trying to connect (attempt ##{counter} of #{Hobo.config[:ssh][:max_tries]})..."
SSH.execute { |ssh| }
rescue Errno::ECONNREFUSED
sleep 5 unless ENV['HOBO_ENV'] == 'test'
if counter >= Hobo.config[:ssh][:max_tries].to_i
HOBO_LOGGER.info "Failed to connect to VM! Failed to boot?"
return false
end
counter += 1
retry
end
HOBO_LOGGER.info "VM booted and ready for use!"
true
end
end
end

View File

@ -118,6 +118,11 @@ class VMTest < Test::Unit::TestCase
Net::SSH.expects(:start).once.in_sequence(ssh_seq)
@vm.start
end
should "try the max number of times then just return" do
Net::SSH.expects(:start).times(Hobo.config[:ssh][:max_tries].to_i).raises(Errno::ECONNREFUSED)
assert !@vm.start
end
end
context "importing" do

View File

@ -28,11 +28,12 @@ require 'mocha'
class Test::Unit::TestCase
def hobo_mock_config
{ :ssh => {
{ :ssh => {
:uname => 'foo',
:pass => 'bar',
:host => 'baz',
:port => 'bak'
:port => 'bak',
:max_tries => 10
},
:vm => {
:base => "foo",