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
|
||||
Env.load!
|
||||
Env.require_persisted_vm
|
||||
error_and_exit(<<-error) unless Env.persisted_vm.saved?
|
||||
The vagrant virtual environment you are trying to resume is not in a
|
||||
suspended state.
|
||||
error
|
||||
Env.persisted_vm.start
|
||||
Env.persisted_vm.resume
|
||||
end
|
||||
|
||||
# Export and package the current vm
|
||||
|
|
|
@ -47,6 +47,10 @@ module Vagrant
|
|||
execute!(Actions::VM::Suspend)
|
||||
end
|
||||
|
||||
def resume
|
||||
execute!(Actions::VM::Resume)
|
||||
end
|
||||
|
||||
def saved?
|
||||
@vm.saved?
|
||||
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
|
||||
setup do
|
||||
@persisted_vm.stubs(:start)
|
||||
@persisted_vm.stubs(:resume)
|
||||
@persisted_vm.stubs(:saved?).returns(true)
|
||||
end
|
||||
|
||||
|
@ -143,15 +143,8 @@ class CommandsTest < Test::Unit::TestCase
|
|||
Vagrant::Commands.resume
|
||||
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
|
||||
@persisted_vm.expects(:start).once
|
||||
@persisted_vm.expects(:resume).once
|
||||
Vagrant::Commands.resume
|
||||
end
|
||||
end
|
||||
|
|
|
@ -68,17 +68,19 @@ class VMTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
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
|
||||
@vm.expects(:execute!).with(Vagrant::Actions::VM::Suspend).once
|
||||
@vm.suspend
|
||||
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
|
||||
setup do
|
||||
@mock_vm.stubs(:running?).returns(false)
|
||||
|
|
Loading…
Reference in New Issue