Dotfile and active list are now updated when environment is torn down
This commit is contained in:
parent
05c4c2f838
commit
c08937d899
|
@ -4,10 +4,19 @@ module Vagrant
|
|||
class Destroy < Base
|
||||
def execute!
|
||||
@runner.invoke_around_callback(:destroy) do
|
||||
logger.info "Destroying VM and associated drives..."
|
||||
@runner.vm.destroy(:destroy_image => true)
|
||||
destroy_vm
|
||||
depersist
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_vm
|
||||
logger.info "Destroying VM and associated drives..."
|
||||
@runner.vm.destroy(:destroy_image => true)
|
||||
end
|
||||
|
||||
def depersist
|
||||
Env.depersist_vm(@runner)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -116,6 +116,14 @@ msg
|
|||
ActiveList.add(vm)
|
||||
end
|
||||
|
||||
def depersist_vm(vm)
|
||||
# Delete the dotfile if it exists
|
||||
File.delete(dotfile_path) if File.exist?(dotfile_path)
|
||||
|
||||
# Remove from the global store
|
||||
ActiveList.remove(vm)
|
||||
end
|
||||
|
||||
def load_root_path!(path=nil)
|
||||
path = Pathname.new(File.expand_path(path || Dir.pwd))
|
||||
|
||||
|
|
|
@ -2,23 +2,36 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|||
|
||||
class DestroyActionTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Destroy)
|
||||
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Destroy)
|
||||
mock_config
|
||||
end
|
||||
|
||||
context "executing" do
|
||||
setup do
|
||||
@vm.stubs(:destroy)
|
||||
end
|
||||
|
||||
should "invoke an around callback around the destroy" do
|
||||
@mock_vm.expects(:invoke_around_callback).with(:destroy).once
|
||||
@runner.expects(:invoke_around_callback).with(:destroy).once
|
||||
@action.execute!
|
||||
end
|
||||
|
||||
should "destroy VM and attached images" do
|
||||
@vm.expects(:destroy).with(:destroy_image => true).once
|
||||
should "destroy VM and clear persist" do
|
||||
@runner.stubs(:invoke_around_callback).yields
|
||||
clear_seq = sequence("clear")
|
||||
@action.expects(:destroy_vm).in_sequence(clear_seq)
|
||||
@action.expects(:depersist).in_sequence(clear_seq)
|
||||
@action.execute!
|
||||
end
|
||||
end
|
||||
|
||||
context "destroying the VM" do
|
||||
should "destroy VM and attached images" do
|
||||
@vm.expects(:destroy).with(:destroy_image => true).once
|
||||
@action.destroy_vm
|
||||
end
|
||||
end
|
||||
|
||||
context "depersisting" do
|
||||
should "call depersist_vm on Env" do
|
||||
Vagrant::Env.expects(:depersist_vm).with(@runner).once
|
||||
@action.depersist
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -176,8 +176,6 @@ 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")
|
||||
|
||||
|
@ -198,6 +196,37 @@ class EnvTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
context "depersisting the VM" do
|
||||
setup do
|
||||
File.stubs(:exist?).returns(false)
|
||||
File.stubs(:delete)
|
||||
|
||||
Vagrant::ActiveList.stubs(:remove)
|
||||
|
||||
@dotfile_path = "foo"
|
||||
Vagrant::Env.stubs(:dotfile_path).returns(@dotfile_path)
|
||||
|
||||
@vm = mock("vm")
|
||||
end
|
||||
|
||||
should "remove the dotfile if it exists" do
|
||||
File.expects(:exist?).with(Vagrant::Env.dotfile_path).returns(true)
|
||||
File.expects(:delete).with(Vagrant::Env.dotfile_path).once
|
||||
Vagrant::Env.depersist_vm(@vm)
|
||||
end
|
||||
|
||||
should "not remove the dotfile if it doesn't exist" do
|
||||
File.expects(:exist?).returns(false)
|
||||
File.expects(:delete).never
|
||||
Vagrant::Env.depersist_vm(@vm)
|
||||
end
|
||||
|
||||
should "remove from the active list" do
|
||||
Vagrant::ActiveList.expects(:remove).with(@vm)
|
||||
Vagrant::Env.depersist_vm(@vm)
|
||||
end
|
||||
end
|
||||
|
||||
context "loading the UUID out from the persisted file" do
|
||||
setup do
|
||||
File.stubs(:file?).returns(true)
|
||||
|
|
Loading…
Reference in New Issue