diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index e859e715f..765a77da3 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -56,6 +56,11 @@ module Vagrant error_key(:no_env) end + class SSHUnavailableWindows < VagrantError + status_code(10) + error_key(:ssh_unavailable_windows) + end + class VirtualBoxInvalidOSE < VagrantError status_code(9) error_key(:virtualbox_invalid_ose) diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index be17126ae..d12565327 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -22,9 +22,8 @@ module Vagrant # of options which override the configuration values. def connect(opts={}) if Mario::Platform.windows? - error_and_exit(:ssh_unavailable_windows, - :key_path => env.config.ssh.private_key_path, - :ssh_port => port(opts)) + raise Errors::SSHUnavailableWindows.new(:key_path => env.config.ssh.private_key_path, + :ssh_port => port(opts)) end options = {} diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 35ae3df95..2ed158fc0 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -11,6 +11,21 @@ en: multi_vm_required: A multi-vm environment is required for name specification to this command. multi_vm_target_required: `vagrant %{command}` requires a specific VM name to target in a multi-VM environment. no_env: No Vagrant environment detected. Run `vagrant init` to set one up. + ssh_unavailable_windows: |- + `vagrant ssh` isn't available on the Windows platform. The + vagrant.ppk file for use with Putty is available at: + + <%= key_path %>.ppk + + To use this create a new Putty session for `vagrant@localhost` + on port `<%= ssh_port %>`, in the Connection>SSH>Auth + configuration section navigate to the vagrant.ppk file, + select it, save the session for later use, and connect. + + For a more detailed guide please consult: + + http://vagrantup.com/docs/getting-started/windows. + virtualbox_invalid_ose: |- Vagrant has detected you're using an OSE ("Open Source Edition") of VirtualBox. Vagrant currently doesn't support any of the OSE editions due to slight API diff --git a/templates/strings.yml b/templates/strings.yml index e546d338c..b49f8fc6b 100644 --- a/templates/strings.yml +++ b/templates/strings.yml @@ -153,20 +153,6 @@ Vagrant assumes that this means the command failed! <%= command %> -:ssh_unavailable_windows: |- - `vagrant ssh` isn't available on the Windows platform. The - vagrant.ppk file is available at - - <%= key_path %>.ppk - - for use with Putty. To do this create a new Putty session for - `vagrant@localhost` on port `<%= ssh_port %>`, in the Connection>SSH>Auth - configuration section navigate to the vagrant.ppk file, - select it, save the session for later use, and connect. - - For a more detailed guide please consult: - - http://vagrantup.com/docs/getting-started/windows.html :system_invalid_class: |- The specified system does not inherit from `Vagrant::Systems::Base`. The specified system class must inherit from this class. diff --git a/test/vagrant/ssh_test.rb b/test/vagrant/ssh_test.rb index 48d4cfbbf..223ce12c9 100644 --- a/test/vagrant/ssh_test.rb +++ b/test/vagrant/ssh_test.rb @@ -68,6 +68,10 @@ class SshTest < Test::Unit::TestCase Vagrant::Util::Platform.stubs(:leopard?).returns(true) end + teardown do + Vagrant::Util::Platform.stubs(:leopard?).returns(false) + end + should "fork, exec, and wait" do pid = mock("pid") @ssh.expects(:fork).once.returns(pid) @@ -78,18 +82,18 @@ class SshTest < Test::Unit::TestCase end context "checking windows" do + teardown do + Mario::Platform.forced = Mario::Platform::Linux + end + should "error and exit if the platform is windows" do - Mario::Platform.expects(:windows?).returns(true) - @ssh.expects(:error_and_exit).with do |error_name, opts| - opts[:key_path] && opts[:ssh_port] - end - @ssh.connect + Mario::Platform.forced = Mario::Platform::Windows7 + assert_raises(Vagrant::Errors::SSHUnavailableWindows) { @ssh.connect } end should "not error and exit if the platform is anything other that windows" do - Mario::Platform.expects(:windows?).returns(false) - @ssh.expects(:error_and_exit).never - @ssh.connect + Mario::Platform.forced = Mario::Platform::Linux + assert_nothing_raised { @ssh.connect } end end @@ -252,11 +256,15 @@ class SshTest < Test::Unit::TestCase @stat.stubs(:owned?).returns(true) File.stubs(:stat).returns(@stat) - Mario::Platform.stubs(:windows?).returns(false) + Mario::Platform.forced = Mario::Platform::Linux + end + + teardown do + Mario::Platform.forced = Mario::Platform::Linux end should "do nothing if on windows" do - Mario::Platform.stubs(:windows?).returns(true) + Mario::Platform.forced = Mario::Platform::Windows7 File.expects(:stat).never @ssh.check_key_permissions(@key_path) end