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]
|
||||
- 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]
|
||||
- Check for VM boot changed to use `timeout` library, which works better with Windows.
|
||||
|
||||
## 0.6.8 (November 30, 2010)
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
require 'timeout'
|
||||
require 'net/ssh'
|
||||
require 'net/scp'
|
||||
require 'mario'
|
||||
|
@ -92,21 +93,16 @@ module Vagrant
|
|||
#
|
||||
# @return [Boolean]
|
||||
def up?
|
||||
check_thread = Thread.new do
|
||||
begin
|
||||
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
|
||||
Timeout.timeout(env.config.ssh.timeout) do
|
||||
execute(:timeout => env.config.ssh.timeout) { |ssh| }
|
||||
end
|
||||
|
||||
check_thread.join(env.config.ssh.timeout)
|
||||
return check_thread[:result]
|
||||
true
|
||||
rescue Net::SSH::AuthenticationFailed
|
||||
raise Errors::SSHAuthenticationFailed.new
|
||||
rescue Timeout::Error, Errno::ECONNREFUSED, Net::SSH::Disconnect,
|
||||
Errors::SSHConnectionRefused, Net::SSH::AuthenticationFailed
|
||||
return false
|
||||
end
|
||||
|
||||
# Checks the file permissions for the private key, resetting them
|
||||
|
|
|
@ -195,16 +195,15 @@ class SshTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "return false if SSH connection times out" do
|
||||
Net::SSH.expects(:start)
|
||||
assert !@ssh.up?
|
||||
end
|
||||
@env.config.ssh.timeout = 0.5
|
||||
|
||||
should "allow the thread the configured timeout time" do
|
||||
@thread = mock("thread")
|
||||
@thread.stubs(:[])
|
||||
Thread.expects(:new).returns(@thread)
|
||||
@thread.expects(:join).with(@env.config.ssh.timeout).once
|
||||
@ssh.up?
|
||||
Net::SSH.stubs(:start).with() do
|
||||
# Sleep here to artificially fake timeout
|
||||
sleep 1
|
||||
true
|
||||
end
|
||||
|
||||
assert !@ssh.up?
|
||||
end
|
||||
|
||||
should "return false if the connection is refused" do
|
||||
|
|
Loading…
Reference in New Issue