hobo-up waits for successful boot now
This commit is contained in:
parent
3e98fc44e5
commit
081c2a0483
|
@ -6,6 +6,7 @@ require 'ftools'
|
|||
require 'pathname'
|
||||
require 'logger'
|
||||
require 'virtualbox'
|
||||
require 'net/ssh'
|
||||
require 'hobo/config'
|
||||
require 'hobo/env'
|
||||
require 'hobo/ssh'
|
||||
|
|
|
@ -2,13 +2,21 @@ module Hobo
|
|||
class SSH
|
||||
SCRIPT = File.join(File.dirname(__FILE__), '..', '..', 'script', 'hobo-ssh-expect.sh')
|
||||
|
||||
def self.connect(opts={})
|
||||
options = {}
|
||||
[:port, :host, :pass, :uname].each do |param|
|
||||
options[param] = opts[param] || Hobo.config[:ssh][param]
|
||||
class <<self
|
||||
def connect(opts={})
|
||||
options = {}
|
||||
[: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
|
||||
|
||||
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
|
||||
|
|
|
@ -93,7 +93,17 @@ module Hobo
|
|||
@vm.start(:headless, true)
|
||||
|
||||
# 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
|
|
@ -1,14 +1,13 @@
|
|||
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
||||
|
||||
class SshTest < Test::Unit::TestCase
|
||||
|
||||
context "Hobo ssh" do
|
||||
context "hobo ssh" do
|
||||
setup do
|
||||
@handler = Hobo::SSH
|
||||
@script = Hobo::SSH::SCRIPT
|
||||
Hobo.config!(hobo_mock_config)
|
||||
end
|
||||
|
||||
|
||||
test "should call exec with defaults when no options are supplied" do
|
||||
ssh = hobo_mock_config[:ssh]
|
||||
Kernel.expects(:exec).with("#{@script} #{ssh[:uname]} #{ssh[:pass]} #{ssh[:host]} #{ssh[:port]}")
|
||||
|
@ -21,4 +20,11 @@ class SshTest < Test::Unit::TestCase
|
|||
Hobo::SSH.connect(args)
|
||||
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
|
||||
|
|
|
@ -7,6 +7,8 @@ class VMTest < Test::Unit::TestCase
|
|||
|
||||
@persisted_vm = mock("persisted_vm")
|
||||
Hobo::Env.stubs(:persisted_vm).returns(@persisted_vm)
|
||||
|
||||
Net::SSH.stubs(:start)
|
||||
end
|
||||
|
||||
context "hobo ssh" do
|
||||
|
@ -101,10 +103,21 @@ class VMTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
context "starting" do
|
||||
setup do
|
||||
@mock_vm.stubs(:start)
|
||||
end
|
||||
|
||||
should "start the VM in headless mode" do
|
||||
@mock_vm.expects(:start).with(:headless, true).once
|
||||
@vm.start
|
||||
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
|
||||
|
||||
context "importing" do
|
||||
|
|
Loading…
Reference in New Issue