diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 337ea75bb..35630bff1 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -81,6 +81,7 @@ module Vagrant # Returns the VMs associated with this environment. def vms + return parent.vms if parent load! if !loaded? @vms ||= {} end @@ -275,7 +276,7 @@ module Vagrant # This environment represents a single sub VM. The VM is then # probably (read: should be) set on the VM attribute, so we do # nothing. - return if vm + return if parent # First load the defaults (blank, noncreated VMs) load_blank_vms! diff --git a/test/vagrant/environment_test.rb b/test/vagrant/environment_test.rb index f278aecd4..fff14b793 100644 --- a/test/vagrant/environment_test.rb +++ b/test/vagrant/environment_test.rb @@ -306,6 +306,15 @@ class EnvironmentTest < Test::Unit::TestCase env.expects(:load!).never env.vms 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 context "loading" do @@ -484,10 +493,15 @@ class EnvironmentTest < Test::Unit::TestCase end end - should "do nothing if the vm is set" do - @env.stubs(:vm).returns(mock("vm")) - File.expects(:open).never - @env.load_vm! + should "do nothing if the parent is set" do + env = vagrant_env(vagrantfile(<<-vf)) + config.vm.define :web + config.vm.define :db + vf + + subenv = env.vms[:web].env + subenv.expects(:load_blank_vms!).never + subenv.load_vm! end should "uuid should be nil if local data contains nothing" do