diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index 45d47b2a6..61458aed9 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -160,25 +160,32 @@ module Vagrant ch[:result] << data if [:stdout, :stderr].include?(type) end - metach = session.open_channel do |channel| - channel.exec(command) do |ch, success| - raise "could not execute command: #{command.inspect}" unless success + tries = 5 - # Output stdout data to the block - channel.on_data do |ch2, data| - block.call(ch2, :stdout, data) - end + begin + metach = session.open_channel do |channel| + channel.exec(command) do |ch, success| + raise "could not execute command: #{command.inspect}" unless success - # Output stderr data to the block - channel.on_extended_data do |ch2, type, data| - block.call(ch2, :stderr, data) - end + # Output stdout data to the block + channel.on_data do |ch2, data| + block.call(ch2, :stdout, data) + end - # Output exit status information to the block - channel.on_request("exit-status") do |ch2, data| - block.call(ch2, :exit_status, data.read_long) + # Output stderr data to the block + channel.on_extended_data do |ch2, type, data| + block.call(ch2, :stderr, data) + end + + # Output exit status information to the block + channel.on_request("exit-status") do |ch2, data| + block.call(ch2, :exit_status, data.read_long) + end end end + rescue IOError + retry if (tries -= 1) > 0 + raise end metach.wait diff --git a/test/vagrant/actions/vm/forward_ports_test.rb b/test/vagrant/actions/vm/forward_ports_test.rb index 0a79ee962..9baafb281 100644 --- a/test/vagrant/actions/vm/forward_ports_test.rb +++ b/test/vagrant/actions/vm/forward_ports_test.rb @@ -139,6 +139,7 @@ class ForwardPortsActionTest < Test::Unit::TestCase @vm.expects(:forwarded_ports).returns(forwarded_ports) @vm.expects(:save).once + @runner.expects(:reload!).once @action.forward_ports end end @@ -151,6 +152,7 @@ class ForwardPortsActionTest < Test::Unit::TestCase @vm.expects(:network_adapters).returns([network_adapter]) network_adapter.expects(:attachment_type).returns(:host_only) @vm.expects(:save).once + @runner.expects(:reload!).once @action.forward_ports end end diff --git a/test/vagrant/ssh_session_test.rb b/test/vagrant/ssh_session_test.rb index 2bdb50ca3..6ebbc4e51 100644 --- a/test/vagrant/ssh_session_test.rb +++ b/test/vagrant/ssh_session_test.rb @@ -8,6 +8,15 @@ class SshTest < Test::Unit::TestCase @instance = @klass.new(@session) 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 should "raise an ActionException if its non-zero" do assert_raises(Vagrant::Actions::ActionException) {