Suspend middleware
This commit is contained in:
parent
d313a106a3
commit
3ed9222ea5
|
@ -33,6 +33,13 @@ module Vagrant
|
||||||
|
|
||||||
register :halt, halt
|
register :halt, halt
|
||||||
|
|
||||||
|
# suspend - Suspends the VM
|
||||||
|
suspend = Builder.new do
|
||||||
|
use VM::Suspend
|
||||||
|
end
|
||||||
|
|
||||||
|
register :suspend, suspend
|
||||||
|
|
||||||
# reload - Halts then restarts the VM
|
# reload - Halts then restarts the VM
|
||||||
reload = Builder.new do
|
reload = Builder.new do
|
||||||
use Action[:halt]
|
use Action[:halt]
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
module Vagrant
|
||||||
|
class Action
|
||||||
|
module VM
|
||||||
|
class Suspend
|
||||||
|
def initialize(app, env)
|
||||||
|
@app = app
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
if env["vm"].vm.running?
|
||||||
|
env.logger.info "Saving VM state and suspending execution..."
|
||||||
|
env["vm"].vm.save_state
|
||||||
|
end
|
||||||
|
|
||||||
|
@app.call(env)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -126,7 +126,7 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def suspend
|
def suspend
|
||||||
execute!(Actions::VM::Suspend)
|
env.actions.run(:suspend)
|
||||||
end
|
end
|
||||||
|
|
||||||
def resume
|
def resume
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||||
|
|
||||||
|
class SuspendVMActionTest < Test::Unit::TestCase
|
||||||
|
setup do
|
||||||
|
@klass = Vagrant::Action::VM::Suspend
|
||||||
|
@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 running" do
|
||||||
|
@internal_vm.expects(:running?).returns(true)
|
||||||
|
|
||||||
|
seq = sequence("seq")
|
||||||
|
@internal_vm.expects(:save_state).once.in_sequence(seq)
|
||||||
|
@app.expects(:call).with(@env).once.in_sequence(seq)
|
||||||
|
@instance.call(@env)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "do nothing if VM is not running" do
|
||||||
|
@internal_vm.expects(:running?).returns(false)
|
||||||
|
|
||||||
|
@internal_vm.expects(:save_state).never
|
||||||
|
@app.expects(:call).with(@env).once
|
||||||
|
@instance.call(@env)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -198,7 +198,7 @@ class VMTest < Test::Unit::TestCase
|
||||||
|
|
||||||
context "suspending" do
|
context "suspending" do
|
||||||
should "execute the suspend action" do
|
should "execute the suspend action" do
|
||||||
@vm.expects(:execute!).with(Vagrant::Actions::VM::Suspend).once
|
@vm.env.actions.expects(:run).with(:suspend).once
|
||||||
@vm.suspend
|
@vm.suspend
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue