core: VAGRANT_VAGRANTFILE affects only project vagrantfile [GH-2130]

This commit is contained in:
Mitchell Hashimoto 2013-09-05 14:46:15 -07:00
parent 933fd8b397
commit 95aba27e59
3 changed files with 34 additions and 10 deletions

View File

@ -4,6 +4,8 @@ BUG FIXES:
- core: Fix various issues where using the same options hash in a - core: Fix various issues where using the same options hash in a
Vagrantfile can cause errors. Vagrantfile can cause errors.
- core: `VAGRANT_VAGRANTFILE` env var only applies to the project
Vagrantfile name. [GH-2130]
- provisioners/puppet: No more "shared folders cannot be found" error. - provisioners/puppet: No more "shared folders cannot be found" error.
[GH-2134] [GH-2134]

View File

@ -85,9 +85,8 @@ module Vagrant
# those continue to work as well, but anything custom will take precedence. # those continue to work as well, but anything custom will take precedence.
opts[:vagrantfile_name] ||= ENV["VAGRANT_VAGRANTFILE"] if \ opts[:vagrantfile_name] ||= ENV["VAGRANT_VAGRANTFILE"] if \
ENV.has_key?("VAGRANT_VAGRANTFILE") ENV.has_key?("VAGRANT_VAGRANTFILE")
opts[:vagrantfile_name] ||= ["Vagrantfile", "vagrantfile"]
opts[:vagrantfile_name] = [opts[:vagrantfile_name]] if \ opts[:vagrantfile_name] = [opts[:vagrantfile_name]] if \
!opts[:vagrantfile_name].is_a?(Array) opts[:vagrantfile_name] && !opts[:vagrantfile_name].is_a?(Array)
# Set instance variables for all the configuration parameters. # Set instance variables for all the configuration parameters.
@cwd = opts[:cwd] @cwd = opts[:cwd]
@ -251,7 +250,7 @@ module Vagrant
home_vagrantfile = nil home_vagrantfile = nil
root_vagrantfile = nil root_vagrantfile = nil
home_vagrantfile = find_vagrantfile(home_path) if home_path home_vagrantfile = find_vagrantfile(home_path) if home_path
root_vagrantfile = find_vagrantfile(root_path) if root_path root_vagrantfile = find_vagrantfile(root_path, @vagrantfile_name) if root_path
# Create the configuration loader and set the sources that are global. # Create the configuration loader and set the sources that are global.
# We use this to load the configuration, and the list of machines we are # We use this to load the configuration, and the list of machines we are
@ -539,11 +538,8 @@ module Vagrant
root_finder = lambda do |path| root_finder = lambda do |path|
# Note: To remain compatible with Ruby 1.8, we have to use # Note: To remain compatible with Ruby 1.8, we have to use
# a `find` here instead of an `each`. # a `find` here instead of an `each`.
found = vagrantfile_name.find do |rootfile| vf = find_vagrantfile(path, @vagrantfile_name)
File.exist?(File.join(path.to_s, rootfile)) return path if vf
end
return path if found
return nil if path.root? || !File.exist?(path) return nil if path.root? || !File.exist?(path)
root_finder.call(path.parent) root_finder.call(path.parent)
end end
@ -715,8 +711,9 @@ module Vagrant
# #
# @param [Pathname] path Path to search in. # @param [Pathname] path Path to search in.
# @return [Pathname] # @return [Pathname]
def find_vagrantfile(search_path) def find_vagrantfile(search_path, filenames=nil)
@vagrantfile_name.each do |vagrantfile| filenames ||= ["Vagrantfile", "vagrantfile"]
filenames.each do |vagrantfile|
current_path = search_path.join(vagrantfile) current_path = search_path.join(vagrantfile)
return current_path if current_path.exist? return current_path if current_path.exist?
end end

View File

@ -581,6 +581,31 @@ VF
machine.config.ssh.port.should == 100 machine.config.ssh.port.should == 100
end end
it "should load the box configuration for a V2 box and custom Vagrantfile name" do
register_provider("foo")
environment = isolated_environment do |env|
env.file("some_other_name", <<-VF)
Vagrant.configure("2") do |config|
config.vm.box = "base"
end
VF
env.box2("base", :foo, :vagrantfile => <<-VF)
Vagrant.configure("2") do |config|
config.ssh.port = 100
end
VF
end
env = with_temp_env("VAGRANT_VAGRANTFILE" => "some_other_name") do
environment.create_vagrant_env
end
machine = env.machine(:default, :foo)
machine.config.ssh.port.should == 100
end
it "should load the box configuration for other formats for a V2 box" do it "should load the box configuration for other formats for a V2 box" do
register_provider("foo", nil, box_format: "bar") register_provider("foo", nil, box_format: "bar")