Skip to content

Commit

Permalink
add remote_base_dir to sync_options to specify where working copies a…
Browse files Browse the repository at this point in the history
…re stored remotely
  • Loading branch information
qxjit committed Aug 4, 2009
1 parent d1b1a57 commit c9a000e
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 18 deletions.
3 changes: 2 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ below in your Rakefile.
t.distributed_hosts = %w[host1 host2]
t.sync_options = {
:source => <absolute path of project root on machine>,
:username => "username"
:username => "username",
:remote_base_dir => <absolute path to keep working copies in on remote machine> # defaults to /tmp
}
end

Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ DeepTest::TestTask.new(:distributed_test) do |t|
t.pattern = "test/**/*_test.rb"
t.distributed_hosts = %w[localhost]
t.sync_options = {:source => File.dirname(__FILE__),
:rsync_options => "--exclude=.svn"}
:rsync_options => "--exclude=.svn",
:remote_base_dir => "/tmp/deep_test"}
end

Spec::Rake::SpecTask.new(:spec) do |t|
Expand Down
2 changes: 1 addition & 1 deletion lib/deep_test/distributed/establish_beachhead.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
STDIN.close

beachhead_port = DeepTest::Distributed::Beachhead.new(
File.join(options.mirror_path('/tmp'), File.basename(options.sync_options[:source])),
File.join(options.mirror_path, File.basename(options.sync_options[:source])),
options
).daemonize

Expand Down
5 changes: 2 additions & 3 deletions lib/deep_test/distributed/landing_ship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ def initialize(config)
end

def push_code(options)
path = options.mirror_path(@config[:work_dir])
RSync.push(@config[:address], options.sync_options, path)
RSync.push(@config[:address], options.sync_options, options.mirror_path)
end

def establish_beachhead(options)
Expand Down Expand Up @@ -49,7 +48,7 @@ def ssh_command(options)

def spawn_command(options)
"#{ShellEnvironment.like_login} && " +
"cd #{options.mirror_path(@config[:work_dir])} && " +
"cd #{options.mirror_path} && " +
"OPTIONS=#{options.to_command_line} " +
"ruby lib/deep_test/distributed/establish_beachhead.rb"
end
Expand Down
6 changes: 3 additions & 3 deletions lib/deep_test/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ def to_command_line
Base64.encode64(Marshal.dump(self)).gsub("\n","")
end

def mirror_path(base)
def mirror_path
raise "No source directory specified in sync_options" unless sync_options[:source]
relative_mirror_path = @origin_hostname + sync_options[:source].gsub('/','_')
"#{base}/#{relative_mirror_path}"
"#{sync_options[:remote_base_dir] || '/tmp'}/#{relative_mirror_path}"
end

def new_deployment
Expand All @@ -94,7 +94,7 @@ def new_deployment

def new_landing_fleet
landing_ships = distributed_hosts.map do |host|
Distributed::LandingShip.new :address => host, :work_dir => '/tmp'
Distributed::LandingShip.new :address => host
end
Distributed::LandingFleet.new self, landing_ships
end
Expand Down
17 changes: 11 additions & 6 deletions spec/deep_test/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,25 @@ class FakeUI; end
yielded_wire.should == :wire
end

it "should be able to calculate mirror_path based on base an sync_options" do
it "should be able to calculate mirror_path based on sync_options" do
Socket.should_receive(:gethostname).and_return("hostname")
options = Options.new(:sync_options => {:source => "/my/source/path"})
options.mirror_path("/mirror/base/path").should ==
"/mirror/base/path/hostname_my_source_path"
options = Options.new(:sync_options => {:source => "/my/source/path", :remote_base_dir => "/mirror/base/path"})
options.mirror_path.should == "/mirror/base/path/hostname_my_source_path"
end

it "should raise a useful error if no source is specified" do
options = DeepTest::Options.new(:sync_options => {})
options = DeepTest::Options.new(:sync_options => {:remote_base_dir => "/mirror/base/path/"})
lambda {
options.mirror_path("base")
options.mirror_path
}.should raise_error("No source directory specified in sync_options")
end

it "should default to /tmp if no remote_base_dir is specified in sync_options" do
Socket.should_receive(:gethostname).and_return("hostname")
options = DeepTest::Options.new(:sync_options => {:source => "/my/source/path"})
options.mirror_path.should == "/tmp/hostname_my_source_path"
end

it "should be gathering metrics if metrics file is set" do
options = DeepTest::Options.new(:metrics_file => "filename")
options.should be_gathering_metrics
Expand Down
6 changes: 3 additions & 3 deletions test/deep_test/distributed/landing_ship_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Distributed
test "generates a local working copy path based on host and source of request" do
Socket.stubs(:gethostname).returns("myhost")
Telegraph::Wire.stubs(:connect).returns :wire
landing_ship = LandingShip.new(:address => "host", :work_dir => "/tmp")
landing_ship = LandingShip.new(:address => "host")
options = Options.new(:sync_options => {:source => "/my/local/dir"})
RSync.expects(:push).with("host", options.sync_options, "/tmp/myhost_my_local_dir")
landing_ship.push_code(options)
Expand All @@ -15,7 +15,7 @@ module Distributed
test "establish_beachhead launches beachhead process on remote machine" do
Socket.stubs(:gethostname).returns("myhost")
Telegraph::Wire.stubs(:connect).returns :wire
landing_ship = LandingShip.new(:address => "remote_host", :work_dir => "/tmp")
landing_ship = LandingShip.new(:address => "remote_host")
options = Options.new(:sync_options => {:source => "/my/local/dir"})

landing_ship.expects(:`).with(
Expand All @@ -31,7 +31,7 @@ module Distributed
test "establish_beachhead launches beachhead process on remote machine with usernames specified in sync_options" do
Socket.stubs(:gethostname).returns("myhost")
Telegraph::Wire.stubs(:connect).returns :wire
landing_ship = LandingShip.new(:address => "remote_host", :work_dir => "/tmp")
landing_ship = LandingShip.new(:address => "remote_host")
options = Options.new(:sync_options => {:username => "me", :source => "/my/local/dir"})

landing_ship.expects(:`).with(
Expand Down

0 comments on commit c9a000e

Please sign in to comment.