`vagrant ssh` now queries for the ssh forwarded port, rather than relying on config

This commit is contained in:
Mitchell Hashimoto 2010-05-27 18:18:25 -07:00
parent cc0a1930d8
commit 0e4ae3530a
4 changed files with 22 additions and 4 deletions

View File

@ -122,8 +122,11 @@ module Vagrant
return pnum if pnum return pnum if pnum
# Check if we have an SSH forwarded port # Check if we have an SSH forwarded port
pnum = env.config.vm.forwarded_ports[env.config.ssh.forwarded_port_key] pnum = env.vm.vm.forwarded_ports.detect do |fp|
return pnum[:hostport] if pnum fp.name == env.config.ssh.forwarded_port_key
end
return pnum.hostport if pnum
# Fall back to the default # Fall back to the default
return env.config.ssh.port return env.config.ssh.port

View File

@ -29,6 +29,7 @@ class Test::Unit::TestCase
config.ssh.username = "foo" config.ssh.username = "foo"
config.ssh.password = "bar" config.ssh.password = "bar"
config.ssh.host = "baz" config.ssh.host = "baz"
config.ssh.port = 22
config.ssh.forwarded_port_key = "ssh" config.ssh.forwarded_port_key = "ssh"
config.ssh.max_tries = 10 config.ssh.max_tries = 10
config.ssh.timeout = 10 config.ssh.timeout = 10

View File

@ -6,6 +6,13 @@ class SshTest < Test::Unit::TestCase
yield config if block_given? yield config if block_given?
end end
@forwarded_ports = []
@vm = mock("vm")
@vm.stubs(:forwarded_ports).returns(@forwarded_ports)
@env.stubs(:vm).returns(mock_vm(@env))
@env.vm.stubs(:vm).returns(@vm)
@ssh = Vagrant::SSH.new(@env) @ssh = Vagrant::SSH.new(@env)
end end
@ -181,10 +188,17 @@ class SshTest < Test::Unit::TestCase
context "getting the ssh port" do context "getting the ssh port" do
setup do setup do
mock_ssh mock_ssh
end end
should "return the configured port by default" do should "return the configured port by default" do
assert_equal @env.config.vm.forwarded_ports[@env.config.ssh.forwarded_port_key][:hostport], @ssh.port port = 2222
fp = mock("fp")
fp.stubs(:name).returns(@env.config.ssh.forwarded_port_key)
fp.stubs(:hostport).returns(port)
@forwarded_ports << fp
assert_equal port, @ssh.port
end end
should "return the port given in options if it exists" do should "return the port given in options if it exists" do

View File

@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Mitchell Hashimoto", "John Bender"] s.authors = ["Mitchell Hashimoto", "John Bender"]
s.date = %q{2010-05-26} s.date = %q{2010-05-27}
s.default_executable = %q{vagrant} s.default_executable = %q{vagrant}
s.description = %q{Vagrant is a tool for building and distributing virtualized development environments.} s.description = %q{Vagrant is a tool for building and distributing virtualized development environments.}
s.email = ["mitchell.hashimoto@gmail.com", "john.m.bender@gmail.com"] s.email = ["mitchell.hashimoto@gmail.com", "john.m.bender@gmail.com"]