Fixed provisioners to the new conventions. Tests passing!
This commit is contained in:
parent
cddccab9ae
commit
a91ad4d89f
|
@ -30,7 +30,7 @@ module Vagrant
|
|||
@env["config"].vm.provisioners.each do |provisioner|
|
||||
@env.ui.info I18n.t("vagrant.actions.vm.provision.enabled", :provisioner => provisioner.shortcut)
|
||||
|
||||
instance = provisioner.provisioner.new(@env)
|
||||
instance = provisioner.provisioner.new(@env, provisioner.config)
|
||||
instance.prepare
|
||||
@provisioners << instance
|
||||
end
|
||||
|
|
|
@ -11,6 +11,10 @@ module Vagrant
|
|||
# {Vagrant::Action::Environment}
|
||||
attr_reader :action_env
|
||||
|
||||
# The configuration for this provisioner. This will be an instance of
|
||||
# the `Config` class which is part of the provisioner.
|
||||
attr_reader :config
|
||||
|
||||
# Registers a provisioner with a given shortcut. This allows that provisioner
|
||||
# to be referenced with the shortcut.
|
||||
#
|
||||
|
@ -24,8 +28,9 @@ module Vagrant
|
|||
@@registered ||= {}
|
||||
end
|
||||
|
||||
def initialize(env)
|
||||
def initialize(env, config)
|
||||
@action_env = env
|
||||
@config = config
|
||||
end
|
||||
|
||||
# Returns the actual {Vagrant::Environment} which this provisioner
|
||||
|
|
|
@ -18,24 +18,24 @@ module Vagrant
|
|||
|
||||
def chown_provisioning_folder
|
||||
vm.ssh.execute do |ssh|
|
||||
ssh.exec!("sudo mkdir -p #{env.config.chef.provisioning_path}")
|
||||
ssh.exec!("sudo chown #{env.config.ssh.username} #{env.config.chef.provisioning_path}")
|
||||
ssh.exec!("sudo mkdir -p #{config.provisioning_path}")
|
||||
ssh.exec!("sudo chown #{env.config.ssh.username} #{config.provisioning_path}")
|
||||
end
|
||||
end
|
||||
|
||||
def setup_config(template, filename, template_vars)
|
||||
config_file = TemplateRenderer.render(template, {
|
||||
:log_level => env.config.chef.log_level.to_sym,
|
||||
:http_proxy => env.config.chef.http_proxy,
|
||||
:http_proxy_user => env.config.chef.http_proxy_user,
|
||||
:http_proxy_pass => env.config.chef.http_proxy_pass,
|
||||
:https_proxy => env.config.chef.https_proxy,
|
||||
:https_proxy_user => env.config.chef.https_proxy_user,
|
||||
:https_proxy_pass => env.config.chef.https_proxy_pass,
|
||||
:no_proxy => env.config.chef.no_proxy
|
||||
:log_level => config.log_level.to_sym,
|
||||
:http_proxy => config.http_proxy,
|
||||
:http_proxy_user => config.http_proxy_user,
|
||||
:http_proxy_pass => config.http_proxy_pass,
|
||||
:https_proxy => config.https_proxy,
|
||||
:https_proxy_user => config.https_proxy_user,
|
||||
:https_proxy_pass => config.https_proxy_pass,
|
||||
:no_proxy => config.no_proxy
|
||||
}.merge(template_vars))
|
||||
|
||||
vm.ssh.upload!(StringIO.new(config_file), File.join(env.config.chef.provisioning_path, filename))
|
||||
vm.ssh.upload!(StringIO.new(config_file), File.join(config.provisioning_path, filename))
|
||||
end
|
||||
|
||||
def setup_json
|
||||
|
@ -52,11 +52,11 @@ module Vagrant
|
|||
|
||||
# Merge with the "extra data" which isn't put under the
|
||||
# vagrant namespace by default
|
||||
data.merge!(env.config.chef.json)
|
||||
data.merge!(config.json)
|
||||
|
||||
json = data.to_json
|
||||
|
||||
vm.ssh.upload!(StringIO.new(json), File.join(env.config.chef.provisioning_path, "dna.json"))
|
||||
vm.ssh.upload!(StringIO.new(json), File.join(config.provisioning_path, "dna.json"))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -70,6 +70,7 @@ module Vagrant
|
|||
# This is the configuration which is available through `config.chef`
|
||||
class Config < Vagrant::Config::Base
|
||||
# Shared config
|
||||
attr_accessor :node_name
|
||||
attr_accessor :provisioning_path
|
||||
attr_accessor :log_level
|
||||
attr_accessor :json
|
||||
|
|
|
@ -12,7 +12,6 @@ module Vagrant
|
|||
attr_accessor :validation_key_path
|
||||
attr_accessor :validation_client_name
|
||||
attr_accessor :client_key_path
|
||||
attr_accessor :node_name
|
||||
|
||||
def initialize
|
||||
super
|
||||
|
@ -31,9 +30,9 @@ module Vagrant
|
|||
end
|
||||
|
||||
def prepare
|
||||
raise ChefError, :server_validation_key_required if env.config.chef.validation_key_path.nil?
|
||||
raise ChefError, :server_validation_key_required if config.validation_key_path.nil?
|
||||
raise ChefError, :server_validation_key_doesnt_exist if !File.file?(validation_key_path)
|
||||
raise ChefError, :server_url_required if env.config.chef.chef_server_url.nil?
|
||||
raise ChefError, :server_url_required if config.chef_server_url.nil?
|
||||
end
|
||||
|
||||
def provision!
|
||||
|
@ -48,7 +47,7 @@ module Vagrant
|
|||
|
||||
def create_client_key_folder
|
||||
env.ui.info I18n.t("vagrant.provisioners.chef.client_key_folder")
|
||||
path = Pathname.new(env.config.chef.client_key_path)
|
||||
path = Pathname.new(config.client_key_path)
|
||||
|
||||
vm.ssh.execute do |ssh|
|
||||
ssh.exec!("sudo mkdir -p #{path.dirname}")
|
||||
|
@ -62,16 +61,16 @@ module Vagrant
|
|||
|
||||
def setup_server_config
|
||||
setup_config("chef_server_client", "client.rb", {
|
||||
:node_name => env.config.chef.node_name,
|
||||
:chef_server_url => env.config.chef.chef_server_url,
|
||||
:validation_client_name => env.config.chef.validation_client_name,
|
||||
:node_name => config.node_name,
|
||||
:chef_server_url => config.chef_server_url,
|
||||
:validation_client_name => config.validation_client_name,
|
||||
:validation_key => guest_validation_key_path,
|
||||
:client_key => env.config.chef.client_key_path
|
||||
:client_key => config.client_key_path
|
||||
})
|
||||
end
|
||||
|
||||
def run_chef_client
|
||||
command = "cd #{env.config.chef.provisioning_path} && sudo -E chef-client -c client.rb -j dna.json"
|
||||
command = "cd #{config.provisioning_path} && sudo -E chef-client -c client.rb -j dna.json"
|
||||
|
||||
env.ui.info I18n.t("vagrant.provisioners.chef.running_client")
|
||||
vm.ssh.execute do |ssh|
|
||||
|
@ -86,11 +85,11 @@ module Vagrant
|
|||
end
|
||||
|
||||
def validation_key_path
|
||||
File.expand_path(env.config.chef.validation_key_path, env.root_path)
|
||||
File.expand_path(config.validation_key_path, env.root_path)
|
||||
end
|
||||
|
||||
def guest_validation_key_path
|
||||
File.join(env.config.chef.provisioning_path, "validation.pem")
|
||||
File.join(config.provisioning_path, "validation.pem")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -51,16 +51,16 @@ module Vagrant
|
|||
|
||||
def setup_solo_config
|
||||
setup_config("chef_solo_solo", "solo.rb", {
|
||||
:node_name => env.config.chef.node_name,
|
||||
:provisioning_path => env.config.chef.provisioning_path,
|
||||
:node_name => config.node_name,
|
||||
:provisioning_path => config.provisioning_path,
|
||||
:cookbooks_path => cookbooks_path,
|
||||
:recipe_url => env.config.chef.recipe_url,
|
||||
:recipe_url => config.recipe_url,
|
||||
:roles_path => roles_path,
|
||||
})
|
||||
end
|
||||
|
||||
def run_chef_solo
|
||||
command = "cd #{env.config.chef.provisioning_path} && sudo -E chef-solo -c solo.rb -j dna.json"
|
||||
command = "cd #{config.provisioning_path} && sudo -E chef-solo -c solo.rb -j dna.json"
|
||||
|
||||
env.ui.info I18n.t("vagrant.provisioners.chef.running_solo")
|
||||
vm.ssh.execute do |ssh|
|
||||
|
@ -86,7 +86,7 @@ module Vagrant
|
|||
end
|
||||
|
||||
def folder_path(*args)
|
||||
File.join(env.config.chef.provisioning_path, args.join("-"))
|
||||
File.join(config.provisioning_path, args.join("-"))
|
||||
end
|
||||
|
||||
def folders_path(folders, folder)
|
||||
|
@ -112,11 +112,11 @@ module Vagrant
|
|||
end
|
||||
|
||||
def host_cookbook_paths
|
||||
host_folder_paths(env.config.chef.cookbooks_path)
|
||||
host_folder_paths(config.cookbooks_path)
|
||||
end
|
||||
|
||||
def host_role_paths
|
||||
host_folder_paths(env.config.chef.roles_path)
|
||||
host_folder_paths(config.roles_path)
|
||||
end
|
||||
|
||||
def cookbook_path(i)
|
||||
|
@ -128,11 +128,11 @@ module Vagrant
|
|||
end
|
||||
|
||||
def cookbooks_path
|
||||
folders_path(env.config.chef.cookbooks_path, "cookbooks").to_json
|
||||
folders_path(config.cookbooks_path, "cookbooks").to_json
|
||||
end
|
||||
|
||||
def roles_path
|
||||
folders_path(env.config.chef.roles_path, "roles").to_json
|
||||
folders_path(config.roles_path, "roles").to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,25 +4,23 @@ module Vagrant
|
|||
error_namespace("vagrant.provisioners.puppet")
|
||||
end
|
||||
|
||||
class PuppetConfig < Vagrant::Config::Base
|
||||
# configures :puppet
|
||||
|
||||
attr_accessor :manifest_file
|
||||
attr_accessor :manifests_path
|
||||
attr_accessor :pp_path
|
||||
attr_accessor :options
|
||||
|
||||
def initialize
|
||||
@manifest_file = ""
|
||||
@manifests_path = "manifests"
|
||||
@pp_path = "/tmp/vagrant-puppet"
|
||||
@options = []
|
||||
end
|
||||
end
|
||||
|
||||
class Puppet < Base
|
||||
register :puppet
|
||||
|
||||
class Config < Vagrant::Config::Base
|
||||
attr_accessor :manifest_file
|
||||
attr_accessor :manifests_path
|
||||
attr_accessor :pp_path
|
||||
attr_accessor :options
|
||||
|
||||
def initialize
|
||||
@manifest_file = ""
|
||||
@manifests_path = "manifests"
|
||||
@pp_path = "/tmp/vagrant-puppet"
|
||||
@options = []
|
||||
end
|
||||
end
|
||||
|
||||
def prepare
|
||||
check_manifest_dir
|
||||
share_manifests
|
||||
|
@ -36,11 +34,11 @@ module Vagrant
|
|||
end
|
||||
|
||||
def check_manifest_dir
|
||||
Dir.mkdir(env.config.puppet.manifests_path) unless File.directory?(env.config.puppet.manifests_path)
|
||||
Dir.mkdir(config.manifests_path) unless File.directory?(config.manifests_path)
|
||||
end
|
||||
|
||||
def share_manifests
|
||||
env.config.vm.share_folder("manifests", env.config.puppet.pp_path, env.config.puppet.manifests_path)
|
||||
env.config.vm.share_folder("manifests", config.pp_path, config.manifests_path)
|
||||
end
|
||||
|
||||
def verify_binary(binary)
|
||||
|
@ -51,15 +49,15 @@ module Vagrant
|
|||
|
||||
def create_pp_path
|
||||
vm.ssh.execute do |ssh|
|
||||
ssh.exec!("sudo mkdir -p #{env.config.puppet.pp_path}")
|
||||
ssh.exec!("sudo chown #{env.config.ssh.username} #{env.config.puppet.pp_path}")
|
||||
ssh.exec!("sudo mkdir -p #{config.pp_path}")
|
||||
ssh.exec!("sudo chown #{env.config.ssh.username} #{config.pp_path}")
|
||||
end
|
||||
end
|
||||
|
||||
def set_manifest
|
||||
@manifest = !env.config.puppet.manifest_file.empty? ? env.config.puppet.manifest_file : "#{env.config.vm.box}.pp"
|
||||
@manifest = !config.manifest_file.empty? ? config.manifest_file : "#{env.config.vm.box}.pp"
|
||||
|
||||
if File.exists?("#{env.config.puppet.manifests_path}/#{@manifest}")
|
||||
if File.exists?("#{config.manifests_path}/#{@manifest}")
|
||||
env.ui.info I18n.t("vagrant.provisioners.puppet.manifest_to_run", :manifest => @manifest)
|
||||
return @manifest
|
||||
else
|
||||
|
@ -68,9 +66,9 @@ module Vagrant
|
|||
end
|
||||
|
||||
def run_puppet_client
|
||||
options = env.config.puppet.options
|
||||
options = config.options
|
||||
options = options.join(" ") if options.is_a?(Array)
|
||||
command = "cd #{env.config.puppet.pp_path} && sudo -E puppet #{options} #{@manifest}"
|
||||
command = "cd #{config.pp_path} && sudo -E puppet #{options} #{@manifest}"
|
||||
|
||||
env.ui.info I18n.t("vagrant.provisioners.puppet.running_puppet")
|
||||
|
||||
|
|
|
@ -4,23 +4,21 @@ module Vagrant
|
|||
error_namespace("vagrant.provisioners.puppet_server")
|
||||
end
|
||||
|
||||
class PuppetServerConfig < Vagrant::Config::Base
|
||||
# configures :puppet_server
|
||||
|
||||
attr_accessor :puppet_server
|
||||
attr_accessor :puppet_node
|
||||
attr_accessor :options
|
||||
|
||||
def initialize
|
||||
@puppet_server = "puppet"
|
||||
@puppet_node = "puppet_node"
|
||||
@options = []
|
||||
end
|
||||
end
|
||||
|
||||
class PuppetServer < Base
|
||||
register :puppet_server
|
||||
|
||||
class Config < Vagrant::Config::Base
|
||||
attr_accessor :puppet_server
|
||||
attr_accessor :puppet_node
|
||||
attr_accessor :options
|
||||
|
||||
def initialize
|
||||
@puppet_server = "puppet"
|
||||
@puppet_node = "puppet_node"
|
||||
@options = []
|
||||
end
|
||||
end
|
||||
|
||||
def provision!
|
||||
verify_binary("puppetd")
|
||||
run_puppetd_client
|
||||
|
@ -35,15 +33,15 @@ module Vagrant
|
|||
end
|
||||
|
||||
def run_puppetd_client
|
||||
options = env.config.puppet_server.options
|
||||
options = config.options
|
||||
options = options.join(" ") if options.is_a?(Array)
|
||||
if env.config.puppet_server.puppet_node
|
||||
cn = env.config.puppet_server.puppet_node
|
||||
if config.puppet_node
|
||||
cn = config.puppet_node
|
||||
else
|
||||
cn = env.config.vm.box
|
||||
end
|
||||
|
||||
command = "sudo -E puppetd #{options} --server #{env.config.puppet_server.puppet_server} --certname #{cn}"
|
||||
command = "sudo -E puppetd #{options} --server #{config.puppet_server} --certname #{cn}"
|
||||
|
||||
env.ui.info I18n.t("vagrant.provisioners.puppet_server.running_puppetd")
|
||||
|
||||
|
|
|
@ -46,14 +46,27 @@ class ProvisionVMActionTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
context "loading a provisioner" do
|
||||
setup do
|
||||
Vagrant::Provisioners::ChefSolo.any_instance.expects(:prepare).at_least(0)
|
||||
end
|
||||
|
||||
should "instantiate and prepare each provisioner" do
|
||||
Vagrant::Provisioners::ChefSolo.any_instance.expects(:prepare).times(2)
|
||||
@env["config"].vm.provision :chef_solo
|
||||
@env["config"].vm.provision :chef_solo
|
||||
@instance.load_provisioners
|
||||
|
||||
assert_equal 2, @instance.provisioners.length
|
||||
end
|
||||
|
||||
should "set the config for each provisioner" do
|
||||
@env["config"].vm.provision :chef_solo do |chef|
|
||||
chef.cookbooks_path = "foo"
|
||||
end
|
||||
|
||||
@instance.load_provisioners
|
||||
|
||||
assert_equal "foo", @instance.provisioners.first.config.cookbooks_path
|
||||
end
|
||||
end
|
||||
|
||||
context "calling" do
|
||||
|
|
|
@ -30,7 +30,8 @@ class BaseProvisionerTest < Test::Unit::TestCase
|
|||
context "base instance" do
|
||||
setup do
|
||||
@env = Vagrant::Action::Environment.new(vagrant_env)
|
||||
@base = Vagrant::Provisioners::Base.new(@env)
|
||||
@config = mock("config")
|
||||
@base = Vagrant::Provisioners::Base.new(@env, @config)
|
||||
end
|
||||
|
||||
should "set the environment" do
|
||||
|
@ -41,6 +42,10 @@ class BaseProvisionerTest < Test::Unit::TestCase
|
|||
assert_equal @env.env.vm, @base.vm
|
||||
end
|
||||
|
||||
should "provide access to the config" do
|
||||
assert_equal @config, @base.config
|
||||
end
|
||||
|
||||
should "implement provision! which does nothing" do
|
||||
assert_nothing_raised do
|
||||
assert @base.respond_to?(:provision!)
|
||||
|
|
|
@ -2,9 +2,12 @@ require "test_helper"
|
|||
|
||||
class ChefServerProvisionerTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@klass = Vagrant::Provisioners::ChefServer
|
||||
|
||||
@action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env)
|
||||
|
||||
@action = Vagrant::Provisioners::ChefServer.new(@action_env)
|
||||
@config = @klass::Config.new
|
||||
@action = @klass.new(@action_env, @config)
|
||||
@env = @action.env
|
||||
@vm = @action.vm
|
||||
end
|
||||
|
@ -29,21 +32,14 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "not raise an exception if validation_key_path is set" do
|
||||
@env = vagrant_env(vagrantfile(<<-vf))
|
||||
config.chef.validation_key_path = "7"
|
||||
config.chef.chef_server_url = "7"
|
||||
vf
|
||||
@config.validation_key_path = "7"
|
||||
@config.chef_server_url = "7"
|
||||
|
||||
@action.stubs(:env).returns(@env)
|
||||
assert_nothing_raised { @action.prepare }
|
||||
end
|
||||
|
||||
should "raise an exception if validation_key_path is nil" do
|
||||
@env = vagrant_env(vagrantfile(<<-vf))
|
||||
config.chef.validation_key_path = nil
|
||||
vf
|
||||
|
||||
@action.stubs(:env).returns(@env)
|
||||
@config.validation_key_path = nil
|
||||
|
||||
assert_raises(Vagrant::Provisioners::Chef::ChefError) {
|
||||
@action.prepare
|
||||
|
@ -51,23 +47,15 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "not raise an exception if validation_key_path does exist" do
|
||||
@env = vagrant_env(vagrantfile(<<-vf))
|
||||
config.chef.validation_key_path = "#{vagrantfile(tmp_path)}"
|
||||
config.chef.chef_server_url = "7"
|
||||
vf
|
||||
@config.validation_key_path = vagrantfile(tmp_path)
|
||||
@config.chef_server_url = "7"
|
||||
|
||||
@action.stubs(:env).returns(@env)
|
||||
assert_nothing_raised { @action.prepare }
|
||||
end
|
||||
|
||||
should "raise an exception if validation_key_path doesn't exist" do
|
||||
@env = vagrant_env(vagrantfile(<<-vf))
|
||||
config.chef.validation_key_path = "7"
|
||||
config.chef.chef_server_url = "7"
|
||||
vf
|
||||
|
||||
@action.stubs(:env).returns(@env)
|
||||
@action.stubs(:validation_key_path).returns("9")
|
||||
@config.validation_key_path = "7"
|
||||
@config.chef_server_url = "7"
|
||||
|
||||
File.expects(:file?).with(@action.validation_key_path).returns(false)
|
||||
assert_raises(Vagrant::Provisioners::Chef::ChefError) {
|
||||
|
@ -76,21 +64,14 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "not raise an exception if chef_server_url is set" do
|
||||
@env = vagrant_env(vagrantfile(<<-vf))
|
||||
config.chef.validation_key_path = "#{vagrantfile(tmp_path)}"
|
||||
config.chef.chef_server_url = "7"
|
||||
vf
|
||||
@config.validation_key_path = vagrantfile(tmp_path)
|
||||
@config.chef_server_url = "7"
|
||||
|
||||
@action.stubs(:env).returns(@env)
|
||||
assert_nothing_raised { @action.prepare }
|
||||
end
|
||||
|
||||
should "raise an exception if chef_server_url is nil" do
|
||||
@env = vagrant_env(vagrantfile(<<-vf))
|
||||
config.chef.chef_server_url = nil
|
||||
vf
|
||||
|
||||
@action.stubs(:env).returns(@env)
|
||||
@config.chef_server_url = nil
|
||||
|
||||
assert_raises(Vagrant::Provisioners::Chef::ChefError) {
|
||||
@action.prepare
|
||||
|
@ -101,7 +82,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
|
|||
context "creating the client key folder" do
|
||||
setup do
|
||||
@raw_path = "/foo/bar/baz.pem"
|
||||
@env.config.chef.client_key_path = @raw_path
|
||||
@config.client_key_path = @raw_path
|
||||
|
||||
@path = Pathname.new(@raw_path)
|
||||
end
|
||||
|
@ -126,7 +107,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
|
|||
context "the validation key path" do
|
||||
should "expand the configured key path" do
|
||||
result = mock("result")
|
||||
File.expects(:expand_path).with(@env.config.chef.validation_key_path, @env.root_path).once.returns(result)
|
||||
File.expects(:expand_path).with(@config.validation_key_path, @env.root_path).once.returns(result)
|
||||
assert_equal result, @action.validation_key_path
|
||||
end
|
||||
end
|
||||
|
@ -134,7 +115,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
|
|||
context "the guest validation key path" do
|
||||
should "be the provisioning path joined with validation.pem" do
|
||||
result = mock("result")
|
||||
File.expects(:join).with(@env.config.chef.provisioning_path, "validation.pem").once.returns(result)
|
||||
File.expects(:join).with(@config.provisioning_path, "validation.pem").once.returns(result)
|
||||
assert_equal result, @action.guest_validation_key_path
|
||||
end
|
||||
end
|
||||
|
@ -146,11 +127,11 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
|
|||
|
||||
should "call setup_config with proper variables" do
|
||||
@action.expects(:setup_config).with("chef_server_client", "client.rb", {
|
||||
:node_name => @env.config.chef.node_name,
|
||||
:chef_server_url => @env.config.chef.chef_server_url,
|
||||
:validation_client_name => @env.config.chef.validation_client_name,
|
||||
:node_name => @config.node_name,
|
||||
:chef_server_url => @config.chef_server_url,
|
||||
:validation_client_name => @config.validation_client_name,
|
||||
:validation_key => @action.guest_validation_key_path,
|
||||
:client_key => @env.config.chef.client_key_path
|
||||
:client_key => @config.client_key_path
|
||||
})
|
||||
|
||||
@action.setup_server_config
|
||||
|
@ -164,7 +145,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "cd into the provisioning directory and run chef client" do
|
||||
@ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo -E chef-client -c client.rb -j dna.json").once
|
||||
@ssh.expects(:exec!).with("cd #{@config.provisioning_path} && sudo -E chef-client -c client.rb -j dna.json").once
|
||||
@action.run_chef_client
|
||||
end
|
||||
|
||||
|
|
|
@ -2,13 +2,36 @@ require "test_helper"
|
|||
|
||||
class ChefSoloProvisionerTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@klass = Vagrant::Provisioners::ChefSolo
|
||||
|
||||
@action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env)
|
||||
|
||||
@action = Vagrant::Provisioners::ChefSolo.new(@action_env)
|
||||
@config = @klass::Config.new
|
||||
@action = @klass.new(@action_env, @config)
|
||||
@env = @action.env
|
||||
@vm = @action.vm
|
||||
end
|
||||
|
||||
context "config validation" do
|
||||
setup do
|
||||
@errors = Vagrant::Config::ErrorRecorder.new
|
||||
@config.run_list = ["foo"]
|
||||
@config.cookbooks_path = "cookbooks"
|
||||
end
|
||||
|
||||
should "be invalid if run list is empty" do
|
||||
@config.run_list = []
|
||||
@config.validate(@errors)
|
||||
assert !@errors.errors.empty?
|
||||
end
|
||||
|
||||
should "be invalid if cookbooks path is empty" do
|
||||
@config.cookbooks_path = nil
|
||||
@config.validate(@errors)
|
||||
assert !@errors.errors.empty?
|
||||
end
|
||||
end
|
||||
|
||||
context "preparing" do
|
||||
should "share cookbook folders" do
|
||||
@action.expects(:share_cookbook_folders).once
|
||||
|
@ -87,8 +110,8 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
|
|||
context "host cookbooks paths" do
|
||||
should "get folders path for configured cookbooks path" do
|
||||
result = mock("result")
|
||||
@env.config.chef.stubs(:cookbooks_path).returns("foo")
|
||||
@action.expects(:host_folder_paths).with(@env.config.chef.cookbooks_path).returns(result)
|
||||
@config.stubs(:cookbooks_path).returns("foo")
|
||||
@action.expects(:host_folder_paths).with(@config.cookbooks_path).returns(result)
|
||||
assert_equal result, @action.host_cookbook_paths
|
||||
end
|
||||
end
|
||||
|
@ -96,15 +119,15 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
|
|||
context "host roles paths" do
|
||||
should "get folders path for configured roles path" do
|
||||
result = mock("result")
|
||||
@env.config.chef.stubs(:roles_path).returns("foo")
|
||||
@action.expects(:host_folder_paths).with(@env.config.chef.roles_path).returns(result)
|
||||
@config.stubs(:roles_path).returns("foo")
|
||||
@action.expects(:host_folder_paths).with(@config.roles_path).returns(result)
|
||||
assert_equal result, @action.host_role_paths
|
||||
end
|
||||
end
|
||||
|
||||
context "folder path" do
|
||||
should "return a proper path to a single folder" do
|
||||
expected = File.join(@env.config.chef.provisioning_path, "cookbooks-5")
|
||||
expected = File.join(@config.provisioning_path, "cookbooks-5")
|
||||
assert_equal expected, @action.folder_path("cookbooks", 5)
|
||||
end
|
||||
|
||||
|
@ -125,33 +148,33 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "properly format VM folder paths" do
|
||||
@env.config.chef.provisioning_path = "/foo"
|
||||
@config.provisioning_path = "/foo"
|
||||
assert_equal "/foo/bar", @action.folders_path([:vm, "bar"], nil)
|
||||
end
|
||||
end
|
||||
|
||||
context "cookbooks path" do
|
||||
should "return a proper path to a single cookbook" do
|
||||
expected = File.join(@env.config.chef.provisioning_path, "cookbooks-5")
|
||||
expected = File.join(@config.provisioning_path, "cookbooks-5")
|
||||
assert_equal expected, @action.cookbook_path(5)
|
||||
end
|
||||
|
||||
should "properly call folders path and return result" do
|
||||
result = [:a, :b, :c]
|
||||
@action.expects(:folders_path).with(@env.config.chef.cookbooks_path, "cookbooks").once.returns(result)
|
||||
@action.expects(:folders_path).with(@config.cookbooks_path, "cookbooks").once.returns(result)
|
||||
assert_equal result.to_json, @action.cookbooks_path
|
||||
end
|
||||
end
|
||||
|
||||
context "roles path" do
|
||||
should "return a proper path to a single role" do
|
||||
expected = File.join(@env.config.chef.provisioning_path, "roles-5")
|
||||
expected = File.join(@config.provisioning_path, "roles-5")
|
||||
assert_equal expected, @action.role_path(5)
|
||||
end
|
||||
|
||||
should "properly call folders path and return result" do
|
||||
result = [:a, :b, :c]
|
||||
@action.expects(:folders_path).with(@env.config.chef.roles_path, "roles").once.returns(result)
|
||||
@action.expects(:folders_path).with(@config.roles_path, "roles").once.returns(result)
|
||||
assert_equal result.to_json, @action.roles_path
|
||||
end
|
||||
end
|
||||
|
@ -160,15 +183,15 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
|
|||
setup do
|
||||
@vm.ssh.stubs(:upload!)
|
||||
|
||||
@env.config.chef.recipe_url = "foo/bar/baz"
|
||||
@config.recipe_url = "foo/bar/baz"
|
||||
end
|
||||
|
||||
should "call setup_config with proper variables" do
|
||||
@action.expects(:setup_config).with("chef_solo_solo", "solo.rb", {
|
||||
:node_name => @env.config.chef.node_name,
|
||||
:provisioning_path => @env.config.chef.provisioning_path,
|
||||
:node_name => @config.node_name,
|
||||
:provisioning_path => @config.provisioning_path,
|
||||
:cookbooks_path => @action.cookbooks_path,
|
||||
:recipe_url => @env.config.chef.recipe_url,
|
||||
:recipe_url => @config.recipe_url,
|
||||
:roles_path => @action.roles_path
|
||||
})
|
||||
|
||||
|
@ -183,7 +206,7 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "cd into the provisioning directory and run chef solo" do
|
||||
@ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo -E chef-solo -c solo.rb -j dna.json").once
|
||||
@ssh.expects(:exec!).with("cd #{@config.provisioning_path} && sudo -E chef-solo -c solo.rb -j dna.json").once
|
||||
@action.run_chef_solo
|
||||
end
|
||||
|
||||
|
|
|
@ -4,24 +4,22 @@ class ChefProvisionerTest < Test::Unit::TestCase
|
|||
setup do
|
||||
@action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env)
|
||||
|
||||
@action = Vagrant::Provisioners::Chef.new(@action_env)
|
||||
@klass = Vagrant::Provisioners::Chef
|
||||
@config = @klass::Config.new
|
||||
@action = @klass.new(@action_env, @config)
|
||||
@env = @action.env
|
||||
@vm = @action.vm
|
||||
end
|
||||
|
||||
context "preparing" do
|
||||
should "error the environment" do
|
||||
assert_raises(Vagrant::Provisioners::Chef::ChefError) {
|
||||
assert_raises(@klass::ChefError) {
|
||||
@action.prepare
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
context "config" do
|
||||
setup do
|
||||
@config = Vagrant::Provisioners::Chef::ChefConfig.new
|
||||
end
|
||||
|
||||
should "not include the 'json' key in the config dump" do
|
||||
result = @config.to_json
|
||||
assert result !~ /"json":/
|
||||
|
@ -66,39 +64,13 @@ class ChefProvisionerTest < Test::Unit::TestCase
|
|||
assert_equal "role[user]", @config.run_list[0]
|
||||
end
|
||||
|
||||
=begin
|
||||
context "validation" do
|
||||
setup do
|
||||
@errors = Vagrant::Config::ErrorRecorder.new
|
||||
@top = @config.top = Vagrant::Config::Top.new(@env)
|
||||
end
|
||||
|
||||
context "chef solo" do
|
||||
setup do
|
||||
@top.vm.provisioner = :chef_solo
|
||||
|
||||
@config.run_list = ["foo"]
|
||||
@config.cookbooks_path = "cookbooks"
|
||||
end
|
||||
|
||||
should "be valid if provisioner is not chef solo" do
|
||||
@top.vm.provisioner = nil
|
||||
@config.validate(@errors)
|
||||
assert @errors.errors.empty?
|
||||
end
|
||||
|
||||
should "be invalid if run list is empty" do
|
||||
@config.run_list = []
|
||||
@config.validate(@errors)
|
||||
assert !@errors.errors.empty?
|
||||
end
|
||||
|
||||
should "be invalid if cookbooks path is empty" do
|
||||
@config.cookbooks_path = nil
|
||||
@config.validate(@errors)
|
||||
assert !@errors.errors.empty?
|
||||
end
|
||||
end
|
||||
|
||||
context "chef server" do
|
||||
setup do
|
||||
@top.vm.provisioner = :chef_server
|
||||
|
@ -133,6 +105,7 @@ class ChefProvisionerTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
=end
|
||||
end
|
||||
|
||||
context "verifying binary" do
|
||||
|
@ -152,8 +125,8 @@ class ChefProvisionerTest < Test::Unit::TestCase
|
|||
should "create and chown the folder to the ssh user" do
|
||||
ssh_seq = sequence("ssh_seq")
|
||||
ssh = mock("ssh")
|
||||
ssh.expects(:exec!).with("sudo mkdir -p #{@env.config.chef.provisioning_path}").once.in_sequence(ssh_seq)
|
||||
ssh.expects(:exec!).with("sudo chown #{@env.config.ssh.username} #{@env.config.chef.provisioning_path}").once.in_sequence(ssh_seq)
|
||||
ssh.expects(:exec!).with("sudo mkdir -p #{@config.provisioning_path}").once.in_sequence(ssh_seq)
|
||||
ssh.expects(:exec!).with("sudo chown #{@env.config.ssh.username} #{@config.provisioning_path}").once.in_sequence(ssh_seq)
|
||||
@vm.ssh.expects(:execute).yields(ssh)
|
||||
@action.chown_provisioning_folder
|
||||
end
|
||||
|
@ -174,7 +147,7 @@ class ChefProvisionerTest < Test::Unit::TestCase
|
|||
string_io = mock("string_io")
|
||||
Vagrant::Util::TemplateRenderer.expects(:render).with(@template, anything).returns(template_data)
|
||||
StringIO.expects(:new).with(template_data).returns(string_io)
|
||||
File.expects(:join).with(@env.config.chef.provisioning_path, @filename).once.returns("bar")
|
||||
File.expects(:join).with(@config.provisioning_path, @filename).once.returns("bar")
|
||||
@vm.ssh.expects(:upload!).with(string_io, "bar")
|
||||
|
||||
@action.setup_config(@template, @filename, {})
|
||||
|
@ -183,7 +156,7 @@ class ChefProvisionerTest < Test::Unit::TestCase
|
|||
should "provide log level by default" do
|
||||
Vagrant::Util::TemplateRenderer.expects(:render).returns("foo").with() do |template, vars|
|
||||
assert vars.has_key?(:log_level)
|
||||
assert_equal @env.config.chef.log_level.to_sym, vars[:log_level]
|
||||
assert_equal @config.log_level.to_sym, vars[:log_level]
|
||||
true
|
||||
end
|
||||
|
||||
|
@ -221,7 +194,7 @@ class ChefProvisionerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "merge in the extra json specified in the config" do
|
||||
@env.config.chef.json = { :foo => "BAR" }
|
||||
@config.json = { :foo => "BAR" }
|
||||
assert_json do |data|
|
||||
assert_equal "BAR", data["foo"]
|
||||
end
|
||||
|
@ -241,7 +214,7 @@ class ChefProvisionerTest < Test::Unit::TestCase
|
|||
|
||||
should "upload a StringIO to dna.json" do
|
||||
StringIO.expects(:new).with(anything).returns("bar")
|
||||
File.expects(:join).with(@env.config.chef.provisioning_path, "dna.json").once.returns("baz")
|
||||
File.expects(:join).with(@config.provisioning_path, "dna.json").once.returns("baz")
|
||||
@vm.ssh.expects(:upload!).with("bar", "baz").once
|
||||
@action.setup_json
|
||||
end
|
||||
|
|
|
@ -2,9 +2,12 @@ require "test_helper"
|
|||
|
||||
class PuppetServerProvisionerTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@klass = Vagrant::Provisioners::PuppetServer
|
||||
|
||||
@action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env)
|
||||
|
||||
@action = Vagrant::Provisioners::PuppetServer.new(@action_env)
|
||||
@config = @klass::Config.new
|
||||
@action = @klass.new(@action_env, @config)
|
||||
@env = @action.env
|
||||
@vm = @action.vm
|
||||
end
|
||||
|
@ -39,19 +42,19 @@ class PuppetServerProvisionerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "run the puppetd client" do
|
||||
@ssh.expects(:exec!).with("sudo -E puppetd --server #{@env.config.puppet_server.puppet_server} --certname #{@cn}").once
|
||||
@ssh.expects(:exec!).with("sudo -E puppetd --server #{@config.puppet_server} --certname #{@cn}").once
|
||||
@action.run_puppetd_client
|
||||
end
|
||||
|
||||
should "run puppetd with given options when given as an array" do
|
||||
@env.config.puppet_server.options = ["--modulepath", "modules", "--verbose"]
|
||||
@ssh.expects(:exec!).with("sudo -E puppetd --modulepath modules --verbose --server #{@env.config.puppet_server.puppet_server} --certname #{@cn}").once
|
||||
@config.options = ["--modulepath", "modules", "--verbose"]
|
||||
@ssh.expects(:exec!).with("sudo -E puppetd --modulepath modules --verbose --server #{@config.puppet_server} --certname #{@cn}").once
|
||||
@action.run_puppetd_client
|
||||
end
|
||||
|
||||
should "run puppetd with the options when given as a string" do
|
||||
@env.config.puppet_server.options = "--modulepath modules --verbose"
|
||||
@ssh.expects(:exec!).with("sudo -E puppetd --modulepath modules --verbose --server #{@env.config.puppet_server.puppet_server} --certname #{@cn}").once
|
||||
@config.options = "--modulepath modules --verbose"
|
||||
@ssh.expects(:exec!).with("sudo -E puppetd --modulepath modules --verbose --server #{@config.puppet_server} --certname #{@cn}").once
|
||||
@action.run_puppetd_client
|
||||
end
|
||||
|
||||
|
|
|
@ -2,9 +2,12 @@ require "test_helper"
|
|||
|
||||
class PuppetProvisionerTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@klass = Vagrant::Provisioners::Puppet
|
||||
|
||||
@action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env)
|
||||
|
||||
@action = Vagrant::Provisioners::Puppet.new(@action_env)
|
||||
@config = @klass::Config.new
|
||||
@action = @klass.new(@action_env, @config)
|
||||
@env = @action.env
|
||||
@vm = @action.vm
|
||||
end
|
||||
|
@ -30,17 +33,17 @@ class PuppetProvisionerTest < Test::Unit::TestCase
|
|||
|
||||
context "check manifest_dir" do
|
||||
setup do
|
||||
@env.config.puppet.manifests_path = "manifests"
|
||||
@config.manifests_path = "manifests"
|
||||
end
|
||||
|
||||
should "should not create the manifest directory if it exists" do
|
||||
File.expects(:directory?).with(@env.config.puppet.manifests_path).returns(true)
|
||||
File.expects(:directory?).with(@config.manifests_path).returns(true)
|
||||
@action.check_manifest_dir
|
||||
end
|
||||
|
||||
should "create the manifest directory if it does not exist" do
|
||||
File.stubs(:directory?).with(@env.config.puppet.manifests_path).returns(false)
|
||||
Dir.expects(:mkdir).with(@env.config.puppet.manifests_path).once
|
||||
File.stubs(:directory?).with(@config.manifests_path).returns(false)
|
||||
Dir.expects(:mkdir).with(@config.manifests_path).once
|
||||
@action.check_manifest_dir
|
||||
end
|
||||
end
|
||||
|
@ -76,8 +79,8 @@ class PuppetProvisionerTest < Test::Unit::TestCase
|
|||
should "create and chown the folder to the ssh user" do
|
||||
ssh_seq = sequence("ssh_seq")
|
||||
ssh = mock("ssh")
|
||||
ssh.expects(:exec!).with("sudo mkdir -p #{@env.config.puppet.pp_path}").once.in_sequence(ssh_seq)
|
||||
ssh.expects(:exec!).with("sudo chown #{@env.config.ssh.username} #{@env.config.puppet.pp_path}").once.in_sequence(ssh_seq)
|
||||
ssh.expects(:exec!).with("sudo mkdir -p #{@config.pp_path}").once.in_sequence(ssh_seq)
|
||||
ssh.expects(:exec!).with("sudo chown #{@env.config.ssh.username} #{@config.pp_path}").once.in_sequence(ssh_seq)
|
||||
@vm.ssh.expects(:execute).yields(ssh)
|
||||
@action.create_pp_path
|
||||
end
|
||||
|
@ -85,18 +88,18 @@ class PuppetProvisionerTest < Test::Unit::TestCase
|
|||
|
||||
context "setting the manifest" do
|
||||
setup do
|
||||
@env.config.puppet.stubs(:manifests_path).returns("manifests")
|
||||
@env.config.puppet.stubs(:manifest_file).returns("foo.pp")
|
||||
@config.stubs(:manifests_path).returns("manifests")
|
||||
@config.stubs(:manifest_file).returns("foo.pp")
|
||||
@env.config.vm.stubs(:box).returns("base")
|
||||
end
|
||||
|
||||
should "set the manifest if it exists" do
|
||||
File.stubs(:exists?).with("#{@env.config.puppet.manifests_path}/#{@env.config.puppet.manifest_file}").returns(true)
|
||||
File.stubs(:exists?).with("#{@config.manifests_path}/#{@config.manifest_file}").returns(true)
|
||||
@action.set_manifest
|
||||
end
|
||||
|
||||
should "raise an error if the manifest does not exist" do
|
||||
File.stubs(:exists?).with("#{@env.config.puppet.manifests_path}/#{@env.config.puppet.manifest_file}").returns(false)
|
||||
File.stubs(:exists?).with("#{@config.manifests_path}/#{@config.manifest_file}").returns(false)
|
||||
assert_raises(Vagrant::Provisioners::PuppetError) {
|
||||
@action.set_manifest
|
||||
}
|
||||
|
@ -110,19 +113,19 @@ class PuppetProvisionerTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "cd into the pp_path directory and run puppet" do
|
||||
@ssh.expects(:exec!).with("cd #{@env.config.puppet.pp_path} && sudo -E puppet #{@manifest}").once
|
||||
@ssh.expects(:exec!).with("cd #{@config.pp_path} && sudo -E puppet #{@manifest}").once
|
||||
@action.run_puppet_client
|
||||
end
|
||||
|
||||
should "cd into the pp_path directory and run puppet with given options when given as an array" do
|
||||
@env.config.puppet.options = ["--modulepath", "modules", "--verbose"]
|
||||
@ssh.expects(:exec!).with("cd #{@env.config.puppet.pp_path} && sudo -E puppet --modulepath modules --verbose #{@manifest}").once
|
||||
@config.options = ["--modulepath", "modules", "--verbose"]
|
||||
@ssh.expects(:exec!).with("cd #{@config.pp_path} && sudo -E puppet --modulepath modules --verbose #{@manifest}").once
|
||||
@action.run_puppet_client
|
||||
end
|
||||
|
||||
should "cd into the pp_path directory and run puppet with the options when given as a string" do
|
||||
@env.config.puppet.options = "--modulepath modules --verbose"
|
||||
@ssh.expects(:exec!).with("cd #{@env.config.puppet.pp_path} && sudo -E puppet --modulepath modules --verbose #{@manifest}").once
|
||||
@config.options = "--modulepath modules --verbose"
|
||||
@ssh.expects(:exec!).with("cd #{@config.pp_path} && sudo -E puppet --modulepath modules --verbose #{@manifest}").once
|
||||
@action.run_puppet_client
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue