diff options
| author | Jacob Helwig <jacob@puppetlabs.com> | 2011-06-28 18:05:49 -0700 |
|---|---|---|
| committer | Jacob Helwig <jacob@puppetlabs.com> | 2011-06-28 18:05:49 -0700 |
| commit | 8772bb7659a8586402802ce80d43fa249a4d6171 (patch) | |
| tree | ff0133bdcee37fde5dfeccaeb4a479f1449a3027 /spec | |
| parent | cf93404e53aa32ac4a919ddd57d09ed78abfc1b5 (diff) | |
| parent | 8432684e25cc82beb1f5d977dd509fd7bab3901b (diff) | |
| download | puppet-8772bb7659a8586402802ce80d43fa249a4d6171.tar.gz puppet-8772bb7659a8586402802ce80d43fa249a4d6171.tar.xz puppet-8772bb7659a8586402802ce80d43fa249a4d6171.zip | |
Merge branch '2.7.x'
* 2.7.x: (23 commits)
Clean up indentation, whitespace, and commented out code
Remove order dependency from functions integration spec
(#7956) Porting cron tests
(#7956) Port resource acceptance tests
(#8048) Gem install puppet no longer fails if rdoc enabled.
Updating for 2.7.1 release.
(#8048) Gem install puppet no longer fails if rdoc enabled.
Readying for release of 2.6.9
Updating CHANGELOG for 2.7.0
(#6854) Update Red Hat spec file
Bumping release in lib/puppet.rb and updating CHANGELOG.
Bumping RPM spec file to 2.6.9rc1.
(#7224) Reword 'hostname was not match' error message
(#7224) Add a helper to Puppet::SSL::Certificate to retrieve alternate names
(#7506) Organize READMEs; specify supported Ruby versions in README.md
(#7506) Specify supported Ruby versions in README.md
(#5641) Help text: document that puppet doc takes modulepath, manifestdir, and environment options
(#6418) Make test 64118 more portable
(#7127) Stop puppet if a prerun command fails
Do not needlessly create multiple reports when creating a transaction
...
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/integration/type_spec.rb | 11 | ||||
| -rwxr-xr-x | spec/shared_behaviours/things_that_declare_options.rb | 3 | ||||
| -rwxr-xr-x | spec/unit/application/apply_spec.rb | 4 | ||||
| -rwxr-xr-x | spec/unit/configurer_spec.rb | 159 | ||||
| -rwxr-xr-x | spec/unit/indirector/certificate/rest_spec.rb | 1 | ||||
| -rwxr-xr-x | spec/unit/indirector/rest_spec.rb | 47 | ||||
| -rwxr-xr-x | spec/unit/resource/catalog_spec.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/ssl/certificate_spec.rb | 25 | ||||
| -rwxr-xr-x | spec/unit/transaction_spec.rb | 10 | ||||
| -rwxr-xr-x | spec/unit/type_spec.rb | 66 |
10 files changed, 271 insertions, 57 deletions
diff --git a/spec/integration/type_spec.rb b/spec/integration/type_spec.rb index 4be01d558..9fd10485f 100755 --- a/spec/integration/type_spec.rb +++ b/spec/integration/type_spec.rb @@ -18,4 +18,15 @@ describe Puppet::Type do type.provider(:myprovider).should equal(provider) end + + it "should not lose its provider parameter when it is reloaded" do + type = Puppet::Type.newtype(:reload_test_type) + + provider = type.provide(:test_provider) + + # reload it + type = Puppet::Type.newtype(:reload_test_type) + + type.parameters.should include(:provider) + end end diff --git a/spec/shared_behaviours/things_that_declare_options.rb b/spec/shared_behaviours/things_that_declare_options.rb index 6e7056157..ebf1b2071 100755 --- a/spec/shared_behaviours/things_that_declare_options.rb +++ b/spec/shared_behaviours/things_that_declare_options.rb @@ -27,13 +27,12 @@ shared_examples_for "things that declare options" do thing = add_options_to do option "--foo" do - desc text description text summary text end end - thing.get_option(:foo).desc.should == text + thing.get_option(:foo).description.should == text end it "should list all the options" do diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb index 19a933950..c9555157c 100755 --- a/spec/unit/application/apply_spec.rb +++ b/spec/unit/application/apply_spec.rb @@ -277,8 +277,8 @@ describe Puppet::Application::Apply do end it "should call the prerun and postrun commands on a Configurer instance" do - Puppet::Configurer.any_instance.expects(:execute_prerun_command) - Puppet::Configurer.any_instance.expects(:execute_postrun_command) + Puppet::Configurer.any_instance.expects(:execute_prerun_command).returns(true) + Puppet::Configurer.any_instance.expects(:execute_postrun_command).returns(true) expect { @apply.main }.to exit_with 0 end diff --git a/spec/unit/configurer_spec.rb b/spec/unit/configurer_spec.rb index 0f255af76..f8a486928 100755 --- a/spec/unit/configurer_spec.rb +++ b/spec/unit/configurer_spec.rb @@ -39,16 +39,16 @@ describe Puppet::Configurer do it "should execute any pre-run command provided via the 'prerun_command' setting" do Puppet.settings[:prerun_command] = "/my/command" - Puppet::Util.expects(:execute).with { |args| args[0] == "/my/command" } + Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed") @agent.execute_prerun_command end it "should fail if the command fails" do Puppet.settings[:prerun_command] = "/my/command" - Puppet::Util.expects(:execute).raises Puppet::ExecutionFailure + Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed") - lambda { @agent.execute_prerun_command }.should raise_error(Puppet::Configurer::CommandHookError) + @agent.execute_prerun_command.should be_false end end @@ -62,16 +62,16 @@ describe Puppet::Configurer do it "should execute any post-run command provided via the 'postrun_command' setting" do Puppet.settings[:postrun_command] = "/my/command" - Puppet::Util.expects(:execute).with { |args| args[0] == "/my/command" } + Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed") @agent.execute_postrun_command end it "should fail if the command fails" do Puppet.settings[:postrun_command] = "/my/command" - Puppet::Util.expects(:execute).raises Puppet::ExecutionFailure + Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed") - lambda { @agent.execute_postrun_command }.should raise_error(Puppet::Configurer::CommandHookError) + @agent.execute_postrun_command.should be_false end end @@ -88,6 +88,9 @@ describe Puppet::Configurer do Puppet::Resource::Catalog.indirection.terminus_class = :rest Puppet::Resource::Catalog.indirection.stubs(:find).returns(@catalog) @agent.stubs(:send_report) + @agent.stubs(:save_last_run_summary) + + Puppet::Util::Log.stubs(:close_all) end it "should prepare for the run" do @@ -98,7 +101,7 @@ describe Puppet::Configurer do 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 + Puppet::Transaction::Report.expects(:new).returns report @agent.run end @@ -128,9 +131,10 @@ describe Puppet::Configurer do 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::Transaction::Report.expects(:new).returns report - Puppet::Util::Log.expects(:newdestination).with(report).at_least_once + Puppet::Util::Log.expects(:newdestination).with(report) + Puppet::Util::Log.expects(:close).with(report) @agent.run end @@ -180,22 +184,10 @@ describe Puppet::Configurer do 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 - - 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.expects(:send_report).with(report) - trans = stub 'transaction' - @catalog.expects(:apply).returns trans - - @agent.expects(:send_report).with { |r, t| t == trans } - - @agent.run :catalog => @catalog + @agent.run end it "should send the transaction report even if the catalog could not be retrieved" do @@ -215,12 +207,12 @@ describe Puppet::Configurer do Puppet::Transaction::Report.expects(:new).returns(report) @agent.expects(:send_report) - lambda { @agent.run }.should raise_error + @agent.run.should be_nil 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) + Puppet::Transaction::Report.expects(:new).returns(report) @agent.run @@ -229,11 +221,100 @@ describe Puppet::Configurer do 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) + Puppet::Transaction::Report.expects(:new).returns(report) @agent.run.should equal(report) end + it "should send the transaction report even if the pre-run command fails" do + report = Puppet::Transaction::Report.new("apply") + Puppet::Transaction::Report.expects(:new).returns(report) + + Puppet.settings[:prerun_command] = "/my/command" + Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed") + @agent.expects(:send_report) + + @agent.run.should be_nil + end + + it "should include the pre-run command failure in the report" do + report = Puppet::Transaction::Report.new("apply") + Puppet::Transaction::Report.expects(:new).returns(report) + + Puppet.settings[:prerun_command] = "/my/command" + Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed") + + report.expects(:<<).with { |log| log.message.start_with?("Could not run command from prerun_command") } + + @agent.run.should be_nil + end + + it "should send the transaction report even if the post-run command fails" do + report = Puppet::Transaction::Report.new("apply") + Puppet::Transaction::Report.expects(:new).returns(report) + + Puppet.settings[:postrun_command] = "/my/command" + Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed") + @agent.expects(:send_report) + + @agent.run.should be_nil + end + + it "should include the post-run command failure in the report" do + report = Puppet::Transaction::Report.new("apply") + Puppet::Transaction::Report.expects(:new).returns(report) + + Puppet.settings[:postrun_command] = "/my/command" + Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed") + + report.expects(:<<).with { |log| log.message.start_with?("Could not run command from postrun_command") } + + @agent.run.should be_nil + end + + it "should execute post-run command even if the pre-run command fails" do + Puppet.settings[:prerun_command] = "/my/precommand" + Puppet.settings[:postrun_command] = "/my/postcommand" + Puppet::Util.expects(:execute).with(["/my/precommand"]).raises(Puppet::ExecutionFailure, "Failed") + Puppet::Util.expects(:execute).with(["/my/postcommand"]) + + @agent.run.should be_nil + end + + it "should finalize the report" do + report = Puppet::Transaction::Report.new("apply") + Puppet::Transaction::Report.expects(:new).returns(report) + + report.expects(:finalize_report) + @agent.run + end + + it "should not apply the catalog if the pre-run command fails" do + report = Puppet::Transaction::Report.new("apply") + Puppet::Transaction::Report.expects(:new).returns(report) + + Puppet.settings[:prerun_command] = "/my/command" + Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed") + + @catalog.expects(:apply).never() + @agent.expects(:send_report) + + @agent.run.should be_nil + end + + it "should apply the catalog, send the report, and return nil if the post-run command fails" do + report = Puppet::Transaction::Report.new("apply") + Puppet::Transaction::Report.expects(:new).returns(report) + + Puppet.settings[:postrun_command] = "/my/command" + Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed") + + @catalog.expects(:apply) + @agent.expects(:send_report) + + @agent.run.should be_nil + 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.indirection.terminus_class = :compiler @@ -268,12 +349,6 @@ describe Puppet::Configurer do Puppet[:lastrunfile] = tmpfile('last_run_file') @report = Puppet::Transaction::Report.new("apply") - @trans = stub 'transaction' - end - - it "should finalize the report" do - @report.expects(:finalize_report) - @configurer.send_report(@report, @trans) end it "should print a report summary if configured to do so" do @@ -282,42 +357,42 @@ describe Puppet::Configurer do @report.expects(:summary).returns "stuff" @configurer.expects(:puts).with("stuff") - @configurer.send_report(@report, nil) + @configurer.send_report(@report) end it "should not print a report summary if not configured to do so" do Puppet.settings[:summarize] = false @configurer.expects(:puts).never - @configurer.send_report(@report, nil) + @configurer.send_report(@report) end it "should save the report if reporting is enabled" do Puppet.settings[:report] = true Puppet::Transaction::Report.indirection.expects(:save).with(@report) - @configurer.send_report(@report, nil) + @configurer.send_report(@report) end it "should not save the report if reporting is disabled" do Puppet.settings[:report] = false Puppet::Transaction::Report.indirection.expects(:save).with(@report).never - @configurer.send_report(@report, nil) + @configurer.send_report(@report) end it "should save the last run summary if reporting is enabled" do Puppet.settings[:report] = true @configurer.expects(:save_last_run_summary).with(@report) - @configurer.send_report(@report, nil) + @configurer.send_report(@report) end it "should save the last run summary if reporting is disabled" do Puppet.settings[:report] = false @configurer.expects(:save_last_run_summary).with(@report) - @configurer.send_report(@report, nil) + @configurer.send_report(@report) end it "should log but not fail if saving the report fails" do @@ -326,7 +401,7 @@ describe Puppet::Configurer do Puppet::Transaction::Report.indirection.expects(:save).raises("whatever") Puppet.expects(:err) - lambda { @configurer.send_report(@report, nil) }.should_not raise_error + lambda { @configurer.send_report(@report) }.should_not raise_error end end @@ -505,7 +580,6 @@ describe Puppet::Configurer 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 @@ -526,10 +600,5 @@ describe Puppet::Configurer do @agent.prepare({}) end - - it "should perform the pre-run commands" do - @agent.expects(:execute_prerun_command) - @agent.prepare({}) - end end end diff --git a/spec/unit/indirector/certificate/rest_spec.rb b/spec/unit/indirector/certificate/rest_spec.rb index 21e10e316..870d9e437 100755 --- a/spec/unit/indirector/certificate/rest_spec.rb +++ b/spec/unit/indirector/certificate/rest_spec.rb @@ -47,6 +47,7 @@ rn/G response = stub 'response', :code => "200", :body => cert_string response.stubs(:[]).with('content-type').returns "text/plain" response.stubs(:[]).with('content-encoding') + network.stubs(:verify_callback=) network.expects(:get).returns response request = Puppet::Indirector::Request.new(:certificate, :find, "foo.com") diff --git a/spec/unit/indirector/rest_spec.rb b/spec/unit/indirector/rest_spec.rb index 5637080e8..ee0111a77 100755 --- a/spec/unit/indirector/rest_spec.rb +++ b/spec/unit/indirector/rest_spec.rb @@ -90,6 +90,43 @@ describe Puppet::Indirector::REST do @rest_class.port.should == 543 end + describe "when making http requests" do + it "should provide a helpful error message when hostname was not match with server certificate" do + Puppet[:certdnsnames] = 'foo:bar:baz' + csr = OpenSSL::X509::Request.new + csr.subject = OpenSSL::X509::Name.new([['CN', 'not_my_server']]) + csr.public_key = OpenSSL::PKey::RSA.generate(Puppet[:keylength]).public_key + cert = Puppet::SSL::CertificateFactory.new('server', csr, csr, 14).result + + connection = Net::HTTP.new('my_server', 8140) + @searcher.stubs(:network).returns(connection) + ssl_context = OpenSSL::SSL::SSLContext.new + ssl_context.stubs(:current_cert).returns(cert) + connection.stubs(:get).with do + connection.verify_callback.call(true, ssl_context) + end.raises(OpenSSL::SSL::SSLError.new('hostname was not match with server certificate')) + + msg = /Server hostname 'my_server' did not match server certificate; expected one of (.+)/ + expect { @searcher.http_request(:get, stub('request')) }.to( + raise_error(Puppet::Error, msg) do |error| + error.message =~ msg + $1.split(', ').should =~ ['foo', 'bar', 'baz', 'not_my_server'] + end + ) + end + + it "should pass along the error message otherwise" do + connection = Net::HTTP.new('my_server', 8140) + @searcher.stubs(:network).returns(connection) + + connection.stubs(:get).raises(OpenSSL::SSL::SSLError.new('certificate verify failed')) + + expect do + @searcher.http_request(:get, stub('request')) + end.to raise_error(/certificate verify failed/) + end + end + describe "when deserializing responses" do it "should return nil if the response code is 404" do response = mock 'response' @@ -219,7 +256,7 @@ describe Puppet::Indirector::REST do describe "when doing a find" do before :each do - @connection = stub('mock http connection', :get => @response) + @connection = stub('mock http connection', :get => @response, :verify_callback= => nil) @searcher.stubs(:network).returns(@connection) # neuter the network connection # Use a key with spaces, so we can test escaping @@ -313,7 +350,7 @@ describe Puppet::Indirector::REST do describe "when doing a head" do before :each do - @connection = stub('mock http connection', :head => @response) + @connection = stub('mock http connection', :head => @response, :verify_callback= => nil) @searcher.stubs(:network).returns(@connection) # Use a key with spaces, so we can test escaping @@ -349,7 +386,7 @@ describe Puppet::Indirector::REST do describe "when doing a search" do before :each do - @connection = stub('mock http connection', :get => @response) + @connection = stub('mock http connection', :get => @response, :verify_callback= => nil) @searcher.stubs(:network).returns(@connection) # neuter the network connection @model.stubs(:convert_from_multiple) @@ -397,7 +434,7 @@ describe Puppet::Indirector::REST do describe "when doing a destroy" do before :each do - @connection = stub('mock http connection', :delete => @response) + @connection = stub('mock http connection', :delete => @response, :verify_callback= => nil) @searcher.stubs(:network).returns(@connection) # neuter the network connection @request = Puppet::Indirector::Request.new(:foo, :destroy, "foo bar") @@ -453,7 +490,7 @@ describe Puppet::Indirector::REST do describe "when doing a save" do before :each do - @connection = stub('mock http connection', :put => @response) + @connection = stub('mock http connection', :put => @response, :verify_callback= => nil) @searcher.stubs(:network).returns(@connection) # neuter the network connection @instance = stub 'instance', :render => "mydata", :mime => "mime" diff --git a/spec/unit/resource/catalog_spec.rb b/spec/unit/resource/catalog_spec.rb index ebf523eab..8f4910af6 100755 --- a/spec/unit/resource/catalog_spec.rb +++ b/spec/unit/resource/catalog_spec.rb @@ -588,7 +588,7 @@ describe Puppet::Resource::Catalog, "when compiling" do before :each do @catalog = Puppet::Resource::Catalog.new("host") - @transaction = mock 'transaction' + @transaction = Puppet::Transaction.new(@catalog) Puppet::Transaction.stubs(:new).returns(@transaction) @transaction.stubs(:evaluate) @transaction.stubs(:add_times) diff --git a/spec/unit/ssl/certificate_spec.rb b/spec/unit/ssl/certificate_spec.rb index 0b635f2bc..de5cedf59 100755 --- a/spec/unit/ssl/certificate_spec.rb +++ b/spec/unit/ssl/certificate_spec.rb @@ -89,6 +89,31 @@ describe Puppet::SSL::Certificate do @certificate.should respond_to(:content) end + describe "#alternate_names" do + before do + Puppet[:certdnsnames] = 'foo:bar:baz' + @csr = OpenSSL::X509::Request.new + @csr.subject = OpenSSL::X509::Name.new([['CN', 'quux']]) + @csr.public_key = OpenSSL::PKey::RSA.generate(Puppet[:keylength]).public_key + end + + it "should list all alternate names when the extension is present" do + cert = Puppet::SSL::CertificateFactory.new('server', @csr, @csr, 14).result + + @certificate = @class.from_s(cert.to_pem) + + @certificate.alternate_names.should =~ ['foo', 'bar', 'baz', 'quux'] + end + + it "should return an empty list of names if the extension is absent" do + cert = Puppet::SSL::CertificateFactory.new('client', @csr, @csr, 14).result + + @certificate = @class.from_s(cert.to_pem) + + @certificate.alternate_names.should == [] + end + end + it "should return a nil expiration if there is no actual certificate" do @certificate.stubs(:content).returns nil diff --git a/spec/unit/transaction_spec.rb b/spec/unit/transaction_spec.rb index 4bf615803..3829cfaf5 100755 --- a/spec/unit/transaction_spec.rb +++ b/spec/unit/transaction_spec.rb @@ -87,13 +87,19 @@ describe Puppet::Transaction do @transaction.should_not be_any_failed end - it "should be possible to replace the report object" do + it "should use the provided report object" do report = Puppet::Transaction::Report.new("apply") - @transaction.report = report + @transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new, report) @transaction.report.should == report end + it "should create a report if none is provided" do + @transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new) + + @transaction.report.should be_kind_of Puppet::Transaction::Report + end + describe "when initializing" do it "should create an event manager" do @transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new) diff --git a/spec/unit/type_spec.rb b/spec/unit/type_spec.rb index ca291c4fa..bbdaec3bc 100755 --- a/spec/unit/type_spec.rb +++ b/spec/unit/type_spec.rb @@ -164,6 +164,72 @@ describe Puppet::Type do end end + describe "when creating a provider" do + before :each do + @type = Puppet::Type.newtype(:provider_test_type) + end + + after :each do + @type.provider_hash.clear + end + + it "should create a subclass of Puppet::Provider for the provider" do + provider = @type.provide(:test_provider) + + provider.ancestors.should include(Puppet::Provider) + end + + it "should use a parent class if specified" do + parent_provider = @type.provide(:parent_provider) + child_provider = @type.provide(:child_provider, :parent => parent_provider) + + child_provider.ancestors.should include(parent_provider) + end + + it "should use a parent class if specified by name" do + parent_provider = @type.provide(:parent_provider) + child_provider = @type.provide(:child_provider, :parent => :parent_provider) + + child_provider.ancestors.should include(parent_provider) + end + + it "should raise an error when the parent class can't be found" do + expect { + @type.provide(:child_provider, :parent => :parent_provider) + }.to raise_error(Puppet::DevError, /Could not find parent provider.+parent_provider/) + end + + it "should ensure its type has a 'provider' parameter" do + @type.provide(:test_provider) + + @type.parameters.should include(:provider) + end + + it "should remove a previously registered provider with the same name" do + old_provider = @type.provide(:test_provider) + new_provider = @type.provide(:test_provider) + + old_provider.should_not equal(new_provider) + end + + it "should register itself as a provider for the type" do + provider = @type.provide(:test_provider) + + provider.should == @type.provider(:test_provider) + end + + it "should create a provider when a provider with the same name previously failed" do + @type.provide(:test_provider) do + raise "failed to create this provider" + end rescue nil + + provider = @type.provide(:test_provider) + + provider.ancestors.should include(Puppet::Provider) + provider.should == @type.provider(:test_provider) + end + end + describe "when choosing a default provider" do it "should choose the provider with the highest specificity" do # Make a fake type |
