Config loader no longer assumes latest version for procs.
Previously, all procs were assumed to just be the current version. This is certainly not going to be true always so now the version number of the configuration must be explicit if you're assigning a proc to the configuration loader.
This commit is contained in:
parent
b3db82e516
commit
7e19d6849b
|
@ -114,30 +114,42 @@ module Vagrant
|
|||
# the configuration object and are expected to mutate this
|
||||
# configuration object.
|
||||
def procs_for_source(source)
|
||||
# If the source is just a proc, we assume it is for the latest
|
||||
# version of the configuration. This may be an ill assumption,
|
||||
# but it made building the initial version of multi-versioned
|
||||
# configuration easy to support the old sub-VM stuff.
|
||||
return [[@version_order.last, source]] if source.is_a?(Proc)
|
||||
# Convert all pathnames to strings so we just have their path
|
||||
source = source.to_s if source.is_a?(Pathname)
|
||||
|
||||
# Assume all string sources are actually pathnames
|
||||
source = Pathname.new(source) if source.is_a?(String)
|
||||
if source.is_a?(Array)
|
||||
# An array must be formatted as [version, proc], so verify
|
||||
# that and then return it
|
||||
raise ArgumentError, "String source must have format [version, proc]" if source.length != 2
|
||||
|
||||
if source.is_a?(Pathname)
|
||||
@logger.debug("Load procs for pathname: #{source.inspect}")
|
||||
# Return it as an array since we're expected to return an array
|
||||
# of [version, proc] pairs, but an array source only has one.
|
||||
return [source]
|
||||
elsif source.is_a?(String)
|
||||
# Strings are considered paths, so load them
|
||||
return procs_for_path(source)
|
||||
else
|
||||
raise ArgumentError, "Unknown configuration source: #{source.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
# This returns an array of `Proc` objects for the given path source.
|
||||
#
|
||||
# @param [String] path Path to the file which contains the proper
|
||||
# `Vagrant.configure` calls.
|
||||
# @return [Array<Proc>]
|
||||
def procs_for_path(path)
|
||||
@logger.debug("Load procs for pathname: #{path}")
|
||||
|
||||
begin
|
||||
return Config.capture_configures do
|
||||
Kernel.load source
|
||||
Kernel.load path
|
||||
end
|
||||
rescue SyntaxError => e
|
||||
# Report syntax errors in a nice way.
|
||||
raise Errors::VagrantfileSyntaxError, :file => e.message
|
||||
end
|
||||
end
|
||||
|
||||
raise Exception, "Unknown configuration source: #{source.inspect}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -395,7 +395,7 @@ module Vagrant
|
|||
|
||||
if subvm
|
||||
# We have subvm configuration, so set that up as well.
|
||||
config_loader.set(:vm, subvm.proc_stack)
|
||||
config_loader.set(:vm, subvm.config_procs)
|
||||
end
|
||||
|
||||
# We activate plugins here because the files which we're loading
|
||||
|
|
|
@ -11,6 +11,16 @@ module VagrantPlugins
|
|||
def initialize
|
||||
@options = {}
|
||||
end
|
||||
|
||||
# This returns an array of the procs to configure this VM, with
|
||||
# the proper version pre-pended for the configuration loader.
|
||||
#
|
||||
# @return [Array]
|
||||
def config_procs
|
||||
proc_stack.map do |proc|
|
||||
["1", proc]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,9 @@ require "vagrant/registry"
|
|||
describe Vagrant::Config::Loader do
|
||||
include_context "unit"
|
||||
|
||||
# This is the current version of configuration for the tests.
|
||||
let(:current_version) { version_order.last }
|
||||
|
||||
# This is just a dummy implementation of a configuraiton loader which
|
||||
# simply acts on hashes.
|
||||
let(:test_loader) do
|
||||
|
@ -46,7 +49,7 @@ describe Vagrant::Config::Loader do
|
|||
end
|
||||
|
||||
instance.load_order = [:proc]
|
||||
instance.set(:proc, proc)
|
||||
instance.set(:proc, [[current_version, proc]])
|
||||
config = instance.load
|
||||
|
||||
config[:foo].should == "yep"
|
||||
|
@ -60,7 +63,7 @@ describe Vagrant::Config::Loader do
|
|||
end
|
||||
|
||||
instance.load_order = [:proc]
|
||||
instance.set(:proc, proc)
|
||||
instance.set(:proc, [[current_version, proc]])
|
||||
|
||||
5.times do
|
||||
result = instance.load
|
||||
|
|
Loading…
Reference in New Issue