Merge branch 'filter_synced_folders' of https://github.com/maxlinc/vagrant into maxlinc-filter_synced_folders

This commit is contained in:
Mitchell Hashimoto 2015-07-09 15:05:52 -06:00
commit cea44847de
3 changed files with 47 additions and 3 deletions

View File

@ -25,6 +25,15 @@ module Vagrant
# Order the plugins by priority. Higher is tried before lower. # Order the plugins by priority. Higher is tried before lower.
ordered = ordered.sort { |a, b| b[0] <=> a[0] } ordered = ordered.sort { |a, b| b[0] <=> a[0] }
allowed_types = machine.config.vm.allowed_synced_folder_types
if allowed_types
ordered = allowed_types.map do |type|
ordered.find do |_, key, impl|
key == type
end
end.compact
end
# Find the proper implementation # Find the proper implementation
ordered.each do |_, key, impl| ordered.each do |_, key, impl|
return key if impl.new.usable?(machine) return key if impl.new.usable?(machine)

View File

@ -14,6 +14,7 @@ module VagrantPlugins
class VMConfig < Vagrant.plugin("2", :config) class VMConfig < Vagrant.plugin("2", :config)
DEFAULT_VM_NAME = :default DEFAULT_VM_NAME = :default
attr_accessor :allowed_synced_folder_types
attr_accessor :base_mac attr_accessor :base_mac
attr_accessor :boot_timeout attr_accessor :boot_timeout
attr_accessor :box attr_accessor :box
@ -39,6 +40,7 @@ module VagrantPlugins
def initialize def initialize
@logger = Log4r::Logger.new("vagrant::config::vm") @logger = Log4r::Logger.new("vagrant::config::vm")
@allowed_synced_folder_types = UNSET_VALUE
@base_mac = UNSET_VALUE @base_mac = UNSET_VALUE
@boot_timeout = UNSET_VALUE @boot_timeout = UNSET_VALUE
@box = UNSET_VALUE @box = UNSET_VALUE
@ -351,6 +353,7 @@ module VagrantPlugins
def finalize! def finalize!
# Defaults # Defaults
@allowed_synced_folder_types = nil if @allowed_synced_folder_types == UNSET_VALUE
@base_mac = nil if @base_mac == UNSET_VALUE @base_mac = nil if @base_mac == UNSET_VALUE
@boot_timeout = 300 if @boot_timeout == UNSET_VALUE @boot_timeout = 300 if @boot_timeout == UNSET_VALUE
@box = nil if @box == UNSET_VALUE @box = nil if @box == UNSET_VALUE
@ -375,6 +378,10 @@ module VagrantPlugins
@usable_port_range = (2200..2250) @usable_port_range = (2200..2250)
end end
if @allowed_synced_folder_types
@allowed_synced_folder_types = Array(@allowed_synced_folder_types).map(&:to_sym)
end
# Make sure that the download checksum is a string and that # Make sure that the download checksum is a string and that
# the type is a symbol # the type is a symbol
@box_download_checksum = "" if !@box_download_checksum @box_download_checksum = "" if !@box_download_checksum

View File

@ -28,19 +28,47 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do
end end
end end
let(:vm_config) { double("machine_vm_config") } let(:vm_config) { double("machine_vm_config", :allowed_synced_folder_types => nil) }
describe "default_synced_folder_type" do describe "default_synced_folder_type" do
it "returns the usable implementation" do it "returns the usable implementation" do
plugins = { plugins = {
"bad" => [impl(false, "bad"), 0], "bad" => [impl(false, "bad"), 0],
"nope" => [impl(true, "nope"), 1], "good" => [impl(true, "good"), 1],
"good" => [impl(true, "good"), 5], "best" => [impl(true, "best"), 5],
}
result = subject.default_synced_folder_type(machine, plugins)
expect(result).to eq("best")
end
it "filters based on allowed_synced_folder_types" do
expect(vm_config).to receive(:allowed_synced_folder_types).and_return(["bad", "good"])
plugins = {
"bad" => [impl(false, "bad"), 0],
"good" => [impl(true, "good"), 1],
"best" => [impl(true, "best"), 5],
} }
result = subject.default_synced_folder_type(machine, plugins) result = subject.default_synced_folder_type(machine, plugins)
expect(result).to eq("good") expect(result).to eq("good")
end end
it "reprioritizes based on allowed_synced_folder_types" do
plugins = {
"bad" => [impl(false, "bad"), 0],
"good" => [impl(true, "good"), 1],
"same" => [impl(true, "same"), 1],
}
expect(vm_config).to receive(:allowed_synced_folder_types).and_return(["good", "same"])
result = subject.default_synced_folder_type(machine, plugins)
expect(result).to eq("good")
expect(vm_config).to receive(:allowed_synced_folder_types).and_return(["same", "good"])
result = subject.default_synced_folder_type(machine, plugins)
expect(result).to eq("same")
end
end end
describe "impl_opts" do describe "impl_opts" do