From f90016bb6fcbe75d58cc8141061ad7cfd5c01c7c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 8 Oct 2010 10:52:34 -0700 Subject: [PATCH] Only validate on the second-pass of loading configuration --- lib/vagrant/config.rb | 8 ++++---- lib/vagrant/environment.rb | 2 +- test/vagrant/config_test.rb | 24 ++++++++++++++++-------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/lib/vagrant/config.rb b/lib/vagrant/config.rb index 9e37bfbd2..1fb3b6835 100644 --- a/lib/vagrant/config.rb +++ b/lib/vagrant/config.rb @@ -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 diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index fec905329..a11bcea12 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -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 diff --git a/test/vagrant/config_test.rb b/test/vagrant/config_test.rb index 4589c2081..f2f3f04dc 100644 --- a/test/vagrant/config_test.rb +++ b/test/vagrant/config_test.rb @@ -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