SSH timeout is now configurable with `config.ssh.timeout`

This commit is contained in:
Mitchell Hashimoto 2010-03-08 19:30:58 -08:00
parent 1139ec9e0c
commit d818bf856b
5 changed files with 13 additions and 2 deletions

View File

@ -9,6 +9,7 @@ Vagrant::Config.run do |config|
config.ssh.host = "localhost" config.ssh.host = "localhost"
config.ssh.forwarded_port_key = "ssh" config.ssh.forwarded_port_key = "ssh"
config.ssh.max_tries = 10 config.ssh.max_tries = 10
config.ssh.timeout = 10
config.vm.box_ovf = "box.ovf" config.vm.box_ovf = "box.ovf"
config.vm.base_mac = "0800279C2E42" config.vm.base_mac = "0800279C2E42"

View File

@ -59,6 +59,7 @@ module Vagrant
attr_accessor :host attr_accessor :host
attr_accessor :forwarded_port_key attr_accessor :forwarded_port_key
attr_accessor :max_tries attr_accessor :max_tries
attr_accessor :timeout
end end
class VMConfig < Base class VMConfig < Base

View File

@ -29,7 +29,7 @@ module Vagrant
check_thread = Thread.new do check_thread = Thread.new do
begin begin
Thread.current[:result] = false Thread.current[:result] = false
Net::SSH.start(Vagrant.config.ssh.host, Vagrant.config.ssh.username, :port => port, :password => Vagrant.config.ssh.password, :timeout => 5) 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 Thread.current[:result] = true
end end
rescue Errno::ECONNREFUSED, Net::SSH::Disconnect rescue Errno::ECONNREFUSED, Net::SSH::Disconnect
@ -37,7 +37,7 @@ module Vagrant
end end
end end
check_thread.join(5) check_thread.join(Vagrant.config.ssh.timeout)
return check_thread[:result] return check_thread[:result]
end end

View File

@ -31,6 +31,7 @@ class Test::Unit::TestCase
config.ssh.host = "baz" config.ssh.host = "baz"
config.ssh.forwarded_port_key = "ssh" config.ssh.forwarded_port_key = "ssh"
config.ssh.max_tries = 10 config.ssh.max_tries = 10
config.ssh.timeout = 10
config.vm.box = "foo" config.vm.box = "foo"
config.vm.box_ovf = "box.ovf" config.vm.box_ovf = "box.ovf"

View File

@ -68,6 +68,14 @@ class SshTest < Test::Unit::TestCase
assert !Vagrant::SSH.up? assert !Vagrant::SSH.up?
end end
should "allow the thread the configured timeout time" do
@thread = mock("thread")
@thread.stubs(:[])
Thread.expects(:new).returns(@thread)
@thread.expects(:join).with(Vagrant.config.ssh.timeout).once
Vagrant::SSH.up?
end
should "return false if the connection is refused" do should "return false if the connection is refused" do
Net::SSH.expects(:start).raises(Errno::ECONNREFUSED) Net::SSH.expects(:start).raises(Errno::ECONNREFUSED)
assert_nothing_raised { assert_nothing_raised {