diff --git a/lib/vagrant/action/vm/nfs.rb b/lib/vagrant/action/vm/nfs.rb new file mode 100644 index 000000000..c7f0892c1 --- /dev/null +++ b/lib/vagrant/action/vm/nfs.rb @@ -0,0 +1,32 @@ +module Vagrant + class Action + module VM + # Enables NFS based shared folders. `nfsd` must already be installed + # on the host machine, and NFS client must already be installed on + # the guest machine. + # + # This is a two part process: + # + # 1. Adds an entry to `/etc/exports` on the host machine using + # the host class to export the proper folder to the proper + # machine. + # 2. After boot, runs `mount` on the guest to mount the shared + # folder. + # + class NFS + def initialize(app,env) + @app = app + @env = env + + verify_host + end + + # Verifies that the host is set and supports NFS. + def verify_host + return @env.error!(:nfs_host_required) if @env["host"].nil? + return @env.error!(:nfs_not_supported) if !@env["host"].nfs? + end + end + end + end +end diff --git a/lib/vagrant/hosts/base.rb b/lib/vagrant/hosts/base.rb index 554de307a..02c46b758 100644 --- a/lib/vagrant/hosts/base.rb +++ b/lib/vagrant/hosts/base.rb @@ -50,6 +50,15 @@ module Vagrant def initialize(env) @env = env end + + # Returns true of false denoting whether or not this host supports + # NFS shared folder setup. This method ideally should verify that + # NFS is installed. + # + # @return [Boolean] + def nfs? + false + end end end end diff --git a/templates/strings.yml b/templates/strings.yml index f2fc149c8..72457406b 100644 --- a/templates/strings.yml +++ b/templates/strings.yml @@ -137,6 +137,14 @@ already be created, but unfortunately this vagrant still appears to have no box! You can setup the environment by setting up your <%= Vagrant::Environment::ROOTFILE_NAME %> and running `vagrant up` +:nfs_host_required: |- + A host class is required for NFS shared folders. By default, these + are auto-detected, but can be overriden with `config.vagrant.host`. + There is currently not host class loaded. +:nfs_not_supported: |- + The host class is reporting that NFS is not supported by this host, + or `nfsd` may not be installed. Please verify that `nfsd` is installed + on your machine, and retry. :network_not_found: |- The specified host network could not be found: <%= name %>. If the name specification is removed, Vagrant will create a new diff --git a/test/vagrant/action/vm/nfs_test.rb b/test/vagrant/action/vm/nfs_test.rb new file mode 100644 index 000000000..e1f87e9a5 --- /dev/null +++ b/test/vagrant/action/vm/nfs_test.rb @@ -0,0 +1,46 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper') + +class NFSVMActionTest < Test::Unit::TestCase + setup do + @klass = Vagrant::Action::VM::NFS + @app, @env = mock_action_data + + @vm = mock("vm") + @env.env.stubs(:host).returns(Vagrant::Hosts::Base.new(@env)) + @env["vm"] = @vm + + @internal_vm = mock("internal") + @vm.stubs(:vm).returns(@internal_vm) + end + + context "with an instance" do + setup do + # Kind of dirty but not sure of a way around this + @klass.send(:alias_method, :verify_host_real, :verify_host) + @klass.any_instance.stubs(:verify_host) + @instance = @klass.new(@app, @env) + end + + context "verifying host" do + should "error environment if host is nil" do + @env.env.stubs(:host).returns(nil) + @instance.verify_host_real + assert @env.error? + assert_equal :nfs_host_required, @env.error.first + end + + should "error environment if host does not support NFS" do + @env.env.host.stubs(:nfs?).returns(false) + @instance.verify_host_real + assert @env.error? + assert_equal :nfs_not_supported, @env.error.first + end + + should "be fine if everything passes" do + @env.env.host.stubs(:nfs?).returns(true) + @instance.verify_host_real + assert !@env.error? + end + end + end +end