diff options
| author | Paul Berry <paul@puppetlabs.com> | 2010-12-29 14:49:16 -0800 |
|---|---|---|
| committer | Paul Berry <paul@puppetlabs.com> | 2010-12-30 11:53:05 -0800 |
| commit | 037eac4383ed5a5e9cdde765b607a180209bad1e (patch) | |
| tree | 9c48d7656ab9ba36f9b2110c2b84284d6e997ee7 | |
| parent | e4a2e049dc9f77569a2dac042e9e847ef34f037d (diff) | |
(#5715) Add status attribute to reports.
| -rw-r--r-- | lib/puppet/transaction/report.rb | 19 | ||||
| -rwxr-xr-x | spec/unit/transaction/report_spec.rb | 21 |
2 files changed, 34 insertions, 6 deletions
diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index f78b5aa21..6315973ba 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -11,7 +11,7 @@ class Puppet::Transaction::Report indirects :report, :terminus_class => :processor attr_accessor :configuration_version - attr_reader :resource_statuses, :logs, :metrics, :host, :time, :kind + attr_reader :resource_statuses, :logs, :metrics, :host, :time, :kind, :status # This is necessary since Marshall doesn't know how to # dump hash with default proc (see below @records) @@ -43,11 +43,23 @@ class Puppet::Transaction::Report @resource_statuses[status.resource] = status end + def compute_status(resource_metrics, change_metric) + if (resource_metrics[:failed] || 0) > 0 + 'failed' + elsif change_metric > 0 + 'changed' + else + 'unchanged' + end + end + def finalize_report - add_metric(:resources, calculate_resource_metrics) + resource_metrics = add_metric(:resources, calculate_resource_metrics) add_metric(:time, calculate_time_metrics) - add_metric(:changes, {:total => calculate_change_metric}) + change_metric = calculate_change_metric + add_metric(:changes, {:total => change_metric}) add_metric(:events, calculate_event_metrics) + @status = compute_status(resource_metrics, change_metric) end def initialize(kind, configuration_version=nil) @@ -61,6 +73,7 @@ class Puppet::Transaction::Report @report_format = 2 @puppet_version = Puppet.version @configuration_version = configuration_version + @status = 'failed' # assume failed until the report is finalized end def name diff --git a/spec/unit/transaction/report_spec.rb b/spec/unit/transaction/report_spec.rb index 5d270dad3..96d464b7a 100755 --- a/spec/unit/transaction/report_spec.rb +++ b/spec/unit/transaction/report_spec.rb @@ -121,7 +121,14 @@ describe Puppet::Transaction::Report do end end - describe "when calculating metrics" do + describe "before finalizing the report" do + it "should have a status of 'failed'" do + report = Puppet::Transaction::Report.new("apply") + report.status.should == 'failed' + end + end + + describe "when finalizing the report" do before do @report = Puppet::Transaction::Report.new("apply") end @@ -166,18 +173,26 @@ describe Puppet::Transaction::Report do metric(:resources, state).should == 3 end end + + it "should mark the report as 'failed' if there are failing resources" do + add_statuses(1) { |status| status.failed = true } + @report.finalize_report + @report.status.should == 'failed' + end end describe "for changes" do - it "should provide the number of changes from the resource statuses" do + it "should provide the number of changes from the resource statuses and mark the report as 'changed'" do add_statuses(3) { |status| 3.times { status << Puppet::Transaction::Event.new(:status => 'success') } } @report.finalize_report metric(:changes, :total).should == 9 + @report.status.should == 'changed' end - it "should provide a total even if there are no changes" do + it "should provide a total even if there are no changes, and mark the report as 'unchanged'" do @report.finalize_report metric(:changes, :total).should == 0 + @report.status.should == 'unchanged' end end |
