Change the way the config is loaded to be all in one step

This commit is contained in:
Mitchell Hashimoto 2010-09-05 01:10:57 -07:00
parent ce9ff73ea4
commit 52a32820db
2 changed files with 23 additions and 15 deletions

View File

@ -206,9 +206,6 @@ module Vagrant
@loaded = true @loaded = true
self.class.check_virtualbox! self.class.check_virtualbox!
load_config! load_config!
load_home_directory!
load_box!
load_config!
load_vm! load_vm!
self self
end end
@ -218,24 +215,36 @@ module Vagrant
# this environment, meaning that it will use the given root directory # this environment, meaning that it will use the given root directory
# to load the Vagrantfile into that context. # to load the Vagrantfile into that context.
def load_config! def load_config!
first_run = @config.nil?
# First load the initial, non config-dependent Vagrantfiles
loader = Config.new(self) loader = Config.new(self)
loader.queue << File.expand_path("config/default.rb", Vagrant.source_root) loader.queue << File.expand_path("config/default.rb", Vagrant.source_root)
loader.queue << File.join(box.directory, ROOTFILE_NAME) if box loader.queue << File.join(box.directory, ROOTFILE_NAME) if !first_run && box
loader.queue << File.join(home_path, ROOTFILE_NAME) if home_path loader.queue << File.join(home_path, ROOTFILE_NAME) if !first_run && home_path
loader.queue << File.join(root_path, ROOTFILE_NAME) if root_path loader.queue << File.join(root_path, ROOTFILE_NAME) if root_path
# If this environment represents some VM in a multi-VM environment, # If this environment is representing a sub-VM, then we push that
# we push that VM's configuration onto the config_queue. # proc on as the last configuration.
if vm_name if !first_run && vm_name
subvm = parent.config.vm.defined_vms[vm_name] subvm = parent.config.vm.defined_vms[vm_name]
loader.queue << subvm.proc_stack if subvm loader.queue << subvm.proc_stack if subvm
end end
# Execute the configuration stack and store the result # Execute the configuration stack and store the result as the final
# value in the config ivar.
@config = loader.load! @config = loader.load!
# (re)load the logger # (re)load the logger
@logger = nil @logger = nil
if first_run
# After the first run we want to load the configuration again since
# it can change due to box Vagrantfiles and home directory Vagrantfiles
load_home_directory!
load_box!
load_config!
end
end end
# Loads the home directory path and creates the necessary subdirectories # Loads the home directory path and creates the necessary subdirectories
@ -256,8 +265,6 @@ module Vagrant
# Loads the specified box for this environment. # Loads the specified box for this environment.
def load_box! def load_box!
return unless root_path
@box = Box.find(self, config.vm.box) if config.vm.box @box = Box.find(self, config.vm.box) if config.vm.box
end end

View File

@ -318,9 +318,6 @@ class EnvironmentTest < Test::Unit::TestCase
call_seq = sequence("call_sequence") call_seq = sequence("call_sequence")
@klass.expects(:check_virtualbox!).once.in_sequence(call_seq) @klass.expects(:check_virtualbox!).once.in_sequence(call_seq)
@env.expects(:load_config!).once.in_sequence(call_seq) @env.expects(:load_config!).once.in_sequence(call_seq)
@env.expects(:load_home_directory!).once.in_sequence(call_seq)
@env.expects(:load_box!).once.in_sequence(call_seq)
@env.expects(:load_config!).once.in_sequence(call_seq)
@env.expects(:load_vm!).once.in_sequence(call_seq) @env.expects(:load_vm!).once.in_sequence(call_seq)
assert_equal @env, @env.load! assert_equal @env, @env.load!
end end
@ -333,6 +330,10 @@ class EnvironmentTest < Test::Unit::TestCase
@env.stubs(:root_path).returns(@root_path) @env.stubs(:root_path).returns(@root_path)
@env.stubs(:home_path).returns(@home_path) @env.stubs(:home_path).returns(@home_path)
# Temporary
@env.stubs(:load_home_directory!)
@env.stubs(:load_box!)
@loader = Vagrant::Config.new(@env) @loader = Vagrant::Config.new(@env)
Vagrant::Config.stubs(:new).returns(@loader) Vagrant::Config.stubs(:new).returns(@loader)
@loader.stubs(:load!) @loader.stubs(:load!)
@ -388,7 +389,7 @@ class EnvironmentTest < Test::Unit::TestCase
should "execute after loading and set result to environment config" do should "execute after loading and set result to environment config" do
result = mock("result") result = mock("result")
@loader.expects(:load!).once.returns(result) @loader.stubs(:load!).returns(result)
@env.load_config! @env.load_config!
assert_equal result, @env.config assert_equal result, @env.config
end end