core: SyncedFolders middleware passes inoptions
This commit is contained in:
parent
079ac12f5d
commit
125584aaf4
|
@ -50,18 +50,18 @@ module Vagrant
|
|||
end
|
||||
|
||||
# Go through each folder and prepare the folders
|
||||
folders.each do |impl, fs|
|
||||
@logger.info("Invoking synced folder prepare for: #{impl}")
|
||||
impl.new.prepare(env[:machine], fs)
|
||||
folders.each do |impl_name, fs|
|
||||
@logger.info("Invoking synced folder prepare for: #{impl_name}")
|
||||
plugins[impl_name.to_sym][0].new.prepare(env[:machine], fs, impl_opts(impl_name, env))
|
||||
end
|
||||
|
||||
# Continue, we need the VM to be booted.
|
||||
@app.call(env)
|
||||
|
||||
# Once booted, setup the folder contents
|
||||
folders.each do |impl, fs|
|
||||
@logger.info("Invoking synced folder enable: #{impl}")
|
||||
impl.new.enable(env[:machine], fs)
|
||||
folders.each do |impl_name, fs|
|
||||
@logger.info("Invoking synced folder enable: #{impl_name}")
|
||||
plugins[impl_name.to_sym][0].new.enable(env[:machine], fs, impl_opts(impl_name, env))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -75,20 +75,34 @@ module Vagrant
|
|||
impl = data[0]
|
||||
priority = data[1]
|
||||
|
||||
ordered << [priority, impl]
|
||||
ordered << [priority, key, impl]
|
||||
end
|
||||
|
||||
# Order the plugins by priority
|
||||
ordered = ordered.sort { |a, b| b[0] <=> a[0] }.map { |p| p[1] }
|
||||
ordered = ordered.sort { |a, b| b[0] <=> a[0] }
|
||||
|
||||
# Find the proper implementation
|
||||
ordered.each do |impl|
|
||||
return impl if impl.new.usable?(machine)
|
||||
ordered.each do |_, key, impl|
|
||||
return key if impl.new.usable?(machine)
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
# This finds the options in the env that are set for a given
|
||||
# synced folder type.
|
||||
def impl_opts(name, env)
|
||||
{}.tap do |result|
|
||||
env.each do |k, v|
|
||||
if k.to_s.start_with?("#{name}_")
|
||||
k = k.dup if !k.is_a?(Symbol)
|
||||
v = v.dup if !v.is_a?(Symbol)
|
||||
result[k] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# This returns the available synced folder implementations. This
|
||||
# is a separate method so that it can be easily stubbed by tests.
|
||||
def plugins
|
||||
|
@ -107,19 +121,15 @@ module Vagrant
|
|||
# Ignore disabled synced folders
|
||||
next if data[:disabled]
|
||||
|
||||
impl = ["", 0]
|
||||
impl = plugins[data[:type].to_sym] if data[:type]
|
||||
impl = ""
|
||||
impl = data[:type].to_sym if data[:type]
|
||||
|
||||
if impl == nil
|
||||
if impl != "" && !plugins[impl]
|
||||
# This should never happen because configuration validation
|
||||
# should catch this case. But we put this here as an assert
|
||||
raise "Internal error. Report this as a bug. Invalid: #{data[:type]}"
|
||||
end
|
||||
|
||||
# The implementation class rather than the priority, since the
|
||||
# array is [class, priority].
|
||||
impl = impl[0]
|
||||
|
||||
# Keep track of this shared folder by the implementation.
|
||||
folders[impl] ||= {}
|
||||
folders[impl][id] = data.dup
|
||||
|
|
|
@ -43,14 +43,19 @@ describe Vagrant::Action::Builtin::SyncedFolders do
|
|||
|
||||
describe "call" do
|
||||
let(:synced_folders) { {} }
|
||||
let(:plugins) { {} }
|
||||
|
||||
before do
|
||||
plugins[:default] = [impl(true, "default"), 10]
|
||||
plugins[:nfs] = [impl(true, "nfs"), 5]
|
||||
|
||||
env[:root_path] = Pathname.new(Dir.mktmpdir)
|
||||
subject.stub(:plugins => plugins)
|
||||
subject.stub(:synced_folders => synced_folders)
|
||||
end
|
||||
|
||||
it "should create on the host if specified" do
|
||||
synced_folders[impl(true, "good")] = {
|
||||
synced_folders["default"] = {
|
||||
"root" => {
|
||||
hostpath: "foo",
|
||||
},
|
||||
|
@ -69,17 +74,19 @@ describe Vagrant::Action::Builtin::SyncedFolders do
|
|||
|
||||
it "should invoke prepare then enable" do
|
||||
order = []
|
||||
sf = Class.new(impl(true, "good")) do
|
||||
define_method(:prepare) do |machine, folders|
|
||||
tracker = Class.new(impl(true, "good")) do
|
||||
define_method(:prepare) do |machine, folders, opts|
|
||||
order << :prepare
|
||||
end
|
||||
|
||||
define_method(:enable) do |machine, folders|
|
||||
define_method(:enable) do |machine, folders, opts|
|
||||
order << :enable
|
||||
end
|
||||
end
|
||||
|
||||
synced_folders[sf] = {
|
||||
plugins[:tracker] = [tracker, 15]
|
||||
|
||||
synced_folders["tracker"] = {
|
||||
"root" => {
|
||||
hostpath: "foo",
|
||||
},
|
||||
|
@ -105,7 +112,22 @@ describe Vagrant::Action::Builtin::SyncedFolders do
|
|||
}
|
||||
|
||||
result = subject.default_synced_folder_type(machine, plugins)
|
||||
result.new.name.should == "good"
|
||||
result.should == "good"
|
||||
end
|
||||
end
|
||||
|
||||
describe "impl_opts" do
|
||||
it "should return only relevant keys" do
|
||||
env = {
|
||||
:foo_bar => "baz",
|
||||
:bar_bar => "nope",
|
||||
:foo_baz => "bar",
|
||||
}
|
||||
|
||||
result = subject.impl_opts("foo", env)
|
||||
result.length.should == 2
|
||||
result[:foo_bar].should == "baz"
|
||||
result[:foo_baz].should == "bar"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -134,8 +156,8 @@ describe Vagrant::Action::Builtin::SyncedFolders do
|
|||
|
||||
result = subject.synced_folders(machine)
|
||||
result.length.should == 2
|
||||
result[plugins[:default][0]].should == { "root" => folders["root"] }
|
||||
result[plugins[:nfs][0]].should == { "nfs" => folders["nfs"] }
|
||||
result[:default].should == { "root" => folders["root"] }
|
||||
result[:nfs].should == { "nfs" => folders["nfs"] }
|
||||
end
|
||||
|
||||
it "should ignore disabled folders" do
|
||||
|
@ -144,7 +166,7 @@ describe Vagrant::Action::Builtin::SyncedFolders do
|
|||
|
||||
result = subject.synced_folders(machine)
|
||||
result.length.should == 1
|
||||
result[plugins[:default][0]].length.should == 1
|
||||
result[:default].length.should == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue