Signed-off-by: Paul Berry <[email protected]>
---
lib/puppet/transaction/report.rb | 19 ++++++++++++++++---
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 f78b5aa..6315973 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 5d270da..96d464b 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
--
1.7.2
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.