From 364233527ec83dd813d574eb8724f59e2efa65f6 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 1 Sep 2010 10:00:49 -0700 Subject: [PATCH] SSH no longer raises ActionException. Raises VagrantError --- lib/vagrant/ssh.rb | 9 ++++----- lib/vagrant/systems/linux.rb | 8 +++++++- templates/locales/en.yml | 6 ++++++ templates/strings.yml | 7 ------- test/vagrant/ssh_session_test.rb | 13 +++---------- test/vagrant/systems/linux_test.rb | 2 +- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index 2c3de79c3..b4c253a27 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -222,13 +222,12 @@ module Vagrant def check_exit_status(exit_status, command, options=nil) if exit_status != 0 options = { - :error_key => :ssh_bad_exit_status, - :error_data => { - :command => command - } + :_error_class => Errors::VagrantError, + :_key => :ssh_bad_exit_status, + :command => command }.merge(options || {}) - raise Action::ActionException.new(options[:error_key], options[:error_data]) + raise options[:_error_class].new(options) end end end diff --git a/lib/vagrant/systems/linux.rb b/lib/vagrant/systems/linux.rb index 1a0fab98c..b1480a455 100644 --- a/lib/vagrant/systems/linux.rb +++ b/lib/vagrant/systems/linux.rb @@ -106,7 +106,7 @@ module Vagrant break unless result attempts += 1 - raise Action::ActionException.new(:vm_mount_fail) if attempts >= 10 + raise LinuxError.new(:mount_fail) if attempts >= 10 sleep sleeptime end end @@ -115,5 +115,11 @@ module Vagrant vm.env.config end end + + class Linux < Base + class LinuxError < Errors::VagrantError + error_namespace("vagrant.systems.linux") + end + end end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 04eeb63fe..4e52dd924 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -16,6 +16,11 @@ en: keypair for the SSH user not being properly set on the guest VM. Please verify that the guest VM is setup with the proper public key, and that the private key path for Vagrant is setup propery as well. + ssh_bad_exit_status: |- + The following SSH command responded with a non-zero exit status. + Vagrant assumes that this means the command failed! + + %{command} ssh_key_bad_permissions: |- The private key to connect to this box via SSH has invalid permissions set on it. The permissions of the private key should be set to 0600, otherwise SSH will @@ -318,3 +323,4 @@ en: systems: linux: attempting_halt: "Attempting graceful shutdown of linux..." + mount_fail: "Failed to mount shared folders. `vboxsf` was not available." diff --git a/templates/strings.yml b/templates/strings.yml index 4ef5c1d52..02e37cbc7 100644 --- a/templates/strings.yml +++ b/templates/strings.yml @@ -34,11 +34,6 @@ vagrant box list :package_requires_export: |- Package must be used in conjunction with export. -:ssh_bad_exit_status: |- - The following SSH command responded with a non-zero exit status. - Vagrant assumes that this means the command failed! - - <%= command %> :system_invalid_class: |- The specified system does not inherit from `Vagrant::Systems::Base`. The specified system class must inherit from this class. @@ -50,8 +45,6 @@ :system_unspecified: |- A VM system type must be specified! This is done via the `config.vm.system` configuration value. Please read the documentation online for more information. -:vm_mount_fail: |- - Failed to mount shared folders. vboxsf was not available. #--------------------------------------------------------------------- # CATEGORY: Error Messages for Linux System #--------------------------------------------------------------------- diff --git a/test/vagrant/ssh_session_test.rb b/test/vagrant/ssh_session_test.rb index f87e05340..070ba2dbb 100644 --- a/test/vagrant/ssh_session_test.rb +++ b/test/vagrant/ssh_session_test.rb @@ -19,21 +19,14 @@ class SshSessionTest < Test::Unit::TestCase context "checking exit status" do should "raise an ActionException if its non-zero" do - assert_raises(Vagrant::Action::ActionException) { + assert_raises(Vagrant::Errors::VagrantError) { @instance.check_exit_status(1, "foo") } end should "raise the given exception if specified" do - options = { - :error_key => :foo, - :error_data => {} - } - result = Exception.new - Vagrant::Action::ActionException.expects(:new).with(options[:error_key], options[:error_data]).once.returns(result) - - assert_raises(Exception) { - @instance.check_exit_status(1, "foo", options) + assert_raises(Vagrant::Errors::BaseVMNotFound) { + @instance.check_exit_status(1, "foo", :_error_class => Vagrant::Errors::BaseVMNotFound) } end diff --git a/test/vagrant/systems/linux_test.rb b/test/vagrant/systems/linux_test.rb index 1e0c16223..65b86c6b5 100644 --- a/test/vagrant/systems/linux_test.rb +++ b/test/vagrant/systems/linux_test.rb @@ -84,7 +84,7 @@ class LinuxSystemTest < Test::Unit::TestCase should "raise an ActionException if the command fails constantly" do @ssh.expects(:exec!).times(@limit).returns(!@success_return) - assert_raises(Vagrant::Action::ActionException) { + assert_raises(Vagrant::Systems::Linux::LinuxError) { mount_folder } end