diff --git a/lib/vagrant/actions/vm/resume.rb b/lib/vagrant/actions/vm/resume.rb new file mode 100644 index 000000000..192ed1d0e --- /dev/null +++ b/lib/vagrant/actions/vm/resume.rb @@ -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 diff --git a/lib/vagrant/commands.rb b/lib/vagrant/commands.rb index d195a57c5..fd87251a6 100644 --- a/lib/vagrant/commands.rb +++ b/lib/vagrant/commands.rb @@ -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 diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index 847597ed9..2d85d2f90 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -47,6 +47,10 @@ module Vagrant execute!(Actions::VM::Suspend) end + def resume + execute!(Actions::VM::Resume) + end + def saved? @vm.saved? end diff --git a/test/vagrant/actions/vm/resume_test.rb b/test/vagrant/actions/vm/resume_test.rb new file mode 100644 index 000000000..5429948ad --- /dev/null +++ b/test/vagrant/actions/vm/resume_test.rb @@ -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 diff --git a/test/vagrant/commands_test.rb b/test/vagrant/commands_test.rb index 2c185ed2d..95b9939ca 100644 --- a/test/vagrant/commands_test.rb +++ b/test/vagrant/commands_test.rb @@ -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 diff --git a/test/vagrant/vm_test.rb b/test/vagrant/vm_test.rb index 066fe8ca9..eb476f71b 100644 --- a/test/vagrant/vm_test.rb +++ b/test/vagrant/vm_test.rb @@ -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)