NFS middleware interface complete. Implemention on host not yet done.

This commit is contained in:
Mitchell Hashimoto 2010-07-11 10:58:17 -07:00
parent 7430cf54ff
commit 30e8b3b8ce
3 changed files with 84 additions and 2 deletions

View File

@ -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.

View File

@ -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

View File

@ -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)