Resume middleware
This commit is contained in:
parent
3ed9222ea5
commit
a11fb717b0
|
@ -40,6 +40,13 @@ module Vagrant
|
|||
|
||||
register :suspend, suspend
|
||||
|
||||
# resume - Resume a VM
|
||||
resume = Builder.new do
|
||||
use VM::Resume
|
||||
end
|
||||
|
||||
register :resume, resume
|
||||
|
||||
# reload - Halts then restarts the VM
|
||||
reload = Builder.new do
|
||||
use Action[:halt]
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
module Vagrant
|
||||
class Action
|
||||
module VM
|
||||
class Resume
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
if env["vm"].vm.saved?
|
||||
env.logger.info "Resuming suspended VM..."
|
||||
env["vm"].start
|
||||
end
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -130,7 +130,7 @@ module Vagrant
|
|||
end
|
||||
|
||||
def resume
|
||||
execute!(Actions::VM::Resume)
|
||||
env.actions.run(:resume)
|
||||
end
|
||||
|
||||
def saved?
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||
|
||||
class ResumeVMActionTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@klass = Vagrant::Action::VM::Resume
|
||||
@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 "calling" do
|
||||
should "run the proper methods when saved" do
|
||||
@internal_vm.expects(:saved?).returns(true)
|
||||
|
||||
seq = sequence("seq")
|
||||
@vm.expects(:start).once.in_sequence(seq)
|
||||
@app.expects(:call).with(@env).once.in_sequence(seq)
|
||||
@instance.call(@env)
|
||||
end
|
||||
|
||||
should "do nothing if VM is not saved" do
|
||||
@internal_vm.expects(:saved?).returns(false)
|
||||
|
||||
@vm.expects(:start).never
|
||||
@app.expects(:call).with(@env).once
|
||||
@instance.call(@env)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -205,7 +205,7 @@ class VMTest < Test::Unit::TestCase
|
|||
|
||||
context "resuming" do
|
||||
should "execute the resume action" do
|
||||
@vm.expects(:execute!).with(Vagrant::Actions::VM::Resume).once
|
||||
@vm.env.actions.expects(:run).with(:resume).once
|
||||
@vm.resume
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue