Only destroy the VM if the exception raised is not a Vagrant error

This commit is contained in:
Mitchell Hashimoto 2010-09-14 00:48:31 -06:00
parent 7c42300002
commit 036edfcc2a
2 changed files with 23 additions and 9 deletions

View File

@ -23,6 +23,8 @@ module Vagrant
def recover(env) def recover(env)
if env["vm"].created? if env["vm"].created?
return if env["vagrant.error"].is_a?(Errors::VagrantError)
# Interrupted, destroy the VM # Interrupted, destroy the VM
env["actions"].run(:destroy) env["actions"].run(:destroy)
end end

View File

@ -40,6 +40,17 @@ class ImportVMActionTest < Test::Unit::TestCase
} }
end end
context "recovery" do
setup do
@env.env.vm.stubs(:created?).returns(true)
end
should "not run the destroy action on recover if error is a VagrantError" do
@env["vagrant.error"] = Vagrant::Errors::VMImportFailure.new
@env.env.actions.expects(:run).never
@instance.recover(@env)
end
should "not run the destroy action on recover if VM is not created" do should "not run the destroy action on recover if VM is not created" do
@env.env.vm.stubs(:created?).returns(false) @env.env.vm.stubs(:created?).returns(false)
@env.env.actions.expects(:run).never @env.env.actions.expects(:run).never
@ -52,3 +63,4 @@ class ImportVMActionTest < Test::Unit::TestCase
@instance.recover(@env) @instance.recover(@env)
end end
end end
end