diff options
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/integration/defaults_spec.rb | 22 | ||||
-rwxr-xr-x | spec/unit/application/agent_spec.rb | 2 | ||||
-rwxr-xr-x | spec/unit/application/apply_spec.rb | 124 | ||||
-rwxr-xr-x | spec/unit/application/facts_spec.rb | 1 | ||||
-rwxr-xr-x | spec/unit/configurer/fact_handler_spec.rb | 82 | ||||
-rwxr-xr-x | spec/unit/configurer_spec.rb | 657 | ||||
-rwxr-xr-x | spec/unit/node_spec.rb | 1 | ||||
-rwxr-xr-x | spec/unit/transaction/report_spec.rb | 6 | ||||
-rwxr-xr-x | spec/unit/util/settings/file_setting_spec.rb | 4 |
9 files changed, 480 insertions, 419 deletions
diff --git a/spec/integration/defaults_spec.rb b/spec/integration/defaults_spec.rb index 8aa59288e..9bec769ab 100755 --- a/spec/integration/defaults_spec.rb +++ b/spec/integration/defaults_spec.rb @@ -22,6 +22,28 @@ describe "Puppet defaults" do end end + describe "when setting :node_name_value" do + it "should default to the value of :certname" do + Puppet.settings[:certname] = 'blargle' + Puppet.settings[:node_name_value].should == 'blargle' + end + end + + describe "when setting the :node_name_fact" do + it "should fail when also setting :node_name_value" do + lambda do + Puppet.settings[:node_name_value] = "some value" + Puppet.settings[:node_name_fact] = "some_fact" + end.should raise_error("Cannot specify both the node_name_value and node_name_fact settings") + end + + it "should not fail when using the default for :node_name_value" do + lambda do + Puppet.settings[:node_name_fact] = "some_fact" + end.should_not raise_error + end + end + describe "when configuring the :crl" do it "should warn if :cacrl is set to false" do Puppet.expects(:warning) diff --git a/spec/unit/application/agent_spec.rb b/spec/unit/application/agent_spec.rb index c4f8e7176..d87f1f563 100755 --- a/spec/unit/application/agent_spec.rb +++ b/spec/unit/application/agent_spec.rb @@ -545,7 +545,7 @@ describe Puppet::Application::Agent do @host.stubs(:certificate).returns(@cert) @cert.stubs(:fingerprint).with(:MD5).returns("DIGEST") - Puppet.expects(:notice).with("DIGEST") + @puppetd.expects(:puts).with "DIGEST" @puppetd.fingerprint end diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb index 74c883a3e..19a933950 100755 --- a/spec/unit/application/apply_spec.rb +++ b/spec/unit/application/apply_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' require 'puppet/application/apply' require 'puppet/file_bucket/dipper' require 'puppet/configurer' +require 'fileutils' describe Puppet::Application::Apply do before :each do @@ -59,13 +60,12 @@ describe Puppet::Application::Apply do end it "should set show_diff on --noop" do - Puppet.stubs(:[]=) - Puppet.stubs(:[]).with(:config) - Puppet.stubs(:[]).with(:noop).returns(true) - - Puppet.expects(:[]=).with(:show_diff, true) + Puppet[:noop] = true + Puppet[:show_diff] = false @apply.setup + + Puppet[:show_diff].should == true end it "should set console as the log destination if logdest option wasn't provided" do @@ -127,28 +127,29 @@ describe Puppet::Application::Apply do end describe "the main command" do + include PuppetSpec::Files + before :each do - Puppet.stubs(:[]) - Puppet.settings.stubs(:use) - Puppet.stubs(:[]).with(:prerun_command).returns "" - Puppet.stubs(:[]).with(:postrun_command).returns "" - Puppet.stubs(:[]).with(:trace).returns(true) + Puppet[:prerun_command] = '' + Puppet[:postrun_command] = '' - @apply.options.stubs(:[]) + Puppet::Node::Facts.indirection.terminus_class = :memory + Puppet::Node.indirection.terminus_class = :memory - @facts = stub_everything 'facts' - Puppet::Node::Facts.indirection.stubs(:find).returns(@facts) + @facts = Puppet::Node::Facts.new(Puppet[:node_name_value]) + Puppet::Node::Facts.indirection.save(@facts) - @node = stub_everything 'node' - Puppet::Node.indirection.stubs(:find).returns(@node) + @node = Puppet::Node.new(Puppet[:node_name_value]) + Puppet::Node.indirection.save(@node) - @catalog = stub_everything 'catalog' + @catalog = Puppet::Resource::Catalog.new @catalog.stubs(:to_ral).returns(@catalog) + Puppet::Resource::Catalog.indirection.stubs(:find).returns(@catalog) STDIN.stubs(:read) - @transaction = stub_everything 'transaction' + @transaction = Puppet::Transaction.new(@catalog) @catalog.stubs(:apply).returns(@transaction) Puppet::Util::Storage.stubs(:load) @@ -156,7 +157,7 @@ describe Puppet::Application::Apply do end it "should set the code to run from --code" do - @apply.options.stubs(:[]).with(:code).returns("code to run") + @apply.options[:code] = "code to run" Puppet.expects(:[]=).with(:code,"code to run") expect { @apply.main }.to exit_with 0 @@ -172,47 +173,63 @@ describe Puppet::Application::Apply do end it "should set the manifest if a file is passed on command line and the file exists" do - File.stubs(:exist?).with('site.pp').returns true - @apply.command_line.stubs(:args).returns(['site.pp']) + manifest = tmpfile('site.pp') + FileUtils.touch(manifest) + @apply.command_line.stubs(:args).returns([manifest]) - Puppet.expects(:[]=).with(:manifest,"site.pp") + Puppet.expects(:[]=).with(:manifest,manifest) expect { @apply.main }.to exit_with 0 end it "should raise an error if a file is passed on command line and the file does not exist" do - File.stubs(:exist?).with('noexist.pp').returns false - @apply.command_line.stubs(:args).returns(['noexist.pp']) - lambda { @apply.main }.should raise_error(RuntimeError, 'Could not find file noexist.pp') + noexist = tmpfile('noexist.pp') + @apply.command_line.stubs(:args).returns([noexist]) + lambda { @apply.main }.should raise_error(RuntimeError, "Could not find file #{noexist}") end it "should set the manifest to the first file and warn other files will be skipped" do - File.stubs(:exist?).with('starwarsIV').returns true - File.expects(:exist?).with('starwarsI').never - @apply.command_line.stubs(:args).returns(['starwarsIV', 'starwarsI', 'starwarsII']) + manifest = tmpfile('starwarsIV') + FileUtils.touch(manifest) + + @apply.command_line.stubs(:args).returns([manifest, 'starwarsI', 'starwarsII']) - Puppet.expects(:[]=).with(:manifest,"starwarsIV") + Puppet.expects(:[]=).with(:manifest,manifest) Puppet.expects(:warning).with('Only one file can be applied per run. Skipping starwarsI, starwarsII') expect { @apply.main }.to exit_with 0 end - it "should collect the node facts" do - Puppet::Node::Facts.indirection.expects(:find).returns(@facts) + it "should set the facts name based on the node_name_fact" do + @facts = Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name') + Puppet::Node::Facts.indirection.save(@facts) + + node = Puppet::Node.new('other_node_name') + Puppet::Node.indirection.save(node) + + Puppet[:node_name_fact] = 'my_name_fact' expect { @apply.main }.to exit_with 0 + + @facts.name.should == 'other_node_name' end - it "should raise an error if we can't find the node" do - Puppet::Node::Facts.indirection.expects(:find).returns(nil) + it "should set the node_name_value based on the node_name_fact" do + facts = Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name') + Puppet::Node::Facts.indirection.save(facts) + node = Puppet::Node.new('other_node_name') + Puppet::Node.indirection.save(node) + Puppet[:node_name_fact] = 'my_name_fact' - lambda { @apply.main }.should raise_error + expect { @apply.main }.to exit_with 0 + + Puppet[:node_name_value].should == 'other_node_name' end - it "should look for the node" do - Puppet::Node.indirection.expects(:find).returns(@node) + it "should raise an error if we can't find the facts" do + Puppet::Node::Facts.indirection.expects(:find).returns(nil) - expect { @apply.main }.to exit_with 0 + lambda { @apply.main }.should raise_error end it "should raise an error if we can't find the node" do @@ -222,21 +239,20 @@ describe Puppet::Application::Apply do end it "should merge in our node the loaded facts" do - @facts.stubs(:values).returns("values") - - @node.expects(:merge).with("values") + @facts.values = {'key' => 'value'} expect { @apply.main }.to exit_with 0 + + @node.parameters['key'].should == 'value' end it "should load custom classes if loadclasses" do - @apply.options.stubs(:[]).with(:loadclasses).returns(true) - Puppet.stubs(:[]).with(:classfile).returns("/etc/puppet/classes.txt") - FileTest.stubs(:exists?).with("/etc/puppet/classes.txt").returns(true) - FileTest.stubs(:readable?).with("/etc/puppet/classes.txt").returns(true) - File.stubs(:read).with("/etc/puppet/classes.txt").returns("class") + @apply.options[:loadclasses] = true + classfile = tmpfile('classfile') + File.open(classfile, 'w') { |c| c.puts 'class' } + Puppet[:classfile] = classfile - @node.expects(:classes=) + @node.expects(:classes=).with(['class']) expect { @apply.main }.to exit_with 0 end @@ -274,7 +290,7 @@ describe Puppet::Application::Apply do end it "should save the last run summary" do - Puppet.stubs(:[]).with(:noop).returns(false) + Puppet[:noop] = false report = Puppet::Transaction::Report.new("apply") Puppet::Transaction::Report.stubs(:new).returns(report) @@ -283,25 +299,26 @@ describe Puppet::Application::Apply do end describe "with detailed_exitcodes" do + before :each do + @apply.options[:detailed_exitcodes] = true + end + it "should exit with report's computed exit status" do - Puppet.stubs(:[]).with(:noop).returns(false) - @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true) + Puppet[:noop] = false Puppet::Transaction::Report.any_instance.stubs(:exit_status).returns(666) expect { @apply.main }.to exit_with 666 end it "should exit with report's computed exit status, even if --noop is set" do - Puppet.stubs(:[]).with(:noop).returns(true) - @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true) + Puppet[:noop] = true Puppet::Transaction::Report.any_instance.stubs(:exit_status).returns(666) expect { @apply.main }.to exit_with 666 end it "should always exit with 0 if option is disabled" do - Puppet.stubs(:[]).with(:noop).returns(false) - @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(false) + Puppet[:noop] = false report = stub 'report', :exit_status => 666 @transaction.stubs(:report).returns(report) @@ -309,8 +326,7 @@ describe Puppet::Application::Apply do end it "should always exit with 0 if --noop" do - Puppet.stubs(:[]).with(:noop).returns(true) - @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true) + Puppet[:noop] = true report = stub 'report', :exit_status => 666 @transaction.stubs(:report).returns(report) diff --git a/spec/unit/application/facts_spec.rb b/spec/unit/application/facts_spec.rb index e11ea165c..7a7c36597 100755 --- a/spec/unit/application/facts_spec.rb +++ b/spec/unit/application/facts_spec.rb @@ -16,6 +16,7 @@ describe Puppet::Application::Facts do end it "should return facts if a key is given to find", :'fails_on_ruby_1.9.2' => true do + Puppet::Node::Facts.indirection.reset_terminus_class subject.command_line.stubs(:args).returns %w{find whatever --render-as yaml} expect { diff --git a/spec/unit/configurer/fact_handler_spec.rb b/spec/unit/configurer/fact_handler_spec.rb index 70d9b17c0..4a3fe8b3b 100755 --- a/spec/unit/configurer/fact_handler_spec.rb +++ b/spec/unit/configurer/fact_handler_spec.rb @@ -12,14 +12,6 @@ describe Puppet::Configurer::FactHandler do @facthandler = FactHandlerTester.new end - it "should have a method for downloading fact plugins" do - @facthandler.should respond_to(:download_fact_plugins) - end - - it "should have a boolean method for determining whether fact plugins should be downloaded" do - @facthandler.should respond_to(:download_fact_plugins?) - end - it "should download fact plugins when :factsync is true" do Puppet.settings.expects(:value).with(:factsync).returns true @facthandler.should be_download_fact_plugins @@ -51,46 +43,62 @@ describe Puppet::Configurer::FactHandler do @facthandler.download_fact_plugins end - it "should warn about factsync deprecation when factsync is enabled" do - Puppet::Configurer::Downloader.stubs(:new).returns mock("downloader", :evaluate => nil) + describe "when finding facts" do + before :each do + @facthandler.stubs(:reload_facter) + Puppet::Node::Facts.indirection.terminus_class = :memory + end - @facthandler.expects(:download_fact_plugins?).returns true - Puppet.expects(:warning) - @facthandler.download_fact_plugins - end + it "should use the node name value to retrieve the facts" do + foo_facts = Puppet::Node::Facts.new('foo') + bar_facts = Puppet::Node::Facts.new('bar') + Puppet::Node::Facts.indirection.save(foo_facts) + Puppet::Node::Facts.indirection.save(bar_facts) + Puppet[:certname] = 'foo' + Puppet[:node_name_value] = 'bar' - it "should have a method for retrieving facts" do - @facthandler.should respond_to(:find_facts) - end + @facthandler.find_facts.should == bar_facts + end - it "should use the Facts class with the :certname to find the facts" do - Puppet.settings.expects(:value).with(:certname).returns "foo" - Puppet::Node::Facts.indirection.expects(:find).with("foo").returns "myfacts" - @facthandler.stubs(:reload_facter) - @facthandler.find_facts.should == "myfacts" - end + it "should set the facts name based on the node_name_fact" do + facts = Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name') + Puppet::Node::Facts.indirection.save(facts) + Puppet[:node_name_fact] = 'my_name_fact' - it "should reload Facter and find local facts when asked to find facts" do - @facthandler.expects(:reload_facter) + @facthandler.find_facts.name.should == 'other_node_name' + end - Puppet.settings.expects(:value).with(:certname).returns "myhost" - Puppet::Node::Facts.indirection.expects(:find).with("myhost") + it "should set the node_name_value based on the node_name_fact" do + facts = Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name') + Puppet::Node::Facts.indirection.save(facts) + Puppet[:node_name_fact] = 'my_name_fact' - @facthandler.find_facts - end + @facthandler.find_facts - it "should fail if finding facts fails" do - @facthandler.stubs(:reload_facter) + Puppet[:node_name_value].should == 'other_node_name' + end - Puppet.settings.stubs(:value).with(:trace).returns false - Puppet.settings.stubs(:value).with(:certname).returns "myhost" - Puppet::Node::Facts.indirection.expects(:find).raises RuntimeError + it "should reload Facter before finding facts" do + @facthandler.expects(:reload_facter) - lambda { @facthandler.find_facts }.should raise_error(Puppet::Error) + @facthandler.find_facts + end + + it "should fail if finding facts fails" do + Puppet[:trace] = false + Puppet[:certname] = "myhost" + Puppet::Node::Facts.indirection.expects(:find).raises RuntimeError + + lambda { @facthandler.find_facts }.should raise_error(Puppet::Error) + end end - it "should have a method to prepare the facts for uploading" do - @facthandler.should respond_to(:facts_for_uploading) + it "should warn about factsync deprecation when factsync is enabled" do + Puppet::Configurer::Downloader.stubs(:new).returns mock("downloader", :evaluate => nil) + + @facthandler.expects(:download_fact_plugins?).returns true + Puppet.expects(:warning) + @facthandler.download_fact_plugins end # I couldn't get marshal to work for this, only yaml, so we hard-code yaml. diff --git a/spec/unit/configurer_spec.rb b/spec/unit/configurer_spec.rb index 7b76c3221..0f255af76 100755 --- a/spec/unit/configurer_spec.rb +++ b/spec/unit/configurer_spec.rb @@ -10,6 +10,10 @@ describe Puppet::Configurer do before do Puppet.settings.stubs(:use).returns(true) @agent = Puppet::Configurer.new + @agent.stubs(:dostorage) + Puppet::Util::Storage.stubs(:store) + Puppet[:server] = "puppetmaster" + Puppet[:report] = true end it "should include the Plugin Handler module" do @@ -70,457 +74,462 @@ describe Puppet::Configurer do lambda { @agent.execute_postrun_command }.should raise_error(Puppet::Configurer::CommandHookError) end end -end -describe Puppet::Configurer, "when executing a catalog run" do - before do - Puppet.settings.stubs(:use).returns(true) - @agent = Puppet::Configurer.new - @agent.stubs(:prepare) - @agent.stubs(:facts_for_uploading).returns({}) - @catalog = Puppet::Resource::Catalog.new - @catalog.stubs(:apply) - @agent.stubs(:retrieve_catalog).returns @catalog - @agent.stubs(:save_last_run_summary) - Puppet::Transaction::Report.indirection.stubs(:save) - end + describe "when executing a catalog run" do + before do + Puppet.settings.stubs(:use).returns(true) + @agent.stubs(:prepare) + Puppet::Node::Facts.indirection.terminus_class = :memory + @facts = Puppet::Node::Facts.new(Puppet[:node_name_value]) + Puppet::Node::Facts.indirection.save(@facts) + + @catalog = Puppet::Resource::Catalog.new + @catalog.stubs(:to_ral).returns(@catalog) + Puppet::Resource::Catalog.indirection.terminus_class = :rest + Puppet::Resource::Catalog.indirection.stubs(:find).returns(@catalog) + @agent.stubs(:send_report) + end - it "should prepare for the run" do - @agent.expects(:prepare) + it "should prepare for the run" do + @agent.expects(:prepare) - @agent.run - end + @agent.run + end - it "should initialize a transaction report if one is not provided" do - report = Puppet::Transaction::Report.new("apply") - Puppet::Transaction::Report.expects(:new).at_least_once.returns report + it "should initialize a transaction report if one is not provided" do + report = Puppet::Transaction::Report.new("apply") + Puppet::Transaction::Report.expects(:new).at_least_once.returns report - @agent.run - end + @agent.run + end - it "should pass the new report to the catalog" do - report = Puppet::Transaction::Report.new("apply") - Puppet::Transaction::Report.stubs(:new).returns report - @catalog.expects(:apply).with{|options| options[:report] == report} + it "should respect node_name_fact when setting the host on a report" do + Puppet[:node_name_fact] = 'my_name_fact' + @facts.values = {'my_name_fact' => 'node_name_from_fact'} - @agent.run - end + @agent.run.host.should == 'node_name_from_fact' + end - it "should use the provided report if it was passed one" do - report = Puppet::Transaction::Report.new("apply") - Puppet::Transaction::Report.expects(:new).never - @catalog.expects(:apply).with{|options| options[:report] == report} + it "should pass the new report to the catalog" do + report = Puppet::Transaction::Report.new("apply") + Puppet::Transaction::Report.stubs(:new).returns report + @catalog.expects(:apply).with{|options| options[:report] == report} - @agent.run(:report => report) - end + @agent.run + end - it "should set the report as a log destination" do - report = Puppet::Transaction::Report.new("apply") - Puppet::Transaction::Report.expects(:new).returns report + it "should use the provided report if it was passed one" do + report = Puppet::Transaction::Report.new("apply") + Puppet::Transaction::Report.expects(:new).never + @catalog.expects(:apply).with{|options| options[:report] == report} - @agent.stubs(:send_report) - Puppet::Util::Log.expects(:newdestination).with(report) + @agent.run(:report => report) + end - @agent.run - end + it "should set the report as a log destination" do + report = Puppet::Transaction::Report.new("apply") + Puppet::Transaction::Report.expects(:new).at_least_once.returns report - it "should retrieve the catalog" do - @agent.expects(:retrieve_catalog) + Puppet::Util::Log.expects(:newdestination).with(report).at_least_once - @agent.run - end + @agent.run + end - it "should log a failure and do nothing if no catalog can be retrieved" do - @agent.expects(:retrieve_catalog).returns nil + it "should retrieve the catalog" do + @agent.expects(:retrieve_catalog) - Puppet.expects(:err).with "Could not retrieve catalog; skipping run" + @agent.run + end - @agent.run - end + it "should log a failure and do nothing if no catalog can be retrieved" do + @agent.expects(:retrieve_catalog).returns nil - it "should apply the catalog with all options to :run" do - @agent.expects(:retrieve_catalog).returns @catalog + Puppet.expects(:err).with "Could not retrieve catalog; skipping run" - @catalog.expects(:apply).with { |args| args[:one] == true } - @agent.run :one => true - end + @agent.run + end - it "should accept a catalog and use it instead of retrieving a different one" do - @agent.expects(:retrieve_catalog).never + it "should apply the catalog with all options to :run" do + @agent.expects(:retrieve_catalog).returns @catalog - @catalog.expects(:apply) - @agent.run :one => true, :catalog => @catalog - end + @catalog.expects(:apply).with { |args| args[:one] == true } + @agent.run :one => true + end - it "should benchmark how long it takes to apply the catalog" do - @agent.expects(:benchmark).with(:notice, "Finished catalog run") + it "should accept a catalog and use it instead of retrieving a different one" do + @agent.expects(:retrieve_catalog).never - @agent.expects(:retrieve_catalog).returns @catalog + @catalog.expects(:apply) + @agent.run :one => true, :catalog => @catalog + end - @catalog.expects(:apply).never # because we're not yielding - @agent.run - end + it "should benchmark how long it takes to apply the catalog" do + @agent.expects(:benchmark).with(:notice, "Finished catalog run") - it "should execute post-run hooks after the run" do - @agent.expects(:execute_postrun_command) + @agent.expects(:retrieve_catalog).returns @catalog - @agent.run - end + @catalog.expects(:apply).never # because we're not yielding + @agent.run + end - it "should send the report" do - report = Puppet::Transaction::Report.new("apply") - Puppet::Transaction::Report.expects(:new).returns(report) - @agent.expects(:send_report).with { |r, trans| r == report } + it "should execute post-run hooks after the run" do + @agent.expects(:execute_postrun_command) - @agent.run - end + @agent.run + end - it "should send the transaction report with a reference to the transaction if a run was actually made" do - report = Puppet::Transaction::Report.new("apply") - Puppet::Transaction::Report.expects(:new).returns(report) + it "should send the report" do + report = Puppet::Transaction::Report.new("apply") + Puppet::Transaction::Report.expects(:new).at_least_once.returns(report) + @agent.expects(:send_report).with { |r, trans| r == report } - trans = stub 'transaction' - @catalog.expects(:apply).returns trans + @agent.run + end - @agent.expects(:send_report).with { |r, t| t == trans } + it "should send the transaction report with a reference to the transaction if a run was actually made" do + report = Puppet::Transaction::Report.new("apply") + Puppet::Transaction::Report.expects(:new).returns(report) - @agent.run :catalog => @catalog - end + trans = stub 'transaction' + @catalog.expects(:apply).returns trans + + @agent.expects(:send_report).with { |r, t| t == trans } - it "should send the transaction report even if the catalog could not be retrieved" do - @agent.expects(:retrieve_catalog).returns nil + @agent.run :catalog => @catalog + end - report = Puppet::Transaction::Report.new("apply") - Puppet::Transaction::Report.expects(:new).returns(report) - @agent.expects(:send_report) + it "should send the transaction report even if the catalog could not be retrieved" do + @agent.expects(:retrieve_catalog).returns nil - @agent.run - end + report = Puppet::Transaction::Report.new("apply") + Puppet::Transaction::Report.expects(:new).returns(report) + @agent.expects(:send_report) - it "should send the transaction report even if there is a failure" do - @agent.expects(:retrieve_catalog).raises "whatever" + @agent.run + end - report = Puppet::Transaction::Report.new("apply") - Puppet::Transaction::Report.expects(:new).returns(report) - @agent.expects(:send_report) + it "should send the transaction report even if there is a failure" do + @agent.expects(:retrieve_catalog).raises "whatever" - lambda { @agent.run }.should raise_error - end + report = Puppet::Transaction::Report.new("apply") + Puppet::Transaction::Report.expects(:new).returns(report) + @agent.expects(:send_report) - it "should remove the report as a log destination when the run is finished" do - report = Puppet::Transaction::Report.new("apply") - Puppet::Transaction::Report.expects(:new).returns(report) + lambda { @agent.run }.should raise_error + end - report.expects(:<<).at_least_once + it "should remove the report as a log destination when the run is finished" do + report = Puppet::Transaction::Report.new("apply") + Puppet::Transaction::Report.expects(:new).at_least_once.returns(report) - @agent.run - Puppet::Util::Log.destinations.should_not include(report) - end + @agent.run - it "should return the report as the result of the run" do - report = Puppet::Transaction::Report.new("apply") - Puppet::Transaction::Report.expects(:new).returns(report) + Puppet::Util::Log.destinations.should_not include(report) + end - @agent.run.should equal(report) - end -end + it "should return the report as the result of the run" do + report = Puppet::Transaction::Report.new("apply") + Puppet::Transaction::Report.expects(:new).at_least_once.returns(report) -describe Puppet::Configurer, "when sending a report" do - include PuppetSpec::Files + @agent.run.should equal(report) + end - before do - Puppet.settings.stubs(:use).returns(true) - @configurer = Puppet::Configurer.new - Puppet[:lastrunfile] = tmpfile('last_run_file') + describe "when not using a REST terminus for catalogs" do + it "should not pass any facts when retrieving the catalog" do + Puppet::Resource::Catalog.indirection.terminus_class = :compiler + @agent.expects(:facts_for_uploading).never + Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| + options[:facts].nil? + }.returns @catalog - @report = Puppet::Transaction::Report.new("apply") - @trans = stub 'transaction' - end + @agent.run + end + end + + describe "when using a REST terminus for catalogs" do + it "should pass the prepared facts and the facts format as arguments when retrieving the catalog" do + Puppet::Resource::Catalog.indirection.terminus_class = :rest + @agent.expects(:facts_for_uploading).returns(:facts => "myfacts", :facts_format => :foo) + Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| + options[:facts] == "myfacts" and options[:facts_format] == :foo + }.returns @catalog - it "should finalize the report" do - @report.expects(:finalize_report) - @configurer.send_report(@report, @trans) + @agent.run + end + end end - it "should print a report summary if configured to do so" do - Puppet.settings[:summarize] = true + describe "when sending a report" do + include PuppetSpec::Files - @report.expects(:summary).returns "stuff" + before do + Puppet.settings.stubs(:use).returns(true) + @configurer = Puppet::Configurer.new + Puppet[:lastrunfile] = tmpfile('last_run_file') - @configurer.expects(:puts).with("stuff") - @configurer.send_report(@report, nil) - end + @report = Puppet::Transaction::Report.new("apply") + @trans = stub 'transaction' + end - it "should not print a report summary if not configured to do so" do - Puppet.settings[:summarize] = false + it "should finalize the report" do + @report.expects(:finalize_report) + @configurer.send_report(@report, @trans) + end - @configurer.expects(:puts).never - @configurer.send_report(@report, nil) - end + it "should print a report summary if configured to do so" do + Puppet.settings[:summarize] = true - it "should save the report if reporting is enabled" do - Puppet.settings[:report] = true + @report.expects(:summary).returns "stuff" - Puppet::Transaction::Report.indirection.expects(:save).with(@report) - @configurer.send_report(@report, nil) - end + @configurer.expects(:puts).with("stuff") + @configurer.send_report(@report, nil) + end - it "should not save the report if reporting is disabled" do - Puppet.settings[:report] = false + it "should not print a report summary if not configured to do so" do + Puppet.settings[:summarize] = false - Puppet::Transaction::Report.indirection.expects(:save).never - @configurer.send_report(@report, nil) - end + @configurer.expects(:puts).never + @configurer.send_report(@report, nil) + end - it "should save the last run summary if reporting is enabled" do - Puppet.settings[:report] = true + it "should save the report if reporting is enabled" do + Puppet.settings[:report] = true - @configurer.expects(:save_last_run_summary).with(@report) - @configurer.send_report(@report, nil) - end + Puppet::Transaction::Report.indirection.expects(:save).with(@report) + @configurer.send_report(@report, nil) + end - it "should save the last run summary if reporting is disabled" do - Puppet.settings[:report] = false + it "should not save the report if reporting is disabled" do + Puppet.settings[:report] = false - @configurer.expects(:save_last_run_summary).with(@report) - @configurer.send_report(@report, nil) - end + Puppet::Transaction::Report.indirection.expects(:save).with(@report).never + @configurer.send_report(@report, nil) + end - it "should log but not fail if saving the report fails" do - Puppet.settings[:report] = true + it "should save the last run summary if reporting is enabled" do + Puppet.settings[:report] = true - Puppet::Transaction::Report.indirection.expects(:save).with(@report).raises "whatever" + @configurer.expects(:save_last_run_summary).with(@report) + @configurer.send_report(@report, nil) + end - Puppet.expects(:err) - lambda { @configurer.send_report(@report, nil) }.should_not raise_error - end -end + it "should save the last run summary if reporting is disabled" do + Puppet.settings[:report] = false -describe Puppet::Configurer, "when saving the summary report file" do - before do - Puppet.settings.stubs(:use).returns(true) - @configurer = Puppet::Configurer.new + @configurer.expects(:save_last_run_summary).with(@report) + @configurer.send_report(@report, nil) + end - @report = stub 'report' - @trans = stub 'transaction' - @lastrunfd = stub 'lastrunfd' - Puppet::Util::FileLocking.stubs(:writelock).yields(@lastrunfd) - end + it "should log but not fail if saving the report fails" do + Puppet.settings[:report] = true - it "should write the raw summary to the lastrunfile setting value" do - Puppet::Util::FileLocking.expects(:writelock).with(Puppet[:lastrunfile], 0660) - @configurer.save_last_run_summary(@report) - end + Puppet::Transaction::Report.indirection.expects(:save).raises("whatever") - it "should write the raw summary as yaml" do - @report.expects(:raw_summary).returns("summary") - @lastrunfd.expects(:print).with(YAML.dump("summary")) - @configurer.save_last_run_summary(@report) + Puppet.expects(:err) + lambda { @configurer.send_report(@report, nil) }.should_not raise_error + end end - it "should log but not fail if saving the last run summary fails" do - Puppet::Util::FileLocking.expects(:writelock).raises "exception" - Puppet.expects(:err) - lambda { @configurer.save_last_run_summary(@report) }.should_not raise_error - end + describe "when saving the summary report file" do + before do + Puppet.settings.stubs(:use).returns(true) + @configurer = Puppet::Configurer.new -end + @report = stub 'report' + @trans = stub 'transaction' + @lastrunfd = stub 'lastrunfd' + Puppet::Util::FileLocking.stubs(:writelock).yields(@lastrunfd) + end -describe Puppet::Configurer, "when retrieving a catalog" do - before do - Puppet.settings.stubs(:use).returns(true) - @agent = Puppet::Configurer.new - @agent.stubs(:facts_for_uploading).returns({}) + it "should write the raw summary to the lastrunfile setting value" do + Puppet::Util::FileLocking.expects(:writelock).with(Puppet[:lastrunfile], 0660) + @configurer.save_last_run_summary(@report) + end - @catalog = Puppet::Resource::Catalog.new + it "should write the raw summary as yaml" do + @report.expects(:raw_summary).returns("summary") + @lastrunfd.expects(:print).with(YAML.dump("summary")) + @configurer.save_last_run_summary(@report) + end - # this is the default when using a Configurer instance - Puppet::Resource::Catalog.indirection.stubs(:terminus_class).returns :rest + it "should log but not fail if saving the last run summary fails" do + Puppet::Util::FileLocking.expects(:writelock).raises "exception" + Puppet.expects(:err) + lambda { @configurer.save_last_run_summary(@report) }.should_not raise_error + end - @agent.stubs(:convert_catalog).returns @catalog end - describe "and configured to only retrieve a catalog from the cache" do + describe "when retrieving a catalog" do before do - Puppet.settings[:use_cached_catalog] = true - end + Puppet.settings.stubs(:use).returns(true) + @agent.stubs(:facts_for_uploading).returns({}) - it "should first look in the cache for a catalog" do - Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog - Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.never - - @agent.retrieve_catalog.should == @catalog - end + @catalog = Puppet::Resource::Catalog.new - it "should compile a new catalog if none is found in the cache" do - Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil - Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog + # this is the default when using a Configurer instance + Puppet::Resource::Catalog.indirection.stubs(:terminus_class).returns :rest - @agent.retrieve_catalog.should == @catalog + @agent.stubs(:convert_catalog).returns @catalog end - end - describe "when not using a REST terminus for catalogs" do - it "should not pass any facts when retrieving the catalog" do - @agent.expects(:facts_for_uploading).never - Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| - options[:facts].nil? - }.returns @catalog + describe "and configured to only retrieve a catalog from the cache" do + before do + Puppet.settings[:use_cached_catalog] = true + end - @agent.retrieve_catalog - end - end + it "should first look in the cache for a catalog" do + Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog + Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.never + + @agent.retrieve_catalog({}).should == @catalog + end - describe "when using a REST terminus for catalogs" do - it "should pass the prepared facts and the facts format as arguments when retrieving the catalog" do - @agent.expects(:facts_for_uploading).returns(:facts => "myfacts", :facts_format => :foo) - Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| - options[:facts] == "myfacts" and options[:facts_format] == :foo - }.returns @catalog + it "should compile a new catalog if none is found in the cache" do + Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil + Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog - @agent.retrieve_catalog + @agent.retrieve_catalog({}).should == @catalog + end end - end - it "should use the Catalog class to get its catalog" do - Puppet::Resource::Catalog.indirection.expects(:find).returns @catalog + it "should use the Catalog class to get its catalog" do + Puppet::Resource::Catalog.indirection.expects(:find).returns @catalog - @agent.retrieve_catalog - end + @agent.retrieve_catalog({}) + end - it "should use its certname to retrieve the catalog" do - Facter.stubs(:value).returns "eh" - Puppet.settings[:certname] = "myhost.domain.com" - Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| name == "myhost.domain.com" }.returns @catalog + it "should use its node_name_value to retrieve the catalog" do + Facter.stubs(:value).returns "eh" + Puppet.settings[:node_name_value] = "myhost.domain.com" + Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| name == "myhost.domain.com" }.returns @catalog - @agent.retrieve_catalog - end + @agent.retrieve_catalog({}) + end - it "should default to returning a catalog retrieved directly from the server, skipping the cache" do - Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog + it "should default to returning a catalog retrieved directly from the server, skipping the cache" do + Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog - @agent.retrieve_catalog.should == @catalog - end + @agent.retrieve_catalog({}).should == @catalog + end - it "should log and return the cached catalog when no catalog can be retrieved from the server" do - Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil - Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog + it "should log and return the cached catalog when no catalog can be retrieved from the server" do + Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil + Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog - Puppet.expects(:notice) + Puppet.expects(:notice) - @agent.retrieve_catalog.should == @catalog - end + @agent.retrieve_catalog({}).should == @catalog + end - it "should not look in the cache for a catalog if one is returned from the server" do - Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog - Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.never + it "should not look in the cache for a catalog if one is returned from the server" do + Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog + Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.never - @agent.retrieve_catalog.should == @catalog - end + @agent.retrieve_catalog({}).should == @catalog + end - it "should return the cached catalog when retrieving the remote catalog throws an exception" do - Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.raises "eh" - Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog + it "should return the cached catalog when retrieving the remote catalog throws an exception" do + Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.raises "eh" + Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog - @agent.retrieve_catalog.should == @catalog - end + @agent.retrieve_catalog({}).should == @catalog + end - it "should log and return nil if no catalog can be retrieved from the server and :usecacheonfailure is disabled" do - Puppet.stubs(:[]) - Puppet.expects(:[]).with(:usecacheonfailure).returns false - Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil + it "should log and return nil if no catalog can be retrieved from the server and :usecacheonfailure is disabled" do + Puppet.stubs(:[]) + Puppet.expects(:[]).with(:usecacheonfailure).returns false + Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil - Puppet.expects(:warning) + Puppet.expects(:warning) - @agent.retrieve_catalog.should be_nil - end + @agent.retrieve_catalog({}).should be_nil + end - it "should return nil if no cached catalog is available and no catalog can be retrieved from the server" do - Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil - Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil + it "should return nil if no cached catalog is available and no catalog can be retrieved from the server" do + Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil + Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil - @agent.retrieve_catalog.should be_nil - end + @agent.retrieve_catalog({}).should be_nil + end - it "should convert the catalog before returning" do - Puppet::Resource::Catalog.indirection.stubs(:find).returns @catalog + it "should convert the catalog before returning" do + Puppet::Resource::Catalog.indirection.stubs(:find).returns @catalog - @agent.expects(:convert_catalog).with { |cat, dur| cat == @catalog }.returns "converted catalog" - @agent.retrieve_catalog.should == "converted catalog" - end + @agent.expects(:convert_catalog).with { |cat, dur| cat == @catalog }.returns "converted catalog" + @agent.retrieve_catalog({}).should == "converted catalog" + end - it "should return nil if there is an error while retrieving the catalog" do - Puppet::Resource::Catalog.indirection.expects(:find).at_least_once.raises "eh" + it "should return nil if there is an error while retrieving the catalog" do + Puppet::Resource::Catalog.indirection.expects(:find).at_least_once.raises "eh" - @agent.retrieve_catalog.should be_nil + @agent.retrieve_catalog({}).should be_nil + end end -end -describe Puppet::Configurer, "when converting the catalog" do - before do - Puppet.settings.stubs(:use).returns(true) - @agent = Puppet::Configurer.new + describe "when converting the catalog" do + before do + Puppet.settings.stubs(:use).returns(true) - @catalog = Puppet::Resource::Catalog.new - @oldcatalog = stub 'old_catalog', :to_ral => @catalog - end + @catalog = Puppet::Resource::Catalog.new + @oldcatalog = stub 'old_catalog', :to_ral => @catalog + end - it "should convert the catalog to a RAL-formed catalog" do - @oldcatalog.expects(:to_ral).returns @catalog + it "should convert the catalog to a RAL-formed catalog" do + @oldcatalog.expects(:to_ral).returns @catalog - @agent.convert_catalog(@oldcatalog, 10).should equal(@catalog) - end + @agent.convert_catalog(@oldcatalog, 10).should equal(@catalog) + end - it "should finalize the catalog" do - @catalog.expects(:finalize) + it "should finalize the catalog" do + @catalog.expects(:finalize) - @agent.convert_catalog(@oldcatalog, 10) - end + @agent.convert_catalog(@oldcatalog, 10) + end - it "should record the passed retrieval time with the RAL catalog" do - @catalog.expects(:retrieval_duration=).with 10 + it "should record the passed retrieval time with the RAL catalog" do + @catalog.expects(:retrieval_duration=).with 10 - @agent.convert_catalog(@oldcatalog, 10) - end + @agent.convert_catalog(@oldcatalog, 10) + end - it "should write the RAL catalog's class file" do - @catalog.expects(:write_class_file) + it "should write the RAL catalog's class file" do + @catalog.expects(:write_class_file) - @agent.convert_catalog(@oldcatalog, 10) + @agent.convert_catalog(@oldcatalog, 10) + end end -end -describe Puppet::Configurer, "when preparing for a run" do - before do - Puppet.settings.stubs(:use).returns(true) - @agent = Puppet::Configurer.new - @agent.stubs(:dostorage) - @agent.stubs(:download_fact_plugins) - @agent.stubs(:download_plugins) - @agent.stubs(:execute_prerun_command) - @facts = {"one" => "two", "three" => "four"} - end + describe "when preparing for a run" do + before do + Puppet.settings.stubs(:use).returns(true) + @agent.stubs(:download_fact_plugins) + @agent.stubs(:download_plugins) + @agent.stubs(:execute_prerun_command) + @facts = {"one" => "two", "three" => "four"} + end - it "should initialize the metadata store" do - @agent.class.stubs(:facts).returns(@facts) - @agent.expects(:dostorage) - @agent.prepare({}) - end + it "should initialize the metadata store" do + @agent.class.stubs(:facts).returns(@facts) + @agent.expects(:dostorage) + @agent.prepare({}) + end - it "should download fact plugins" do - @agent.expects(:download_fact_plugins) + it "should download fact plugins" do + @agent.expects(:download_fact_plugins) - @agent.prepare({}) - end + @agent.prepare({}) + end - it "should download plugins" do - @agent.expects(:download_plugins) + it "should download plugins" do + @agent.expects(:download_plugins) - @agent.prepare({}) - end + @agent.prepare({}) + end - it "should perform the pre-run commands" do - @agent.expects(:execute_prerun_command) - @agent.prepare({}) + it "should perform the pre-run commands" do + @agent.expects(:execute_prerun_command) + @agent.prepare({}) + end end end diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index 169a9cdcf..c15093d90 100755 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -129,6 +129,7 @@ end describe Puppet::Node, "when indirecting" do it "should default to the 'plain' node terminus" do + Puppet::Node.indirection.reset_terminus_class Puppet::Node.indirection.terminus_class.should == :plain end diff --git a/spec/unit/transaction/report_spec.rb b/spec/unit/transaction/report_spec.rb index 191a30eb7..4b04cc157 100755 --- a/spec/unit/transaction/report_spec.rb +++ b/spec/unit/transaction/report_spec.rb @@ -9,9 +9,9 @@ describe Puppet::Transaction::Report do Puppet::Util::Storage.stubs(:store) end - it "should set its host name to the certname" do - Puppet.settings.expects(:value).with(:certname).returns "myhost" - Puppet::Transaction::Report.new("apply").host.should == "myhost" + it "should set its host name to the node_name_value" do + Puppet[:node_name_value] = 'mynode' + Puppet::Transaction::Report.new("apply").host.should == "mynode" end it "should return its host name as its name" do diff --git a/spec/unit/util/settings/file_setting_spec.rb b/spec/unit/util/settings/file_setting_spec.rb index 734b41f3a..489628a78 100755 --- a/spec/unit/util/settings/file_setting_spec.rb +++ b/spec/unit/util/settings/file_setting_spec.rb @@ -248,6 +248,10 @@ describe Puppet::Util::Settings::FileSetting do it "should tag the resource with 'settings'" do @file.to_resource.should be_tagged("settings") end + + it "should set links to 'follow'" do + @file.to_resource[:links].should == :follow + end end end |