summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2011-06-08 17:18:22 -0700
committerNick Lewis <nick@puppetlabs.com>2011-06-08 18:01:31 -0700
commit376e0f04af01810d00eede4de52744bb8c8e1681 (patch)
tree4723aa8e5667a664dffa2f3cd10832d9b511b604
parent4922409a2bdf3ad6a094762c9e2e60371ed16a1b (diff)
parentb1a506c7dec849415073e1bf4b3c92f3c898d6d9 (diff)
downloadpuppet-376e0f04af01810d00eede4de52744bb8c8e1681.tar.gz
puppet-376e0f04af01810d00eede4de52744bb8c8e1681.tar.xz
puppet-376e0f04af01810d00eede4de52744bb8c8e1681.zip
Merge branch '2.6.x' into 2.7.x
Conflicts: acceptance/tests/ticket_5477_master_not_dectect_sitepp.rb lib/puppet/application/apply.rb lib/puppet/configurer.rb lib/puppet/configurer/fact_handler.rb spec/unit/application/apply_spec.rb spec/unit/configurer/fact_handler_spec.rb spec/unit/configurer_spec.rb
-rw-r--r--acceptance/tests/allow_arbitrary_node_name_fact_for_agent.rb46
-rw-r--r--acceptance/tests/allow_arbitrary_node_name_fact_for_apply.rb30
-rw-r--r--acceptance/tests/allow_arbitrary_node_name_for_agent.rb29
-rw-r--r--acceptance/tests/allow_arbitrary_node_name_for_apply.rb17
-rw-r--r--acceptance/tests/allow_symlinks_as_config_directories.rb27
-rw-r--r--acceptance/tests/ticket_3360_allow_duplicate_csr_with_option_set.rb2
-rw-r--r--acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb6
-rw-r--r--acceptance/tests/ticket_5477_master_not_dectect_sitepp.rb48
-rw-r--r--acceptance/tests/ticket_6734_6256_5530_5503.rb14
-rw-r--r--acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb2
-rw-r--r--lib/puppet/application/agent.rb2
-rw-r--r--lib/puppet/application/apply.rb13
-rw-r--r--lib/puppet/configurer.rb25
-rw-r--r--lib/puppet/configurer/fact_handler.rb7
-rw-r--r--lib/puppet/defaults.rb19
-rw-r--r--lib/puppet/transaction/report.rb2
-rw-r--r--lib/puppet/util/settings/file_setting.rb1
-rwxr-xr-xspec/integration/defaults_spec.rb22
-rwxr-xr-xspec/unit/application/agent_spec.rb2
-rwxr-xr-xspec/unit/application/apply_spec.rb124
-rwxr-xr-xspec/unit/application/facts_spec.rb1
-rwxr-xr-xspec/unit/configurer/fact_handler_spec.rb82
-rwxr-xr-xspec/unit/configurer_spec.rb657
-rwxr-xr-xspec/unit/node_spec.rb1
-rwxr-xr-xspec/unit/transaction/report_spec.rb6
-rwxr-xr-xspec/unit/util/settings/file_setting_spec.rb4
26 files changed, 705 insertions, 484 deletions
diff --git a/acceptance/tests/allow_arbitrary_node_name_fact_for_agent.rb b/acceptance/tests/allow_arbitrary_node_name_fact_for_agent.rb
new file mode 100644
index 000000000..2e89d765f
--- /dev/null
+++ b/acceptance/tests/allow_arbitrary_node_name_fact_for_agent.rb
@@ -0,0 +1,46 @@
+test_name "node_name_fact should be used to determine the node name for puppet agent"
+
+success_message = "node_name_fact setting was correctly used to determine the node name"
+
+node_names = []
+
+on agents, facter('kernel') do
+ node_names << stdout.chomp
+end
+
+node_names.uniq!
+
+authfile = "/tmp/auth.conf-2128-#{$$}"
+authconf = node_names.map do |node_name|
+ %Q[
+path /catalog/#{node_name}
+auth yes
+allow *
+]
+end.join("\n")
+
+manifest_file = "/tmp/node_name_value-test-#{$$}.pp"
+manifest = %Q[
+ Exec { path => "/usr/bin:/bin" }
+ node default {
+ exec { "false": }
+ }
+]
+manifest << node_names.map do |node_name|
+ %Q[
+ node "#{node_name}" {
+ exec { "echo #{success_message}": }
+ }
+ ]
+end.join("\n")
+
+create_remote_file master, authfile, authconf
+create_remote_file master, manifest_file, manifest
+
+on master, "chmod 644 #{authfile} #{manifest_file}"
+
+with_master_running_on(master, "--rest_authconfig #{authfile} --manifest #{manifest_file} --daemonize --autosign true") do
+ run_agent_on(agents, "--no-daemonize --verbose --onetime --node_name_fact kernel --server #{master}") do
+ assert_match(success_message, stdout)
+ end
+end
diff --git a/acceptance/tests/allow_arbitrary_node_name_fact_for_apply.rb b/acceptance/tests/allow_arbitrary_node_name_fact_for_apply.rb
new file mode 100644
index 000000000..d7cf2dcac
--- /dev/null
+++ b/acceptance/tests/allow_arbitrary_node_name_fact_for_apply.rb
@@ -0,0 +1,30 @@
+test_name "node_name_fact should be used to determine the node name for puppet apply"
+
+success_message = "node_name_fact setting was correctly used to determine the node name"
+
+node_names = []
+
+on agents, facter('kernel') do
+ node_names << stdout.chomp
+end
+
+node_names.uniq!
+
+manifest = %Q[
+ Exec { path => "/usr/bin:/bin" }
+ node default {
+ exec { "false": }
+ }
+]
+
+node_names.each do |node_name|
+ manifest << %Q[
+ node "#{node_name}" {
+ exec { "echo #{success_message}": }
+ }
+ ]
+end
+
+on agents, puppet_apply("--verbose --node_name_fact kernel"), :stdin => manifest do
+ assert_match(success_message, stdout)
+end
diff --git a/acceptance/tests/allow_arbitrary_node_name_for_agent.rb b/acceptance/tests/allow_arbitrary_node_name_for_agent.rb
new file mode 100644
index 000000000..f5e027660
--- /dev/null
+++ b/acceptance/tests/allow_arbitrary_node_name_for_agent.rb
@@ -0,0 +1,29 @@
+test_name "node_name_value should be used as the node name for puppet agent"
+
+success_message = "node_name_value setting was correctly used as the node name"
+
+authfile = "/tmp/auth.conf-2128-#{$$}"
+create_remote_file master, authfile, <<AUTHCONF
+path /catalog/specified_node_name
+auth yes
+allow *
+AUTHCONF
+
+manifest_file = "/tmp/node_name_value-test-#{$$}.pp"
+create_remote_file master, manifest_file, <<MANIFEST
+ Exec { path => "/usr/bin:/bin" }
+ node default {
+ exec { "false": }
+ }
+ node specified_node_name {
+ exec { "echo #{success_message}": }
+ }
+MANIFEST
+
+on master, "chmod 644 #{authfile} #{manifest_file}"
+
+with_master_running_on(master, "--rest_authconfig #{authfile} --manifest #{manifest_file} --daemonize --autosign true") do
+ run_agent_on(agents, "--no-daemonize --verbose --onetime --node_name_value specified_node_name --server #{master}") do
+ assert_match(success_message, stdout)
+ end
+end
diff --git a/acceptance/tests/allow_arbitrary_node_name_for_apply.rb b/acceptance/tests/allow_arbitrary_node_name_for_apply.rb
new file mode 100644
index 000000000..4daa8a65b
--- /dev/null
+++ b/acceptance/tests/allow_arbitrary_node_name_for_apply.rb
@@ -0,0 +1,17 @@
+test_name "node_name_value should be used as the node name for puppet apply"
+
+success_message = "node_name_value setting was correctly used as the node name"
+
+manifest = %Q[
+ Exec { path => "/usr/bin:/bin" }
+ node default {
+ exec { "false": }
+ }
+ node a_different_node_name {
+ exec { "echo #{success_message}": }
+ }
+]
+
+on agents, puppet_apply("--verbose --node_name_value a_different_node_name"), :stdin => manifest do
+ assert_match(success_message, stdout)
+end
diff --git a/acceptance/tests/allow_symlinks_as_config_directories.rb b/acceptance/tests/allow_symlinks_as_config_directories.rb
new file mode 100644
index 000000000..66c6ccca0
--- /dev/null
+++ b/acceptance/tests/allow_symlinks_as_config_directories.rb
@@ -0,0 +1,27 @@
+test_name "Should allow symlinks to directories as configuration directories"
+
+step "Create the test confdir with a link to it"
+confdir = "/tmp/puppet_conf-directory-#{$$}"
+conflink = "/tmp/puppet_conf-symlink-#{$$}"
+
+on agents, "rm -rf #{conflink} #{confdir}"
+
+on agents, "mkdir #{confdir}"
+on agents, "ln -s #{confdir} #{conflink}"
+
+create_remote_file agents, "#{confdir}/puppet.conf", <<CONFFILE
+[main]
+certname = "awesome_certname"
+CONFFILE
+
+manifest = 'notify{"My certname is $clientcert": }'
+
+step "Run Puppet and ensure it used the conf file in the confdir"
+on agents, puppet_apply("--confdir #{conflink}"), :stdin => manifest do
+ assert_match("My certname is awesome_certname", stdout)
+end
+
+step "Check that the symlink and confdir are unchanged"
+on agents, "[ -L #{conflink} ]"
+on agents, "[ -d #{confdir} ]"
+on agents, "[ $(readlink #{conflink}) = #{confdir} ]"
diff --git a/acceptance/tests/ticket_3360_allow_duplicate_csr_with_option_set.rb b/acceptance/tests/ticket_3360_allow_duplicate_csr_with_option_set.rb
index ba02227ea..58f98d2a0 100644
--- a/acceptance/tests/ticket_3360_allow_duplicate_csr_with_option_set.rb
+++ b/acceptance/tests/ticket_3360_allow_duplicate_csr_with_option_set.rb
@@ -46,5 +46,5 @@ step "Verify the certs have changed"
# where certs might be signed with long names.
old_certs.each_key { |key|
next if key.include? master # skip the masters cert, only care about agents
- fail_test("#{key} does not have a new signed certificate") if old_certs[key] == new_certs[key]
+ assert_not_equal(old_certs[key], new_certs[key], "Expected #{key} to have a changed key")
}
diff --git a/acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb b/acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb
index 4b5bc377b..22a5b4b92 100644
--- a/acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb
+++ b/acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb
@@ -3,7 +3,7 @@ test_name "#3961: puppet ca should produce certs spec"
scratch = "/tmp/puppet-ssl-3961"
target = "working3961.example.org"
-options = { :confdir => scratch, :vardir => scratch, :ssldir => scratch }
+options = { :confdir => scratch, :vardir => scratch }
expect = ['notice: Signed certificate request for ca',
'notice: Rebuilding inventory file',
@@ -23,7 +23,7 @@ on(agents,puppet_cert('--trace', '--generate', target, options)) do
end
step "verify the certificate for #{target} exists"
-on agents, "test -f #{scratch}/certs/#{target}.pem"
+on agents, "test -f #{scratch}/ssl/certs/#{target}.pem"
step "verify the private key for #{target} exists"
-on agents, "grep -q 'BEGIN RSA PRIVATE KEY' #{scratch}/private_keys/#{target}.pem"
+on agents, "grep -q 'BEGIN RSA PRIVATE KEY' #{scratch}/ssl/private_keys/#{target}.pem"
diff --git a/acceptance/tests/ticket_5477_master_not_dectect_sitepp.rb b/acceptance/tests/ticket_5477_master_not_dectect_sitepp.rb
index 792e88b46..d8723b2ec 100644
--- a/acceptance/tests/ticket_5477_master_not_dectect_sitepp.rb
+++ b/acceptance/tests/ticket_5477_master_not_dectect_sitepp.rb
@@ -6,41 +6,25 @@
test_name "Ticket 5477, Puppet Master does not detect newly created site.pp file"
-# Kill running Puppet Master
-step "Master: kill running Puppet Master"
-on master, "ps -U puppet | awk '/puppet/ { print \$1 }' | xargs kill"
+manifest_file = "/tmp/missing_site-5477-#{$$}.pp"
-# Run tests against Master first
-step "Master: mv site.pp file to /tmp, if existing"
-on master, "if [ -e /etc/puppet/manifests/site.pp ] ; then mv /etc/puppet/manifests/site.pp /tmp/site.pp-5477 ; fi"
+on master, "rm -f #{manifest_file}"
-# Start Puppet Master
-#step "Master: Run Puppet Master in verbose mode"
-#on master, puppet_master("--verbose")
-step "Master: Start Puppet Master"
-on master, puppet_master("--certdnsnames=\"puppet:$(hostname -s):$(hostname -f)\" --verbose")
+with_master_running_on(master, "--manifest #{manifest_file} --certdnsnames=\"puppet:$(hostname -s):$(hostname -f)\" --verbose --filetimeout 1") do
+ # Run test on Agents
+ step "Agent: agent --test"
+ on agents, puppet_agent("--test --server #{master}")
-# Allow puppet server to start accepting conections
-sleep 10
+ # Create a new site.pp
+ step "Master: create basic site.pp file"
+ create_remote_file master, manifest_file, "notify{ticket_5477_notify:}"
-# Run test on Agents
-step "Agent: agent --test"
-agents.each { |agent|
- on agent, puppet_agent("--test")
-}
-
-# Create a new site.pp
-step "Master: create basic site.pp file"
-on master, "echo 'notify{ticket_5477_notify:}' > /etc/puppet/manifests/site.pp"
-
-sleep 20
+ on master, "chmod 644 #{manifest_file}"
-step "Agent: puppet agent --test"
-agents.each { |agent|
- on agent, "puppet agent -t", :acceptable_exit_codes => [2]
- fail_test "Site.pp not detect at Master?" unless
- stdout.include? 'ticket_5477_notify'
-}
+ sleep 3
-step "Clean-up site.pp"
-on master, "rm /etc/puppet/manifests/site.pp"
+ step "Agent: puppet agent --test"
+ on agents, puppet_agent("--test --server #{master}"), :acceptable_exit_codes => [2] do
+ fail_test "Site.pp not detect at Master?" unless stdout.include? 'ticket_5477_notify'
+ end
+end
diff --git a/acceptance/tests/ticket_6734_6256_5530_5503.rb b/acceptance/tests/ticket_6734_6256_5530_5503.rb
index fe8866901..8f0155efb 100644
--- a/acceptance/tests/ticket_6734_6256_5530_5503.rb
+++ b/acceptance/tests/ticket_6734_6256_5530_5503.rb
@@ -5,12 +5,10 @@
test_name "Tickets 6734 6256 5530 5503i Puppet Master fails to start"
# Kill running Puppet Master
-step "Check for running Puppet Master"
-on master, "ps -ef | grep puppet"
- fail_test "Puppet Master not running" unless
- stdout.include? 'master'
+with_master_running_on(master) do
-step "Check permissions on puppet/rrd/"
-on master, "ls -l /var/lib/puppet | grep rrd | awk '{print $3\" \"$4}'"
- fail_test "puppet/rrd does not exist/wrong permission" unless
- stdout.include? 'puppet puppet'
+ step "Check permissions on puppet/rrd/"
+ on master, "ls -l /var/lib/puppet | grep rrd | awk '{print $3\" \"$4}'" do
+ fail_test "puppet/rrd does not exist/wrong permission" unless stdout.include? 'puppet puppet'
+ end
+end
diff --git a/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb b/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb
index 07b427306..f8f03f287 100644
--- a/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb
+++ b/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb
@@ -42,7 +42,7 @@ Log.notify "Slept for #{elapsed} seconds waiting for Puppet Master to become rea
# Run test on Agents
step "Agent: agent --test"
-on agents, puppet_agent("--test")
+on agents, puppet_agent("--test --server #{master}")
step "Fetch agent facts from Puppet Master"
agents.each do |host|
diff --git a/lib/puppet/application/agent.rb b/lib/puppet/application/agent.rb
index 06a158fb3..f0442648b 100644
--- a/lib/puppet/application/agent.rb
+++ b/lib/puppet/application/agent.rb
@@ -320,7 +320,7 @@ Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
unless fingerprint = cert.fingerprint(options[:digest])
raise ArgumentError, "Could not get fingerprint for digest '#{options[:digest]}'"
end
- Puppet.notice fingerprint
+ puts fingerprint
end
def onetime
diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb
index 5779e799c..3ba06d34a 100644
--- a/lib/puppet/application/apply.rb
+++ b/lib/puppet/application/apply.rb
@@ -168,13 +168,18 @@ Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
end
# Collect our facts.
- unless facts = Puppet::Node::Facts.indirection.find(Puppet[:certname])
- raise "Could not find facts for #{Puppet[:certname]}"
+ unless facts = Puppet::Node::Facts.indirection.find(Puppet[:node_name_value])
+ raise "Could not find facts for #{Puppet[:node_name_value]}"
+ end
+
+ unless Puppet[:node_name_fact].empty?
+ Puppet[:node_name_value] = facts.values[Puppet[:node_name_fact]]
+ facts.name = Puppet[:node_name_value]
end
# Find our Node
- unless node = Puppet::Node.indirection.find(Puppet[:certname])
- raise "Could not find node #{Puppet[:certname]}"
+ unless node = Puppet::Node.indirection.find(Puppet[:node_name_value])
+ raise "Could not find node #{Puppet[:node_name_value]}"
end
# Merge in the facts.
diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb
index cfeb73a1f..980da634e 100644
--- a/lib/puppet/configurer.rb
+++ b/lib/puppet/configurer.rb
@@ -84,16 +84,8 @@ class Puppet::Configurer
end
# Get the remote catalog, yo. Returns nil if no catalog can be found.
- def retrieve_catalog
- if Puppet::Resource::Catalog.indirection.terminus_class == :rest
- # This is a bit complicated. We need the serialized and escaped facts,
- # and we need to know which format they're encoded in. Thus, we
- # get a hash with both of these pieces of information.
- fact_options = facts_for_uploading
- else
- fact_options = {}
- end
-
+ def retrieve_catalog(fact_options)
+ fact_options ||= {}
# First try it with no cache, then with the cache.
unless (Puppet[:use_cached_catalog] and result = retrieve_catalog_from_cache(fact_options)) or result = retrieve_new_catalog(fact_options)
if ! Puppet[:usecacheonfailure]
@@ -130,13 +122,20 @@ class Puppet::Configurer
Puppet.err "Failed to prepare catalog: #{detail}"
end
+ if Puppet::Resource::Catalog.indirection.terminus_class == :rest
+ # This is a bit complicated. We need the serialized and escaped facts,
+ # and we need to know which format they're encoded in. Thus, we
+ # get a hash with both of these pieces of information.
+ fact_options = facts_for_uploading
+ end
+
options[:report] ||= Puppet::Transaction::Report.new("apply")
report = options[:report]
Puppet::Util::Log.newdestination(report)
if catalog = options[:catalog]
options.delete(:catalog)
- elsif ! catalog = retrieve_catalog
+ elsif ! catalog = retrieve_catalog(fact_options)
Puppet.err "Could not retrieve catalog; skipping run"
return
end
@@ -220,7 +219,7 @@ class Puppet::Configurer
def retrieve_catalog_from_cache(fact_options)
result = nil
@duration = thinmark do
- result = Puppet::Resource::Catalog.indirection.find(Puppet[:certname], fact_options.merge(:ignore_terminus => true))
+ result = Puppet::Resource::Catalog.indirection.find(Puppet[:node_name_value], fact_options.merge(:ignore_terminus => true))
end
Puppet.notice "Using cached catalog"
result
@@ -233,7 +232,7 @@ class Puppet::Configurer
def retrieve_new_catalog(fact_options)
result = nil
@duration = thinmark do
- result = Puppet::Resource::Catalog.indirection.find(Puppet[:certname], fact_options.merge(:ignore_cache => true))
+ result = Puppet::Resource::Catalog.indirection.find(Puppet[:node_name_value], fact_options.merge(:ignore_cache => true))
end
result
rescue SystemExit,NoMemoryError
diff --git a/lib/puppet/configurer/fact_handler.rb b/lib/puppet/configurer/fact_handler.rb
index abe032010..803495773 100644
--- a/lib/puppet/configurer/fact_handler.rb
+++ b/lib/puppet/configurer/fact_handler.rb
@@ -16,7 +16,12 @@ module Puppet::Configurer::FactHandler
# compile them and then "cache" them on the server.
begin
reload_facter
- Puppet::Node::Facts.indirection.find(Puppet[:certname])
+ facts = Puppet::Node::Facts.indirection.find(Puppet[:node_name_value])
+ unless Puppet[:node_name_fact].empty?
+ Puppet[:node_name_value] = facts.values[Puppet[:node_name_fact]]
+ facts.name = Puppet[:node_name_value]
+ end
+ facts
rescue SystemExit,NoMemoryError
raise
rescue Exception => detail
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 139c3c763..07442d0e9 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -493,6 +493,25 @@ module Puppet
)
setdefaults(:agent,
+ :node_name_value => { :default => "$certname",
+ :desc => "The explicit value used for the node name for all requests the agent
+ makes to the master. WARNING: This setting is mutually exclusive with
+ node_name_fact. Changing this setting also requires changes to the default
+ auth.conf configuration on the Puppet Master. Please see
+ http://links.puppetlabs.com/node_name_value for more information."
+ },
+ :node_name_fact => { :default => "",
+ :desc => "The fact name used to determine the node name used for all requests the agent
+ makes to the master. WARNING: This setting is mutually exclusive with
+ node_name_value. Changing this setting also requires changes to the default
+ auth.conf configuration on the Puppet Master. Please see
+ http://links.puppetlabs.com/node_name_fact for more information.",
+ :hook => proc do |value|
+ if !value.empty? and Puppet[:node_name_value] != Puppet[:certname]
+ raise "Cannot specify both the node_name_value and node_name_fact settings"
+ end
+ end
+ },
:localconfig => { :default => "$statedir/localconfig",
:owner => "root",
:mode => 0660,
diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb
index 652b3874a..020a5efce 100644
--- a/lib/puppet/transaction/report.rb
+++ b/lib/puppet/transaction/report.rb
@@ -73,7 +73,7 @@ class Puppet::Transaction::Report
@logs = []
@resource_statuses = {}
@external_times ||= {}
- @host = Puppet[:certname]
+ @host = Puppet[:node_name_value]
@time = Time.now
@kind = kind
@report_format = 2
diff --git a/lib/puppet/util/settings/file_setting.rb b/lib/puppet/util/settings/file_setting.rb
index edbab1d0c..776398ef4 100644
--- a/lib/puppet/util/settings/file_setting.rb
+++ b/lib/puppet/util/settings/file_setting.rb
@@ -101,6 +101,7 @@ class Puppet::Util::Settings::FileSetting < Puppet::Util::Settings::Setting
resource[:ensure] = type
resource[:loglevel] = :debug
+ resource[:links] = :follow
resource[:backup] = false
resource.tag(self.section, self.name, "settings")
diff --git a/spec/integration/defaults_spec.rb b/spec/integration/defaults_spec.rb
index 8aa59288e..9bec769ab 100755
--- a/spec/integration/defaults_spec.rb
+++ b/spec/integration/defaults_spec.rb
@@ -22,6 +22,28 @@ describe "Puppet defaults" do
end
end
+ describe "when setting :node_name_value" do
+ it "should default to the value of :certname" do
+ Puppet.settings[:certname] = 'blargle'
+ Puppet.settings[:node_name_value].should == 'blargle'
+ end
+ end
+
+ describe "when setting the :node_name_fact" do
+ it "should fail when also setting :node_name_value" do
+ lambda do
+ Puppet.settings[:node_name_value] = "some value"
+ Puppet.settings[:node_name_fact] = "some_fact"
+ end.should raise_error("Cannot specify both the node_name_value and node_name_fact settings")
+ end
+
+ it "should not fail when using the default for :node_name_value" do
+ lambda do
+ Puppet.settings[:node_name_fact] = "some_fact"
+ end.should_not raise_error
+ end
+ end
+
describe "when configuring the :crl" do
it "should warn if :cacrl is set to false" do
Puppet.expects(:warning)
diff --git a/spec/unit/application/agent_spec.rb b/spec/unit/application/agent_spec.rb
index c4f8e7176..d87f1f563 100755
--- a/spec/unit/application/agent_spec.rb
+++ b/spec/unit/application/agent_spec.rb
@@ -545,7 +545,7 @@ describe Puppet::Application::Agent do
@host.stubs(:certificate).returns(@cert)
@cert.stubs(:fingerprint).with(:MD5).returns("DIGEST")
- Puppet.expects(:notice).with("DIGEST")
+ @puppetd.expects(:puts).with "DIGEST"
@puppetd.fingerprint
end
diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb
index 74c883a3e..19a933950 100755
--- a/spec/unit/application/apply_spec.rb
+++ b/spec/unit/application/apply_spec.rb
@@ -4,6 +4,7 @@ require 'spec_helper'
require 'puppet/application/apply'
require 'puppet/file_bucket/dipper'
require 'puppet/configurer'
+require 'fileutils'
describe Puppet::Application::Apply do
before :each do
@@ -59,13 +60,12 @@ describe Puppet::Application::Apply do
end
it "should set show_diff on --noop" do
- Puppet.stubs(:[]=)
- Puppet.stubs(:[]).with(:config)
- Puppet.stubs(:[]).with(:noop).returns(true)
-
- Puppet.expects(:[]=).with(:show_diff, true)
+ Puppet[:noop] = true
+ Puppet[:show_diff] = false
@apply.setup
+
+ Puppet[:show_diff].should == true
end
it "should set console as the log destination if logdest option wasn't provided" do
@@ -127,28 +127,29 @@ describe Puppet::Application::Apply do
end
describe "the main command" do
+ include PuppetSpec::Files
+
before :each do
- Puppet.stubs(:[])
- Puppet.settings.stubs(:use)
- Puppet.stubs(:[]).with(:prerun_command).returns ""
- Puppet.stubs(:[]).with(:postrun_command).returns ""
- Puppet.stubs(:[]).with(:trace).returns(true)
+ Puppet[:prerun_command] = ''
+ Puppet[:postrun_command] = ''
- @apply.options.stubs(:[])
+ Puppet::Node::Facts.indirection.terminus_class = :memory
+ Puppet::Node.indirection.terminus_class = :memory
- @facts = stub_everything 'facts'
- Puppet::Node::Facts.indirection.stubs(:find).returns(@facts)
+ @facts = Puppet::Node::Facts.new(Puppet[:node_name_value])
+ Puppet::Node::Facts.indirection.save(@facts)
- @node = stub_everything 'node'
- Puppet::Node.indirection.stubs(:find).returns(@node)
+ @node = Puppet::Node.new(Puppet[:node_name_value])
+ Puppet::Node.indirection.save(@node)
- @catalog = stub_everything 'catalog'
+ @catalog = Puppet::Resource::Catalog.new
@catalog.stubs(:to_ral).returns(@catalog)
+
Puppet::Resource::Catalog.indirection.stubs(:find).returns(@catalog)
STDIN.stubs(:read)
- @transaction = stub_everything 'transaction'
+ @transaction = Puppet::Transaction.new(@catalog)
@catalog.stubs(:apply).returns(@transaction)
Puppet::Util::Storage.stubs(:load)
@@ -156,7 +157,7 @@ describe Puppet::Application::Apply do
end
it "should set the code to run from --code" do
- @apply.options.stubs(:[]).with(:code).returns("code to run")
+ @apply.options[:code] = "code to run"
Puppet.expects(:[]=).with(:code,"code to run")
expect { @apply.main }.to exit_with 0
@@ -172,47 +173,63 @@ describe Puppet::Application::Apply do
end
it "should set the manifest if a file is passed on command line and the file exists" do
- File.stubs(:exist?).with('site.pp').returns true
- @apply.command_line.stubs(:args).returns(['site.pp'])
+ manifest = tmpfile('site.pp')
+ FileUtils.touch(manifest)
+ @apply.command_line.stubs(:args).returns([manifest])
- Puppet.expects(:[]=).with(:manifest,"site.pp")
+ Puppet.expects(:[]=).with(:manifest,manifest)
expect { @apply.main }.to exit_with 0
end
it "should raise an error if a file is passed on command line and the file does not exist" do
- File.stubs(:exist?).with('noexist.pp').returns false
- @apply.command_line.stubs(:args).returns(['noexist.pp'])
- lambda { @apply.main }.should raise_error(RuntimeError, 'Could not find file noexist.pp')
+ noexist = tmpfile('noexist.pp')
+ @apply.command_line.stubs(:args).returns([noexist])
+ lambda { @apply.main }.should raise_error(RuntimeError, "Could not find file #{noexist}")
end
it "should set the manifest to the first file and warn other files will be skipped" do
- File.stubs(:exist?).with('starwarsIV').returns true
- File.expects(:exist?).with('starwarsI').never
- @apply.command_line.stubs(:args).returns(['starwarsIV', 'starwarsI', 'starwarsII'])
+ manifest = tmpfile('starwarsIV')
+ FileUtils.touch(manifest)
+
+ @apply.command_line.stubs(:args).returns([manifest, 'starwarsI', 'starwarsII'])
- Puppet.expects(:[]=).with(:manifest,"starwarsIV")
+ Puppet.expects(:[]=).with(:manifest,manifest)
Puppet.expects(:warning).with('Only one file can be applied per run. Skipping starwarsI, starwarsII')
expect { @apply.main }.to exit_with 0
end
- it "should collect the node facts" do
- Puppet::Node::Facts.indirection.expects(:find).returns(@facts)
+ it "should set the facts name based on the node_name_fact" do
+ @facts = Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name')
+ Puppet::Node::Facts.indirection.save(@facts)
+
+ node = Puppet::Node.new('other_node_name')
+ Puppet::Node.indirection.save(node)
+
+ Puppet[:node_name_fact] = 'my_name_fact'
expect { @apply.main }.to exit_with 0
+
+ @facts.name.should == 'other_node_name'
end
- it "should raise an error if we can't find the node" do
- Puppet::Node::Facts.indirection.expects(:find).returns(nil)
+ it "should set the node_name_value based on the node_name_fact" do
+ facts = Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name')
+ Puppet::Node::Facts.indirection.save(facts)
+ node = Puppet::Node.new('other_node_name')
+ Puppet::Node.indirection.save(node)
+ Puppet[:node_name_fact] = 'my_name_fact'
- lambda { @apply.main }.should raise_error
+ expect { @apply.main }.to exit_with 0
+
+ Puppet[:node_name_value].should == 'other_node_name'
end
- it "should look for the node" do
- Puppet::Node.indirection.expects(:find).returns(@node)
+ it "should raise an error if we can't find the facts" do
+ Puppet::Node::Facts.indirection.expects(:find).returns(nil)
- expect { @apply.main }.to exit_with 0
+ lambda { @apply.main }.should raise_error
end
it "should raise an error if we can't find the node" do
@@ -222,21 +239,20 @@ describe Puppet::Application::Apply do
end
it "should merge in our node the loaded facts" do
- @facts.stubs(:values).returns("values")
-
- @node.expects(:merge).with("values")
+ @facts.values = {'key' => 'value'}
expect { @apply.main }.to exit_with 0
+
+ @node.parameters['key'].should == 'value'
end
it "should load custom classes if loadclasses" do
- @apply.options.stubs(:[]).with(:loadclasses).returns(true)
- Puppet.stubs(:[]).with(:classfile).returns("/etc/puppet/classes.txt")
- FileTest.stubs(:exists?).with("/etc/puppet/classes.txt").returns(true)
- FileTest.stubs(:readable?).with("/etc/puppet/classes.txt").returns(true)
- File.stubs(:read).with("/etc/puppet/classes.txt").returns("class")
+ @apply.options[:loadclasses] = true
+ classfile = tmpfile('classfile')
+ File.open(classfile, 'w') { |c| c.puts 'class' }
+ Puppet[:classfile] = classfile
- @node.expects(:classes=)
+ @node.expects(:classes=).with(['class'])
expect { @apply.main }.to exit_with 0
end
@@ -274,7 +290,7 @@ describe Puppet::Application::Apply do
end
it "should save the last run summary" do
- Puppet.stubs(:[]).with(:noop).returns(false)
+ Puppet[:noop] = false
report = Puppet::Transaction::Report.new("apply")
Puppet::Transaction::Report.stubs(:new).returns(report)
@@ -283,25 +299,26 @@ describe Puppet::Application::Apply do
end
describe "with detailed_exitcodes" do
+ before :each do
+ @apply.options[:detailed_exitcodes] = true
+ end
+
it "should exit with report's computed exit status" do
- Puppet.stubs(:[]).with(:noop).returns(false)
- @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true)
+ Puppet[:noop] = false
Puppet::Transaction::Report.any_instance.stubs(:exit_status).returns(666)
expect { @apply.main }.to exit_with 666
end
it "should exit with report's computed exit status, even if --noop is set" do
- Puppet.stubs(:[]).with(:noop).returns(true)
- @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true)
+ Puppet[:noop] = true
Puppet::Transaction::Report.any_instance.stubs(:exit_status).returns(666)
expect { @apply.main }.to exit_with 666
end
it "should always exit with 0 if option is disabled" do
- Puppet.stubs(:[]).with(:noop).returns(false)
- @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(false)
+ Puppet[:noop] = false
report = stub 'report', :exit_status => 666
@transaction.stubs(:report).returns(report)
@@ -309,8 +326,7 @@ describe Puppet::Application::Apply do
end
it "should always exit with 0 if --noop" do
- Puppet.stubs(:[]).with(:noop).returns(true)
- @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true)
+ Puppet[:noop] = true
report = stub 'report', :exit_status => 666
@transaction.stubs(:report).returns(report)
diff --git a/spec/unit/application/facts_spec.rb b/spec/unit/application/facts_spec.rb
index e11ea165c..7a7c36597 100755
--- a/spec/unit/application/facts_spec.rb
+++ b/spec/unit/application/facts_spec.rb
@@ -16,6 +16,7 @@ describe Puppet::Application::Facts do
end
it "should return facts if a key is given to find", :'fails_on_ruby_1.9.2' => true do
+ Puppet::Node::Facts.indirection.reset_terminus_class
subject.command_line.stubs(:args).returns %w{find whatever --render-as yaml}
expect {
diff --git a/spec/unit/configurer/fact_handler_spec.rb b/spec/unit/configurer/fact_handler_spec.rb
index 70d9b17c0..4a3fe8b3b 100755
--- a/spec/unit/configurer/fact_handler_spec.rb
+++ b/spec/unit/configurer/fact_handler_spec.rb
@@ -12,14 +12,6 @@ describe Puppet::Configurer::FactHandler do
@facthandler = FactHandlerTester.new
end
- it "should have a method for downloading fact plugins" do
- @facthandler.should respond_to(:download_fact_plugins)
- end
-
- it "should have a boolean method for determining whether fact plugins should be downloaded" do
- @facthandler.should respond_to(:download_fact_plugins?)
- end
-
it "should download fact plugins when :factsync is true" do
Puppet.settings.expects(:value).with(:factsync).returns true
@facthandler.should be_download_fact_plugins
@@ -51,46 +43,62 @@ describe Puppet::Configurer::FactHandler do
@facthandler.download_fact_plugins
end
- it "should warn about factsync deprecation when factsync is enabled" do
- Puppet::Configurer::Downloader.stubs(:new).returns mock("downloader", :evaluate => nil)
+ describe "when finding facts" do
+ before :each do
+ @facthandler.stubs(:reload_facter)
+ Puppet::Node::Facts.indirection.terminus_class = :memory
+ end
- @facthandler.expects(:download_fact_plugins?).returns true
- Puppet.expects(:warning)
- @facthandler.download_fact_plugins
- end
+ it "should use the node name value to retrieve the facts" do
+ foo_facts = Puppet::Node::Facts.new('foo')
+ bar_facts = Puppet::Node::Facts.new('bar')
+ Puppet::Node::Facts.indirection.save(foo_facts)
+ Puppet::Node::Facts.indirection.save(bar_facts)
+ Puppet[:certname] = 'foo'
+ Puppet[:node_name_value] = 'bar'
- it "should have a method for retrieving facts" do
- @facthandler.should respond_to(:find_facts)
- end
+ @facthandler.find_facts.should == bar_facts
+ end
- it "should use the Facts class with the :certname to find the facts" do
- Puppet.settings.expects(:value).with(:certname).returns "foo"
- Puppet::Node::Facts.indirection.expects(:find).with("foo").returns "myfacts"
- @facthandler.stubs(:reload_facter)
- @facthandler.find_facts.should == "myfacts"
- end
+ it "should set the facts name based on the node_name_fact" do
+ facts = Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name')
+ Puppet::Node::Facts.indirection.save(facts)
+ Puppet[:node_name_fact] = 'my_name_fact'
- it "should reload Facter and find local facts when asked to find facts" do
- @facthandler.expects(:reload_facter)
+ @facthandler.find_facts.name.should == 'other_node_name'
+ end
- Puppet.settings.expects(:value).with(:certname).returns "myhost"
- Puppet::Node::Facts.indirection.expects(:find).with("myhost")
+ it "should set the node_name_value based on the node_name_fact" do
+ facts = Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name')
+ Puppet::Node::Facts.indirection.save(facts)
+ Puppet[:node_name_fact] = 'my_name_fact'
- @facthandler.find_facts
- end
+ @facthandler.find_facts
- it "should fail if finding facts fails" do
- @facthandler.stubs(:reload_facter)
+ Puppet[:node_name_value].should == 'other_node_name'
+ end
- Puppet.settings.stubs(:value).with(:trace).returns false
- Puppet.settings.stubs(:value).with(:certname).returns "myhost"
- Puppet::Node::Facts.indirection.expects(:find).raises RuntimeError
+ it "should reload Facter before finding facts" do
+ @facthandler.expects(:reload_facter)
- lambda { @facthandler.find_facts }.should raise_error(Puppet::Error)
+ @facthandler.find_facts
+ end
+
+ it "should fail if finding facts fails" do
+ Puppet[:trace] = false
+ Puppet[:certname] = "myhost"
+ Puppet::Node::Facts.indirection.expects(:find).raises RuntimeError
+
+ lambda { @facthandler.find_facts }.should raise_error(Puppet::Error)
+ end
end
- it "should have a method to prepare the facts for uploading" do
- @facthandler.should respond_to(:facts_for_uploading)
+ it "should warn about factsync deprecation when factsync is enabled" do
+ Puppet::Configurer::Downloader.stubs(:new).returns mock("downloader", :evaluate => nil)
+
+ @facthandler.expects(:download_fact_plugins?).returns true
+ Puppet.expects(:warning)
+ @facthandler.download_fact_plugins
end
# I couldn't get marshal to work for this, only yaml, so we hard-code yaml.
diff --git a/spec/unit/configurer_spec.rb b/spec/unit/configurer_spec.rb
index 7b76c3221..0f255af76 100755
--- a/spec/unit/configurer_spec.rb
+++ b/spec/unit/configurer_spec.rb
@@ -10,6 +10,10 @@ describe Puppet::Configurer do
before do
Puppet.settings.stubs(:use).returns(true)
@agent = Puppet::Configurer.new
+ @agent.stubs(:dostorage)
+ Puppet::Util::Storage.stubs(:store)
+ Puppet[:server] = "puppetmaster"
+ Puppet[:report] = true
end
it "should include the Plugin Handler module" do
@@ -70,457 +74,462 @@ describe Puppet::Configurer do
lambda { @agent.execute_postrun_command }.should raise_error(Puppet::Configurer::CommandHookError)
end
end
-end
-describe Puppet::Configurer, "when executing a catalog run" do
- before do
- Puppet.settings.stubs(:use).returns(true)
- @agent = Puppet::Configurer.new
- @agent.stubs(:prepare)
- @agent.stubs(:facts_for_uploading).returns({})
- @catalog = Puppet::Resource::Catalog.new
- @catalog.stubs(:apply)
- @agent.stubs(:retrieve_catalog).returns @catalog
- @agent.stubs(:save_last_run_summary)
- Puppet::Transaction::Report.indirection.stubs(:save)
- end
+ describe "when executing a catalog run" do
+ before do
+ Puppet.settings.stubs(:use).returns(true)
+ @agent.stubs(:prepare)
+ Puppet::Node::Facts.indirection.terminus_class = :memory
+ @facts = Puppet::Node::Facts.new(Puppet[:node_name_value])
+ Puppet::Node::Facts.indirection.save(@facts)
+
+ @catalog = Puppet::Resource::Catalog.new
+ @catalog.stubs(:to_ral).returns(@catalog)
+ Puppet::Resource::Catalog.indirection.terminus_class = :rest
+ Puppet::Resource::Catalog.indirection.stubs(:find).returns(@catalog)
+ @agent.stubs(:send_report)
+ end
- it "should prepare for the run" do
- @agent.expects(:prepare)
+ it "should prepare for the run" do
+ @agent.expects(:prepare)
- @agent.run
- end
+ @agent.run
+ end
- it "should initialize a transaction report if one is not provided" do
- report = Puppet::Transaction::Report.new("apply")
- Puppet::Transaction::Report.expects(:new).at_least_once.returns report
+ it "should initialize a transaction report if one is not provided" do
+ report = Puppet::Transaction::Report.new("apply")
+ Puppet::Transaction::Report.expects(:new).at_least_once.returns report
- @agent.run
- end
+ @agent.run
+ end
- it "should pass the new report to the catalog" do
- report = Puppet::Transaction::Report.new("apply")
- Puppet::Transaction::Report.stubs(:new).returns report
- @catalog.expects(:apply).with{|options| options[:report] == report}
+ it "should respect node_name_fact when setting the host on a report" do
+ Puppet[:node_name_fact] = 'my_name_fact'
+ @facts.values = {'my_name_fact' => 'node_name_from_fact'}
- @agent.run
- end
+ @agent.run.host.should == 'node_name_from_fact'
+ end
- it "should use the provided report if it was passed one" do
- report = Puppet::Transaction::Report.new("apply")
- Puppet::Transaction::Report.expects(:new).never
- @catalog.expects(:apply).with{|options| options[:report] == report}
+ it "should pass the new report to the catalog" do
+ report = Puppet::Transaction::Report.new("apply")
+ Puppet::Transaction::Report.stubs(:new).returns report
+ @catalog.expects(:apply).with{|options| options[:report] == report}
- @agent.run(:report => report)
- end
+ @agent.run
+ end
- it "should set the report as a log destination" do
- report = Puppet::Transaction::Report.new("apply")
- Puppet::Transaction::Report.expects(:new).returns report
+ it "should use the provided report if it was passed one" do
+ report = Puppet::Transaction::Report.new("apply")
+ Puppet::Transaction::Report.expects(:new).never
+ @catalog.expects(:apply).with{|options| options[:report] == report}
- @agent.stubs(:send_report)
- Puppet::Util::Log.expects(:newdestination).with(report)
+ @agent.run(:report => report)
+ end
- @agent.run
- end
+ it "should set the report as a log destination" do
+ report = Puppet::Transaction::Report.new("apply")
+ Puppet::Transaction::Report.expects(:new).at_least_once.returns report
- it "should retrieve the catalog" do
- @agent.expects(:retrieve_catalog)
+ Puppet::Util::Log.expects(:newdestination).with(report).at_least_once
- @agent.run
- end
+ @agent.run
+ end
- it "should log a failure and do nothing if no catalog can be retrieved" do
- @agent.expects(:retrieve_catalog).returns nil
+ it "should retrieve the catalog" do
+ @agent.expects(:retrieve_catalog)
- Puppet.expects(:err).with "Could not retrieve catalog; skipping run"
+ @agent.run
+ end
- @agent.run
- end
+ it "should log a failure and do nothing if no catalog can be retrieved" do
+ @agent.expects(:retrieve_catalog).returns nil
- it "should apply the catalog with all options to :run" do
- @agent.expects(:retrieve_catalog).returns @catalog
+ Puppet.expects(:err).with "Could not retrieve catalog; skipping run"
- @catalog.expects(:apply).with { |args| args[:one] == true }
- @agent.run :one => true
- end
+ @agent.run
+ end
- it "should accept a catalog and use it instead of retrieving a different one" do
- @agent.expects(:retrieve_catalog).never
+ it "should apply the catalog with all options to :run" do
+ @agent.expects(:retrieve_catalog).returns @catalog
- @catalog.expects(:apply)
- @agent.run :one => true, :catalog => @catalog
- end
+ @catalog.expects(:apply).with { |args| args[:one] == true }
+ @agent.run :one => true
+ end
- it "should benchmark how long it takes to apply the catalog" do
- @agent.expects(:benchmark).with(:notice, "Finished catalog run")
+ it "should accept a catalog and use it instead of retrieving a different one" do
+ @agent.expects(:retrieve_catalog).never
- @agent.expects(:retrieve_catalog).returns @catalog
+ @catalog.expects(:apply)
+ @agent.run :one => true, :catalog => @catalog
+ end
- @catalog.expects(:apply).never # because we're not yielding
- @agent.run
- end
+ it "should benchmark how long it takes to apply the catalog" do
+ @agent.expects(:benchmark).with(:notice, "Finished catalog run")
- it "should execute post-run hooks after the run" do
- @agent.expects(:execute_postrun_command)
+ @agent.expects(:retrieve_catalog).returns @catalog
- @agent.run
- end
+ @catalog.expects(:apply).never # because we're not yielding
+ @agent.run
+ end
- it "should send the report" do
- report = Puppet::Transaction::Report.new("apply")
- Puppet::Transaction::Report.expects(:new).returns(report)
- @agent.expects(:send_report).with { |r, trans| r == report }
+ it "should execute post-run hooks after the run" do
+ @agent.expects(:execute_postrun_command)
- @agent.run
- end
+ @agent.run
+ end
- it "should send the transaction report with a reference to the transaction if a run was actually made" do
- report = Puppet::Transaction::Report.new("apply")
- Puppet::Transaction::Report.expects(:new).returns(report)
+ it "should send the report" do
+ report = Puppet::Transaction::Report.new("apply")
+ Puppet::Transaction::Report.expects(:new).at_least_once.returns(report)
+ @agent.expects(:send_report).with { |r, trans| r == report }
- trans = stub 'transaction'
- @catalog.expects(:apply).returns trans
+ @agent.run
+ end
- @agent.expects(:send_report).with { |r, t| t == trans }
+ it "should send the transaction report with a reference to the transaction if a run was actually made" do
+ report = Puppet::Transaction::Report.new("apply")
+ Puppet::Transaction::Report.expects(:new).returns(report)
- @agent.run :catalog => @catalog
- end
+ trans = stub 'transaction'
+ @catalog.expects(:apply).returns trans
+
+ @agent.expects(:send_report).with { |r, t| t == trans }
- it "should send the transaction report even if the catalog could not be retrieved" do
- @agent.expects(:retrieve_catalog).returns nil
+ @agent.run :catalog => @catalog
+ end
- report = Puppet::Transaction::Report.new("apply")
- Puppet::Transaction::Report.expects(:new).returns(report)
- @agent.expects(:send_report)
+ it "should send the transaction report even if the catalog could not be retrieved" do
+ @agent.expects(:retrieve_catalog).returns nil
- @agent.run
- end
+ report = Puppet::Transaction::Report.new("apply")
+ Puppet::Transaction::Report.expects(:new).returns(report)
+ @agent.expects(:send_report)
- it "should send the transaction report even if there is a failure" do
- @agent.expects(:retrieve_catalog).raises "whatever"
+ @agent.run
+ end
- report = Puppet::Transaction::Report.new("apply")
- Puppet::Transaction::Report.expects(:new).returns(report)
- @agent.expects(:send_report)
+ it "should send the transaction report even if there is a failure" do
+ @agent.expects(:retrieve_catalog).raises "whatever"
- lambda { @agent.run }.should raise_error
- end
+ report = Puppet::Transaction::Report.new("apply")
+ Puppet::Transaction::Report.expects(:new).returns(report)
+ @agent.expects(:send_report)
- it "should remove the report as a log destination when the run is finished" do
- report = Puppet::Transaction::Report.new("apply")
- Puppet::Transaction::Report.expects(:new).returns(report)
+ lambda { @agent.run }.should raise_error
+ end
- report.expects(:<<).at_least_once
+ it "should remove the report as a log destination when the run is finished" do
+ report = Puppet::Transaction::Report.new("apply")
+ Puppet::Transaction::Report.expects(:new).at_least_once.returns(report)
- @agent.run
- Puppet::Util::Log.destinations.should_not include(report)
- end
+ @agent.run
- it "should return the report as the result of the run" do
- report = Puppet::Transaction::Report.new("apply")
- Puppet::Transaction::Report.expects(:new).returns(report)
+ Puppet::Util::Log.destinations.should_not include(report)
+ end
- @agent.run.should equal(report)
- end
-end
+ it "should return the report as the result of the run" do
+ report = Puppet::Transaction::Report.new("apply")
+ Puppet::Transaction::Report.expects(:new).at_least_once.returns(report)
-describe Puppet::Configurer, "when sending a report" do
- include PuppetSpec::Files
+ @agent.run.should equal(report)
+ end
- before do
- Puppet.settings.stubs(:use).returns(true)
- @configurer = Puppet::Configurer.new
- Puppet[:lastrunfile] = tmpfile('last_run_file')
+ describe "when not using a REST terminus for catalogs" do
+ it "should not pass any facts when retrieving the catalog" do
+ Puppet::Resource::Catalog.indirection.terminus_class = :compiler
+ @agent.expects(:facts_for_uploading).never
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options|
+ options[:facts].nil?
+ }.returns @catalog
- @report = Puppet::Transaction::Report.new("apply")
- @trans = stub 'transaction'
- end
+ @agent.run
+ end
+ end
+
+ describe "when using a REST terminus for catalogs" do
+ it "should pass the prepared facts and the facts format as arguments when retrieving the catalog" do
+ Puppet::Resource::Catalog.indirection.terminus_class = :rest
+ @agent.expects(:facts_for_uploading).returns(:facts => "myfacts", :facts_format => :foo)
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options|
+ options[:facts] == "myfacts" and options[:facts_format] == :foo
+ }.returns @catalog
- it "should finalize the report" do
- @report.expects(:finalize_report)
- @configurer.send_report(@report, @trans)
+ @agent.run
+ end
+ end
end
- it "should print a report summary if configured to do so" do
- Puppet.settings[:summarize] = true
+ describe "when sending a report" do
+ include PuppetSpec::Files
- @report.expects(:summary).returns "stuff"
+ before do
+ Puppet.settings.stubs(:use).returns(true)
+ @configurer = Puppet::Configurer.new
+ Puppet[:lastrunfile] = tmpfile('last_run_file')
- @configurer.expects(:puts).with("stuff")
- @configurer.send_report(@report, nil)
- end
+ @report = Puppet::Transaction::Report.new("apply")
+ @trans = stub 'transaction'
+ end
- it "should not print a report summary if not configured to do so" do
- Puppet.settings[:summarize] = false
+ it "should finalize the report" do
+ @report.expects(:finalize_report)
+ @configurer.send_report(@report, @trans)
+ end
- @configurer.expects(:puts).never
- @configurer.send_report(@report, nil)
- end
+ it "should print a report summary if configured to do so" do
+ Puppet.settings[:summarize] = true
- it "should save the report if reporting is enabled" do
- Puppet.settings[:report] = true
+ @report.expects(:summary).returns "stuff"
- Puppet::Transaction::Report.indirection.expects(:save).with(@report)
- @configurer.send_report(@report, nil)
- end
+ @configurer.expects(:puts).with("stuff")
+ @configurer.send_report(@report, nil)
+ end
- it "should not save the report if reporting is disabled" do
- Puppet.settings[:report] = false
+ it "should not print a report summary if not configured to do so" do
+ Puppet.settings[:summarize] = false
- Puppet::Transaction::Report.indirection.expects(:save).never
- @configurer.send_report(@report, nil)
- end
+ @configurer.expects(:puts).never
+ @configurer.send_report(@report, nil)
+ end
- it "should save the last run summary if reporting is enabled" do
- Puppet.settings[:report] = true
+ it "should save the report if reporting is enabled" do
+ Puppet.settings[:report] = true
- @configurer.expects(:save_last_run_summary).with(@report)
- @configurer.send_report(@report, nil)
- end
+ Puppet::Transaction::Report.indirection.expects(:save).with(@report)
+ @configurer.send_report(@report, nil)
+ end
- it "should save the last run summary if reporting is disabled" do
- Puppet.settings[:report] = false
+ it "should not save the report if reporting is disabled" do
+ Puppet.settings[:report] = false
- @configurer.expects(:save_last_run_summary).with(@report)
- @configurer.send_report(@report, nil)
- end
+ Puppet::Transaction::Report.indirection.expects(:save).with(@report).never
+ @configurer.send_report(@report, nil)
+ end
- it "should log but not fail if saving the report fails" do
- Puppet.settings[:report] = true
+ it "should save the last run summary if reporting is enabled" do
+ Puppet.settings[:report] = true
- Puppet::Transaction::Report.indirection.expects(:save).with(@report).raises "whatever"
+ @configurer.expects(:save_last_run_summary).with(@report)
+ @configurer.send_report(@report, nil)
+ end
- Puppet.expects(:err)
- lambda { @configurer.send_report(@report, nil) }.should_not raise_error
- end
-end
+ it "should save the last run summary if reporting is disabled" do
+ Puppet.settings[:report] = false
-describe Puppet::Configurer, "when saving the summary report file" do
- before do
- Puppet.settings.stubs(:use).returns(true)
- @configurer = Puppet::Configurer.new
+ @configurer.expects(:save_last_run_summary).with(@report)
+ @configurer.send_report(@report, nil)
+ end
- @report = stub 'report'
- @trans = stub 'transaction'
- @lastrunfd = stub 'lastrunfd'
- Puppet::Util::FileLocking.stubs(:writelock).yields(@lastrunfd)
- end
+ it "should log but not fail if saving the report fails" do
+ Puppet.settings[:report] = true
- it "should write the raw summary to the lastrunfile setting value" do
- Puppet::Util::FileLocking.expects(:writelock).with(Puppet[:lastrunfile], 0660)
- @configurer.save_last_run_summary(@report)
- end
+ Puppet::Transaction::Report.indirection.expects(:save).raises("whatever")
- it "should write the raw summary as yaml" do
- @report.expects(:raw_summary).returns("summary")
- @lastrunfd.expects(:print).with(YAML.dump("summary"))
- @configurer.save_last_run_summary(@report)
+ Puppet.expects(:err)
+ lambda { @configurer.send_report(@report, nil) }.should_not raise_error
+ end
end
- it "should log but not fail if saving the last run summary fails" do
- Puppet::Util::FileLocking.expects(:writelock).raises "exception"
- Puppet.expects(:err)
- lambda { @configurer.save_last_run_summary(@report) }.should_not raise_error
- end
+ describe "when saving the summary report file" do
+ before do
+ Puppet.settings.stubs(:use).returns(true)
+ @configurer = Puppet::Configurer.new
-end
+ @report = stub 'report'
+ @trans = stub 'transaction'
+ @lastrunfd = stub 'lastrunfd'
+ Puppet::Util::FileLocking.stubs(:writelock).yields(@lastrunfd)
+ end
-describe Puppet::Configurer, "when retrieving a catalog" do
- before do
- Puppet.settings.stubs(:use).returns(true)
- @agent = Puppet::Configurer.new
- @agent.stubs(:facts_for_uploading).returns({})
+ it "should write the raw summary to the lastrunfile setting value" do
+ Puppet::Util::FileLocking.expects(:writelock).with(Puppet[:lastrunfile], 0660)
+ @configurer.save_last_run_summary(@report)
+ end
- @catalog = Puppet::Resource::Catalog.new
+ it "should write the raw summary as yaml" do
+ @report.expects(:raw_summary).returns("summary")
+ @lastrunfd.expects(:print).with(YAML.dump("summary"))
+ @configurer.save_last_run_summary(@report)
+ end
- # this is the default when using a Configurer instance
- Puppet::Resource::Catalog.indirection.stubs(:terminus_class).returns :rest
+ it "should log but not fail if saving the last run summary fails" do
+ Puppet::Util::FileLocking.expects(:writelock).raises "exception"
+ Puppet.expects(:err)
+ lambda { @configurer.save_last_run_summary(@report) }.should_not raise_error
+ end
- @agent.stubs(:convert_catalog).returns @catalog
end
- describe "and configured to only retrieve a catalog from the cache" do
+ describe "when retrieving a catalog" do
before do
- Puppet.settings[:use_cached_catalog] = true
- end
+ Puppet.settings.stubs(:use).returns(true)
+ @agent.stubs(:facts_for_uploading).returns({})
- it "should first look in the cache for a catalog" do
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.never
-
- @agent.retrieve_catalog.should == @catalog
- end
+ @catalog = Puppet::Resource::Catalog.new
- it "should compile a new catalog if none is found in the cache" do
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
+ # this is the default when using a Configurer instance
+ Puppet::Resource::Catalog.indirection.stubs(:terminus_class).returns :rest
- @agent.retrieve_catalog.should == @catalog
+ @agent.stubs(:convert_catalog).returns @catalog
end
- end
- describe "when not using a REST terminus for catalogs" do
- it "should not pass any facts when retrieving the catalog" do
- @agent.expects(:facts_for_uploading).never
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options|
- options[:facts].nil?
- }.returns @catalog
+ describe "and configured to only retrieve a catalog from the cache" do
+ before do
+ Puppet.settings[:use_cached_catalog] = true
+ end
- @agent.retrieve_catalog
- end
- end
+ it "should first look in the cache for a catalog" do
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.never
+
+ @agent.retrieve_catalog({}).should == @catalog
+ end
- describe "when using a REST terminus for catalogs" do
- it "should pass the prepared facts and the facts format as arguments when retrieving the catalog" do
- @agent.expects(:facts_for_uploading).returns(:facts => "myfacts", :facts_format => :foo)
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options|
- options[:facts] == "myfacts" and options[:facts_format] == :foo
- }.returns @catalog
+ it "should compile a new catalog if none is found in the cache" do
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
- @agent.retrieve_catalog
+ @agent.retrieve_catalog({}).should == @catalog
+ end
end
- end
- it "should use the Catalog class to get its catalog" do
- Puppet::Resource::Catalog.indirection.expects(:find).returns @catalog
+ it "should use the Catalog class to get its catalog" do
+ Puppet::Resource::Catalog.indirection.expects(:find).returns @catalog
- @agent.retrieve_catalog
- end
+ @agent.retrieve_catalog({})
+ end
- it "should use its certname to retrieve the catalog" do
- Facter.stubs(:value).returns "eh"
- Puppet.settings[:certname] = "myhost.domain.com"
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| name == "myhost.domain.com" }.returns @catalog
+ it "should use its node_name_value to retrieve the catalog" do
+ Facter.stubs(:value).returns "eh"
+ Puppet.settings[:node_name_value] = "myhost.domain.com"
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| name == "myhost.domain.com" }.returns @catalog
- @agent.retrieve_catalog
- end
+ @agent.retrieve_catalog({})
+ end
- it "should default to returning a catalog retrieved directly from the server, skipping the cache" do
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
+ it "should default to returning a catalog retrieved directly from the server, skipping the cache" do
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
- @agent.retrieve_catalog.should == @catalog
- end
+ @agent.retrieve_catalog({}).should == @catalog
+ end
- it "should log and return the cached catalog when no catalog can be retrieved from the server" do
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
+ it "should log and return the cached catalog when no catalog can be retrieved from the server" do
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
- Puppet.expects(:notice)
+ Puppet.expects(:notice)
- @agent.retrieve_catalog.should == @catalog
- end
+ @agent.retrieve_catalog({}).should == @catalog
+ end
- it "should not look in the cache for a catalog if one is returned from the server" do
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.never
+ it "should not look in the cache for a catalog if one is returned from the server" do
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.never
- @agent.retrieve_catalog.should == @catalog
- end
+ @agent.retrieve_catalog({}).should == @catalog
+ end
- it "should return the cached catalog when retrieving the remote catalog throws an exception" do
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.raises "eh"
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
+ it "should return the cached catalog when retrieving the remote catalog throws an exception" do
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.raises "eh"
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
- @agent.retrieve_catalog.should == @catalog
- end
+ @agent.retrieve_catalog({}).should == @catalog
+ end
- it "should log and return nil if no catalog can be retrieved from the server and :usecacheonfailure is disabled" do
- Puppet.stubs(:[])
- Puppet.expects(:[]).with(:usecacheonfailure).returns false
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
+ it "should log and return nil if no catalog can be retrieved from the server and :usecacheonfailure is disabled" do
+ Puppet.stubs(:[])
+ Puppet.expects(:[]).with(:usecacheonfailure).returns false
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
- Puppet.expects(:warning)
+ Puppet.expects(:warning)
- @agent.retrieve_catalog.should be_nil
- end
+ @agent.retrieve_catalog({}).should be_nil
+ end
- it "should return nil if no cached catalog is available and no catalog can be retrieved from the server" do
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
+ it "should return nil if no cached catalog is available and no catalog can be retrieved from the server" do
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
- @agent.retrieve_catalog.should be_nil
- end
+ @agent.retrieve_catalog({}).should be_nil
+ end
- it "should convert the catalog before returning" do
- Puppet::Resource::Catalog.indirection.stubs(:find).returns @catalog
+ it "should convert the catalog before returning" do
+ Puppet::Resource::Catalog.indirection.stubs(:find).returns @catalog
- @agent.expects(:convert_catalog).with { |cat, dur| cat == @catalog }.returns "converted catalog"
- @agent.retrieve_catalog.should == "converted catalog"
- end
+ @agent.expects(:convert_catalog).with { |cat, dur| cat == @catalog }.returns "converted catalog"
+ @agent.retrieve_catalog({}).should == "converted catalog"
+ end
- it "should return nil if there is an error while retrieving the catalog" do
- Puppet::Resource::Catalog.indirection.expects(:find).at_least_once.raises "eh"
+ it "should return nil if there is an error while retrieving the catalog" do
+ Puppet::Resource::Catalog.indirection.expects(:find).at_least_once.raises "eh"
- @agent.retrieve_catalog.should be_nil
+ @agent.retrieve_catalog({}).should be_nil
+ end
end
-end
-describe Puppet::Configurer, "when converting the catalog" do
- before do
- Puppet.settings.stubs(:use).returns(true)
- @agent = Puppet::Configurer.new
+ describe "when converting the catalog" do
+ before do
+ Puppet.settings.stubs(:use).returns(true)
- @catalog = Puppet::Resource::Catalog.new
- @oldcatalog = stub 'old_catalog', :to_ral => @catalog
- end
+ @catalog = Puppet::Resource::Catalog.new
+ @oldcatalog = stub 'old_catalog', :to_ral => @catalog
+ end
- it "should convert the catalog to a RAL-formed catalog" do
- @oldcatalog.expects(:to_ral).returns @catalog
+ it "should convert the catalog to a RAL-formed catalog" do
+ @oldcatalog.expects(:to_ral).returns @catalog
- @agent.convert_catalog(@oldcatalog, 10).should equal(@catalog)
- end
+ @agent.convert_catalog(@oldcatalog, 10).should equal(@catalog)
+ end
- it "should finalize the catalog" do
- @catalog.expects(:finalize)
+ it "should finalize the catalog" do
+ @catalog.expects(:finalize)
- @agent.convert_catalog(@oldcatalog, 10)
- end
+ @agent.convert_catalog(@oldcatalog, 10)
+ end
- it "should record the passed retrieval time with the RAL catalog" do
- @catalog.expects(:retrieval_duration=).with 10
+ it "should record the passed retrieval time with the RAL catalog" do
+ @catalog.expects(:retrieval_duration=).with 10
- @agent.convert_catalog(@oldcatalog, 10)
- end
+ @agent.convert_catalog(@oldcatalog, 10)
+ end
- it "should write the RAL catalog's class file" do
- @catalog.expects(:write_class_file)
+ it "should write the RAL catalog's class file" do
+ @catalog.expects(:write_class_file)
- @agent.convert_catalog(@oldcatalog, 10)
+ @agent.convert_catalog(@oldcatalog, 10)
+ end
end
-end
-describe Puppet::Configurer, "when preparing for a run" do
- before do
- Puppet.settings.stubs(:use).returns(true)
- @agent = Puppet::Configurer.new
- @agent.stubs(:dostorage)
- @agent.stubs(:download_fact_plugins)
- @agent.stubs(:download_plugins)
- @agent.stubs(:execute_prerun_command)
- @facts = {"one" => "two", "three" => "four"}
- end
+ describe "when preparing for a run" do
+ before do
+ Puppet.settings.stubs(:use).returns(true)
+ @agent.stubs(:download_fact_plugins)
+ @agent.stubs(:download_plugins)
+ @agent.stubs(:execute_prerun_command)
+ @facts = {"one" => "two", "three" => "four"}
+ end
- it "should initialize the metadata store" do
- @agent.class.stubs(:facts).returns(@facts)
- @agent.expects(:dostorage)
- @agent.prepare({})
- end
+ it "should initialize the metadata store" do
+ @agent.class.stubs(:facts).returns(@facts)
+ @agent.expects(:dostorage)
+ @agent.prepare({})
+ end
- it "should download fact plugins" do
- @agent.expects(:download_fact_plugins)
+ it "should download fact plugins" do
+ @agent.expects(:download_fact_plugins)
- @agent.prepare({})
- end
+ @agent.prepare({})
+ end
- it "should download plugins" do
- @agent.expects(:download_plugins)
+ it "should download plugins" do
+ @agent.expects(:download_plugins)
- @agent.prepare({})
- end
+ @agent.prepare({})
+ end
- it "should perform the pre-run commands" do
- @agent.expects(:execute_prerun_command)
- @agent.prepare({})
+ it "should perform the pre-run commands" do
+ @agent.expects(:execute_prerun_command)
+ @agent.prepare({})
+ end
end
end
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index 169a9cdcf..c15093d90 100755
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -129,6 +129,7 @@ end
describe Puppet::Node, "when indirecting" do
it "should default to the 'plain' node terminus" do
+ Puppet::Node.indirection.reset_terminus_class
Puppet::Node.indirection.terminus_class.should == :plain
end
diff --git a/spec/unit/transaction/report_spec.rb b/spec/unit/transaction/report_spec.rb
index 191a30eb7..4b04cc157 100755
--- a/spec/unit/transaction/report_spec.rb
+++ b/spec/unit/transaction/report_spec.rb
@@ -9,9 +9,9 @@ describe Puppet::Transaction::Report do
Puppet::Util::Storage.stubs(:store)
end
- it "should set its host name to the certname" do
- Puppet.settings.expects(:value).with(:certname).returns "myhost"
- Puppet::Transaction::Report.new("apply").host.should == "myhost"
+ it "should set its host name to the node_name_value" do
+ Puppet[:node_name_value] = 'mynode'
+ Puppet::Transaction::Report.new("apply").host.should == "mynode"
end
it "should return its host name as its name" do
diff --git a/spec/unit/util/settings/file_setting_spec.rb b/spec/unit/util/settings/file_setting_spec.rb
index 734b41f3a..489628a78 100755
--- a/spec/unit/util/settings/file_setting_spec.rb
+++ b/spec/unit/util/settings/file_setting_spec.rb
@@ -248,6 +248,10 @@ describe Puppet::Util::Settings::FileSetting do
it "should tag the resource with 'settings'" do
@file.to_resource.should be_tagged("settings")
end
+
+ it "should set links to 'follow'" do
+ @file.to_resource[:links].should == :follow
+ end
end
end