Suspend subcommand

This commit is contained in:
Mitchell Hashimoto 2010-04-13 16:36:08 -07:00
parent 28a2fd5466
commit 5efa7bded5
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,23 @@
module Vagrant
class Commands
# Suspend a running vagrant instance. This suspends the instance, saving
# the state of the VM and "pausing" it. The instance can be resumed
# again with {resume}.
#
# This command requires that an instance already be brought up with
# `vagrant up`.
class Suspend < Base
Base.subcommand "suspend", self
description "Suspends the currently running vagrant environment"
def execute(args=[])
env.require_persisted_vm
env.vm.suspend
end
def options_spec(opts)
opts.banner = "Usage: vagrant suspend"
end
end
end
end

View File

@ -0,0 +1,33 @@
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
class CommandsSuspendTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Commands::Suspend
@persisted_vm = mock("persisted_vm")
@persisted_vm.stubs(:execute!)
@env = mock_environment
@env.stubs(:require_persisted_vm)
@env.stubs(:vm).returns(@persisted_vm)
@instance = @klass.new(@env)
end
context "executing" do
setup do
@persisted_vm.stubs(:suspend)
@persisted_vm.stubs(:saved?).returns(false)
end
should "require a persisted VM" do
@env.expects(:require_persisted_vm).once
@instance.execute
end
should "suspend the VM" do
@persisted_vm.expects(:suspend).once
@instance.execute
end
end
end