summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2011-06-06 15:59:01 -0700
committerNick Lewis <nick@puppetlabs.com>2011-06-06 15:59:01 -0700
commit3d09ca82e57d0c8836b77623d876cd5dc9a3a5e6 (patch)
tree8a55f2319be5042200b66e6c547f02ad52ac3c0f
parent8ebec1effc8038b1f59537450f3fe27249d543ee (diff)
parent1c70f0ce54022b55119b9e2d6d60cd1ae9bc019e (diff)
downloadpuppet-3d09ca82e57d0c8836b77623d876cd5dc9a3a5e6.tar.gz
puppet-3d09ca82e57d0c8836b77623d876cd5dc9a3a5e6.tar.xz
puppet-3d09ca82e57d0c8836b77623d876cd5dc9a3a5e6.zip
Merge branch 'ticket/2.6.x/2128' into 2.6.x
-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--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.rb9
-rw-r--r--lib/puppet/transaction/report.rb2
-rwxr-xr-xspec/integration/defaults_spec.rb22
-rwxr-xr-xspec/unit/application/apply_spec.rb112
-rwxr-xr-xspec/unit/configurer/fact_handler_spec.rb80
-rwxr-xr-xspec/unit/configurer_spec.rb658
-rwxr-xr-xspec/unit/node_spec.rb1
-rwxr-xr-xspec/unit/transaction/report_spec.rb6
15 files changed, 624 insertions, 433 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/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb
index 7f0b95a89..717935640 100644
--- a/lib/puppet/application/apply.rb
+++ b/lib/puppet/application/apply.rb
@@ -85,13 +85,18 @@ class Puppet::Application::Apply < Puppet::Application
end
# Collect our facts.
- unless facts = Puppet::Node::Facts.find(Puppet[:certname])
- raise "Could not find facts for #{Puppet[:certname]}"
+ unless facts = Puppet::Node::Facts.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.find(Puppet[:certname])
- raise "Could not find node #{Puppet[:certname]}"
+ unless node = Puppet::Node.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 9f68ca499..596d2dc53 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.find(Puppet[:certname], fact_options.merge(:ignore_terminus => true))
+ result = Puppet::Resource::Catalog.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.find(Puppet[:certname], fact_options.merge(:ignore_cache => true))
+ result = Puppet::Resource::Catalog.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 075a59458..77bd1e5f1 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.find(Puppet[:certname])
+ facts = Puppet::Node::Facts.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 2a1ded592..4502dae16 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -486,6 +486,15 @@ module Puppet
)
setdefaults(:agent,
+ :node_name_value => ["$certname", "The name of the node."],
+ :node_name_fact => { :default => "",
+ :desc => "The fact to use as the node name.",
+ :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 16fee42ae..841c56968 100644
--- a/lib/puppet/transaction/report.rb
+++ b/lib/puppet/transaction/report.rb
@@ -67,7 +67,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/spec/integration/defaults_spec.rb b/spec/integration/defaults_spec.rb
index 2f30014e8..3178fca11 100755
--- a/spec/integration/defaults_spec.rb
+++ b/spec/integration/defaults_spec.rb
@@ -23,6 +23,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/apply_spec.rb b/spec/unit/application/apply_spec.rb
index 67edd4ed7..cf9d44ca2 100755
--- a/spec/unit/application/apply_spec.rb
+++ b/spec/unit/application/apply_spec.rb
@@ -5,6 +5,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/application/apply'
require 'puppet/file_bucket/dipper'
require 'puppet/configurer'
+require 'fileutils'
describe Puppet::Application::Apply do
before :each do
@@ -182,38 +183,39 @@ 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.terminus_class = :memory
+ Puppet::Node.terminus_class = :memory
- @facts = stub_everything 'facts'
- Puppet::Node::Facts.stubs(:find).returns(@facts)
+ @facts = Puppet::Node::Facts.new(Puppet[:node_name_value])
+ @facts.save
- @node = stub_everything 'node'
- Puppet::Node.stubs(:find).returns(@node)
+ @node = Puppet::Node.new(Puppet[:node_name_value])
+ @node.save
- @catalog = stub_everything 'catalog'
+ @catalog = Puppet::Resource::Catalog.new
@catalog.stubs(:to_ral).returns(@catalog)
+
Puppet::Resource::Catalog.stubs(:find).returns(@catalog)
STDIN.stubs(:read)
- @transaction = stub_everything 'transaction'
- @catalog.stubs(:apply).returns(@transaction)
-
@apply.stubs(:exit)
+ @transaction = Puppet::Transaction.new(@catalog)
+ @catalog.stubs(:apply).returns(@transaction)
+
Puppet::Util::Storage.stubs(:load)
Puppet::Configurer.any_instance.stubs(:save_last_run_summary) # to prevent it from trying to write files
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")
@apply.main
@@ -229,47 +231,58 @@ 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)
@apply.main
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')
@apply.main
end
- it "should collect the node facts" do
- Puppet::Node::Facts.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')
+ @facts.save
+ Puppet::Node.new('other_node_name').save
+ Puppet[:node_name_fact] = 'my_name_fact'
@apply.main
+
+ @facts.name.should == 'other_node_name'
end
- it "should raise an error if we can't find the node" do
- Puppet::Node::Facts.expects(:find).returns(nil)
+ it "should set the node_name_value based on the node_name_fact" do
+ Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name').save
+ Puppet::Node.new('other_node_name').save
+ Puppet[:node_name_fact] = 'my_name_fact'
- lambda { @apply.main }.should raise_error
+ @apply.main
+
+ Puppet[:node_name_value].should == 'other_node_name'
end
- it "should look for the node" do
- Puppet::Node.expects(:find).returns(@node)
+ it "should raise an error if we can't find the facts" do
+ Puppet::Node::Facts.expects(:find).returns(nil)
- @apply.main
+ lambda { @apply.main }.should raise_error
end
it "should raise an error if we can't find the node" do
@@ -279,21 +292,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'}
@apply.main
+
+ @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'])
@apply.main
end
@@ -331,9 +343,12 @@ 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)
@apply.expects(:exit).with(666)
@@ -341,8 +356,7 @@ describe Puppet::Application::Apply do
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)
@apply.expects(:exit).with(666)
@@ -350,8 +364,7 @@ describe Puppet::Application::Apply do
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)
@apply.expects(:exit).with(0)
@@ -360,8 +373,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)
@apply.expects(:exit).with(0)
diff --git a/spec/unit/configurer/fact_handler_spec.rb b/spec/unit/configurer/fact_handler_spec.rb
index 051270144..ced743ea6 100755
--- a/spec/unit/configurer/fact_handler_spec.rb
+++ b/spec/unit/configurer/fact_handler_spec.rb
@@ -13,14 +13,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
@@ -52,46 +44,60 @@ 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.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')
+ foo_facts.save
+ bar_facts.save
+ 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.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
+ Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name').save
+ 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.expects(:find).with("myhost")
+ it "should set the node_name_value based on the node_name_fact" do
+ Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name').save
+ 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.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.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 a4b627c08..b825e3404 100755
--- a/spec/unit/configurer_spec.rb
+++ b/spec/unit/configurer_spec.rb
@@ -10,6 +10,7 @@ describe Puppet::Configurer do
before do
Puppet.settings.stubs(:use).returns(true)
@agent = Puppet::Configurer.new
+ Puppet::Util::Storage.stubs(:store)
end
it "should include the Plugin Handler module" do
@@ -70,457 +71,466 @@ 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::Util::Log.stubs(:newdestination)
- Puppet::Util::Log.stubs(:close)
- end
+ describe "when executing a catalog run" do
+ before do
+ Puppet.settings.stubs(:use).returns(true)
+ @agent.stubs(:prepare)
+ Puppet::Node::Facts.terminus_class = :memory
+ @facts = Puppet::Node::Facts.new(Puppet[:node_name_value])
+ @facts.save
+
+ @catalog = Puppet::Resource::Catalog.new
+ @catalog.stubs(:to_ral).returns(@catalog)
+ Puppet::Resource::Catalog.terminus_class = :rest
+ Puppet::Resource::Catalog.stubs(:find).returns(@catalog)
+ @agent.stubs(:send_report)
+
+ Puppet::Util::Log.stubs(:newdestination)
+ Puppet::Util::Log.stubs(:close)
+ 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).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}
- 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)
- @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
- it "should send the transaction report even if the catalog could not be retrieved" do
- @agent.expects(:retrieve_catalog).returns nil
+ @agent.expects(:send_report).with { |r, t| t == trans }
- report = Puppet::Transaction::Report.new("apply")
- Puppet::Transaction::Report.expects(:new).returns(report)
- @agent.expects(:send_report)
+ @agent.run :catalog => @catalog
+ end
- @agent.run
- end
+ it "should send the transaction report even if the catalog could not be retrieved" do
+ @agent.expects(:retrieve_catalog).returns nil
- it "should send the transaction report even if there is a failure" do
- @agent.expects(:retrieve_catalog).raises "whatever"
+ report = Puppet::Transaction::Report.new("apply")
+ Puppet::Transaction::Report.expects(:new).returns(report)
+ @agent.expects(:send_report)
- report = Puppet::Transaction::Report.new("apply")
- Puppet::Transaction::Report.expects(:new).returns(report)
- @agent.expects(:send_report)
+ @agent.run
+ end
- lambda { @agent.run }.should raise_error
- end
+ it "should send the transaction report even if there is a failure" do
+ @agent.expects(:retrieve_catalog).raises "whatever"
- 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)
+ report = Puppet::Transaction::Report.new("apply")
+ Puppet::Transaction::Report.expects(:new).returns(report)
+ @agent.expects(:send_report)
- Puppet::Util::Log.expects(:close).with(report)
+ lambda { @agent.run }.should raise_error
+ end
- @agent.run
- end
+ 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)
- 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.expects(:close).with(report)
- @agent.run.should equal(report)
- end
-end
+ @agent.run
+ end
-describe Puppet::Configurer, "when sending a report" do
- include PuppetSpec::Files
+ 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)
- before do
- Puppet.settings.stubs(:use).returns(true)
- @configurer = Puppet::Configurer.new
- Puppet[:lastrunfile] = tmpfile('last_run_file')
+ @agent.run.should equal(report)
+ end
- @report = Puppet::Transaction::Report.new("apply")
- @trans = stub 'transaction'
- end
+ describe "when not using a REST terminus for catalogs" do
+ it "should not pass any facts when retrieving the catalog" do
+ Puppet::Resource::Catalog.terminus_class = :compiler
+ @agent.expects(:facts_for_uploading).never
+ Puppet::Resource::Catalog.expects(:find).with { |name, options|
+ options[:facts].nil?
+ }.returns @catalog
- it "should finalize the report" do
- @report.expects(:finalize_report)
- @configurer.send_report(@report, @trans)
+ @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.terminus_class = :rest
+ @agent.expects(:facts_for_uploading).returns(:facts => "myfacts", :facts_format => :foo)
+ Puppet::Resource::Catalog.expects(:find).with { |name, options|
+ options[:facts] == "myfacts" and options[:facts_format] == :foo
+ }.returns @catalog
+
+ @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"
- @report.expects(:save)
- @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
- @report.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
+ @report.expects(:save)
+ @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
+ @report.expects(:save).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
- @report.expects(:save).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
+ @report.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.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.never
+ @catalog = Puppet::Resource::Catalog.new
- @agent.retrieve_catalog.should == @catalog
- end
+ # this is the default when using a Configurer instance
+ Puppet::Resource::Catalog.indirection.stubs(:terminus_class).returns :rest
- it "should compile a new catalog if none is found in the cache" do
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
-
- @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.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.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.never
- 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.expects(:find).with { |name, options|
- options[:facts] == "myfacts" and options[:facts_format] == :foo
- }.returns @catalog
+ @agent.retrieve_catalog({}).should == @catalog
+ end
- @agent.retrieve_catalog
+ it "should compile a new catalog if none is found in the cache" do
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
+
+ @agent.retrieve_catalog({}).should == @catalog
+ end
end
- end
- it "should use the Catalog class to get its catalog" do
- Puppet::Resource::Catalog.expects(:find).returns @catalog
+ it "should use the Catalog class to get its catalog" do
+ Puppet::Resource::Catalog.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.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.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.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.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.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
- Puppet::Resource::Catalog.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.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
+ Puppet::Resource::Catalog.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.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
- Puppet::Resource::Catalog.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.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
+ Puppet::Resource::Catalog.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.expects(:find).with { |name, options| options[:ignore_cache] == true }.raises "eh"
- Puppet::Resource::Catalog.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.expects(:find).with { |name, options| options[:ignore_cache] == true }.raises "eh"
+ Puppet::Resource::Catalog.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.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.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.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
- Puppet::Resource::Catalog.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.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
+ Puppet::Resource::Catalog.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.stubs(:find).returns @catalog
+ it "should convert the catalog before returning" do
+ Puppet::Resource::Catalog.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.expects(:find).at_least_once.raises "eh"
+ it "should return nil if there is an error while retrieving the catalog" do
+ Puppet::Resource::Catalog.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(:dostorage)
+ @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 36334ea05..2fcde8f5d 100755
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -136,6 +136,7 @@ describe Puppet::Node, "when indirecting" do
end
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 81efa340e..26d90acb4 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