diff --git a/CHANGELOG.md b/CHANGELOG.md index c8d8e8415..19c426e7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,14 @@ ## 0.5.1 (unreleased) + - Fixed `halt`, `destroy`, `reload` to where they failed if the VM was + in a saved state. [GH-123] - Added `config.chef.recipe_url` which allows you to specify a URL to a gzipped tar file for chef solo to download cookbooks. See the [chef-solo docs](http://wiki.opscode.com/display/chef/Chef+Solo#ChefSolo-RunningfromaURL) for more information. + [GH-121] - Added `vagrant box repackage` which repackages boxes which have been added. This is useful in case you want to redistribute a base - box you have but may have lost the actual "box" file. + box you have but may have lost the actual "box" file. [GH-120] ## Previous diff --git a/lib/vagrant/action/builtin.rb b/lib/vagrant/action/builtin.rb index 93071e261..765ee0a40 100644 --- a/lib/vagrant/action/builtin.rb +++ b/lib/vagrant/action/builtin.rb @@ -32,6 +32,7 @@ module Vagrant # halt - Halts the VM, attempting gracefully but then forcing # a restart if fails. halt = Builder.new do + use VM::DiscardState use VM::Halt use VM::DisableNetworks end diff --git a/lib/vagrant/action/vm/discard_state.rb b/lib/vagrant/action/vm/discard_state.rb new file mode 100644 index 000000000..087ca69f0 --- /dev/null +++ b/lib/vagrant/action/vm/discard_state.rb @@ -0,0 +1,22 @@ +module Vagrant + class Action + module VM + # Discards the saved state of the VM if its saved. If its + # not saved, does nothing. + class DiscardState + def initialize(app, env) + @app = app + end + + def call(env) + if env["vm"].vm.saved? + env.logger.info "Discarding saved state of VM..." + env["vm"].vm.discard_state + end + + @app.call(env) + end + end + end + end +end diff --git a/test/vagrant/action/vm/discard_state_test.rb b/test/vagrant/action/vm/discard_state_test.rb new file mode 100644 index 000000000..3e710b2e6 --- /dev/null +++ b/test/vagrant/action/vm/discard_state_test.rb @@ -0,0 +1,36 @@ +require "test_helper" + +class DiscardStateVMActionTest < Test::Unit::TestCase + setup do + @klass = Vagrant::Action::VM::DiscardState + @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 + setup do + @internal_vm.stubs(:saved?).returns(false) + end + + should "do nothing if not saved and continue chain" do + @internal_vm.expects(:saved?).returns(false) + @app.expects(:call).with(@env).once + @instance.call(@env) + end + + should "discard state and continue chain" do + seq = sequence("sequence") + @internal_vm.expects(:saved?).returns(true).in_sequence(seq) + @internal_vm.expects(:discard_state).in_sequence(seq) + @app.expects(:call).with(@env).once.in_sequence(seq) + @instance.call(@env) + end + end +end