diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index 61458aed9..3a5f24487 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -57,9 +57,16 @@ module Vagrant # or StringIO, and `to` is expected to be a path. This method simply forwards # the arguments to `Net::SCP#upload!` so view that for more information. def upload!(from, to) - execute do |ssh| - scp = Net::SCP.new(ssh.session) - scp.upload!(from, to) + tries = 5 + + begin + execute do |ssh| + scp = Net::SCP.new(ssh.session) + scp.upload!(from, to) + end + rescue IOError + retry if (tries -= 1) > 0 + raise end end diff --git a/test/vagrant/ssh_test.rb b/test/vagrant/ssh_test.rb index a13b4ed60..802515679 100644 --- a/test/vagrant/ssh_test.rb +++ b/test/vagrant/ssh_test.rb @@ -144,6 +144,13 @@ class SshTest < Test::Unit::TestCase @ssh.expects(:execute).yields(ssh).once @ssh.upload!("foo", "bar") end + + should "retry 5 times" do + @ssh.expects(:execute).times(5).raises(IOError) + assert_raises(IOError) { + @ssh.upload!("foo", "bar") + } + end end context "checking if host is up" do