Revert up-ramping SSH timeout. Doesn't solve issue with SSH.execute slowness on internet-less machines.
This commit is contained in:
parent
0ebebe14a0
commit
9c8db3b48a
|
@ -9,9 +9,7 @@ Vagrant::Config.run do |config|
|
|||
config.ssh.host = "localhost"
|
||||
config.ssh.forwarded_port_key = "ssh"
|
||||
config.ssh.max_tries = 10
|
||||
config.ssh.timeout = 5
|
||||
config.ssh.retry_timeout_delta = 5
|
||||
config.ssh.max_timeout_delta = 30
|
||||
config.ssh.timeout = 30
|
||||
|
||||
config.vm.box_ovf = "box.ovf"
|
||||
config.vm.base_mac = "0800279C2E42"
|
||||
|
|
|
@ -29,18 +29,14 @@ error
|
|||
def wait_for_boot(sleeptime=5)
|
||||
logger.info "Waiting for VM to boot..."
|
||||
|
||||
current_timeout = Vagrant.config.ssh.timeout
|
||||
max_timeout = current_timeout + Vagrant.config.ssh.max_timeout_delta
|
||||
|
||||
Vagrant.config[:ssh][:max_tries].to_i.times do |i|
|
||||
logger.info "Trying to connect (attempt ##{i+1} of #{Vagrant.config[:ssh][:max_tries]})..."
|
||||
|
||||
if Vagrant::SSH.up?(current_timeout)
|
||||
if Vagrant::SSH.up?
|
||||
logger.info "VM booted and ready for use!"
|
||||
return true
|
||||
end
|
||||
|
||||
current_timeout += Vagrant.config.ssh.retry_timeout_delta unless current_timeout >= max_timeout
|
||||
sleep sleeptime
|
||||
end
|
||||
|
||||
|
|
|
@ -64,8 +64,6 @@ module Vagrant
|
|||
attr_accessor :forwarded_port_key
|
||||
attr_accessor :max_tries
|
||||
attr_accessor :timeout
|
||||
attr_accessor :retry_timeout_delta
|
||||
attr_accessor :max_timeout_delta
|
||||
end
|
||||
|
||||
class VMConfig < Base
|
||||
|
|
|
@ -25,13 +25,11 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
|
||||
def up?(timeout=nil)
|
||||
timeout ||= Vagrant.config.ssh.timeout
|
||||
|
||||
def up?
|
||||
check_thread = Thread.new do
|
||||
begin
|
||||
Thread.current[:result] = false
|
||||
Net::SSH.start(Vagrant.config.ssh.host, Vagrant.config.ssh.username, :port => port, :password => Vagrant.config.ssh.password, :timeout => timeout) do |ssh|
|
||||
Net::SSH.start(Vagrant.config.ssh.host, Vagrant.config.ssh.username, :port => port, :password => Vagrant.config.ssh.password, :timeout => Vagrant.config.ssh.timeout) do |ssh|
|
||||
Thread.current[:result] = true
|
||||
end
|
||||
rescue Errno::ECONNREFUSED, Net::SSH::Disconnect
|
||||
|
@ -39,7 +37,7 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
|
||||
check_thread.join(timeout)
|
||||
check_thread.join(Vagrant.config.ssh.timeout)
|
||||
return check_thread[:result]
|
||||
end
|
||||
|
||||
|
|
|
@ -31,8 +31,6 @@ class Test::Unit::TestCase
|
|||
config.ssh.forwarded_port_key = "ssh"
|
||||
config.ssh.max_tries = 10
|
||||
config.ssh.timeout = 10
|
||||
config.ssh.retry_timeout_delta = 5
|
||||
config.ssh.max_timeout_delta = 30
|
||||
|
||||
config.vm.box = "foo"
|
||||
config.vm.box_ovf = "box.ovf"
|
||||
|
|
|
@ -51,27 +51,5 @@ class BootActionTest < Test::Unit::TestCase
|
|||
Vagrant::SSH.expects(:up?).times(Vagrant.config[:ssh][:max_tries].to_i).returns(false)
|
||||
assert !@action.wait_for_boot(0)
|
||||
end
|
||||
|
||||
should "slowly increase timeout given to up? up to maximum specified" do
|
||||
@timeout = 30
|
||||
@retry_delta = 5
|
||||
@max_delta = 30
|
||||
|
||||
mock_config do |config|
|
||||
config.ssh.timeout = @timeout
|
||||
config.ssh.retry_timeout_delta = @retry_delta
|
||||
config.ssh.max_timeout_delta = @max_delta
|
||||
end
|
||||
|
||||
up_sequence = sequence("up_seq")
|
||||
current_timeout = @timeout
|
||||
max_timeout = @timeout + @max_delta
|
||||
Vagrant.config.ssh.max_tries.times do |i|
|
||||
Vagrant::SSH.expects(:up?).with(current_timeout).returns(false).in_sequence(up_sequence)
|
||||
current_timeout += @retry_delta unless current_timeout >= max_timeout
|
||||
end
|
||||
|
||||
assert !@action.wait_for_boot
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -56,59 +56,26 @@ class SshTest < Test::Unit::TestCase
|
|||
context "checking if host is up" do
|
||||
setup do
|
||||
mock_config
|
||||
end
|
||||
|
||||
@timeout = 7
|
||||
should "return true if SSH connection works" do
|
||||
Net::SSH.expects(:start).yields("success")
|
||||
assert Vagrant::SSH.up?
|
||||
end
|
||||
|
||||
should "return false if SSH connection times out" do
|
||||
Net::SSH.expects(:start)
|
||||
assert !Vagrant::SSH.up?
|
||||
end
|
||||
|
||||
should "allow the thread the configured timeout time" do
|
||||
@thread = mock("thread")
|
||||
@thread.stubs(:[])
|
||||
@thread.stubs(:[]=)
|
||||
@thread.stubs(:join)
|
||||
Thread.stubs(:current).returns(@thread)
|
||||
Thread.stubs(:new).returns(@thread).yields
|
||||
|
||||
Net::SSH.stubs(:start)
|
||||
end
|
||||
|
||||
should "return the value of result in thread" do
|
||||
result = mock("result")
|
||||
@thread.expects(:[]).with(:result).returns(result)
|
||||
assert_equal result, Vagrant::SSH.up?
|
||||
end
|
||||
|
||||
should "start SSH with proper configuration" do
|
||||
Net::SSH.expects(:start).with(Vagrant.config.ssh.host, Vagrant.config.ssh.username, :port => Vagrant::SSH.port, :password => Vagrant.config.ssh.password, :timeout => Vagrant.config.ssh.timeout).once
|
||||
Vagrant::SSH.up?
|
||||
end
|
||||
|
||||
should "start SSH with proper timeout value if given" do
|
||||
Net::SSH.expects(:start).with(Vagrant.config.ssh.host, Vagrant.config.ssh.username, :port => Vagrant::SSH.port, :password => Vagrant.config.ssh.password, :timeout => @timeout).once
|
||||
Vagrant::SSH.up?(@timeout)
|
||||
end
|
||||
|
||||
should "set result to true if SSH connection works" do
|
||||
@thread.expects(:[]=).with(:result, true)
|
||||
Net::SSH.expects(:start).yields("success")
|
||||
Vagrant::SSH.up?
|
||||
end
|
||||
|
||||
should "set result to false if SSH connection times out" do
|
||||
@thread.expects(:[]=).with(:result, false)
|
||||
Net::SSH.expects(:start)
|
||||
Vagrant::SSH.up?
|
||||
end
|
||||
|
||||
should "allow the thread the configured timeout time by default" do
|
||||
Thread.expects(:new).returns(@thread)
|
||||
@thread.expects(:join).with(Vagrant.config.ssh.timeout).once
|
||||
Vagrant::SSH.up?
|
||||
end
|
||||
|
||||
should "allow the thread the given timeout time if given" do
|
||||
Thread.expects(:new).returns(@thread)
|
||||
@thread.expects(:join).with(@timeout).once
|
||||
Vagrant::SSH.up?(@timeout)
|
||||
end
|
||||
|
||||
should "return false if the connection is refused" do
|
||||
Net::SSH.expects(:start).raises(Errno::ECONNREFUSED)
|
||||
assert_nothing_raised {
|
||||
|
|
Loading…
Reference in New Issue