Determine SSH on main thread for up? to fix issues with multi-thread access on JRuby

This commit is contained in:
Mitchell Hashimoto 2010-12-19 10:27:07 -08:00
parent 53b3a9c39d
commit e98db8dc86
2 changed files with 19 additions and 4 deletions

View File

@ -61,12 +61,12 @@ module Vagrant
# Merge in any additional options
opts = opts.dup
opts[:forward_agent] = true if env.config.ssh.forward_agent
opts[:port] ||= port
retryable(:tries => 5, :on => Errno::ECONNREFUSED) do
Net::SSH.start(env.config.ssh.host,
env.config.ssh.username,
opts.merge( :port => port,
:keys => [env.config.ssh.private_key_path],
opts.merge( :keys => [env.config.ssh.private_key_path],
:user_known_hosts_file => [],
:paranoid => false,
:config => false)) do |ssh|
@ -93,8 +93,14 @@ module Vagrant
#
# @return [Boolean]
def up?
# We have to determine the port outside of the block since it uses
# API calls which can only be used from the main thread in JRuby on
# Windows
ssh_port = port
Timeout.timeout(env.config.ssh.timeout) do
execute(:timeout => env.config.ssh.timeout) { |ssh| }
execute(:timeout => env.config.ssh.timeout,
:port => ssh_port) { |ssh| }
end
true

View File

@ -221,7 +221,11 @@ class SshTest < Test::Unit::TestCase
end
should "specifity the timeout as an option to execute" do
@ssh.expects(:execute).with(:timeout => @env.config.ssh.timeout).yields(true)
@ssh.expects(:execute).yields(true).with() do |opts|
assert_equal @env.config.ssh.timeout, opts[:timeout]
true
end
assert @ssh.up?
end
@ -229,6 +233,11 @@ class SshTest < Test::Unit::TestCase
@ssh.expects(:execute).raises(Net::SSH::AuthenticationFailed)
assert_raises(Vagrant::Errors::SSHAuthenticationFailed) { @ssh.up? }
end
should "only get the port once (in the main thread)" do
@ssh.expects(:port).once.returns(2222)
@ssh.up?
end
end
context "getting the ssh port" do