moved rescue to recover
This commit is contained in:
parent
0c011e80c7
commit
c519f14626
|
@ -22,6 +22,8 @@ module Vagrant
|
||||||
return if env.error?
|
return if env.error?
|
||||||
|
|
||||||
@app.call(@env)
|
@app.call(@env)
|
||||||
|
|
||||||
|
recover(env) # called in both cases to cleanup workspace
|
||||||
end
|
end
|
||||||
|
|
||||||
def instantiate_downloader
|
def instantiate_downloader
|
||||||
|
@ -48,7 +50,7 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def rescue(env)
|
def recover(env)
|
||||||
if temp_path && File.exist?(temp_path)
|
if temp_path && File.exist?(temp_path)
|
||||||
env.logger.info "Cleaning up downloaded box..."
|
env.logger.info "Cleaning up downloaded box..."
|
||||||
File.unlink(temp_path)
|
File.unlink(temp_path)
|
||||||
|
|
|
@ -32,7 +32,7 @@ module Vagrant
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
def rescue(env)
|
def recover(env)
|
||||||
# Cleanup any packaged files if the packaging failed at some point.
|
# Cleanup any packaged files if the packaging failed at some point.
|
||||||
File.delete(tar_path) if File.exist?(tar_path)
|
File.delete(tar_path) if File.exist?(tar_path)
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,7 +25,7 @@ module Vagrant
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
def rescue(env)
|
def recover(env)
|
||||||
# Interrupted, destroy the VM
|
# Interrupted, destroy the VM
|
||||||
env["actions"].run(:destroy)
|
env["actions"].run(:destroy)
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,7 +21,7 @@ module Vagrant
|
||||||
|
|
||||||
def begin_rescue(env)
|
def begin_rescue(env)
|
||||||
@stack.reverse.each do |act|
|
@stack.reverse.each do |act|
|
||||||
act.rescue(env) if act.respond_to?(:rescue)
|
act.recover(env) if act.respond_to?(:recover)
|
||||||
end
|
end
|
||||||
|
|
||||||
exit if env.interrupted?
|
exit if env.interrupted?
|
||||||
|
|
|
@ -32,6 +32,7 @@ class DownloadBoxActionTest < Test::Unit::TestCase
|
||||||
@instance.expects(:instantiate_downloader).in_sequence(seq).returns(true)
|
@instance.expects(:instantiate_downloader).in_sequence(seq).returns(true)
|
||||||
@instance.expects(:download).in_sequence(seq)
|
@instance.expects(:download).in_sequence(seq)
|
||||||
@app.expects(:call).with(@env).in_sequence(seq)
|
@app.expects(:call).with(@env).in_sequence(seq)
|
||||||
|
@instance.expects(:recover).with(@env).in_sequence(seq)
|
||||||
@instance.call(@env)
|
@instance.call(@env)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -113,13 +114,13 @@ class DownloadBoxActionTest < 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_path).once
|
File.expects(:unlink).with(@temp_path).once
|
||||||
@instance.rescue(@env)
|
@instance.recover(@env)
|
||||||
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.rescue(@env)
|
@instance.recover(@env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -110,14 +110,14 @@ class PackageGeneralActionTest < Test::Unit::TestCase
|
||||||
File.expects(:exist?).with(@instance.tar_path).returns(false)
|
File.expects(:exist?).with(@instance.tar_path).returns(false)
|
||||||
File.expects(:delete).never
|
File.expects(:delete).never
|
||||||
|
|
||||||
@instance.rescue(@env)
|
@instance.recover(@env)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "delete the packaged box if it exists" do
|
should "delete the packaged box if it exists" do
|
||||||
File.expects(:exist?).returns(true)
|
File.expects(:exist?).returns(true)
|
||||||
File.expects(:delete).with(@instance.tar_path).once
|
File.expects(:delete).with(@instance.tar_path).once
|
||||||
|
|
||||||
@instance.rescue(@env)
|
@instance.recover(@env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -37,11 +37,11 @@ class ImportVMActionTest < Test::Unit::TestCase
|
||||||
assert @env.error?
|
assert @env.error?
|
||||||
end
|
end
|
||||||
|
|
||||||
should "run the destroy action on rescue" do
|
should "run the destroy action on recover" do
|
||||||
env = mock("env")
|
env = mock("env")
|
||||||
destroy = mock("destory")
|
destroy = mock("destory")
|
||||||
env.expects(:[]).with("actions").returns(destroy)
|
env.expects(:[]).with("actions").returns(destroy)
|
||||||
destroy.expects(:run).with(:destroy)
|
destroy.expects(:run).with(:destroy)
|
||||||
@instance.rescue(env)
|
@instance.recover(env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -55,7 +55,7 @@ class ActionWardenTest < Test::Unit::TestCase
|
||||||
@instance.call(new_env)
|
@instance.call(new_env)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "begin rescue on environment error" do
|
should "begin recover on environment error" do
|
||||||
@instance.expects(:begin_rescue)
|
@instance.expects(:begin_rescue)
|
||||||
@instance.actions << lambda {}
|
@instance.actions << lambda {}
|
||||||
@instance.actions.first.expects(:call).never
|
@instance.actions.first.expects(:call).never
|
||||||
|
@ -70,7 +70,7 @@ class ActionWardenTest < Test::Unit::TestCase
|
||||||
@instance.call(new_env_with_error)
|
@instance.call(new_env_with_error)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "call begin rescue when the called action returns with an env error" do
|
should "call begin recover when the called action returns with an env error" do
|
||||||
class Foo
|
class Foo
|
||||||
def initialize(*args); end
|
def initialize(*args); end
|
||||||
def call(env)
|
def call(env)
|
||||||
|
@ -90,23 +90,23 @@ class ActionWardenTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "rescue" do
|
context "recover" do
|
||||||
should "call rescue on all items in the stack" do
|
should "call recover on all items in the stack" do
|
||||||
mock_action = rescueable_mock("action")
|
mock_action = rescueable_mock("action")
|
||||||
mock_action.expects(:rescue).times(2)
|
mock_action.expects(:recover).times(2)
|
||||||
@instance.stack = [mock_action, mock_action]
|
@instance.stack = [mock_action, mock_action]
|
||||||
@instance.begin_rescue(new_env)
|
@instance.begin_rescue(new_env)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "call rescue on stack in reversed order" do
|
should "call recover on stack in reversed order" do
|
||||||
seq = sequence("reverse")
|
seq = sequence("reverse")
|
||||||
first_mock_action = rescueable_mock("first")
|
first_mock_action = rescueable_mock("first")
|
||||||
second_mock_action = rescueable_mock("second")
|
second_mock_action = rescueable_mock("second")
|
||||||
|
|
||||||
@instance.stack = [first_mock_action, second_mock_action]
|
@instance.stack = [first_mock_action, second_mock_action]
|
||||||
|
|
||||||
second_mock_action.expects(:rescue).in_sequence(seq)
|
second_mock_action.expects(:recover).in_sequence(seq)
|
||||||
first_mock_action.expects(:rescue).in_sequence(seq)
|
first_mock_action.expects(:recover).in_sequence(seq)
|
||||||
|
|
||||||
@instance.begin_rescue(new_env)
|
@instance.begin_rescue(new_env)
|
||||||
end
|
end
|
||||||
|
@ -138,7 +138,7 @@ class ActionWardenTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def rescueable_mock(name)
|
def rescueable_mock(name)
|
||||||
mock_action = mock(name)
|
mock_action = mock(name)
|
||||||
mock_action.stubs(:respond_to?).with(:rescue).returns(true)
|
mock_action.stubs(:respond_to?).with(:recover).returns(true)
|
||||||
mock_action
|
mock_action
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue