SSH gives error message if `ssh` binary is not found. [closes GH-161]

This commit is contained in:
Mitchell Hashimoto 2010-09-29 23:47:17 -07:00
parent 0fcc1150c5
commit c5b81b5998
5 changed files with 22 additions and 0 deletions

View File

@ -1,5 +1,6 @@
## 0.6.4 (unreleased)
- SSH gives error message if `ssh` binary is not found. [GH-161]
- SSH gives proper error message if VM is not running. [GH-167]
- Fix some issues with undefined constants in command errors.

View File

@ -243,6 +243,11 @@ module Vagrant
error_key(:ssh_key_bad_permissions)
end
class SSHUnavailable < VagrantError
status_code(45)
error_key(:ssh_unavailable)
end
class SSHUnavailableWindows < VagrantError
status_code(10)
error_key(:ssh_unavailable_windows)

View File

@ -26,6 +26,8 @@ module Vagrant
:ssh_port => port(opts))
end
raise Errors::SSHUnavailable.new if !Kernel.system("which ssh > /dev/null 2>&1")
options = {}
options[:port] = port(opts)
[:host, :username, :private_key_path].each do |param|

View File

@ -43,6 +43,7 @@ en:
permissions on the following file to 0600 and then try running this command again:
%{key_path}
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
vagrant.ppk file for use with Putty is available at:

View File

@ -22,10 +22,23 @@ class SshTest < Test::Unit::TestCase
mock_ssh
@ssh.stubs(:check_key_permissions)
Kernel.stubs(:exec)
Kernel.stubs(:system).returns(true)
Vagrant::Util::Platform.stubs(:leopard?).returns(false)
end
should "raise an exception if SSH is not found" do
Kernel.stubs(:system).returns(false)
Kernel.expects(:system).returns(false).with() do |command|
assert command =~ /^which ssh/
true
end
assert_raises(Vagrant::Errors::SSHUnavailable) {
@ssh.connect
}
end
should "check key permissions prior to exec" do
exec_seq = sequence("exec_seq")
@ssh.expects(:check_key_permissions).with(@env.config.ssh.private_key_path).once.in_sequence(exec_seq)