From 30e8b3b8ce9f4c0330fa666de3286d927a38c0d4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 11 Jul 2010 10:58:17 -0700 Subject: [PATCH] NFS middleware interface complete. Implemention on host not yet done. --- lib/vagrant/action/vm/nfs.rb | 19 +++++++++- lib/vagrant/hosts/base.rb | 7 ++++ test/vagrant/action/vm/nfs_test.rb | 60 ++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/action/vm/nfs.rb b/lib/vagrant/action/vm/nfs.rb index 91b5c2090..4f3a0b744 100644 --- a/lib/vagrant/action/vm/nfs.rb +++ b/lib/vagrant/action/vm/nfs.rb @@ -14,7 +14,7 @@ module Vagrant # folder. # class NFS - attr_reader :folders + include ExceptionCatcher def initialize(app,env) @app = app @@ -27,9 +27,17 @@ module Vagrant @env = env extract_folders - export_folders + export_folders if !folders.empty? + return if env.error? @app.call(env) + + mount_folders if !folders.empty? && !env.error? + end + + # Returns the folders which are to be synced via NFS. + def folders + @folders ||= {} end # Removes the NFS enabled shared folders from the configuration, @@ -54,6 +62,13 @@ module Vagrant # involves adding a line to `/etc/exports` for this VM, but it is # up to the host class to define the specific behavior. def export_folders + catch_action_exception(@env) do + @env["host"].nfs_export(folders) + end + end + + # Uses the system class to mount the NFS folders. + def mount_folders end # Verifies that the host is set and supports NFS. diff --git a/lib/vagrant/hosts/base.rb b/lib/vagrant/hosts/base.rb index 02c46b758..b153b3c75 100644 --- a/lib/vagrant/hosts/base.rb +++ b/lib/vagrant/hosts/base.rb @@ -59,6 +59,13 @@ module Vagrant def nfs? false end + + # Exports the given hash of folders via NFS. This method will raise + # an {Vagrant::Action::ActionException} if anything goes wrong. + # + # @param [Hash] folders Shared folders to sync. + def nfs_export(folders) + end end end end diff --git a/test/vagrant/action/vm/nfs_test.rb b/test/vagrant/action/vm/nfs_test.rb index 2e43b38db..a37933f10 100644 --- a/test/vagrant/action/vm/nfs_test.rb +++ b/test/vagrant/action/vm/nfs_test.rb @@ -22,11 +22,53 @@ class NFSVMActionTest < Test::Unit::TestCase end context "calling" do + setup do + @instance.stubs(:folders).returns([:a]) + + [:extract_folders, :export_folders, :mount_folders].each do |meth| + @instance.stubs(meth) + end + end + should "call the proper sequence and succeed" do seq = sequence('seq') @instance.expects(:extract_folders).in_sequence(seq) @instance.expects(:export_folders).in_sequence(seq) @app.expects(:call).with(@env).in_sequence(seq) + @instance.expects(:mount_folders).in_sequence(seq) + @instance.call(@env) + end + + should "not export folders if folders is empty" do + @instance.stubs(:folders).returns([]) + + seq = sequence('seq') + @instance.expects(:extract_folders).in_sequence(seq) + @instance.expects(:export_folders).never + @app.expects(:call).with(@env).in_sequence(seq) + @instance.expects(:mount_folders).never + @instance.call(@env) + end + + should "halt chain if environment error occured" do + @env.error!(:foo) + + seq = sequence('seq') + @instance.expects(:extract_folders).in_sequence(seq) + @instance.expects(:export_folders).in_sequence(seq) + @app.expects(:call).never + @instance.call(@env) + end + + should "not mount folders if an error occured" do + @app.expects(:call).with() do + # Use this mark the env as error + @env.error!(:foo) + + true + end + + @instance.expects(:mount_folders).never @instance.call(@env) end end @@ -49,6 +91,24 @@ class NFSVMActionTest < Test::Unit::TestCase end end + context "exporting folders" do + setup do + @instance.stubs(:folders).returns({}) + end + + should "call nfs_export on the host" do + @env["host"].expects(:nfs_export).with(@instance.folders) + @instance.export_folders + end + + should "error the environment if exception is raised" do + @env["host"].expects(:nfs_export).raises(Vagrant::Action::ActionException.new(:foo)) + @instance.export_folders + assert @env.error? + assert_equal :foo, @env.error.first + end + end + context "verifying host" do should "error environment if host is nil" do @env.env.stubs(:host).returns(nil)