diff --git a/config/default.rb b/config/default.rb index 4725d2b5e..fe41e3398 100644 --- a/config/default.rb +++ b/config/default.rb @@ -5,7 +5,6 @@ Vagrant::Config.run do |config| config.ssh.username = "vagrant" config.ssh.host = "localhost" - config.ssh.port = 22 config.ssh.forwarded_port_key = "ssh" config.ssh.max_tries = 10 config.ssh.timeout = 30 diff --git a/lib/vagrant/config/ssh.rb b/lib/vagrant/config/ssh.rb index de4347ce5..da504051a 100644 --- a/lib/vagrant/config/ssh.rb +++ b/lib/vagrant/config/ssh.rb @@ -5,7 +5,6 @@ module Vagrant attr_accessor :username attr_accessor :host - attr_accessor :port attr_accessor :forwarded_port_key attr_accessor :max_tries attr_accessor :timeout @@ -18,7 +17,7 @@ module Vagrant end def validate(errors) - [:username, :host, :port, :forwarded_port_key, :max_tries, :timeout, :private_key_path].each do |field| + [:username, :host, :forwarded_port_key, :max_tries, :timeout, :private_key_path].each do |field| errors.add(I18n.t("vagrant.config.common.error_empty", :field => field)) if !instance_variable_get("@#{field}".to_sym) end diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 051f195fa..cf3aa13b3 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -245,6 +245,11 @@ module Vagrant error_key(:ssh_key_bad_permissions) end + class SSHPortNotDetected < VagrantError + status_code(50) + error_key(:ssh_port_not_detected) + end + class SSHUnavailable < VagrantError status_code(45) error_key(:ssh_unavailable) diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index a53d248f5..3d6ba9e26 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -142,8 +142,7 @@ module Vagrant # Returns the port which is either given in the options hash or taken from # the config by finding it in the forwarded ports hash based on the - # `config.ssh.forwarded_port_key` or use the default port given by `config.ssh.port` - # when port forwarding isn't used. + # `config.ssh.forwarded_port_key`. def port(opts={}) # Check if port was specified in options hash pnum = opts[:port] @@ -161,8 +160,8 @@ module Vagrant return pnum.hostport if pnum - # Fall back to the default - return env.config.ssh.port + # This should NEVER happen. + raise Errors::SSHPortNotDetected end end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 47fe41d82..5af6c769e 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -84,6 +84,10 @@ en: permissions on the following file to 0600 and then try running this command again: %{key_path} + ssh_port_not_detected: |- + Vagrant couldn't determine the SSH port for your VM! This is a rare, + exceptional event, and a bug should be filed. Please try recreating your + VM (vagrant destroy, then vagrant up). Sorry! ssh_unavailable: "`ssh` binary could not be found. Is an SSH client installed?" ssh_unavailable_windows: |- `vagrant ssh` isn't available on the Windows platform. The diff --git a/test/vagrant/ssh_test.rb b/test/vagrant/ssh_test.rb index 0e96c4e1b..92fbfddd8 100644 --- a/test/vagrant/ssh_test.rb +++ b/test/vagrant/ssh_test.rb @@ -19,6 +19,7 @@ class SshTest < Test::Unit::TestCase setup do mock_ssh @ssh.stubs(:check_key_permissions) + @ssh.stubs(:port).returns(2222) Kernel.stubs(:exec) Kernel.stubs(:system).returns(true) @@ -53,8 +54,8 @@ class SshTest < Test::Unit::TestCase end should "call exec with supplied params" do - args = {:username => 'bar', :private_key_path => 'baz', :host => 'bak', :port => 'bag'} - ssh_exec_expect(args[:port], args[:private_key_path], args[:username], args[:host]) + args = {:username => 'bar', :private_key_path => 'baz', :host => 'bak'} + ssh_exec_expect(@ssh.port, args[:private_key_path], args[:username], args[:host]) @ssh.connect(args) end @@ -116,10 +117,10 @@ class SshTest < Test::Unit::TestCase def ssh_exec_expect(port, key_path, uname, host) Kernel.expects(:exec).with() do |arg| - assert arg =~ /^ssh/ - assert arg =~ /-p #{port}/ - assert arg =~ /-i #{key_path}/ - assert arg =~ /#{uname}@#{host}/ + assert arg =~ /^ssh/, "ssh command expected" + assert arg =~ /-p #{port}/, "-p #{port} expected" + assert arg =~ /-i #{key_path}/, "-i #{key_path} expected" + assert arg =~ /#{uname}@#{host}/, "#{uname}@{host} expected" yield arg if block_given? true end @@ -198,6 +199,7 @@ class SshTest < Test::Unit::TestCase setup do mock_ssh @ssh.stubs(:check_key_permissions) + @ssh.stubs(:port).returns(2222) end should "return true if SSH connection works" do