switched directory syncing over to unison

This commit is contained in:
John Bender 2010-06-05 00:39:25 -07:00
parent 7b6523371c
commit eec0986bc7
11 changed files with 150 additions and 150 deletions

View File

@ -28,9 +28,9 @@ Vagrant::Config.run do |config|
config.vm.share_folder("v-root", "/vagrant", ".") config.vm.share_folder("v-root", "/vagrant", ".")
# TODO new config class # TODO new config class
config.vm.rsync_opts = "-ur --delete" config.vm.sync_opts = "-terse -group -owner -batch -silent"
config.vm.rsync_script = "/tmp/rsync" config.vm.sync_script = "/tmp/sync"
config.vm.rsync_crontab_entry_file = "/tmp/crontab-entry" config.vm.sync_crontab_entry_file = "/tmp/crontab-entry"
config.package.name = 'vagrant' config.package.name = 'vagrant'
config.package.extension = '.box' config.package.extension = '.box'

View File

@ -5,7 +5,7 @@ module Vagrant
def shared_folders def shared_folders
@runner.env.config.vm.shared_folders.inject([]) do |acc, data| @runner.env.config.vm.shared_folders.inject([]) do |acc, data|
name, value = data name, value = data
acc << [name, File.expand_path(value[:hostpath], @runner.env.root_path), value[:guestpath], value[:rsyncpath]].compact acc << [name, File.expand_path(value[:hostpath], @runner.env.root_path), value[:guestpath], value[:syncpath]].compact
end end
end end
@ -18,13 +18,13 @@ module Vagrant
logger.info "Mounting shared folders..." logger.info "Mounting shared folders..."
@runner.ssh.execute do |ssh| @runner.ssh.execute do |ssh|
@runner.system.prepare_rsync(ssh) if @runner.env.config.vm.rsync_required @runner.system.prepare_sync(ssh) if @runner.env.config.vm.sync_required
shared_folders.each do |name, hostpath, guestpath, rsyncpath| shared_folders.each do |name, hostpath, guestpath, syncpath|
logger.info "-- #{name}: #{rsyncpath ? guestpath + " -rsync-> " + rsyncpath : guestpath}" logger.info "-- #{name}: #{syncpath ? guestpath + " -sync-> " + syncpath : guestpath}"
@runner.system.mount_shared_folder(ssh, name, guestpath) @runner.system.mount_shared_folder(ssh, name, guestpath)
if rsyncpath if syncpath
@runner.system.create_rsync(ssh, :rsyncpath => rsyncpath, :guestpath => guestpath) @runner.system.create_sync(ssh, :syncpath => syncpath, :guestpath => guestpath)
end end
end end
end end

View File

@ -85,10 +85,10 @@ module Vagrant
attr_accessor :box_ovf attr_accessor :box_ovf
attr_accessor :base_mac attr_accessor :base_mac
attr_accessor :boot_mode attr_accessor :boot_mode
attr_accessor :rsync_opts attr_accessor :sync_opts
attr_accessor :rsync_script attr_accessor :sync_script
attr_accessor :rsync_crontab_entry_file attr_accessor :sync_crontab_entry_file
attr_reader :rsync_required attr_reader :sync_required
attr_reader :forwarded_ports attr_reader :forwarded_ports
attr_reader :shared_folders attr_reader :shared_folders
attr_reader :network_options attr_reader :network_options
@ -129,15 +129,15 @@ module Vagrant
end end
def share_folder(name, guestpath, hostpath = nil, opts = {}) def share_folder(name, guestpath, hostpath = nil, opts = {})
guestpath, opts[:rsync] = shift(guestpath, opts[:rsync]) guestpath, opts[:sync] = shift(guestpath, opts[:sync])
# TODO if both are nil the exception information will be unusable # TODO if both are nil the exception information will be unusable
if opts[:rsync] == guestpath if opts[:sync] == guestpath
raise Exception.new("The rsync directory #{opts[:rsync]} is identical to the shifted shared folder mount point #{guestpath}") raise Exception.new("The sync directory #{opts[:sync]} is identical to the shifted shared folder mount point #{guestpath}")
end end
@shared_folders[name] = { @shared_folders[name] = {
:rsyncpath => opts[:rsync], :syncpath => opts[:sync],
:guestpath => guestpath, :guestpath => guestpath,
:hostpath => hostpath :hostpath => hostpath
} }
@ -186,12 +186,12 @@ module Vagrant
defined_vms[name.to_sym].push_proc(&block) defined_vms[name.to_sym].push_proc(&block)
end end
def shift(orig, rsync) def shift(orig, sync)
if rsync if sync
@rsync_required = true @sync_required = true
[orig + '-rsync', rsync == true ? orig : rsync] [orig + '-sync', sync == true ? orig : sync]
else else
[orig, rsync] [orig, sync]
end end
end end
end end

View File

@ -52,21 +52,21 @@ module Vagrant
chown(ssh, guestpath) chown(ssh, guestpath)
end end
def create_rsync(ssh, opts) def create_sync(ssh, opts)
crontab_entry = render_crontab_entry(opts.merge(:rsyncopts => config.vm.rsync_opts, crontab_entry = render_crontab_entry(opts.merge(:syncopts => config.vm.sync_opts,
:scriptname => config.vm.rsync_script)) :scriptname => config.vm.sync_script))
ssh.exec!("sudo mkdir -p #{opts[:rsyncpath]}") ssh.exec!("sudo mkdir -p #{opts[:syncpath]}")
chown(ssh, opts[:rsyncpath]) chown(ssh, opts[:syncpath])
ssh.exec!("sudo echo \"#{crontab_entry}\" >> #{config.vm.rsync_crontab_entry_file}") ssh.exec!("sudo echo \"#{crontab_entry}\" >> #{config.vm.sync_crontab_entry_file}")
ssh.exec!("crontab #{config.vm.rsync_crontab_entry_file}") ssh.exec!("crontab #{config.vm.sync_crontab_entry_file}")
end end
def prepare_rsync(ssh) def prepare_sync(ssh)
logger.info "Preparing system for rsync..." logger.info "Preparing system for sync..."
vm.ssh.upload!(StringIO.new(render_rsync), config.vm.rsync_script) vm.ssh.upload!(StringIO.new(render_sync), config.vm.sync_script)
ssh.exec!("sudo chmod +x #{config.vm.rsync_script}") ssh.exec!("sudo chmod +x #{config.vm.sync_script}")
ssh.exec!("sudo rm #{config.vm.rsync_crontab_entry_file}", :error_check => false) ssh.exec!("sudo rm #{config.vm.sync_crontab_entry_file}", :error_check => false)
end end
def prepare_host_only_network def prepare_host_only_network
@ -125,8 +125,8 @@ module Vagrant
vm.env.config vm.env.config
end end
def render_rsync def render_sync
TemplateRenderer.render('rsync') TemplateRenderer.render('sync')
end end
def render_crontab_entry(opts) def render_crontab_entry(opts)

View File

@ -1 +1 @@
* * * * * <%= scriptname %> '<%= rsyncopts %>' '<%= guestpath %>/' '<%= rsyncpath %>/' * * * * * <%= scriptname %> '<%= syncopts %>' '<%= guestpath %>' '<%= syncpath %>' '-prefer <%= guestpath %>'

View File

@ -3,11 +3,11 @@ TIMESTART=`date +%s`
while [ 1 ] while [ 1 ]
do do
echo 'Syncing...' echo 'Syncing...'
rsync $1 $2 $3 unison $1 $2 $3 $4
TIME=$((`date +%s`-$TIMESTART)) TIME=$((`date +%s`-$TIMESTART))
echo $TIME echo $TIME
if [ $TIME -ge 50 ] if [ $TIME -ge 50 ]
then then
break break
fi fi
sleep 1 sleep 1

View File

@ -42,8 +42,8 @@ class Test::Unit::TestCase
config.vm.shared_folder_uid = nil config.vm.shared_folder_uid = nil
config.vm.shared_folder_gid = nil config.vm.shared_folder_gid = nil
config.vm.system = :linux config.vm.system = :linux
config.vm.rsync_script = "/foo" config.vm.sync_script = "/foo"
config.vm.rsync_crontab_entry_file = "/tmp/foo" config.vm.sync_crontab_entry_file = "/tmp/foo"
config.vm.share_folder("v-root", "/vagrant", ".") config.vm.share_folder("v-root", "/vagrant", ".")
config.package.name = 'vagrant' config.package.name = 'vagrant'

View File

@ -47,11 +47,11 @@ class SharedFoldersActionTest < Test::Unit::TestCase
assert_equal result, @action.shared_folders assert_equal result, @action.shared_folders
end end
context "with rsync" do context "with sync" do
should "append the rsync value to the other config values" do should "append the sync value to the other config values" do
mock_env_shared_folders(:rsync => true) mock_env_shared_folders(:sync => true)
assert_equal [["foo", "baz", "bar-rsync", "bar"]], @action.shared_folders assert_equal [["foo", "baz", "bar-sync", "bar"]], @action.shared_folders
end end
end end
@ -123,10 +123,10 @@ class SharedFoldersActionTest < Test::Unit::TestCase
@action.after_boot @action.after_boot
end end
should "execute the necessary rysnc commands for each rsync folder" do should "execute the necessary rysnc commands for each sync folder" do
@folders.map { |f| f << 'rsync' } @folders.map { |f| f << 'sync' }
@folders.each do |name, hostpath, guestpath, rsyncd| @folders.each do |name, hostpath, guestpath, syncd|
@runner.system.expects(:create_rsync).with(@ssh, :rsyncpath => rsyncd, :guestpath => guestpath) @runner.system.expects(:create_sync).with(@ssh, :syncpath => syncd, :guestpath => guestpath)
end end
@runner.ssh.expects(:execute).yields(@ssh) @runner.ssh.expects(:execute).yields(@ssh)
@ -134,9 +134,9 @@ class SharedFoldersActionTest < Test::Unit::TestCase
end end
end end
context "with rsyncd folders" do context "with syncd folders" do
# TODO prevented by odd configuration swapping when stubbing ssh.execute # TODO prevented by odd configuration swapping when stubbing ssh.execute
should "prepare the system for rsync if necessary" do should "prepare the system for sync if necessary" do
end end
end end
end end

View File

@ -262,32 +262,32 @@ class ConfigTest < Test::Unit::TestCase
end end
end end
context "rsyncd folders" do context "syncd folders" do
should "set the rsyncpath to nil by default" do should "set the syncpath to nil by default" do
share_with_opts share_with_opts
assert !@config.shared_folders['foo'][:rsyncpath] assert !@config.shared_folders['foo'][:syncpath]
end end
should "append rsync to directory name when boolean" do should "append sync to directory name when boolean" do
share_with_opts(:rsync => true) share_with_opts(:sync => true)
assert_equal @config.shared_folders['foo'][:rsyncpath], 'foo-dir' assert_equal @config.shared_folders['foo'][:syncpath], 'foo-dir'
assert_equal @config.shared_folders['foo'][:guestpath], 'foo-dir-rsync' assert_equal @config.shared_folders['foo'][:guestpath], 'foo-dir-sync'
end end
should "use the specified rsync directory" do should "use the specified sync directory" do
share_with_opts(:rsync => 'bar-baz') share_with_opts(:sync => 'bar-baz')
assert_equal @config.shared_folders['foo'][:rsyncpath], 'bar-baz' assert_equal @config.shared_folders['foo'][:syncpath], 'bar-baz'
end end
should "raise an exception an exception if the guestpath and rsyncpath are the same" do should "raise an exception an exception if the guestpath and syncpath are the same" do
assert_raise Exception do assert_raise Exception do
share_with_opts(:rsync => 'foo-dir-rsync') share_with_opts(:sync => 'foo-dir-sync')
end end
end end
should "set the rsync required flag to true" do should "set the sync required flag to true" do
share_with_opts(:rsync => true) share_with_opts(:sync => true)
assert @config.rsync_required assert @config.sync_required
end end
def share_with_opts(opts={}) def share_with_opts(opts={})

View File

@ -43,59 +43,59 @@ class LinuxSystemTest < Test::Unit::TestCase
end end
end end
context "preparing rsync" do context "preparing sync" do
setup do setup do
@ssh.stubs(:exec!) @ssh.stubs(:exec!)
@vm.stubs(:ssh).returns(@ssh) @vm.stubs(:ssh).returns(@ssh)
@vm.ssh.stubs(:upload!) @vm.ssh.stubs(:upload!)
end end
should "upload the rsync template" do should "upload the sync template" do
@vm.ssh.expects(:upload!).with do |string_io, guest_path| @vm.ssh.expects(:upload!).with do |string_io, guest_path|
string_io.string =~ /#!\/bin\/sh/ && guest_path == @mock_env.config.vm.rsync_script string_io.string =~ /#!\/bin\/sh/ && guest_path == @mock_env.config.vm.sync_script
end end
@instance.prepare_rsync(@ssh) @instance.prepare_sync(@ssh)
end end
should "remove old crontab entries file" do should "remove old crontab entries file" do
@ssh.expects(:exec!).with("sudo rm #{@mock_env.config.vm.rsync_crontab_entry_file}", :error_check => false) @ssh.expects(:exec!).with("sudo rm #{@mock_env.config.vm.sync_crontab_entry_file}", :error_check => false)
@instance.prepare_rsync(@ssh) @instance.prepare_sync(@ssh)
end end
should "prepare the rsync template for execution" do should "prepare the sync template for execution" do
@ssh.expects(:exec!).with("sudo chmod +x #{@mock_env.config.vm.rsync_script}") @ssh.expects(:exec!).with("sudo chmod +x #{@mock_env.config.vm.sync_script}")
@instance.prepare_rsync(@ssh) @instance.prepare_sync(@ssh)
end end
end end
context "setting up an rsync folder" do context "setting up an sync folder" do
setup do setup do
@ssh.stubs(:exec!) @ssh.stubs(:exec!)
end end
should "create the new rysnc destination directory" do should "create the new rysnc destination directory" do
rsync_path = 'foo' sync_path = 'foo'
@ssh.expects(:exec!).with("sudo mkdir -p #{rsync_path}") @ssh.expects(:exec!).with("sudo mkdir -p #{sync_path}")
@instance.create_rsync(@ssh, :rsyncpath => "foo") @instance.create_sync(@ssh, :syncpath => "foo")
end end
should "add an entry to the crontab file" do should "add an entry to the crontab file" do
@instance.expects(:render_crontab_entry).returns('foo') @instance.expects(:render_crontab_entry).returns('foo')
@ssh.expects(:exec!).with do |cmd| @ssh.expects(:exec!).with do |cmd|
cmd =~ /echo/ && cmd =~ /foo/ && cmd =~ /#{@mock_env.config.vm.rsync_crontab_entry_file}/ cmd =~ /echo/ && cmd =~ /foo/ && cmd =~ /#{@mock_env.config.vm.sync_crontab_entry_file}/
end end
@instance.create_rsync(@ssh, {}) @instance.create_sync(@ssh, {})
end end
should "use the crontab entry file to define vagrant users cron entries" do should "use the crontab entry file to define vagrant users cron entries" do
@ssh.expects(:exec!).with("crontab #{@mock_env.config.vm.rsync_crontab_entry_file}") @ssh.expects(:exec!).with("crontab #{@mock_env.config.vm.sync_crontab_entry_file}")
@instance.create_rsync(@ssh, {}) @instance.create_sync(@ssh, {})
end end
should "chown the rsync directory" do should "chown the sync directory" do
@instance.expects(:chown).with(@ssh, "foo") @instance.expects(:chown).with(@ssh, "foo")
@instance.create_rsync(@ssh, :rsyncpath => "foo") @instance.create_sync(@ssh, :syncpath => "foo")
end end
should "return provide a formatted crontab entry that runs every minute" do should "return provide a formatted crontab entry that runs every minute" do

View File

@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Mitchell Hashimoto", "John Bender"] s.authors = ["Mitchell Hashimoto", "John Bender"]
s.date = %q{2010-06-03} s.date = %q{2010-06-05}
s.default_executable = %q{vagrant} s.default_executable = %q{vagrant}
s.description = %q{Vagrant is a tool for building and distributing virtualized development environments.} s.description = %q{Vagrant is a tool for building and distributing virtualized development environments.}
s.email = ["mitchell.hashimoto@gmail.com", "john.m.bender@gmail.com"] s.email = ["mitchell.hashimoto@gmail.com", "john.m.bender@gmail.com"]
@ -109,9 +109,9 @@ Gem::Specification.new do |s|
"templates/crontab_entry.erb", "templates/crontab_entry.erb",
"templates/network_entry.erb", "templates/network_entry.erb",
"templates/package_Vagrantfile.erb", "templates/package_Vagrantfile.erb",
"templates/rsync.erb",
"templates/ssh_config.erb", "templates/ssh_config.erb",
"templates/strings.yml", "templates/strings.yml",
"templates/sync.erb",
"test/test_helper.rb", "test/test_helper.rb",
"test/vagrant/actions/base_test.rb", "test/vagrant/actions/base_test.rb",
"test/vagrant/actions/box/add_test.rb", "test/vagrant/actions/box/add_test.rb",
@ -189,75 +189,75 @@ Gem::Specification.new do |s|
s.rubygems_version = %q{1.3.6} s.rubygems_version = %q{1.3.6}
s.summary = %q{Vagrant is a tool for building and distributing virtualized development environments.} s.summary = %q{Vagrant is a tool for building and distributing virtualized development environments.}
s.test_files = [ s.test_files = [
"test/test_helper.rb", "test/vagrant/util_test.rb",
"test/vagrant/vm_test.rb",
"test/vagrant/command_test.rb",
"test/vagrant/environment_test.rb",
"test/vagrant/util_test.rb",
"test/vagrant/box_test.rb", "test/vagrant/box_test.rb",
"test/vagrant/busy_test.rb",
"test/vagrant/provisioners/base_test.rb",
"test/vagrant/provisioners/chef_test.rb",
"test/vagrant/provisioners/chef_server_test.rb",
"test/vagrant/provisioners/chef_solo_test.rb",
"test/vagrant/systems/linux_test.rb",
"test/vagrant/config_test.rb",
"test/vagrant/actions/base_test.rb",
"test/vagrant/actions/runner_test.rb",
"test/vagrant/actions/box/verify_test.rb",
"test/vagrant/actions/box/destroy_test.rb",
"test/vagrant/actions/box/add_test.rb",
"test/vagrant/actions/box/unpackage_test.rb",
"test/vagrant/actions/box/download_test.rb",
"test/vagrant/actions/collection_test.rb",
"test/vagrant/actions/vm/reload_test.rb",
"test/vagrant/actions/vm/suspend_test.rb",
"test/vagrant/actions/vm/boot_test.rb",
"test/vagrant/actions/vm/package_test.rb",
"test/vagrant/actions/vm/down_test.rb",
"test/vagrant/actions/vm/shared_folders_test.rb",
"test/vagrant/actions/vm/destroy_test.rb",
"test/vagrant/actions/vm/halt_test.rb",
"test/vagrant/actions/vm/import_test.rb",
"test/vagrant/actions/vm/customize_test.rb",
"test/vagrant/actions/vm/start_test.rb",
"test/vagrant/actions/vm/network_test.rb",
"test/vagrant/actions/vm/move_hard_drive_test.rb",
"test/vagrant/actions/vm/up_test.rb",
"test/vagrant/actions/vm/export_test.rb",
"test/vagrant/actions/vm/provision_test.rb",
"test/vagrant/actions/vm/resume_test.rb",
"test/vagrant/actions/vm/forward_ports_test.rb",
"test/vagrant/active_list_test.rb",
"test/vagrant/commands/base_test.rb",
"test/vagrant/commands/reload_test.rb",
"test/vagrant/commands/ssh_config_test.rb",
"test/vagrant/commands/suspend_test.rb",
"test/vagrant/commands/package_test.rb",
"test/vagrant/commands/status_test.rb",
"test/vagrant/commands/init_test.rb",
"test/vagrant/commands/destroy_test.rb",
"test/vagrant/commands/halt_test.rb",
"test/vagrant/commands/box/remove_test.rb",
"test/vagrant/commands/box/add_test.rb",
"test/vagrant/commands/box/list_test.rb",
"test/vagrant/commands/up_test.rb",
"test/vagrant/commands/provision_test.rb",
"test/vagrant/commands/resume_test.rb",
"test/vagrant/commands/ssh_test.rb",
"test/vagrant/resource_logger_test.rb", "test/vagrant/resource_logger_test.rb",
"test/vagrant/ssh_test.rb",
"test/vagrant/environment_test.rb",
"test/vagrant/provisioners/base_test.rb",
"test/vagrant/provisioners/chef_solo_test.rb",
"test/vagrant/provisioners/chef_server_test.rb",
"test/vagrant/provisioners/chef_test.rb",
"test/vagrant/commands/ssh_test.rb",
"test/vagrant/commands/destroy_test.rb",
"test/vagrant/commands/resume_test.rb",
"test/vagrant/commands/halt_test.rb",
"test/vagrant/commands/provision_test.rb",
"test/vagrant/commands/status_test.rb",
"test/vagrant/commands/base_test.rb",
"test/vagrant/commands/up_test.rb",
"test/vagrant/commands/reload_test.rb",
"test/vagrant/commands/package_test.rb",
"test/vagrant/commands/init_test.rb",
"test/vagrant/commands/ssh_config_test.rb",
"test/vagrant/commands/box/list_test.rb",
"test/vagrant/commands/box/add_test.rb",
"test/vagrant/commands/box/remove_test.rb",
"test/vagrant/commands/suspend_test.rb",
"test/vagrant/config_test.rb",
"test/vagrant/vm_test.rb",
"test/vagrant/downloaders/base_test.rb", "test/vagrant/downloaders/base_test.rb",
"test/vagrant/downloaders/file_test.rb",
"test/vagrant/downloaders/http_test.rb", "test/vagrant/downloaders/http_test.rb",
"test/vagrant/util/stacked_proc_runner_test.rb", "test/vagrant/downloaders/file_test.rb",
"test/vagrant/command_test.rb",
"test/vagrant/active_list_test.rb",
"test/vagrant/busy_test.rb",
"test/vagrant/systems/linux_test.rb",
"test/vagrant/ssh_session_test.rb",
"test/vagrant/util/output_helper_test.rb", "test/vagrant/util/output_helper_test.rb",
"test/vagrant/util/plain_logger_test.rb",
"test/vagrant/util/stacked_proc_runner_test.rb",
"test/vagrant/util/error_helper_test.rb",
"test/vagrant/util/platform_test.rb",
"test/vagrant/util/template_renderer_test.rb", "test/vagrant/util/template_renderer_test.rb",
"test/vagrant/util/translator_test.rb", "test/vagrant/util/translator_test.rb",
"test/vagrant/util/platform_test.rb", "test/vagrant/actions/vm/start_test.rb",
"test/vagrant/util/error_helper_test.rb", "test/vagrant/actions/vm/destroy_test.rb",
"test/vagrant/util/plain_logger_test.rb", "test/vagrant/actions/vm/customize_test.rb",
"test/vagrant/ssh_session_test.rb", "test/vagrant/actions/vm/resume_test.rb",
"test/vagrant/ssh_test.rb" "test/vagrant/actions/vm/halt_test.rb",
"test/vagrant/actions/vm/provision_test.rb",
"test/vagrant/actions/vm/import_test.rb",
"test/vagrant/actions/vm/network_test.rb",
"test/vagrant/actions/vm/up_test.rb",
"test/vagrant/actions/vm/boot_test.rb",
"test/vagrant/actions/vm/reload_test.rb",
"test/vagrant/actions/vm/shared_folders_test.rb",
"test/vagrant/actions/vm/package_test.rb",
"test/vagrant/actions/vm/move_hard_drive_test.rb",
"test/vagrant/actions/vm/forward_ports_test.rb",
"test/vagrant/actions/vm/suspend_test.rb",
"test/vagrant/actions/vm/down_test.rb",
"test/vagrant/actions/vm/export_test.rb",
"test/vagrant/actions/base_test.rb",
"test/vagrant/actions/runner_test.rb",
"test/vagrant/actions/collection_test.rb",
"test/vagrant/actions/box/destroy_test.rb",
"test/vagrant/actions/box/download_test.rb",
"test/vagrant/actions/box/verify_test.rb",
"test/vagrant/actions/box/unpackage_test.rb",
"test/vagrant/actions/box/add_test.rb",
"test/test_helper.rb"
] ]
if s.respond_to? :specification_version then if s.respond_to? :specification_version then