From eaaf55ea8a70f2c46314ba7cf6435b558f01c779 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 3 Oct 2010 18:34:33 -0700 Subject: [PATCH] `up --no-provision` works again. This disables provisioning during the process. --- CHANGELOG.md | 2 ++ lib/vagrant/action/vm/provision.rb | 3 ++- lib/vagrant/command/up.rb | 5 ++--- lib/vagrant/vm.rb | 4 ++-- test/vagrant/action/vm/provision_test.rb | 14 ++++++++++++++ test/vagrant/vm_test.rb | 14 ++++++++++++-- 6 files changed, 34 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 187204390..c4b9dae32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.6.4 (unreleased) + - `up --no-provision` works again. This disables provisioning during the + boot process. - Action warden doesn't do recovery process on `SystemExit` exceptions, allowing the double ctrl-C to work properly again. [related to GH-166] - Initial Vagrantfile is now heavily commented with various available diff --git a/lib/vagrant/action/vm/provision.rb b/lib/vagrant/action/vm/provision.rb index b8771746e..9a370f766 100644 --- a/lib/vagrant/action/vm/provision.rb +++ b/lib/vagrant/action/vm/provision.rb @@ -5,6 +5,7 @@ module Vagrant def initialize(app, env) @app = app @env = env + @env["provision.enabled"] = true if !@env.has_key?("provision.enabled") load_provisioner if provisioning_enabled? end @@ -19,7 +20,7 @@ module Vagrant end def provisioning_enabled? - !@env["config"].vm.provisioner.nil? + !@env["config"].vm.provisioner.nil? && @env["provision.enabled"] end def load_provisioner diff --git a/lib/vagrant/command/up.rb b/lib/vagrant/command/up.rb index 9b29292ba..fa81a0030 100644 --- a/lib/vagrant/command/up.rb +++ b/lib/vagrant/command/up.rb @@ -5,13 +5,12 @@ module Vagrant register "up", "Creates the Vagrant environment" def execute - # TODO: Make the options[:provision] actually mean something target_vms.each do |vm| if vm.created? vm.env.ui.info I18n.t("vagrant.commands.up.vm_created") - vm.start + vm.start("provision.enabled" => options[:provision]) else - vm.up + vm.up("provision.enabled" => options[:provision]) end end end diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index 26414e481..038c1d1ee 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -115,11 +115,11 @@ module Vagrant env.actions.run(:up, options) end - def start + def start(options=nil) return if @vm.running? return resume if @vm.saved? - env.actions.run(:start) + env.actions.run(:start, options) end def halt(options=nil) diff --git a/test/vagrant/action/vm/provision_test.rb b/test/vagrant/action/vm/provision_test.rb index 6a683df43..4607fa70d 100644 --- a/test/vagrant/action/vm/provision_test.rb +++ b/test/vagrant/action/vm/provision_test.rb @@ -31,6 +31,12 @@ class ProvisionVMActionTest < Test::Unit::TestCase @klass.any_instance.expects(:load_provisioner).never @klass.new(@app, @env) end + + should "not load provisioner if disabled through env hash" do + @env["provision.enabled"] = false + @klass.any_instance.expects(:load_provisioner).never + @klass.new(@app, @env) + end end context "with an instance" do @@ -122,6 +128,14 @@ class ProvisionVMActionTest < Test::Unit::TestCase @instance.call(@env) end + + should "continue chain and not provision if not enabled through env hash" do + @env["provision.enabled"] = false + @prov.expects(:provision!).never + @app.expects(:call).with(@env).once + + @instance.call(@env) + end end end end diff --git a/test/vagrant/vm_test.rb b/test/vagrant/vm_test.rb index 5b2070698..15c6bb034 100644 --- a/test/vagrant/vm_test.rb +++ b/test/vagrant/vm_test.rb @@ -177,6 +177,11 @@ class VMTest < Test::Unit::TestCase @vm.env.actions.expects(:run).with(:up, nil).once @vm.up end + + should "forward options to the action sequence" do + @vm.env.actions.expects(:run).with(:up, :foo => :bar).once + @vm.up(:foo => :bar) + end end context "halting" do @@ -236,14 +241,19 @@ class VMTest < Test::Unit::TestCase should "execute the resume action if saved" do @mock_vm.expects(:saved?).returns(true) @vm.expects(:resume).once - @vm.env.actions.expects(:run).with(:start).never + @vm.env.actions.expects(:run).with(:start, nil).never @vm.start end should "execute the start action" do - @vm.env.actions.expects(:run).with(:start).once + @vm.env.actions.expects(:run).with(:start, nil).once @vm.start end + + should "forward options to the action sequence" do + @vm.env.actions.expects(:run).with(:start, :foo => :bar).once + @vm.start(:foo => :bar) + end end end end