From 036edfcc2ab6e39bc47ece40e4f909a10a77342b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 14 Sep 2010 00:48:31 -0600 Subject: [PATCH] Only destroy the VM if the exception raised is not a Vagrant error --- lib/vagrant/action/vm/import.rb | 2 ++ test/vagrant/action/vm/import_test.rb | 30 +++++++++++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/vagrant/action/vm/import.rb b/lib/vagrant/action/vm/import.rb index 6b9861f3c..1396e15b8 100644 --- a/lib/vagrant/action/vm/import.rb +++ b/lib/vagrant/action/vm/import.rb @@ -23,6 +23,8 @@ module Vagrant def recover(env) if env["vm"].created? + return if env["vagrant.error"].is_a?(Errors::VagrantError) + # Interrupted, destroy the VM env["actions"].run(:destroy) end diff --git a/test/vagrant/action/vm/import_test.rb b/test/vagrant/action/vm/import_test.rb index f4fd14a55..1dc5d3569 100644 --- a/test/vagrant/action/vm/import_test.rb +++ b/test/vagrant/action/vm/import_test.rb @@ -40,15 +40,27 @@ class ImportVMActionTest < Test::Unit::TestCase } end - should "not run the destroy action on recover if VM is not created" do - @env.env.vm.stubs(:created?).returns(false) - @env.env.actions.expects(:run).never - @instance.recover(@env) - end + context "recovery" do + setup do + @env.env.vm.stubs(:created?).returns(true) + end - should "run the destroy action on recover" do - @env.env.vm.stubs(:created?).returns(true) - @env.env.actions.expects(:run).with(:destroy).once - @instance.recover(@env) + 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 + @env.env.vm.stubs(:created?).returns(false) + @env.env.actions.expects(:run).never + @instance.recover(@env) + end + + should "run the destroy action on recover" do + @env.env.vm.stubs(:created?).returns(true) + @env.env.actions.expects(:run).with(:destroy).once + @instance.recover(@env) + end end end