From c7bbfcc5a17ed36fc0a276ba04d5b5a719b598db Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 20 Jun 2010 02:16:32 -0700 Subject: [PATCH] `create_unison` method implemented on the system --- lib/vagrant/systems/linux.rb | 30 ++++++++------------ templates/unison/crontab_entry.erb | 2 +- test/vagrant/systems/linux_test.rb | 45 ++++++++++-------------------- 3 files changed, 26 insertions(+), 51 deletions(-) diff --git a/lib/vagrant/systems/linux.rb b/lib/vagrant/systems/linux.rb index 011676d6c..6552f7f68 100644 --- a/lib/vagrant/systems/linux.rb +++ b/lib/vagrant/systems/linux.rb @@ -49,19 +49,9 @@ module Vagrant def mount_shared_folder(ssh, name, guestpath) ssh.exec!("sudo mkdir -p #{guestpath}") mount_folder(ssh, name, guestpath) - chown(ssh, guestpath) + ssh.exec!("sudo chown #{config.ssh.username} #{guestpath}") end - # def create_sync(ssh, opts) - # crontab_entry = render_crontab_entry(opts.merge(:syncopts => config.vm.sync_opts, - # :scriptname => config.vm.sync_script)) - - # ssh.exec!("sudo mkdir -p #{opts[:syncpath]}") - # chown(ssh, opts[:syncpath]) - # ssh.exec!("sudo echo \"#{crontab_entry}\" >> #{config.vm.sync_crontab_entry_file}") - # ssh.exec!("crontab #{config.vm.sync_crontab_entry_file}") - # end - def prepare_unison(ssh) logger.info "Preparing system for unison sync..." vm.ssh.upload!(StringIO.new(TemplateRenderer.render('/unison/script')), config.unison.script) @@ -69,6 +59,16 @@ module Vagrant ssh.exec!("sudo rm #{config.unison.crontab_entry_file}", :error_check => false) end + def create_unison(ssh, opts) + crontab_entry = TemplateRenderer.render('/unison/crontab_entry', + :from => opts[:original][:guestpath], + :to => opts[:guestpath], + :options => config.unison.options, + :script => config.unison.script) + ssh.exec!("sudo echo \"#{crontab_entry}\" >> #{config.unison.crontab_entry_file}") + ssh.exec!("crontab #{config.unison.crontab_entry_file}") + end + def prepare_host_only_network # Remove any previous host only network additions to the # interface file. @@ -117,17 +117,9 @@ module Vagrant end end - def chown(ssh, dir) - ssh.exec!("sudo chown #{config.ssh.username} #{dir}") - end - def config vm.env.config end - - def render_crontab_entry(opts) - TemplateRenderer.render('crontab_entry', opts) - end end end end diff --git a/templates/unison/crontab_entry.erb b/templates/unison/crontab_entry.erb index c06032358..462225f2a 100644 --- a/templates/unison/crontab_entry.erb +++ b/templates/unison/crontab_entry.erb @@ -1 +1 @@ -* * * * * <%= scriptname %> '<%= from %>' '<%= to %>' '<%= options %>' +* * * * * <%= script %> '<%= from %>' '<%= to %>' '<%= options %>' diff --git a/test/vagrant/systems/linux_test.rb b/test/vagrant/systems/linux_test.rb index 219ce33fb..cc6523915 100644 --- a/test/vagrant/systems/linux_test.rb +++ b/test/vagrant/systems/linux_test.rb @@ -70,39 +70,22 @@ class LinuxSystemTest < Test::Unit::TestCase end end - # context "setting up an sync folder" do - # setup do - # @ssh.stubs(:exec!) - # end + context "creating unison entry" do + setup do + @ssh.stubs(:exec!) + @options = { + :guestpath => "foo", + :original => { :guestpath => "bar" } + } + end - # should "create the new rysnc destination directory" do - # sync_path = 'foo' - # @ssh.expects(:exec!).with("sudo mkdir -p #{sync_path}") - # @instance.create_sync(@ssh, :syncpath => "foo") - # end + # TODO Test crontab entry - # should "add an entry to the crontab file" do - # @instance.expects(:render_crontab_entry).returns('foo') - # @ssh.expects(:exec!).with do |cmd| - # cmd =~ /echo/ && cmd =~ /foo/ && cmd =~ /#{@mock_env.config.vm.sync_crontab_entry_file}/ - # end - # @instance.create_sync(@ssh, {}) - # end - - # should "use the crontab entry file to define vagrant users cron entries" do - # @ssh.expects(:exec!).with("crontab #{@mock_env.config.vm.sync_crontab_entry_file}") - # @instance.create_sync(@ssh, {}) - # end - - # should "chown the sync directory" do - # @instance.expects(:chown).with(@ssh, "foo") - # @instance.create_sync(@ssh, :syncpath => "foo") - # end - - # should "return provide a formatted crontab entry that runs every minute" do - # assert @instance.render_crontab_entry({}).include?("* * * * *") - # end - # end + should "enable the crontab file" do + @ssh.expects(:exec!).with("crontab #{@mock_env.config.unison.crontab_entry_file}") + @instance.create_unison(@ssh, @options) + end + end #------------------------------------------------------------------- # "Private" methods tests