From 30a84c6e5067eb38d0c2ce955b0f791b678cd69b Mon Sep 17 00:00:00 2001 From: John Bender Date: Sun, 22 Aug 2010 00:37:15 -0700 Subject: [PATCH] moved export to warden --- lib/vagrant/action/vm/export.rb | 7 +++--- test/vagrant/action/vm/export_test.rb | 33 ++++----------------------- 2 files changed, 7 insertions(+), 33 deletions(-) diff --git a/lib/vagrant/action/vm/export.rb b/lib/vagrant/action/vm/export.rb index e4c7e0909..ab7f13bf1 100644 --- a/lib/vagrant/action/vm/export.rb +++ b/lib/vagrant/action/vm/export.rb @@ -13,17 +13,16 @@ module Vagrant @env = env return env.error!(:vm_power_off_to_package) if !@env["vm"].vm.powered_off? - return if env.error? setup_temp_dir export - @app.call(env) if !env.error? + @app.call(env) - cleanup + recover # called to cleanup temp directory end - def cleanup + def recover(env) if temp_dir && File.exist?(temp_dir) FileUtils.rm_rf(temp_dir) end diff --git a/test/vagrant/action/vm/export_test.rb b/test/vagrant/action/vm/export_test.rb index 9efebded9..b639c5b8a 100644 --- a/test/vagrant/action/vm/export_test.rb +++ b/test/vagrant/action/vm/export_test.rb @@ -24,7 +24,7 @@ class ExportVMActionTest < Test::Unit::TestCase @instance.expects(:setup_temp_dir).in_sequence(seq) @instance.expects(:export).in_sequence(seq) @app.expects(:call).with(@env).in_sequence(seq) - @instance.expects(:cleanup).in_sequence(seq) + @instance.expects(:recover).in_sequence(seq) @instance.call(@env) end @@ -34,37 +34,12 @@ class ExportVMActionTest < Test::Unit::TestCase @instance.expects(:setup_temp_dir).never @instance.expects(:export).never @app.expects(:call).with(@env).never - @instance.expects(:cleanup).never + @instance.expects(:recover).never @instance.call(@env) assert @env.error? assert_equal :vm_power_off_to_package, @env.error.first end - - should "halt the chain if env error" do - @internal_vm.stubs(:powered_off?).returns(true) - @instance.expects(:setup_temp_dir).never - @instance.expects(:export).never - @app.expects(:call).with(@env).never - @instance.expects(:cleanup).never - - @env.error!(:interrupt) - @instance.call(@env) - end - - should "halt the chain if env error when call is reached" do - @internal_vm.stubs(:powered_off?).returns(true) - @instance.expects(:setup_temp_dir).once - @instance.expects(:export).once.with() do - @env.error!(:interrupt) - true - end - - @app.expects(:call).with(@env).never - @instance.expects(:cleanup).once - - @instance.call(@env) - end end context "cleaning up" do @@ -76,13 +51,13 @@ class ExportVMActionTest < Test::Unit::TestCase should "delete the temporary file if it exists" do File.expects(:unlink).with(@temp_dir).once - @instance.cleanup + @instance.recover(nil) end should "not delete anything if it doesn't exist" do File.stubs(:exist?).returns(false) File.expects(:unlink).never - @instance.cleanup + @instance.recover(nil) end end