diff options
author | Nick Lewis <nick@puppetlabs.com> | 2011-01-13 16:03:41 -0800 |
---|---|---|
committer | Nick Lewis <nick@puppetlabs.com> | 2011-01-13 16:03:41 -0800 |
commit | 17843d5e86a8841728a77c77d5f2ea4661c0f417 (patch) | |
tree | d8a188a48e180f8179a97c29d6da6c9f28926031 /spec/unit/application | |
parent | 8c60cebababafbacf031a4ad842a615e82910cf0 (diff) | |
download | puppet-17843d5e86a8841728a77c77d5f2ea4661c0f417.tar.gz puppet-17843d5e86a8841728a77c77d5f2ea4661c0f417.tar.xz puppet-17843d5e86a8841728a77c77d5f2ea4661c0f417.zip |
(#5882) Added error-handling to puppet inspect when auditing
If auditing a resource fails, the report will contain failure events for every
audited property of the resource. The report itself will also be marked as
"failed".
Paired-With: Paul Berry
Diffstat (limited to 'spec/unit/application')
-rw-r--r-- | spec/unit/application/inspect_spec.rb | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/spec/unit/application/inspect_spec.rb b/spec/unit/application/inspect_spec.rb index 0c7b61f59..15b0c40ad 100644 --- a/spec/unit/application/inspect_spec.rb +++ b/spec/unit/application/inspect_spec.rb @@ -144,7 +144,6 @@ describe Puppet::Application::Inspect do end it "should not send unreadable files" do - pending "see bug #5882" File.open(@file, 'w') { |f| f.write('stuff') } File.chmod(0, @file) Puppet::FileBucketFile::Rest.any_instance.expects(:head).never @@ -197,6 +196,65 @@ describe Puppet::Application::Inspect do end end end + + describe "when there are failures" do + before :each do + Puppet::Type.newtype(:stub_type) do + newparam(:name) do + desc "The name var" + isnamevar + end + + newproperty(:content) do + desc "content" + def retrieve + raise "failed" + end + end + end + + @catalog = Puppet::Resource::Catalog.new + Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(@catalog) + + Puppet::Transaction::Report::Rest.any_instance.expects(:save).with do |request| + @report = request.instance + end + end + + after :each do + Puppet::Type.rmtype(:stub_type) + end + + it "should mark the report failed and create failed events for each property" do + @resource = Puppet::Resource.new(:stub_type, 'foo', :parameters => {:audit => "all"}) + @catalog.add_resource(@resource) + + @inspect.run_command + + @report.status.should == "failed" + #@report.logs.select{|log| log.message =~ /Could not inspect/}.count.should == 1 + @report.resource_statuses.count.should == 1 + @report.resource_statuses['Stub_type[foo]'].events.count.should == 1 + + event = @report.resource_statuses['Stub_type[foo]'].events.first + event.property.should == "content" + event.status.should == "failure" + event.audited.should == true + event.instance_variables.should_not include("@previous_value") + end + + it "should continue to the next resource" do + @resource = Puppet::Resource.new(:stub_type, 'foo', :parameters => {:audit => "all"}) + @other_resource = Puppet::Resource.new(:stub_type, 'bar', :parameters => {:audit => "all"}) + @catalog.add_resource(@resource) + @catalog.add_resource(@other_resource) + + @inspect.run_command + + @report.resource_statuses.count.should == 2 + @report.resource_statuses.keys.should =~ ['Stub_type[foo]', 'Stub_type[bar]'] + end + end end after :all do |