Propery load box configuration

This commit is contained in:
Mitchell Hashimoto 2011-12-03 19:15:53 -08:00
parent e154ae7c6d
commit 1921ce17e8
5 changed files with 37 additions and 23 deletions

View File

@ -1,8 +1,9 @@
This is a TODO file for only this branch (config-overhaul)
* Config validation
* What happens if a configured box doesn't exist?
* Separation of global vs VM configuration.
# Put VM-specific config directly into Vagrant::VM objects
* Only allow one kind of vagrantfile to be loaded (i.e. if both
Vagrantfile and vagrantfile exist, throw an error)
* Nicer error if can't setup home directory
* Nicer error if can't setup home directory

View File

@ -162,13 +162,6 @@ module Vagrant
@_boxes ||= BoxCollection.new(self)
end
# Returns the box that this environment represents.
#
# @return [Box]
def box
boxes.find(config.vm.box)
end
# Returns the VMs associated with this environment.
#
# @return [Hash<Symbol,VM>]
@ -458,7 +451,7 @@ module Vagrant
config = inner_load[subvm]
# Second pass, with the box
config = inner_load[subvm, config.vm.box]
config = inner_load[subvm, boxes.find(config.vm.box)]
config.vm.name = vm_name.to_s
# Return the final configuration for this VM

View File

@ -43,10 +43,23 @@ module Unit
Vagrant::Environment.new(:cwd => @workdir, :home_path => @homedir)
end
def vagrantfile(contents)
@workdir.join("Vagrantfile").open("w+") do |f|
def vagrantfile(contents, root=nil)
root ||= @workdir
root.join("Vagrantfile").open("w+") do |f|
f.write(contents)
end
end
def box(name, vagrantfile_contents)
box_dir = boxes_dir.join(name)
box_dir.mkdir
vagrantfile(vagrantfile_contents, box_dir)
end
def boxes_dir
dir = @homedir.join("boxes")
dir.mkdir
dir
end
end
end

View File

@ -84,6 +84,25 @@ VF
env.config.for_vm("foo").ssh.port.should == 100
env.config.for_vm("bar").ssh.port.should == 200
end
it "should load box configuration" do
environment = isolated_environment do |env|
env.vagrantfile(<<-VF)
Vagrant::Config.run do |config|
config.vm.box = "base"
end
VF
env.box("base", <<-VF)
Vagrant::Config.run do |config|
config.ssh.port = 100
end
VF
end
env = environment.create_vagrant_env
env.config.for_vm("default").ssh.port.should == 100
end
end
describe "ui" do

View File

@ -372,18 +372,6 @@ class EnvironmentTest < Test::Unit::TestCase
end
end
context "accessing the current box" do
should "return the box that is specified in the config" do
vagrant_box("foo")
env = vagrant_env(vagrantfile(<<-vf))
config.vm.box = "foo"
vf
assert env.box
assert_equal "foo", env.box.name
end
end
context "accessing the VMs hash" do
should "load the environment if its not already loaded" do
env = @klass.new(:cwd => vagrantfile)