Futher work to the NFS middleware
This commit is contained in:
parent
1e92f0d58f
commit
7430cf54ff
|
@ -14,6 +14,8 @@ module Vagrant
|
|||
# folder.
|
||||
#
|
||||
class NFS
|
||||
attr_reader :folders
|
||||
|
||||
def initialize(app,env)
|
||||
@app = app
|
||||
@env = env
|
||||
|
@ -21,6 +23,39 @@ module Vagrant
|
|||
verify_host
|
||||
end
|
||||
|
||||
def call(env)
|
||||
@env = env
|
||||
|
||||
extract_folders
|
||||
export_folders
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
|
||||
# Removes the NFS enabled shared folders from the configuration,
|
||||
# so they will no longer be mounted by the actual shared folder
|
||||
# task.
|
||||
def extract_folders
|
||||
# Load the NFS enabled shared folders
|
||||
@folders = @env["config"].vm.shared_folders.inject({}) do |acc, data|
|
||||
key, opts = data
|
||||
acc[key] = opts if opts[:nfs]
|
||||
acc
|
||||
end
|
||||
|
||||
# Delete them from the original configuration so they aren't
|
||||
# mounted by the ShareFolders middleware
|
||||
@folders.each do |key, opts|
|
||||
@env["config"].vm.shared_folders.delete(key)
|
||||
end
|
||||
end
|
||||
|
||||
# Uses the host class to export the folders via NFS. This typically
|
||||
# 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
|
||||
end
|
||||
|
||||
# Verifies that the host is set and supports NFS.
|
||||
def verify_host
|
||||
return @env.error!(:nfs_host_required) if @env["host"].nil?
|
||||
|
|
|
@ -21,6 +21,34 @@ class NFSVMActionTest < Test::Unit::TestCase
|
|||
@instance = @klass.new(@app, @env)
|
||||
end
|
||||
|
||||
context "calling" do
|
||||
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.call(@env)
|
||||
end
|
||||
end
|
||||
|
||||
context "extracting folders" do
|
||||
setup do
|
||||
@env.env.config.vm.share_folder("v-foo", "/foo", ".", :nfs => true)
|
||||
@env.env.config.vm.share_folder("v-bar", "/bar", ".", :nfs => true)
|
||||
end
|
||||
|
||||
should "extract the NFS enabled folders" do
|
||||
@instance.extract_folders
|
||||
assert_equal 2, @instance.folders.length
|
||||
end
|
||||
|
||||
should "remove the folders from the original config" do
|
||||
@instance.extract_folders
|
||||
assert_equal 1, @env["config"].vm.shared_folders.length
|
||||
assert @env["config"].vm.shared_folders.has_key?("v-root")
|
||||
end
|
||||
end
|
||||
|
||||
context "verifying host" do
|
||||
should "error environment if host is nil" do
|
||||
@env.env.stubs(:host).returns(nil)
|
||||
|
|
Loading…
Reference in New Issue