From b2c2c76b557ef74e05d5e09856795cb445b8455b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 8 Jul 2010 20:33:47 -0700 Subject: [PATCH] Provisioner now uses the action environment --- lib/vagrant/action/vm/provision.rb | 4 +-- lib/vagrant/provisioners/base.rb | 26 ++++++++++++------- test/vagrant/action/vm/provision_test.rb | 6 ++--- test/vagrant/provisioners/base_test.rb | 11 +++++--- test/vagrant/provisioners/chef_server_test.rb | 9 ++++--- test/vagrant/provisioners/chef_solo_test.rb | 9 ++++--- test/vagrant/provisioners/chef_test.rb | 9 ++++--- 7 files changed, 47 insertions(+), 27 deletions(-) diff --git a/lib/vagrant/action/vm/provision.rb b/lib/vagrant/action/vm/provision.rb index f14c9d494..aa5da22d0 100644 --- a/lib/vagrant/action/vm/provision.rb +++ b/lib/vagrant/action/vm/provision.rb @@ -26,7 +26,7 @@ module Vagrant provisioner = @env["config"].vm.provisioner if provisioner.is_a?(Class) - @provisioner = provisioner.new(@env["vm"]) + @provisioner = provisioner.new(@env) return @env.error!(:provisioner_invalid_class) unless @provisioner.is_a?(Provisioners::Base) elsif provisioner.is_a?(Symbol) # We have a few hard coded provisioners for built-ins @@ -37,7 +37,7 @@ module Vagrant provisioner_klass = mapping[provisioner] return @env.error!(:provisioner_unknown_type, :provisioner => provisioner.to_s) if provisioner_klass.nil? - @provisioner = provisioner_klass.new(@env["vm"]) + @provisioner = provisioner_klass.new(@env) end @env.logger.info "Provisioning enabled with #{@provisioner.class}" diff --git a/lib/vagrant/provisioners/base.rb b/lib/vagrant/provisioners/base.rb index f393e2152..be2d450f0 100644 --- a/lib/vagrant/provisioners/base.rb +++ b/lib/vagrant/provisioners/base.rb @@ -7,19 +7,27 @@ module Vagrant class Base include Vagrant::Util - # The VM which this is being provisioned for - attr_reader :vm + # The environment which provisioner is running in. This is a + # {Vagrant::Action::Environment} + attr_reader :action_env - def initialize(vm) - @vm = vm + def initialize(env) + @action_env = env end - # This method returns the environment which the provisioner is working - # on. This is also the environment of the VM. This method is provided - # as a simple helper since the environment is often used throughout the - # provisioner. + # Returns the actual {Vagrant::Environment} which this provisioner + # represents. + # + # @return [Vagrant::Environment] def env - @vm.env + action_env.env + end + + # Returns the VM which this provisioner is working on. + # + # @return [Vagrant::VM] + def vm + env.vm end # This method returns the environment's logger as a convenience diff --git a/test/vagrant/action/vm/provision_test.rb b/test/vagrant/action/vm/provision_test.rb index 279c89d3b..bdc34e2a9 100644 --- a/test/vagrant/action/vm/provision_test.rb +++ b/test/vagrant/action/vm/provision_test.rb @@ -48,13 +48,13 @@ class ProvisionVMActionTest < Test::Unit::TestCase @prov.stubs(:prepare) @klass = mock("klass") @klass.stubs(:is_a?).with(Class).returns(true) - @klass.stubs(:new).with(@env["vm"]).returns(@prov) + @klass.stubs(:new).with(@env).returns(@prov) @env["config"].vm.provisioner = @klass end should "set the provisioner to an instantiation of the class" do - @klass.expects(:new).with(@vm).once.returns(@prov) + @klass.expects(:new).with(@env).once.returns(@prov) assert_equal @prov, @instance.load_provisioner end @@ -77,7 +77,7 @@ class ProvisionVMActionTest < Test::Unit::TestCase instance = mock("instance") instance.expects(:prepare).once - provisioner.expects(:new).with(@vm).returns(instance) + provisioner.expects(:new).with(@env).returns(instance) assert_equal instance, @instance.load_provisioner end diff --git a/test/vagrant/provisioners/base_test.rb b/test/vagrant/provisioners/base_test.rb index 1820bfa46..ec3947f63 100644 --- a/test/vagrant/provisioners/base_test.rb +++ b/test/vagrant/provisioners/base_test.rb @@ -7,13 +7,16 @@ class BaseProvisionerTest < Test::Unit::TestCase context "base instance" do setup do - @vm = mock("vm") - @base = Vagrant::Provisioners::Base.new(@vm) + @env = Vagrant::Action::Environment.new(mock_environment) + @base = Vagrant::Provisioners::Base.new(@env) end should "set the environment" do - base = Vagrant::Provisioners::Base.new(@vm) - assert_equal @vm, base.vm + assert_equal @env.env, @base.env + end + + should "return the VM which the provisioner is acting on" do + assert_equal @env.env.vm, @base.vm end should "implement provision! which does nothing" do diff --git a/test/vagrant/provisioners/chef_server_test.rb b/test/vagrant/provisioners/chef_server_test.rb index 026979c28..c3d6c6cc4 100644 --- a/test/vagrant/provisioners/chef_server_test.rb +++ b/test/vagrant/provisioners/chef_server_test.rb @@ -2,9 +2,12 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') class ChefServerProvisionerTest < Test::Unit::TestCase setup do - @vm = mock_vm - @env = @vm.env - @action = Vagrant::Provisioners::ChefServer.new(@vm) + @action_env = Vagrant::Action::Environment.new(mock_environment) + @action_env.env.vm = mock_vm + + @action = Vagrant::Provisioners::ChefServer.new(@action_env) + @env = @action.env + @vm = @action.vm end context "provisioning" do diff --git a/test/vagrant/provisioners/chef_solo_test.rb b/test/vagrant/provisioners/chef_solo_test.rb index ce33a3f09..f92af4218 100644 --- a/test/vagrant/provisioners/chef_solo_test.rb +++ b/test/vagrant/provisioners/chef_solo_test.rb @@ -2,9 +2,12 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') class ChefSoloProvisionerTest < Test::Unit::TestCase setup do - @vm = mock_vm - @env = @vm.env - @action = Vagrant::Provisioners::ChefSolo.new(@vm) + @action_env = Vagrant::Action::Environment.new(mock_environment) + @action_env.env.vm = mock_vm + + @action = Vagrant::Provisioners::ChefSolo.new(@action_env) + @env = @action.env + @vm = @action.vm end context "preparing" do diff --git a/test/vagrant/provisioners/chef_test.rb b/test/vagrant/provisioners/chef_test.rb index bf9ca1768..6e98e1c57 100644 --- a/test/vagrant/provisioners/chef_test.rb +++ b/test/vagrant/provisioners/chef_test.rb @@ -2,9 +2,12 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') class ChefProvisionerTest < Test::Unit::TestCase setup do - @vm = mock_vm - @env = @vm.env - @action = Vagrant::Provisioners::Chef.new(@vm) + @action_env = Vagrant::Action::Environment.new(mock_environment) + @action_env.env.vm = mock_vm + + @action = Vagrant::Provisioners::Chef.new(@action_env) + @env = @action.env + @vm = @action.vm end context "preparing" do