From abef4d29cede5b7c974a124570d5a11a439e5a38 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 3 Jun 2010 20:58:04 -0700 Subject: [PATCH] Retry SCP upload 5 times as well --- lib/vagrant/ssh.rb | 13 ++++++++++--- test/vagrant/ssh_test.rb | 7 +++++++ 2 files changed, 17 insertions(+), 3 deletions(-) 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