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,6 +1,7 @@
This is a TODO file for only this branch (config-overhaul) This is a TODO file for only this branch (config-overhaul)
* Config validation * Config validation
* What happens if a configured box doesn't exist?
* Separation of global vs VM configuration. * Separation of global vs VM configuration.
# Put VM-specific config directly into Vagrant::VM objects # Put VM-specific config directly into Vagrant::VM objects
* Only allow one kind of vagrantfile to be loaded (i.e. if both * Only allow one kind of vagrantfile to be loaded (i.e. if both

View File

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

View File

@ -43,10 +43,23 @@ module Unit
Vagrant::Environment.new(:cwd => @workdir, :home_path => @homedir) Vagrant::Environment.new(:cwd => @workdir, :home_path => @homedir)
end end
def vagrantfile(contents) def vagrantfile(contents, root=nil)
@workdir.join("Vagrantfile").open("w+") do |f| root ||= @workdir
root.join("Vagrantfile").open("w+") do |f|
f.write(contents) f.write(contents)
end end
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
end end

View File

@ -84,6 +84,25 @@ VF
env.config.for_vm("foo").ssh.port.should == 100 env.config.for_vm("foo").ssh.port.should == 100
env.config.for_vm("bar").ssh.port.should == 200 env.config.for_vm("bar").ssh.port.should == 200
end 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 end
describe "ui" do describe "ui" do

View File

@ -372,18 +372,6 @@ class EnvironmentTest < Test::Unit::TestCase
end end
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 context "accessing the VMs hash" do
should "load the environment if its not already loaded" do should "load the environment if its not already loaded" do
env = @klass.new(:cwd => vagrantfile) env = @klass.new(:cwd => vagrantfile)