Retry SSH commands 5 times if an IOError occurs
This commit is contained in:
parent
dc760c73b9
commit
8dc57c6796
|
@ -160,6 +160,9 @@ module Vagrant
|
||||||
ch[:result] << data if [:stdout, :stderr].include?(type)
|
ch[:result] << data if [:stdout, :stderr].include?(type)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
tries = 5
|
||||||
|
|
||||||
|
begin
|
||||||
metach = session.open_channel do |channel|
|
metach = session.open_channel do |channel|
|
||||||
channel.exec(command) do |ch, success|
|
channel.exec(command) do |ch, success|
|
||||||
raise "could not execute command: #{command.inspect}" unless success
|
raise "could not execute command: #{command.inspect}" unless success
|
||||||
|
@ -180,6 +183,10 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
rescue IOError
|
||||||
|
retry if (tries -= 1) > 0
|
||||||
|
raise
|
||||||
|
end
|
||||||
|
|
||||||
metach.wait
|
metach.wait
|
||||||
metach[:result]
|
metach[:result]
|
||||||
|
|
|
@ -139,6 +139,7 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
@vm.expects(:forwarded_ports).returns(forwarded_ports)
|
@vm.expects(:forwarded_ports).returns(forwarded_ports)
|
||||||
@vm.expects(:save).once
|
@vm.expects(:save).once
|
||||||
|
@runner.expects(:reload!).once
|
||||||
@action.forward_ports
|
@action.forward_ports
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -151,6 +152,7 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
||||||
@vm.expects(:network_adapters).returns([network_adapter])
|
@vm.expects(:network_adapters).returns([network_adapter])
|
||||||
network_adapter.expects(:attachment_type).returns(:host_only)
|
network_adapter.expects(:attachment_type).returns(:host_only)
|
||||||
@vm.expects(:save).once
|
@vm.expects(:save).once
|
||||||
|
@runner.expects(:reload!).once
|
||||||
@action.forward_ports
|
@action.forward_ports
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,6 +8,15 @@ class SshTest < Test::Unit::TestCase
|
||||||
@instance = @klass.new(@session)
|
@instance = @klass.new(@session)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "exec!" do
|
||||||
|
should "retry 5 times" do
|
||||||
|
@session.expects(:open_channel).times(5).raises(IOError)
|
||||||
|
assert_raises(IOError) {
|
||||||
|
@instance.exec!("foo")
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "checking exit status" do
|
context "checking exit status" do
|
||||||
should "raise an ActionException if its non-zero" do
|
should "raise an ActionException if its non-zero" do
|
||||||
assert_raises(Vagrant::Actions::ActionException) {
|
assert_raises(Vagrant::Actions::ActionException) {
|
||||||
|
|
Loading…
Reference in New Issue