SSH exec! can now be given options which are used for bad exit status error messages

This commit is contained in:
Mitchell Hashimoto 2010-05-29 11:18:27 -07:00
parent ad96f0090a
commit 4c8713ecd4
2 changed files with 24 additions and 4 deletions

View File

@ -148,9 +148,9 @@ module Vagrant
# the command completes. This is an almost line for line copy of
# the actual `exec!` implementation, except that this
# implementation also reports `:exit_status` to the block if given.
def exec!(command, &block)
def exec!(command, options=nil, &block)
block ||= Proc.new do |ch, type, data|
check_exit_status(data, command) if type == :exit_status
check_exit_status(data, command, options) if type == :exit_status
ch[:result] ||= ""
ch[:result] << data if [:stdout, :stderr].include?(type)
@ -183,9 +183,16 @@ module Vagrant
# Checks for an erroroneous exit status and raises an exception
# if so.
def check_exit_status(exit_status, command)
def check_exit_status(exit_status, command, options=nil)
if exit_status != 0
raise Actions::ActionException.new(:ssh_bad_exit_status, :command => command)
options = {
:error_key => :ssh_bad_exit_status,
:error_data => {
:command => command
}
}.merge(options || {})
raise Actions::ActionException.new(options[:error_key], options[:error_data])
end
end
end

View File

@ -15,6 +15,19 @@ class SshTest < Test::Unit::TestCase
}
end
should "raise the given exception if specified" do
options = {
:error_key => :foo,
:error_data => {}
}
result = Exception.new
Vagrant::Actions::ActionException.expects(:new).with(options[:error_key], options[:error_data]).once.returns(result)
assert_raises(Exception) {
@instance.check_exit_status(1, "foo", options)
}
end
should "raise nothing if its zero" do
assert_nothing_raised {
@instance.check_exit_status(0, "foo")