Provisioner now uses the action environment

This commit is contained in:
Mitchell Hashimoto 2010-07-08 20:33:47 -07:00
parent 5d2e3d9f6f
commit b2c2c76b55
7 changed files with 47 additions and 27 deletions

View File

@ -26,7 +26,7 @@ module Vagrant
provisioner = @env["config"].vm.provisioner provisioner = @env["config"].vm.provisioner
if provisioner.is_a?(Class) 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) return @env.error!(:provisioner_invalid_class) unless @provisioner.is_a?(Provisioners::Base)
elsif provisioner.is_a?(Symbol) elsif provisioner.is_a?(Symbol)
# We have a few hard coded provisioners for built-ins # We have a few hard coded provisioners for built-ins
@ -37,7 +37,7 @@ module Vagrant
provisioner_klass = mapping[provisioner] provisioner_klass = mapping[provisioner]
return @env.error!(:provisioner_unknown_type, :provisioner => provisioner.to_s) if provisioner_klass.nil? 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 end
@env.logger.info "Provisioning enabled with #{@provisioner.class}" @env.logger.info "Provisioning enabled with #{@provisioner.class}"

View File

@ -7,19 +7,27 @@ module Vagrant
class Base class Base
include Vagrant::Util include Vagrant::Util
# The VM which this is being provisioned for # The environment which provisioner is running in. This is a
attr_reader :vm # {Vagrant::Action::Environment}
attr_reader :action_env
def initialize(vm) def initialize(env)
@vm = vm @action_env = env
end end
# This method returns the environment which the provisioner is working # Returns the actual {Vagrant::Environment} which this provisioner
# on. This is also the environment of the VM. This method is provided # represents.
# as a simple helper since the environment is often used throughout the #
# provisioner. # @return [Vagrant::Environment]
def env 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 end
# This method returns the environment's logger as a convenience # This method returns the environment's logger as a convenience

View File

@ -48,13 +48,13 @@ class ProvisionVMActionTest < Test::Unit::TestCase
@prov.stubs(:prepare) @prov.stubs(:prepare)
@klass = mock("klass") @klass = mock("klass")
@klass.stubs(:is_a?).with(Class).returns(true) @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 @env["config"].vm.provisioner = @klass
end end
should "set the provisioner to an instantiation of the class" do 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 assert_equal @prov, @instance.load_provisioner
end end
@ -77,7 +77,7 @@ class ProvisionVMActionTest < Test::Unit::TestCase
instance = mock("instance") instance = mock("instance")
instance.expects(:prepare).once instance.expects(:prepare).once
provisioner.expects(:new).with(@vm).returns(instance) provisioner.expects(:new).with(@env).returns(instance)
assert_equal instance, @instance.load_provisioner assert_equal instance, @instance.load_provisioner
end end

View File

@ -7,13 +7,16 @@ class BaseProvisionerTest < Test::Unit::TestCase
context "base instance" do context "base instance" do
setup do setup do
@vm = mock("vm") @env = Vagrant::Action::Environment.new(mock_environment)
@base = Vagrant::Provisioners::Base.new(@vm) @base = Vagrant::Provisioners::Base.new(@env)
end end
should "set the environment" do should "set the environment" do
base = Vagrant::Provisioners::Base.new(@vm) assert_equal @env.env, @base.env
assert_equal @vm, base.vm end
should "return the VM which the provisioner is acting on" do
assert_equal @env.env.vm, @base.vm
end end
should "implement provision! which does nothing" do should "implement provision! which does nothing" do

View File

@ -2,9 +2,12 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
class ChefServerProvisionerTest < Test::Unit::TestCase class ChefServerProvisionerTest < Test::Unit::TestCase
setup do setup do
@vm = mock_vm @action_env = Vagrant::Action::Environment.new(mock_environment)
@env = @vm.env @action_env.env.vm = mock_vm
@action = Vagrant::Provisioners::ChefServer.new(@vm)
@action = Vagrant::Provisioners::ChefServer.new(@action_env)
@env = @action.env
@vm = @action.vm
end end
context "provisioning" do context "provisioning" do

View File

@ -2,9 +2,12 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
class ChefSoloProvisionerTest < Test::Unit::TestCase class ChefSoloProvisionerTest < Test::Unit::TestCase
setup do setup do
@vm = mock_vm @action_env = Vagrant::Action::Environment.new(mock_environment)
@env = @vm.env @action_env.env.vm = mock_vm
@action = Vagrant::Provisioners::ChefSolo.new(@vm)
@action = Vagrant::Provisioners::ChefSolo.new(@action_env)
@env = @action.env
@vm = @action.vm
end end
context "preparing" do context "preparing" do

View File

@ -2,9 +2,12 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
class ChefProvisionerTest < Test::Unit::TestCase class ChefProvisionerTest < Test::Unit::TestCase
setup do setup do
@vm = mock_vm @action_env = Vagrant::Action::Environment.new(mock_environment)
@env = @vm.env @action_env.env.vm = mock_vm
@action = Vagrant::Provisioners::Chef.new(@vm)
@action = Vagrant::Provisioners::Chef.new(@action_env)
@env = @action.env
@vm = @action.vm
end end
context "preparing" do context "preparing" do