SSH exec! can now be given options which are used for bad exit status error messages
This commit is contained in:
parent
ad96f0090a
commit
4c8713ecd4
|
@ -148,9 +148,9 @@ module Vagrant
|
||||||
# the command completes. This is an almost line for line copy of
|
# the command completes. This is an almost line for line copy of
|
||||||
# the actual `exec!` implementation, except that this
|
# the actual `exec!` implementation, except that this
|
||||||
# implementation also reports `:exit_status` to the block if given.
|
# 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|
|
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] ||= ""
|
||||||
ch[:result] << data if [:stdout, :stderr].include?(type)
|
ch[:result] << data if [:stdout, :stderr].include?(type)
|
||||||
|
@ -183,9 +183,16 @@ module Vagrant
|
||||||
|
|
||||||
# Checks for an erroroneous exit status and raises an exception
|
# Checks for an erroroneous exit status and raises an exception
|
||||||
# if so.
|
# if so.
|
||||||
def check_exit_status(exit_status, command)
|
def check_exit_status(exit_status, command, options=nil)
|
||||||
if exit_status != 0
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,6 +15,19 @@ class SshTest < Test::Unit::TestCase
|
||||||
}
|
}
|
||||||
end
|
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
|
should "raise nothing if its zero" do
|
||||||
assert_nothing_raised {
|
assert_nothing_raised {
|
||||||
@instance.check_exit_status(0, "foo")
|
@instance.check_exit_status(0, "foo")
|
||||||
|
|
Loading…
Reference in New Issue