Only validate on the second-pass of loading configuration

This commit is contained in:
Mitchell Hashimoto 2010-10-08 10:52:34 -07:00
parent 5fcf10d6cd
commit f90016bb6f
3 changed files with 21 additions and 13 deletions

View File

@ -68,13 +68,13 @@ module Vagrant
# and returns the final configured object. This also validates the
# configuration by calling {Top#validate!} on every configuration
# class.
def execute!(config_object=nil)
def execute!(validate=true)
config_object ||= config
run_procs!(config_object)
# Validate if we're looking at a config object which represents a
# real VM.
config_object.validate! if config_object.env.vm
config_object.validate! if validate && config_object.env.vm
config_object
end
end
@ -90,7 +90,7 @@ module Vagrant
# Loads the queue of files/procs, executes them in the proper
# sequence, and returns the resulting configuration object.
def load!
def load!(validate=true)
self.class.reset!(@env)
queue.flatten.each do |item|
@ -106,7 +106,7 @@ module Vagrant
end
end
return self.class.execute!
return self.class.execute!(validate)
end
end

View File

@ -313,7 +313,7 @@ module Vagrant
# Execute the configuration stack and store the result as the final
# value in the config ivar.
@config = loader.load!
@config = loader.load!(!first_run)
# (re)load the logger
@logger = nil

View File

@ -10,7 +10,6 @@ class ConfigTest < Test::Unit::TestCase
@env = vagrant_env
@instance = @klass.new(@env)
# Don't want validation to occur for these tests
@klass::Top.any_instance.stubs(:validate!)
end
@ -21,10 +20,17 @@ class ConfigTest < Test::Unit::TestCase
should "reset the config class on load, then execute" do
seq = sequence("sequence")
@klass.expects(:reset!).with(@env).in_sequence(seq)
@klass.expects(:execute!).in_sequence(seq)
@klass.expects(:execute!).with(true).in_sequence(seq)
@instance.load!
end
should "not validate if told not to" do
seq = sequence("sequence")
@klass.expects(:reset!).with(@env).in_sequence(seq)
@klass.expects(:execute!).with(false).in_sequence(seq)
@instance.load!(false)
end
should "run the queue in the order given" do
@instance.queue << Proc.new { |config| config.vm.box = "foo" }
@instance.queue << Proc.new { |config| config.vm.box = "bar" }
@ -131,17 +137,19 @@ class ConfigTest < Test::Unit::TestCase
@klass.execute!
end
should "not run the validation if explicitly told not to" do
@klass.reset!(vagrant_env.vms[:default].env)
seq = sequence('seq')
@klass.expects(:run_procs!).with(@klass.config).once.in_sequence(seq)
@klass.config.expects(:validate!).never
@klass.execute!(false)
end
should "return the configuration on execute!" do
@klass.run {}
result = @klass.execute!
assert result.is_a?(@klass::Top)
end
should "use given configuration object if given" do
config = @klass::Top.new(vagrant_env)
result = @klass.execute!(config)
assert_equal config.env, result.env
end
end
context "top config class" do