From a0fa3755b50b5924ac2e6f6593e09527b2e0f7e2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 13 Jul 2010 20:35:47 -0700 Subject: [PATCH] Halt on destroy will not attempt graceful [closes GH-110] --- lib/vagrant/action/builtin.rb | 2 +- lib/vagrant/action/vm/halt.rb | 5 +++-- test/vagrant/action/vm/halt_test.rb | 9 ++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/vagrant/action/builtin.rb b/lib/vagrant/action/builtin.rb index ea4387155..ec55ea86d 100644 --- a/lib/vagrant/action/builtin.rb +++ b/lib/vagrant/action/builtin.rb @@ -71,7 +71,7 @@ module Vagrant # destroy - Halts, cleans up, and destroys an existing VM destroy = Builder.new do - use Action[:halt] + use Action[:halt], :force => true use VM::DestroyUnusedNetworkInterfaces use VM::Destroy end diff --git a/lib/vagrant/action/vm/halt.rb b/lib/vagrant/action/vm/halt.rb index 4615c49be..8bd069408 100644 --- a/lib/vagrant/action/vm/halt.rb +++ b/lib/vagrant/action/vm/halt.rb @@ -4,13 +4,14 @@ module Vagrant class Halt include ExceptionCatcher - def initialize(app, env) + def initialize(app, env, options=nil) @app = app + env.merge!(options || {}) end def call(env) if env["vm"].vm.running? - if !env["force"] + if !env[:force] catch_action_exception(env) { env["vm"].system.halt } return if env.error? end diff --git a/test/vagrant/action/vm/halt_test.rb b/test/vagrant/action/vm/halt_test.rb index 75641fbae..a1a17d74f 100644 --- a/test/vagrant/action/vm/halt_test.rb +++ b/test/vagrant/action/vm/halt_test.rb @@ -17,6 +17,13 @@ class HaltVMActionTest < Test::Unit::TestCase @instance = @klass.new(@app, @env) end + context "initializing" do + should "merge in the given options" do + @klass.new(@app, @env, :foo => :bar) + assert_equal :bar, @env[:foo] + end + end + context "calling" do setup do @internal_vm.stubs(:running?).returns(true) @@ -54,7 +61,7 @@ class HaltVMActionTest < Test::Unit::TestCase end should "not call halt on the system if forcing" do - @env["force"] = true + @env[:force] = true @vm.system.expects(:halt).never @instance.call(@env) end