Env.persist_vm also persists UUID to the ActiveList

This commit is contained in:
Mitchell Hashimoto 2010-03-14 16:39:52 -07:00
parent 62d3172e57
commit 05c4c2f838
4 changed files with 23 additions and 11 deletions

View File

@ -35,8 +35,8 @@ msg
end end
def persist def persist
logger.info "Persisting the VM UUID (#{@runner.vm.uuid})..." logger.info "Persisting the VM UUID (#{@runner.uuid})..."
Env.persist_vm(@runner.vm) Env.persist_vm(@runner)
end end
def setup_mac_address def setup_mac_address

View File

@ -107,9 +107,13 @@ msg
end end
def persist_vm(vm) def persist_vm(vm)
# Save to the dotfile for this project
File.open(dotfile_path, 'w+') do |f| File.open(dotfile_path, 'w+') do |f|
f.write(vm.uuid) f.write(vm.uuid)
end end
# Also add to the global store
ActiveList.add(vm)
end end
def load_root_path!(path=nil) def load_root_path!(path=nil)

View File

@ -78,8 +78,8 @@ class UpActionTest < Test::Unit::TestCase
context "persisting" do context "persisting" do
should "persist the VM with Env" do should "persist the VM with Env" do
@vm.stubs(:uuid) @mock_vm.stubs(:uuid)
Vagrant::Env.expects(:persist_vm).with(@vm).once Vagrant::Env.expects(:persist_vm).with(@mock_vm).once
@action.persist @action.persist
end end
end end

View File

@ -161,7 +161,7 @@ class EnvTest < Test::Unit::TestCase
end end
context "initial load" do 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") call_seq = sequence("call_sequence")
Vagrant::Env.expects(:load_root_path!).once.in_sequence(call_seq) Vagrant::Env.expects(:load_root_path!).once.in_sequence(call_seq)
Vagrant::Env.expects(:load_config!).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 context "persisting the VM into a file" do
setup do setup do
mock_config mock_config
@vm = mock("vm")
@vm.stubs(:uuid).returns("foo")
File.stubs(:open)
Vagrant::ActiveList.stubs(:add)
end end
test "should save it to the dotfile path" do should "should save it to the dotfile path" do
vm = mock("vm")
vm.stubs(:uuid).returns("foo")
filemock = mock("filemock") 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) 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
end end