summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2011-06-02 15:47:21 -0700
committerNick Lewis <nick@puppetlabs.com>2011-06-02 16:29:56 -0700
commita00fd25547db6dec8fcd57a004fbec58324ce3dc (patch)
treee3a272176a91984087c998e0d52854537a99d0e8
parent805b2878d0b23d76917f5210abe35489f6f84c74 (diff)
downloadpuppet-a00fd25547db6dec8fcd57a004fbec58324ce3dc.tar.gz
puppet-a00fd25547db6dec8fcd57a004fbec58324ce3dc.tar.xz
puppet-a00fd25547db6dec8fcd57a004fbec58324ce3dc.zip
maint: Refactor specs in preparation for making node name more flexible
These tests were stubbing when it was unnecessary, so replace much of it with actual objects and files. Paired-With: Jacob Helwig <jacob@puppetlabs.com>
-rwxr-xr-xspec/unit/application/apply_spec.rb95
-rwxr-xr-xspec/unit/configurer/fact_handler_spec.rb61
-rwxr-xr-xspec/unit/configurer_spec.rb649
-rwxr-xr-xspec/unit/node_spec.rb1
4 files changed, 393 insertions, 413 deletions
diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb
index 67edd4ed7..5bd902a03 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[:certname])
+ @facts.save
- @node = stub_everything 'node'
- Puppet::Node.stubs(:find).returns(@node)
+ @node = Puppet::Node.new(Puppet[:certname])
+ @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,26 +231,28 @@ 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)
- Puppet.expects(:[]=).with(:manifest,"starwarsIV")
+ @apply.command_line.stubs(:args).returns([manifest, 'starwarsI', 'starwarsII'])
+
+ Puppet.expects(:[]=).with(:manifest,manifest)
Puppet.expects(:warning).with('Only one file can be applied per run. Skipping starwarsI, starwarsII')
@apply.main
@@ -260,18 +264,12 @@ describe Puppet::Application::Apply do
@apply.main
end
- it "should raise an error if we can't find the node" do
+ it "should raise an error if we can't find the facts" do
Puppet::Node::Facts.expects(:find).returns(nil)
lambda { @apply.main }.should raise_error
end
- it "should look for the node" do
- Puppet::Node.expects(:find).returns(@node)
-
- @apply.main
- end
-
it "should raise an error if we can't find the node" do
Puppet::Node.expects(:find).returns(nil)
@@ -279,21 +277,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 +328,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 +341,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 +349,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 +358,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..241da57d6 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,33 @@ 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)
-
- @facthandler.expects(:download_fact_plugins?).returns true
- Puppet.expects(:warning)
- @facthandler.download_fact_plugins
- end
-
- it "should have a method for retrieving facts" do
- @facthandler.should respond_to(:find_facts)
- end
+ describe "when finding facts" do
+ before :each do
+ @facthandler.stubs(:reload_facter)
+ Puppet::Node::Facts.terminus_class = :memory
+ 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 reload Facter before finding facts" do
+ @facthandler.expects(:reload_facter)
- it "should reload Facter and find local facts when asked to find facts" do
- @facthandler.expects(:reload_facter)
+ @facthandler.find_facts
+ end
- Puppet.settings.expects(:value).with(:certname).returns "myhost"
- Puppet::Node::Facts.expects(:find).with("myhost")
+ it "should fail if finding facts fails" do
+ Puppet[:trace] = false
+ Puppet[:certname] = "myhost"
+ Puppet::Node::Facts.expects(:find).raises RuntimeError
- @facthandler.find_facts
+ lambda { @facthandler.find_facts }.should raise_error(Puppet::Error)
+ end
end
- it "should fail if finding facts fails" do
- @facthandler.stubs(:reload_facter)
-
- Puppet.settings.stubs(:value).with(:trace).returns false
- Puppet.settings.stubs(:value).with(:certname).returns "myhost"
- Puppet::Node::Facts.expects(:find).raises RuntimeError
-
- lambda { @facthandler.find_facts }.should raise_error(Puppet::Error)
- end
+ it "should warn about factsync deprecation when factsync is enabled" do
+ Puppet::Configurer::Downloader.stubs(:new).returns mock("downloader", :evaluate => nil)
- it "should have a method to prepare the facts for uploading" do
- @facthandler.should respond_to(:facts_for_uploading)
+ @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..1504ae5c0 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,459 @@ 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[:certname])
+ @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 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
- end
+ @agent.run
+ 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 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.run(:report => report)
- end
+ @agent.run(:report => report)
+ 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 set the report as a log destination" do
+ report = Puppet::Transaction::Report.new("apply")
+ Puppet::Transaction::Report.expects(:new).at_least_once.returns report
- Puppet::Util::Log.expects(:newdestination).with(report)
+ Puppet::Util::Log.expects(:newdestination).with(report)
- @agent.run
- end
+ @agent.run
+ end
- it "should retrieve the catalog" do
- @agent.expects(:retrieve_catalog)
+ it "should retrieve the catalog" do
+ @agent.expects(:retrieve_catalog)
- @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 log a failure and do nothing if no catalog can be retrieved" do
+ @agent.expects(:retrieve_catalog).returns nil
- Puppet.expects(:err).with "Could not retrieve catalog; skipping run"
+ Puppet.expects(:err).with "Could not retrieve catalog; skipping run"
- @agent.run
- end
+ @agent.run
+ end
- it "should apply the catalog with all options to :run" do
- @agent.expects(:retrieve_catalog).returns @catalog
+ it "should apply the catalog with all options to :run" do
+ @agent.expects(:retrieve_catalog).returns @catalog
- @catalog.expects(:apply).with { |args| args[:one] == true }
- @agent.run :one => true
- end
+ @catalog.expects(:apply).with { |args| args[:one] == true }
+ @agent.run :one => true
+ end
- it "should accept a catalog and use it instead of retrieving a different one" do
- @agent.expects(:retrieve_catalog).never
+ it "should accept a catalog and use it instead of retrieving a different one" do
+ @agent.expects(:retrieve_catalog).never
- @catalog.expects(:apply)
- @agent.run :one => true, :catalog => @catalog
- end
+ @catalog.expects(:apply)
+ @agent.run :one => true, :catalog => @catalog
+ end
- it "should benchmark how long it takes to apply the catalog" do
- @agent.expects(:benchmark).with(:notice, "Finished catalog run")
+ it "should benchmark how long it takes to apply the catalog" do
+ @agent.expects(:benchmark).with(:notice, "Finished catalog run")
- @agent.expects(:retrieve_catalog).returns @catalog
+ @agent.expects(:retrieve_catalog).returns @catalog
- @catalog.expects(:apply).never # because we're not yielding
- @agent.run
- end
+ @catalog.expects(:apply).never # because we're not yielding
+ @agent.run
+ end
- it "should execute post-run hooks after the run" do
- @agent.expects(:execute_postrun_command)
+ 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 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 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 }
- @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 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)
- trans = stub 'transaction'
- @catalog.expects(:apply).returns trans
+ trans = stub 'transaction'
+ @catalog.expects(:apply).returns trans
- @agent.expects(:send_report).with { |r, t| t == trans }
+ @agent.expects(:send_report).with { |r, t| t == trans }
- @agent.run :catalog => @catalog
- end
+ @agent.run :catalog => @catalog
+ 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 the catalog could not be retrieved" do
+ @agent.expects(:retrieve_catalog).returns nil
- 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
+ @agent.run
+ end
- it "should send the transaction report even if there is a failure" do
- @agent.expects(:retrieve_catalog).raises "whatever"
+ 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)
- lambda { @agent.run }.should raise_error
- end
+ lambda { @agent.run }.should raise_error
+ 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).returns(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).at_least_once.returns(report)
- Puppet::Util::Log.expects(:close).with(report)
+ Puppet::Util::Log.expects(:close).with(report)
- @agent.run
- end
+ @agent.run
+ end
- 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)
+ 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)
- @agent.run.should equal(report)
- end
-end
+ @agent.run.should equal(report)
+ end
-describe Puppet::Configurer, "when sending a report" do
- include PuppetSpec::Files
+ 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
- before do
- Puppet.settings.stubs(:use).returns(true)
- @configurer = Puppet::Configurer.new
- Puppet[:lastrunfile] = tmpfile('last_run_file')
+ @agent.run
+ end
+ end
- @report = Puppet::Transaction::Report.new("apply")
- @trans = stub 'transaction'
- 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
- 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"
- @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
+ # this is the default when using a Configurer instance
+ Puppet::Resource::Catalog.indirection.stubs(:terminus_class).returns :rest
+
+ @agent.stubs(:convert_catalog).returns @catalog
end
- 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
+ describe "and configured to only retrieve a catalog from the cache" do
+ before do
+ Puppet.settings[:use_cached_catalog] = true
+ end
- @agent.retrieve_catalog.should == @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 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
+ @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
- 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
+ it "should use the Catalog class to get its catalog" do
+ Puppet::Resource::Catalog.expects(:find).returns @catalog
@agent.retrieve_catalog
end
- end
-
- it "should use the Catalog class to get its catalog" do
- Puppet::Resource::Catalog.expects(:find).returns @catalog
-
- @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 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
- @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