From 05c4c2f83840793818042834887d1f5a7e7aefe6 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 14 Mar 2010 16:39:52 -0700 Subject: [PATCH] Env.persist_vm also persists UUID to the ActiveList --- lib/vagrant/actions/vm/up.rb | 4 ++-- lib/vagrant/env.rb | 4 ++++ test/vagrant/actions/vm/up_test.rb | 4 ++-- test/vagrant/env_test.rb | 22 +++++++++++++++------- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/vagrant/actions/vm/up.rb b/lib/vagrant/actions/vm/up.rb index 0603452ca..a6532a75e 100644 --- a/lib/vagrant/actions/vm/up.rb +++ b/lib/vagrant/actions/vm/up.rb @@ -35,8 +35,8 @@ msg end def persist - logger.info "Persisting the VM UUID (#{@runner.vm.uuid})..." - Env.persist_vm(@runner.vm) + logger.info "Persisting the VM UUID (#{@runner.uuid})..." + Env.persist_vm(@runner) end def setup_mac_address diff --git a/lib/vagrant/env.rb b/lib/vagrant/env.rb index 6cfffa951..da43196f2 100644 --- a/lib/vagrant/env.rb +++ b/lib/vagrant/env.rb @@ -107,9 +107,13 @@ msg end def persist_vm(vm) + # Save to the dotfile for this project File.open(dotfile_path, 'w+') do |f| f.write(vm.uuid) end + + # Also add to the global store + ActiveList.add(vm) end def load_root_path!(path=nil) diff --git a/test/vagrant/actions/vm/up_test.rb b/test/vagrant/actions/vm/up_test.rb index c39dfedca..eab488ccf 100644 --- a/test/vagrant/actions/vm/up_test.rb +++ b/test/vagrant/actions/vm/up_test.rb @@ -78,8 +78,8 @@ class UpActionTest < Test::Unit::TestCase context "persisting" do should "persist the VM with Env" do - @vm.stubs(:uuid) - Vagrant::Env.expects(:persist_vm).with(@vm).once + @mock_vm.stubs(:uuid) + Vagrant::Env.expects(:persist_vm).with(@mock_vm).once @action.persist end end diff --git a/test/vagrant/env_test.rb b/test/vagrant/env_test.rb index cb007c5d7..65eebfc16 100644 --- a/test/vagrant/env_test.rb +++ b/test/vagrant/env_test.rb @@ -161,7 +161,7 @@ class EnvTest < Test::Unit::TestCase end context "initial load" do - test "load! should load the config and set the persisted_uid" do + should "load! should load the config and set the persisted_uid" do call_seq = sequence("call_sequence") Vagrant::Env.expects(:load_root_path!).once.in_sequence(call_seq) Vagrant::Env.expects(:load_config!).once.in_sequence(call_seq) @@ -177,16 +177,24 @@ class EnvTest < Test::Unit::TestCase context "persisting the VM into a file" do setup do mock_config + + @vm = mock("vm") + @vm.stubs(:uuid).returns("foo") + + File.stubs(:open) + Vagrant::ActiveList.stubs(:add) end - test "should save it to the dotfile path" do - vm = mock("vm") - vm.stubs(:uuid).returns("foo") - + should "should save it to the dotfile path" do filemock = mock("filemock") - filemock.expects(:write).with(vm.uuid) + filemock.expects(:write).with(@vm.uuid) File.expects(:open).with(Vagrant::Env.dotfile_path, 'w+').once.yields(filemock) - Vagrant::Env.persist_vm(vm) + Vagrant::Env.persist_vm(@vm) + end + + should "add the VM to the activelist" do + Vagrant::ActiveList.expects(:add).with(@vm) + Vagrant::Env.persist_vm(@vm) end end