Resume uses the resume action now
This commit is contained in:
parent
0a791d1c58
commit
da2150da89
|
@ -0,0 +1,16 @@
|
||||||
|
module Vagrant
|
||||||
|
module Actions
|
||||||
|
module VM
|
||||||
|
class Resume < Base
|
||||||
|
def execute!
|
||||||
|
if !@runner.vm.saved?
|
||||||
|
raise ActionException.new("The vagrant virtual environment you are trying to resume is not in a suspended state.")
|
||||||
|
end
|
||||||
|
|
||||||
|
logger.info "Resuming suspended VM..."
|
||||||
|
@runner.start
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -107,11 +107,7 @@ error
|
||||||
def resume
|
def resume
|
||||||
Env.load!
|
Env.load!
|
||||||
Env.require_persisted_vm
|
Env.require_persisted_vm
|
||||||
error_and_exit(<<-error) unless Env.persisted_vm.saved?
|
Env.persisted_vm.resume
|
||||||
The vagrant virtual environment you are trying to resume is not in a
|
|
||||||
suspended state.
|
|
||||||
error
|
|
||||||
Env.persisted_vm.start
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Export and package the current vm
|
# Export and package the current vm
|
||||||
|
|
|
@ -47,6 +47,10 @@ module Vagrant
|
||||||
execute!(Actions::VM::Suspend)
|
execute!(Actions::VM::Suspend)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def resume
|
||||||
|
execute!(Actions::VM::Resume)
|
||||||
|
end
|
||||||
|
|
||||||
def saved?
|
def saved?
|
||||||
@vm.saved?
|
@vm.saved?
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||||
|
|
||||||
|
class ResumeActionTest < Test::Unit::TestCase
|
||||||
|
setup do
|
||||||
|
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Resume)
|
||||||
|
mock_config
|
||||||
|
end
|
||||||
|
|
||||||
|
context "executing" do
|
||||||
|
setup do
|
||||||
|
@vm.stubs(:saved?).returns(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "save the state of the VM" do
|
||||||
|
@runner.expects(:start).once
|
||||||
|
@action.execute!
|
||||||
|
end
|
||||||
|
|
||||||
|
should "raise an ActionException if the VM is not saved" do
|
||||||
|
@vm.expects(:saved?).returns(false)
|
||||||
|
@vm.expects(:start).never
|
||||||
|
assert_raises(Vagrant::Actions::ActionException) {
|
||||||
|
@action.execute!
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -134,7 +134,7 @@ class CommandsTest < Test::Unit::TestCase
|
||||||
|
|
||||||
context "resume" do
|
context "resume" do
|
||||||
setup do
|
setup do
|
||||||
@persisted_vm.stubs(:start)
|
@persisted_vm.stubs(:resume)
|
||||||
@persisted_vm.stubs(:saved?).returns(true)
|
@persisted_vm.stubs(:saved?).returns(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -143,15 +143,8 @@ class CommandsTest < Test::Unit::TestCase
|
||||||
Vagrant::Commands.resume
|
Vagrant::Commands.resume
|
||||||
end
|
end
|
||||||
|
|
||||||
should "error and exit if the VM is not already saved" do
|
|
||||||
@persisted_vm.expects(:saved?).returns(false)
|
|
||||||
Vagrant::Commands.expects(:error_and_exit).once
|
|
||||||
@persisted_vm.expects(:save_state).never
|
|
||||||
Vagrant::Commands.resume
|
|
||||||
end
|
|
||||||
|
|
||||||
should "save the state of the VM" do
|
should "save the state of the VM" do
|
||||||
@persisted_vm.expects(:start).once
|
@persisted_vm.expects(:resume).once
|
||||||
Vagrant::Commands.resume
|
Vagrant::Commands.resume
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -68,17 +68,19 @@ class VMTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
context "suspending" do
|
context "suspending" do
|
||||||
should "check if a VM is saved" do
|
|
||||||
@mock_vm.expects(:saved?).returns("foo")
|
|
||||||
assert_equal "foo", @vm.saved?
|
|
||||||
end
|
|
||||||
|
|
||||||
should "execute the suspend action" do
|
should "execute the suspend action" do
|
||||||
@vm.expects(:execute!).with(Vagrant::Actions::VM::Suspend).once
|
@vm.expects(:execute!).with(Vagrant::Actions::VM::Suspend).once
|
||||||
@vm.suspend
|
@vm.suspend
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "resuming" do
|
||||||
|
should "execute the resume action" do
|
||||||
|
@vm.expects(:execute!).with(Vagrant::Actions::VM::Resume).once
|
||||||
|
@vm.resume
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "starting" do
|
context "starting" do
|
||||||
setup do
|
setup do
|
||||||
@mock_vm.stubs(:running?).returns(false)
|
@mock_vm.stubs(:running?).returns(false)
|
||||||
|
|
Loading…
Reference in New Issue