No need to reload the VMs hash if has a parent environment.

This commit is contained in:
Mitchell Hashimoto 2010-09-06 00:06:55 -07:00
parent ed48170b24
commit 4342c87473
2 changed files with 20 additions and 5 deletions

View File

@ -81,6 +81,7 @@ module Vagrant
# Returns the VMs associated with this environment. # Returns the VMs associated with this environment.
def vms def vms
return parent.vms if parent
load! if !loaded? load! if !loaded?
@vms ||= {} @vms ||= {}
end end
@ -275,7 +276,7 @@ module Vagrant
# This environment represents a single sub VM. The VM is then # This environment represents a single sub VM. The VM is then
# probably (read: should be) set on the VM attribute, so we do # probably (read: should be) set on the VM attribute, so we do
# nothing. # nothing.
return if vm return if parent
# First load the defaults (blank, noncreated VMs) # First load the defaults (blank, noncreated VMs)
load_blank_vms! load_blank_vms!

View File

@ -306,6 +306,15 @@ class EnvironmentTest < Test::Unit::TestCase
env.expects(:load!).never env.expects(:load!).never
env.vms env.vms
end end
should "return the parent's VMs hash if it has one" do
env = vagrant_env(vagrantfile(<<-vf))
config.vm.define :web
config.vm.define :db
vf
assert env.vms[:web].env.vms.equal?(env.vms)
end
end end
context "loading" do context "loading" do
@ -484,10 +493,15 @@ class EnvironmentTest < Test::Unit::TestCase
end end
end end
should "do nothing if the vm is set" do should "do nothing if the parent is set" do
@env.stubs(:vm).returns(mock("vm")) env = vagrant_env(vagrantfile(<<-vf))
File.expects(:open).never config.vm.define :web
@env.load_vm! config.vm.define :db
vf
subenv = env.vms[:web].env
subenv.expects(:load_blank_vms!).never
subenv.load_vm!
end end
should "uuid should be nil if local data contains nothing" do should "uuid should be nil if local data contains nothing" do