Waiting for a VM to boot maxes out (configurable # of times)
This commit is contained in:
parent
081c2a0483
commit
303cc90a12
|
@ -3,6 +3,7 @@
|
|||
:pass: hobo
|
||||
:host: localhost
|
||||
:port: 2222
|
||||
:max_tries: 10
|
||||
|
||||
:dotfile_name: .hobo
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue