Determine SSH on main thread for up? to fix issues with multi-thread access on JRuby
This commit is contained in:
parent
53b3a9c39d
commit
e98db8dc86
|
@ -61,12 +61,12 @@ module Vagrant
|
||||||
# Merge in any additional options
|
# Merge in any additional options
|
||||||
opts = opts.dup
|
opts = opts.dup
|
||||||
opts[:forward_agent] = true if env.config.ssh.forward_agent
|
opts[:forward_agent] = true if env.config.ssh.forward_agent
|
||||||
|
opts[:port] ||= port
|
||||||
|
|
||||||
retryable(:tries => 5, :on => Errno::ECONNREFUSED) do
|
retryable(:tries => 5, :on => Errno::ECONNREFUSED) do
|
||||||
Net::SSH.start(env.config.ssh.host,
|
Net::SSH.start(env.config.ssh.host,
|
||||||
env.config.ssh.username,
|
env.config.ssh.username,
|
||||||
opts.merge( :port => port,
|
opts.merge( :keys => [env.config.ssh.private_key_path],
|
||||||
:keys => [env.config.ssh.private_key_path],
|
|
||||||
:user_known_hosts_file => [],
|
:user_known_hosts_file => [],
|
||||||
:paranoid => false,
|
:paranoid => false,
|
||||||
:config => false)) do |ssh|
|
:config => false)) do |ssh|
|
||||||
|
@ -93,8 +93,14 @@ module Vagrant
|
||||||
#
|
#
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def up?
|
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
|
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
|
end
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
|
@ -221,7 +221,11 @@ class SshTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
should "specifity the timeout as an option to execute" do
|
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?
|
assert @ssh.up?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -229,6 +233,11 @@ class SshTest < Test::Unit::TestCase
|
||||||
@ssh.expects(:execute).raises(Net::SSH::AuthenticationFailed)
|
@ssh.expects(:execute).raises(Net::SSH::AuthenticationFailed)
|
||||||
assert_raises(Vagrant::Errors::SSHAuthenticationFailed) { @ssh.up? }
|
assert_raises(Vagrant::Errors::SSHAuthenticationFailed) { @ssh.up? }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "only get the port once (in the main thread)" do
|
||||||
|
@ssh.expects(:port).once.returns(2222)
|
||||||
|
@ssh.up?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "getting the ssh port" do
|
context "getting the ssh port" do
|
||||||
|
|
Loading…
Reference in New Issue