Vagrantfiles are loaded only once, instead of 4+ times [closes GH-238]
This commit is contained in:
parent
e258395346
commit
b8c84b67b7
|
@ -1,5 +1,6 @@
|
|||
## 0.7.0.beta2 (unreleased)
|
||||
|
||||
- Puppet server provisioner. [GH-262]
|
||||
- Use numeric uid/gid in mounting shared folders to increase portability. [GH-252]
|
||||
- HTTP downloading follows redirects. [GH-163]
|
||||
- Downloaders have clearer output to note what they're doing.
|
||||
|
@ -9,7 +10,7 @@
|
|||
- `config.ssh.forward_x11` to enable the ForwardX11 SSH option. [GH-255]
|
||||
- Vagrant source now has a `contrib` directory where contributions of miscellaneous
|
||||
addons for Vagrant will be added.
|
||||
- Puppet server provisioner. [GH-262]
|
||||
- Vagrantfiles are now loaded only once (instead of 4+ times) [GH-238]
|
||||
|
||||
## 0.7.0.beta (December 24, 2010)
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ module Vagrant
|
|||
class Config
|
||||
# An array of symbols specifying the load order for the procs.
|
||||
attr_accessor :load_order
|
||||
attr_reader :procs
|
||||
|
||||
# This is the method which is called by all Vagrantfiles to configure Vagrant.
|
||||
# This method expects a block which accepts a single argument representing
|
||||
|
@ -55,15 +56,22 @@ module Vagrant
|
|||
value
|
||||
end
|
||||
|
||||
def initialize
|
||||
def initialize(parent=nil)
|
||||
@procs = {}
|
||||
@load_order = []
|
||||
|
||||
if parent
|
||||
# Shallow copy the procs and load order from parent if given
|
||||
@procs = parent.procs.dup
|
||||
@load_order = parent.load_order.dup
|
||||
end
|
||||
end
|
||||
|
||||
# Adds a Vagrantfile to be loaded to the queue of config procs. Note
|
||||
# that this causes the Vagrantfile file to be loaded at this point,
|
||||
# and it will never be loaded again.
|
||||
def set(key, path)
|
||||
return if @procs.has_key?(key)
|
||||
@procs[key] = [path].flatten.map(&method(:proc_for))
|
||||
end
|
||||
|
||||
|
|
|
@ -23,6 +23,9 @@ module Vagrant
|
|||
# The {UI} object to communicate with the outside world.
|
||||
attr_writer :ui
|
||||
|
||||
# The {Config} object representing the Vagrantfile loader
|
||||
attr_reader :config_loader
|
||||
|
||||
#---------------------------------------------------------------
|
||||
# Class Methods
|
||||
#---------------------------------------------------------------
|
||||
|
@ -308,6 +311,7 @@ module Vagrant
|
|||
# Reloads the configuration of this environment.
|
||||
def reload_config!
|
||||
@config = nil
|
||||
@config_loader = nil
|
||||
load_config!
|
||||
self
|
||||
end
|
||||
|
@ -320,23 +324,23 @@ module Vagrant
|
|||
first_run = @config.nil?
|
||||
|
||||
# First load the initial, non config-dependent Vagrantfiles
|
||||
loader = Config.new
|
||||
loader.load_order = [:default, :box, :home, :root, :sub_vm]
|
||||
loader.set(:default, File.expand_path("config/default.rb", Vagrant.source_root))
|
||||
loader.set(:box, File.join(box.directory, ROOTFILE_NAME)) if !first_run && box
|
||||
loader.set(:home, File.join(home_path, ROOTFILE_NAME)) if !first_run && home_path
|
||||
loader.set(:root, File.join(root_path, ROOTFILE_NAME)) if root_path
|
||||
@config_loader ||= Config.new(parent ? parent.config_loader : nil)
|
||||
@config_loader.load_order = [:default, :box, :home, :root, :sub_vm]
|
||||
@config_loader.set(:default, File.expand_path("config/default.rb", Vagrant.source_root))
|
||||
@config_loader.set(:box, File.join(box.directory, ROOTFILE_NAME)) if !first_run && vm && box
|
||||
@config_loader.set(:home, File.join(home_path, ROOTFILE_NAME)) if !first_run && home_path
|
||||
@config_loader.set(:root, File.join(root_path, ROOTFILE_NAME)) if root_path
|
||||
|
||||
# If this environment is representing a sub-VM, then we push that
|
||||
# proc on as the last configuration.
|
||||
if vm
|
||||
subvm = parent.config.vm.defined_vms[vm.name]
|
||||
loader.set(:sub_vm, subvm.proc_stack) if subvm
|
||||
@config_loader.set(:sub_vm, subvm.proc_stack) if subvm
|
||||
end
|
||||
|
||||
# Execute the configuration stack and store the result as the final
|
||||
# value in the config ivar.
|
||||
@config = loader.load(self)
|
||||
@config = @config_loader.load(self)
|
||||
|
||||
# (re)load the logger
|
||||
@logger = nil
|
||||
|
|
|
@ -62,6 +62,17 @@ class ConfigTest < Test::Unit::TestCase
|
|||
assert_nothing_raised { @instance.load(nil) }
|
||||
end
|
||||
|
||||
should "not reload a file" do
|
||||
foo_path = vagrant_box("foo").join("Vagrantfile")
|
||||
|
||||
vagrantfile(vagrant_box("foo"))
|
||||
@instance.set(:foo, foo_path)
|
||||
|
||||
# Nothing should be raised in this case because the file isn't reloaded
|
||||
vagrantfile(vagrant_box("foo"), "^%&8318")
|
||||
assert_nothing_raised { @instance.set(:foo, foo_path) }
|
||||
end
|
||||
|
||||
should "raise an exception if there is a syntax error in a file" do
|
||||
vagrantfile(vagrant_box("foo"), "^%&8318")
|
||||
|
||||
|
|
|
@ -393,7 +393,7 @@ class EnvironmentTest < Test::Unit::TestCase
|
|||
create_box_vagrantfile
|
||||
vagrantfile(@env.root_path, "config.vm.box = 'box'")
|
||||
|
||||
assert_equal "box.box", @env.config.package.name
|
||||
assert_equal "box.box", @env.primary_vm.env.config.package.name
|
||||
end
|
||||
|
||||
should "load from home path if exists" do
|
||||
|
|
Loading…
Reference in New Issue