hobo-up waits for successful boot now

This commit is contained in:
Mitchell Hashimoto 2010-01-31 22:23:19 -08:00
parent 3e98fc44e5
commit 081c2a0483
5 changed files with 47 additions and 9 deletions

View File

@ -6,6 +6,7 @@ require 'ftools'
require 'pathname' require 'pathname'
require 'logger' require 'logger'
require 'virtualbox' require 'virtualbox'
require 'net/ssh'
require 'hobo/config' require 'hobo/config'
require 'hobo/env' require 'hobo/env'
require 'hobo/ssh' require 'hobo/ssh'

View File

@ -2,13 +2,21 @@ module Hobo
class SSH class SSH
SCRIPT = File.join(File.dirname(__FILE__), '..', '..', 'script', 'hobo-ssh-expect.sh') SCRIPT = File.join(File.dirname(__FILE__), '..', '..', 'script', 'hobo-ssh-expect.sh')
def self.connect(opts={}) class <<self
options = {} def connect(opts={})
[:port, :host, :pass, :uname].each do |param| options = {}
options[param] = opts[param] || Hobo.config[:ssh][param] [:port, :host, :pass, :uname].each do |param|
options[param] = opts[param] || Hobo.config[:ssh][param]
end
Kernel.exec "#{SCRIPT} #{options[:uname]} #{options[:pass]} #{options[:host]} #{options[:port]}".strip
end end
Kernel.exec "#{SCRIPT} #{options[:uname]} #{options[:pass]} #{options[:host]} #{options[:port]}".strip def execute
Net::SSH.start("localhost", Hobo.config[:ssh][:uname], :port => Hobo.config[:ssh][:port], :password => Hobo.config[:ssh][:pass]) do |ssh|
yield ssh
end
end
end end
end end
end end

View File

@ -93,7 +93,17 @@ module Hobo
@vm.start(:headless, true) @vm.start(:headless, true)
# Now we have to wait for the boot to be successful # Now we have to wait for the boot to be successful
# TODO HOBO_LOGGER.info "Waiting for VM to boot..."
counter = 1
begin
SSH.execute { |ssh| }
rescue Errno::ECONNREFUSED
sleep 5 unless ENV['HOBO_ENV'] == 'test'
counter += 1
retry
end
HOBO_LOGGER.info "VM booted and ready for use!"
end end
end end
end end

View File

@ -1,8 +1,7 @@
require File.join(File.dirname(__FILE__), '..', 'test_helper') require File.join(File.dirname(__FILE__), '..', 'test_helper')
class SshTest < Test::Unit::TestCase class SshTest < Test::Unit::TestCase
context "hobo ssh" do
context "Hobo ssh" do
setup do setup do
@handler = Hobo::SSH @handler = Hobo::SSH
@script = Hobo::SSH::SCRIPT @script = Hobo::SSH::SCRIPT
@ -21,4 +20,11 @@ class SshTest < Test::Unit::TestCase
Hobo::SSH.connect(args) Hobo::SSH.connect(args)
end end
end end
context "net-ssh interaction" do
should "call net::ssh.start with the proper names" do
Net::SSH.expects(:start).with("localhost", Hobo.config[:ssh][:uname], anything).once
Hobo::SSH.execute
end
end
end end

View File

@ -7,6 +7,8 @@ class VMTest < Test::Unit::TestCase
@persisted_vm = mock("persisted_vm") @persisted_vm = mock("persisted_vm")
Hobo::Env.stubs(:persisted_vm).returns(@persisted_vm) Hobo::Env.stubs(:persisted_vm).returns(@persisted_vm)
Net::SSH.stubs(:start)
end end
context "hobo ssh" do context "hobo ssh" do
@ -101,10 +103,21 @@ class VMTest < Test::Unit::TestCase
end end
context "starting" do context "starting" do
setup do
@mock_vm.stubs(:start)
end
should "start the VM in headless mode" do should "start the VM in headless mode" do
@mock_vm.expects(:start).with(:headless, true).once @mock_vm.expects(:start).with(:headless, true).once
@vm.start @vm.start
end end
should "repeatedly SSH while waiting for the VM to start" do
ssh_seq = sequence("ssh_seq")
Net::SSH.expects(:start).once.raises(Errno::ECONNREFUSED).in_sequence(ssh_seq)
Net::SSH.expects(:start).once.in_sequence(ssh_seq)
@vm.start
end
end end
context "importing" do context "importing" do