diff --git a/CHANGELOG.md b/CHANGELOG.md index 5db495165..a157b2d75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,8 @@ - FreeBSD guests can now have their hostnames changed. [GH-757] - FreeBSD guests now support host only networking and bridged networking. [GH-762] - `VM#run_action` is now public so plugin-devs can hook into it. + - Fix crashing bug when attempting to run commands on the "primary" + VM in a multi-VM environment. [GH-761] ## 0.9.7 (February 9, 2012) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index d74adb69e..c7ed90a17 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -138,7 +138,7 @@ module Vagrant def primary_vm return vms.values.first if !multivm? - config.vm.defined_vms.each do |name, subvm| + config.global.vm.defined_vms.each do |name, subvm| return vms[name] if subvm.options[:primary] end diff --git a/test/unit/vagrant/environment_test.rb b/test/unit/vagrant/environment_test.rb index 520500214..738b469e3 100644 --- a/test/unit/vagrant/environment_test.rb +++ b/test/unit/vagrant/environment_test.rb @@ -86,6 +86,26 @@ describe Vagrant::Environment do end end + describe "primary VM" do + it "should be the only VM if not a multi-VM environment" do + instance.primary_vm.should == instance.vms.values.first + end + + it "should be the VM marked as the primary" do + environment = isolated_environment do |env| + env.vagrantfile(<<-VF) +Vagrant::Config.run do |config| + config.vm.define :foo + config.vm.define :bar, :primary => true +end +VF + end + + env = environment.create_vagrant_env + env.primary_vm.should == env.vms[:bar] + end + end + describe "loading configuration" do it "should load global configuration" do environment = isolated_environment do |env|