Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ def update_local_cache

def update_remote_cache
finder_options = {:except => { :no_release => true }}
find_servers(finder_options).each {|s| system(rsync_command_for(s)) }
find_servers(finder_options).each {|s| system(rsync_command_for(s)) or raise "Command failed" }
end

def copy_remote_cache
run("rsync -a --delete #{repository_cache_path}/ #{configuration[:release_path]}/")
end

def rsync_command_for(server)
"rsync #{rsync_options} --rsh='ssh -p #{ssh_port(server)}' #{local_cache_path}/ #{rsync_host(server)}:#{repository_cache_path}/"
"rsync #{rsync_options} --rsh='ssh -p #{ssh_port(server)}#{" -o \"ProxyCommand ssh #{configuration[:gateway]} nc -w300 %h %p\"" if configuration[:gateway]}' #{local_cache_path}/ #{rsync_host(server)}:#{repository_cache_path}/"
end

def mark_local_cache
Expand Down
35 changes: 33 additions & 2 deletions test/capistrano_rsync_with_remote_cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,50 @@ class CapistranoRsyncWithRemoteCacheTest < Test::Unit::TestCase
@strategy.rsync_command_for(server).should == expected
end

should "be able to run the rsync command through a gateway" do
server = stub()

@strategy.stubs(:rsync_host).with(server).returns('rsync_host')
@strategy.configuration.stubs(:[]).with(:gateway).returns('ssh_gateway')

@strategy.stubs(
:rsync_options => 'rsync_options',
:ssh_port => 'ssh_port',
:local_cache_path => 'local_cache_path',
:repository_cache_path => 'repository_cache_path'
)

expected = "rsync rsync_options --rsh='ssh -p ssh_port -o \"ProxyCommand ssh ssh_gateway nc -w300 %h %p\"' local_cache_path/ rsync_host:repository_cache_path/"

@strategy.rsync_command_for(server).should == expected
end

should "be able to update the remote cache" do
server_1, server_2 = [stub(), stub()]
@strategy.stubs(:find_servers).with(:except => {:no_release => true}).returns([server_1, server_2])

@strategy.stubs(:rsync_command_for).with(server_1).returns('server_1_rsync_command')
@strategy.stubs(:rsync_command_for).with(server_2).returns('server_2_rsync_command')

@strategy.expects(:system).with('server_1_rsync_command')
@strategy.expects(:system).with('server_2_rsync_command')
@strategy.expects(:system).with('server_1_rsync_command').returns(true)
@strategy.expects(:system).with('server_2_rsync_command').returns(true)

@strategy.update_remote_cache
end

should "notice failure to update teh remote cache" do
server_1, server_2 = [stub(), stub()]
@strategy.stubs(:find_servers).with(:except => {:no_release => true}).returns([server_1, server_2])

@strategy.stubs(:rsync_command_for).with(server_1).returns('server_1_rsync_command')
@strategy.stubs(:rsync_command_for).with(server_2).returns('server_2_rsync_command')

@strategy.expects(:system).with('server_1_rsync_command').returns(false)
@strategy.expects(:system).with('server_2_rsync_command').never

lambda { @strategy.update_remote_cache }.should raise_error
end

should "be able copy the remote cache into place" do
@strategy.stubs(
:repository_cache_path => 'repository_cache_path',
Expand Down