From 6f287aa17a461b57db109ee65f8361b5927ccb99 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 26 May 2010 21:13:56 -0700 Subject: [PATCH] Fix some small issues with up, down, and halt with the latest refactor. --- lib/vagrant/actions/vm/down.rb | 2 +- lib/vagrant/actions/vm/halt.rb | 4 ++++ lib/vagrant/actions/vm/start.rb | 7 ++++++- test/vagrant/actions/vm/down_test.rb | 2 +- test/vagrant/actions/vm/halt_test.rb | 12 ++++++++++++ test/vagrant/actions/vm/start_test.rb | 18 ++++++++++++++++++ 6 files changed, 42 insertions(+), 3 deletions(-) diff --git a/lib/vagrant/actions/vm/down.rb b/lib/vagrant/actions/vm/down.rb index 1b6457746..2092180c7 100644 --- a/lib/vagrant/actions/vm/down.rb +++ b/lib/vagrant/actions/vm/down.rb @@ -5,7 +5,7 @@ module Vagrant def prepare # The true as the 2nd parameter always forces the shutdown so its # fast (since we're destroying anyways) - @runner.add_action(Halt, true) if @runner.vm.running? + @runner.add_action(Halt, :force => true) if @runner.vm.running? @runner.add_action(Destroy) end diff --git a/lib/vagrant/actions/vm/halt.rb b/lib/vagrant/actions/vm/halt.rb index 4a9a026cd..ca5c9abab 100644 --- a/lib/vagrant/actions/vm/halt.rb +++ b/lib/vagrant/actions/vm/halt.rb @@ -14,6 +14,10 @@ module Vagrant end end end + + def force? + !!options[:force] + end end end end diff --git a/lib/vagrant/actions/vm/start.rb b/lib/vagrant/actions/vm/start.rb index f084d7215..5553504a9 100644 --- a/lib/vagrant/actions/vm/start.rb +++ b/lib/vagrant/actions/vm/start.rb @@ -8,13 +8,18 @@ module Vagrant steps = [Boot] if !@runner.vm || !@runner.vm.saved? steps.unshift([Customize, ForwardPorts, SharedFolders]) - steps << Provision if !@runner.env.config.vm.provisioner.nil? && options[:provision] + steps << Provision if provision? end steps.flatten.each do |action_klass| @runner.add_action(action_klass, options) end end + + def provision? + enabled = options[:provision].nil? ? true : options[:provision] + !@runner.env.config.vm.provisioner.nil? && enabled + end end end end diff --git a/test/vagrant/actions/vm/down_test.rb b/test/vagrant/actions/vm/down_test.rb index d59d3b335..ffde492a8 100644 --- a/test/vagrant/actions/vm/down_test.rb +++ b/test/vagrant/actions/vm/down_test.rb @@ -25,7 +25,7 @@ class DownActionTest < Test::Unit::TestCase should "add the halt action if the VM is running" do @vm.expects(:running?).returns(true) - setup_action_expectations([[Vagrant::Actions::VM::Halt, true], Vagrant::Actions::VM::Destroy]) + setup_action_expectations([[Vagrant::Actions::VM::Halt, {:force => true}], Vagrant::Actions::VM::Destroy]) @action.prepare end end diff --git a/test/vagrant/actions/vm/halt_test.rb b/test/vagrant/actions/vm/halt_test.rb index eb814e776..85f240cd0 100644 --- a/test/vagrant/actions/vm/halt_test.rb +++ b/test/vagrant/actions/vm/halt_test.rb @@ -6,6 +6,18 @@ class HaltActionTest < Test::Unit::TestCase @runner.stubs(:system).returns(linux_system(@vm)) end + context "force?" do + should "not force by default" do + @action.options[:force] = nil + assert !@action.force? + end + + should "force if specified" do + @action.options[:force] = true + assert @action.force? + end + end + context "executing" do setup do @vm.stubs(:running?).returns(true) diff --git a/test/vagrant/actions/vm/start_test.rb b/test/vagrant/actions/vm/start_test.rb index dbbcb39e2..426c4953e 100644 --- a/test/vagrant/actions/vm/start_test.rb +++ b/test/vagrant/actions/vm/start_test.rb @@ -52,4 +52,22 @@ class StartActionTest < Test::Unit::TestCase @action.prepare end end + + context "provision?" do + should "return false if no provisioner is set" do + @vm.env.config.vm.provisioner = nil + assert !@action.provision? + end + + should "return true if a provisioner is set" do + @vm.env.config.vm.provisioner = :chef_solo + assert @action.provision? + end + + should "return false if provisioning is specifically disabled" do + @vm.env.config.vm.provisioner = :chef_solo + @action.options[:provision] = false + assert !@action.provision? + end + end end