moved export to warden
This commit is contained in:
parent
a98a504849
commit
30a84c6e50
|
@ -13,17 +13,16 @@ module Vagrant
|
||||||
@env = env
|
@env = env
|
||||||
|
|
||||||
return env.error!(:vm_power_off_to_package) if !@env["vm"].vm.powered_off?
|
return env.error!(:vm_power_off_to_package) if !@env["vm"].vm.powered_off?
|
||||||
return if env.error?
|
|
||||||
|
|
||||||
setup_temp_dir
|
setup_temp_dir
|
||||||
export
|
export
|
||||||
|
|
||||||
@app.call(env) if !env.error?
|
@app.call(env)
|
||||||
|
|
||||||
cleanup
|
recover # called to cleanup temp directory
|
||||||
end
|
end
|
||||||
|
|
||||||
def cleanup
|
def recover(env)
|
||||||
if temp_dir && File.exist?(temp_dir)
|
if temp_dir && File.exist?(temp_dir)
|
||||||
FileUtils.rm_rf(temp_dir)
|
FileUtils.rm_rf(temp_dir)
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,7 +24,7 @@ class ExportVMActionTest < Test::Unit::TestCase
|
||||||
@instance.expects(:setup_temp_dir).in_sequence(seq)
|
@instance.expects(:setup_temp_dir).in_sequence(seq)
|
||||||
@instance.expects(:export).in_sequence(seq)
|
@instance.expects(:export).in_sequence(seq)
|
||||||
@app.expects(:call).with(@env).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)
|
@instance.call(@env)
|
||||||
end
|
end
|
||||||
|
@ -34,37 +34,12 @@ class ExportVMActionTest < Test::Unit::TestCase
|
||||||
@instance.expects(:setup_temp_dir).never
|
@instance.expects(:setup_temp_dir).never
|
||||||
@instance.expects(:export).never
|
@instance.expects(:export).never
|
||||||
@app.expects(:call).with(@env).never
|
@app.expects(:call).with(@env).never
|
||||||
@instance.expects(:cleanup).never
|
@instance.expects(:recover).never
|
||||||
|
|
||||||
@instance.call(@env)
|
@instance.call(@env)
|
||||||
assert @env.error?
|
assert @env.error?
|
||||||
assert_equal :vm_power_off_to_package, @env.error.first
|
assert_equal :vm_power_off_to_package, @env.error.first
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "cleaning up" do
|
context "cleaning up" do
|
||||||
|
@ -76,13 +51,13 @@ class ExportVMActionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
should "delete the temporary file if it exists" do
|
should "delete the temporary file if it exists" do
|
||||||
File.expects(:unlink).with(@temp_dir).once
|
File.expects(:unlink).with(@temp_dir).once
|
||||||
@instance.cleanup
|
@instance.recover(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not delete anything if it doesn't exist" do
|
should "not delete anything if it doesn't exist" do
|
||||||
File.stubs(:exist?).returns(false)
|
File.stubs(:exist?).returns(false)
|
||||||
File.expects(:unlink).never
|
File.expects(:unlink).never
|
||||||
@instance.cleanup
|
@instance.recover(nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue