Use timeout library instead of threads to check for VM boot
This commit is contained in:
parent
3f2f5685b2
commit
59ae5747d0
|
@ -8,6 +8,7 @@
|
||||||
- Arbitrary options to puppet binary can be set with `config.puppet.options`. [GH-242]
|
- Arbitrary options to puppet binary can be set with `config.puppet.options`. [GH-242]
|
||||||
- BSD hosts use proper GNU sed syntax for clearing NFS shares. [GH-243]
|
- BSD hosts use proper GNU sed syntax for clearing NFS shares. [GH-243]
|
||||||
- Enumerate VMs in a multi-VM environment in order they were defined. [GH-244]
|
- Enumerate VMs in a multi-VM environment in order they were defined. [GH-244]
|
||||||
|
- Check for VM boot changed to use `timeout` library, which works better with Windows.
|
||||||
|
|
||||||
## 0.6.8 (November 30, 2010)
|
## 0.6.8 (November 30, 2010)
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
require 'timeout'
|
||||||
require 'net/ssh'
|
require 'net/ssh'
|
||||||
require 'net/scp'
|
require 'net/scp'
|
||||||
require 'mario'
|
require 'mario'
|
||||||
|
@ -92,21 +93,16 @@ module Vagrant
|
||||||
#
|
#
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def up?
|
def up?
|
||||||
check_thread = Thread.new do
|
Timeout.timeout(env.config.ssh.timeout) do
|
||||||
begin
|
execute(:timeout => env.config.ssh.timeout) { |ssh| }
|
||||||
Thread.current[:result] = false
|
|
||||||
execute(:timeout => env.config.ssh.timeout) do |ssh|
|
|
||||||
Thread.current[:result] = true
|
|
||||||
end
|
|
||||||
rescue Errno::ECONNREFUSED, Net::SSH::Disconnect, Errors::SSHConnectionRefused
|
|
||||||
# False, its defaulted above
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
check_thread.join(env.config.ssh.timeout)
|
true
|
||||||
return check_thread[:result]
|
|
||||||
rescue Net::SSH::AuthenticationFailed
|
rescue Net::SSH::AuthenticationFailed
|
||||||
raise Errors::SSHAuthenticationFailed.new
|
raise Errors::SSHAuthenticationFailed.new
|
||||||
|
rescue Timeout::Error, Errno::ECONNREFUSED, Net::SSH::Disconnect,
|
||||||
|
Errors::SSHConnectionRefused, Net::SSH::AuthenticationFailed
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks the file permissions for the private key, resetting them
|
# Checks the file permissions for the private key, resetting them
|
||||||
|
|
|
@ -195,16 +195,15 @@ class SshTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return false if SSH connection times out" do
|
should "return false if SSH connection times out" do
|
||||||
Net::SSH.expects(:start)
|
@env.config.ssh.timeout = 0.5
|
||||||
assert !@ssh.up?
|
|
||||||
end
|
|
||||||
|
|
||||||
should "allow the thread the configured timeout time" do
|
Net::SSH.stubs(:start).with() do
|
||||||
@thread = mock("thread")
|
# Sleep here to artificially fake timeout
|
||||||
@thread.stubs(:[])
|
sleep 1
|
||||||
Thread.expects(:new).returns(@thread)
|
true
|
||||||
@thread.expects(:join).with(@env.config.ssh.timeout).once
|
end
|
||||||
@ssh.up?
|
|
||||||
|
assert !@ssh.up?
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return false if the connection is refused" do
|
should "return false if the connection is refused" do
|
||||||
|
|
Loading…
Reference in New Issue