Provisioner now uses the action environment
This commit is contained in:
parent
5d2e3d9f6f
commit
b2c2c76b55
|
@ -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}"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue