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