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