Retry SCP upload 5 times as well

This commit is contained in:
Mitchell Hashimoto 2010-06-03 20:58:04 -07:00
parent 8dc57c6796
commit abef4d29ce
2 changed files with 17 additions and 3 deletions

View File

@ -57,10 +57,17 @@ 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)
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
# Checks if this environment's machine is up (i.e. responding to SSH).

View File

@ -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