Destroy middleware
This commit is contained in:
parent
a14850c564
commit
77cca19b7e
|
@ -20,6 +20,8 @@ module Vagrant
|
|||
|
||||
down = Builder.new do
|
||||
use VM::Halt
|
||||
use VM::DestroyUnusedNetworkInterfaces
|
||||
use VM::Destroy
|
||||
end
|
||||
|
||||
register :up, up
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
module Vagrant
|
||||
class Action
|
||||
module VM
|
||||
class Destroy
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
env.logger.info "Destroying VM and associated drives..."
|
||||
env["vm"].vm.destroy(:destroy_medium => :delete)
|
||||
env["vm"].vm = nil
|
||||
env.env.update_dotfile
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,26 @@
|
|||
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||
|
||||
class DestroyVMActionTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@klass = Vagrant::Action::VM::Destroy
|
||||
@app, @env = mock_action_data
|
||||
|
||||
@vm = mock("vm")
|
||||
@env["vm"] = @vm
|
||||
|
||||
@internal_vm = mock("internal")
|
||||
@vm.stubs(:vm).returns(@internal_vm)
|
||||
|
||||
@instance = @klass.new(@app, @env)
|
||||
end
|
||||
|
||||
context "destroying the VM" do
|
||||
should "destroy VM and attached images" do
|
||||
@internal_vm.expects(:destroy).with(:destroy_medium => :delete).once
|
||||
@env["vm"].expects(:vm=).with(nil).once
|
||||
@env.env.expects(:update_dotfile).once
|
||||
@app.expects(:call).with(@env).once
|
||||
@instance.call(@env)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue