diff --git a/config/default.rb b/config/default.rb index 87cd728d1..e925c15c0 100644 --- a/config/default.rb +++ b/config/default.rb @@ -9,6 +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 = 10 config.vm.box_ovf = "box.ovf" config.vm.base_mac = "0800279C2E42" diff --git a/lib/vagrant/config.rb b/lib/vagrant/config.rb index fee8047dc..1219517ea 100644 --- a/lib/vagrant/config.rb +++ b/lib/vagrant/config.rb @@ -59,6 +59,7 @@ module Vagrant attr_accessor :host attr_accessor :forwarded_port_key attr_accessor :max_tries + attr_accessor :timeout end class VMConfig < Base diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index d9979b2df..9da69b3f7 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -29,7 +29,7 @@ module Vagrant 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 => 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 end rescue Errno::ECONNREFUSED, Net::SSH::Disconnect @@ -37,7 +37,7 @@ module Vagrant end end - check_thread.join(5) + check_thread.join(Vagrant.config.ssh.timeout) return check_thread[:result] end diff --git a/test/test_helper.rb b/test/test_helper.rb index 214c95247..cd0c028be 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -31,6 +31,7 @@ class Test::Unit::TestCase config.ssh.host = "baz" config.ssh.forwarded_port_key = "ssh" config.ssh.max_tries = 10 + config.ssh.timeout = 10 config.vm.box = "foo" config.vm.box_ovf = "box.ovf" diff --git a/test/vagrant/ssh_test.rb b/test/vagrant/ssh_test.rb index a7cb2b2db..aafe07344 100644 --- a/test/vagrant/ssh_test.rb +++ b/test/vagrant/ssh_test.rb @@ -68,6 +68,14 @@ class SshTest < Test::Unit::TestCase assert !Vagrant::SSH.up? 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 Net::SSH.expects(:start).raises(Errno::ECONNREFUSED) assert_nothing_raised {