From 9f4950375e34729a335d3192b5cde601743618ed Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 12 Jul 2010 22:10:17 -0700 Subject: [PATCH] Host NFS export --- lib/vagrant/hosts/bsd.rb | 16 +++++++++++++++ templates/nfs/exports.erb | 3 +++ test/vagrant/hosts/bsd_test.rb | 36 ++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 templates/nfs/exports.erb create mode 100644 test/vagrant/hosts/bsd_test.rb diff --git a/lib/vagrant/hosts/bsd.rb b/lib/vagrant/hosts/bsd.rb index 5e5260bd1..d3c7e2825 100644 --- a/lib/vagrant/hosts/bsd.rb +++ b/lib/vagrant/hosts/bsd.rb @@ -2,10 +2,26 @@ module Vagrant module Hosts # Represents a BSD host, such as FreeBSD and Darwin (Mac OS X). class BSD < Base + include Util + def nfs? # TODO: verify it exists true end + + def nfs_export(ip, folders) + output = TemplateRenderer.render('nfs/exports', + :uuid => env.vm.uuid, + :ip => ip, + :folders => folders) + + env.logger.info "Preparing to edit /etc/exports. Administrator priveleges will be required..." + output.split("\n").each do |line| + # This should only ask for administrative permission once, even + # though its executed in multiple subshells. + system(%Q[sudo su root -c "echo '#{line}' >> /etc/exports"]) + end + end end end end diff --git a/templates/nfs/exports.erb b/templates/nfs/exports.erb new file mode 100644 index 000000000..2fc418220 --- /dev/null +++ b/templates/nfs/exports.erb @@ -0,0 +1,3 @@ +# VAGRANT-BEGIN: <%= uuid %> +<%= folders.inspect %> +# VAGRANT-END: <%= uuid %> \ No newline at end of file diff --git a/test/vagrant/hosts/bsd_test.rb b/test/vagrant/hosts/bsd_test.rb new file mode 100644 index 000000000..36e624fa0 --- /dev/null +++ b/test/vagrant/hosts/bsd_test.rb @@ -0,0 +1,36 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class BSDHostTest < Test::Unit::TestCase + setup do + @klass = Vagrant::Hosts::BSD + @env = mock_environment + @env.stubs(:vm).returns(Vagrant::VM.new(:env => @env)) + @instance = @klass.new(@env) + end + + context "supporting nfs check" do + should "support NFS" do + assert @instance.nfs? + end + end + + context "nfs export" do + setup do + @instance.stubs(:system) + + @ip = "foo" + @folders = "bar" + end + + should "output the lines of the rendered template" do + output = %W[foo bar baz].join("\n") + Vagrant::Util::TemplateRenderer.expects(:render).with("nfs/exports", + :uuid => @env.vm.uuid, + :ip => @ip, + :folders => @folders).returns(output) + + @instance.expects(:system).times(output.split("\n").length) + @instance.nfs_export(@ip, @folders) + end + end +end