This attribute is always present in version 2 reports, and sometimes
present in version 1 reports.  Modified dashboard to accept it and add
it to the database.

Paired-with: Nick Lewis <[email protected]>
Signed-off-by: Paul Berry <[email protected]>
---
Local-branch: ticket/next/5900
 db/schema.rb                                       |    3 +-
 lib/puppet/report.rb                               |    5 +-
 lib/report_transformer.rb                          |    1 +
 .../puppet26/report_ok_service_started_ok.yaml     |    1 +
 spec/fixtures/reports/version2/example.yaml        |   12 +++++
 spec/lib/puppet/report_spec.rb                     |   27 ++++++++----
 spec/lib/report_transformer_spec.rb                |   11 +++++
 spec/models/report_spec.rb                         |   47 ++++++++++---------
 8 files changed, 73 insertions(+), 34 deletions(-)

diff --git a/db/schema.rb b/db/schema.rb
index ca4413e..8e4af6c 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
 #
 # It's strongly recommended to check this file into your version control 
system.
 
-ActiveRecord::Schema.define(:version => 20110113195253) do
+ActiveRecord::Schema.define(:version => 20110114190814) do
 
   create_table "metrics", :force => true do |t|
     t.integer "report_id",                                :null => false
@@ -146,6 +146,7 @@ ActiveRecord::Schema.define(:version => 20110113195253) do
     t.integer  "change_count"
     t.integer  "out_of_sync_count"
     t.boolean  "skipped"
+    t.boolean  "failed"
   end
 
   add_index "resource_statuses", ["report_id"], :name => 
"index_resource_statuses_on_report_id"
diff --git a/lib/puppet/report.rb b/lib/puppet/report.rb
index 1d4b4b7..f1d4cef 100644
--- a/lib/puppet/report.rb
+++ b/lib/puppet/report.rb
@@ -88,7 +88,7 @@ module Puppet #:nodoc:
     class Status
       attr_reader :evaluation_time, :resource, :tags,
       :file, :events, :time, :line, :changed, :change_count,
-      :skipped
+      :skipped, :failed
 
       def to_hash
         {
@@ -99,7 +99,8 @@ module Puppet #:nodoc:
           "time" => time,
           "change_count" => change_count || 0,
           "events" => events.map(&:to_hash),
-          "skipped" => skipped
+          "skipped" => skipped,
+          "failed" => failed,
         }
       end
     end
diff --git a/lib/report_transformer.rb b/lib/report_transformer.rb
index 3c535f2..d90fe16 100644
--- a/lib/report_transformer.rb
+++ b/lib/report_transformer.rb
@@ -72,6 +72,7 @@ class ReportTransformer::OneToTwo < 
ReportTransformer::ReportTransformation
       resource_status["resource_type"], resource_status["title"] = $1, $2
       resource_status["skipped"] ||= false # ensure that we represent 
falsehood as "false", not "nil"
       resource_status["out_of_sync_count"] = resource_status["change_count"]
+      resource_status["failed"] ||= false
       resource_status["events"].each do |event|
         event["audited"] = event["status"] == "audit"
         if event["audited"]
diff --git a/spec/fixtures/reports/puppet26/report_ok_service_started_ok.yaml 
b/spec/fixtures/reports/puppet26/report_ok_service_started_ok.yaml
index 5d2796a..288572d 100644
--- a/spec/fixtures/reports/puppet26/report_ok_service_started_ok.yaml
+++ b/spec/fixtures/reports/puppet26/report_ok_service_started_ok.yaml
@@ -148,6 +148,7 @@
             - class
           time: 2010-07-22 12:19:47.360626 -07:00
           version: 1279826342
+      failed: true
       file: *id002
       line: 9
       out_of_sync: true
diff --git a/spec/fixtures/reports/version2/example.yaml 
b/spec/fixtures/reports/version2/example.yaml
index 8df6a40..1a938b0 100644
--- a/spec/fixtures/reports/version2/example.yaml
+++ b/spec/fixtures/reports/version2/example.yaml
@@ -200,6 +200,7 @@
       changed: false
       evaluation_time: 0.000283
       events: []
+      failed: false
       file: 
       line: 
       out_of_sync: false
@@ -216,6 +217,7 @@
       changed: false
       evaluation_time: 0.000258
       events: []
+      failed: false
       file: 
       line: 
       out_of_sync: false
@@ -242,6 +244,7 @@
           property: owner
           status: audit
           time: 2010-12-30 16:56:37.436191 -08:00
+      failed: false
       file: *id001
       line: 7
       out_of_sync: false
@@ -268,6 +271,7 @@
           property: mode
           status: noop
           time: 2010-12-30 17:13:28.925582 -08:00
+      failed: false
       file: *id001
       line: 7
       out_of_sync: true
@@ -284,6 +288,7 @@
       changed: false
       evaluation_time: 0.000256
       events: []
+      failed: false
       file: 
       line: 
       out_of_sync: false
@@ -300,6 +305,7 @@
       changed: false
       evaluation_time: 0.00027
       events: []
+      failed: false
       file: 
       line: 
       out_of_sync: false
@@ -326,6 +332,7 @@
           property: ensure
           status: success
           time: 2010-12-30 16:56:37.440618 -08:00
+      failed: false
       file: *id001
       line: 7
       out_of_sync: true
@@ -352,6 +359,7 @@
           property: ensure
           status: success
           time: 2010-12-30 16:56:37.445044 -08:00
+      failed: false
       file: *id001
       line: 7
       out_of_sync: true
@@ -368,6 +376,7 @@
       changed: false
       evaluation_time: 0.000264
       events: []
+      failed: false
       file: 
       line: 
       out_of_sync: false
@@ -384,6 +393,7 @@
       changed: false
       evaluation_time: 0.00031
       events: []
+      failed: false
       file: 
       line: 
       out_of_sync: false
@@ -410,6 +420,7 @@
           property: mode
           status: success
           time: 2010-12-30 16:56:37.438029 -08:00
+      failed: true
       file: *id001
       line: 7
       out_of_sync: true
@@ -426,6 +437,7 @@
       changed: false
       evaluation_time: 0.000261
       events: []
+      failed: false
       file: 
       line: 
       out_of_sync: false
diff --git a/spec/lib/puppet/report_spec.rb b/spec/lib/puppet/report_spec.rb
index 70ba2fd..8e2fc31 100644
--- a/spec/lib/puppet/report_spec.rb
+++ b/spec/lib/puppet/report_spec.rb
@@ -218,7 +218,8 @@ describe Puppet::Transaction::Report do
             ],
             "file"               => nil,
             "events"             => [],
-            "version"            => 1279826342
+            "version"            => 1279826342,
+            "failed"             => nil
           },
           "Filebucket[puppet]" => {
             "skipped"            => nil,
@@ -232,7 +233,8 @@ describe Puppet::Transaction::Report do
             ],
             "file"               => nil,
             "events"             => [],
-            "version"            => 1279826342
+            "version"            => 1279826342,
+            "failed"             => nil
           },
           "Service[mysqld]" => {
             "skipped"            => nil,
@@ -257,7 +259,8 @@ describe Puppet::Transaction::Report do
               "status"             => "success",
               "time"               => Time.parse("2010-07-22 12:19:48.921431 
-07:00")
             }],
-            "version"            => 1279826342
+            "version"            => 1279826342,
+            "failed"             => nil
           },
           "Schedule[never]" => {
             "skipped"            => nil,
@@ -271,7 +274,8 @@ describe Puppet::Transaction::Report do
             ],
             "file"               => nil,
             "events"             => [],
-            "version"            => 1279826342
+            "version"            => 1279826342,
+            "failed"             => nil
           },
           "Schedule[weekly]" => {
             "skipped"            => nil,
@@ -285,7 +289,8 @@ describe Puppet::Transaction::Report do
             ],
             "file"               => nil,
             "events"             => [],
-            "version"            => 1279826342
+            "version"            => 1279826342,
+            "failed"             => nil
           },
           "Exec[/bin/true]" => {
             "skipped"            => nil,
@@ -309,7 +314,8 @@ describe Puppet::Transaction::Report do
               "status"             => "success",
               "time"               => Time.parse("2010-07-22 12:19:47.360626 
-07:00")
             }],
-            "version"            => 1279826342
+            "version"            => 1279826342,
+            "failed"             => true
           },
           "Schedule[puppet]" => {
             "skipped"            => nil,
@@ -323,7 +329,8 @@ describe Puppet::Transaction::Report do
             ],
             "file"               => nil,
             "events"             => [],
-            "version"            => 1279826342
+            "version"            => 1279826342,
+            "failed"             => nil
           },
           "Schedule[daily]" => {
             "skipped"         => nil,
@@ -337,7 +344,8 @@ describe Puppet::Transaction::Report do
             ],
             "file"               => nil,
             "events"             => [],
-            "version"            => 1279826342
+            "version"            => 1279826342,
+            "failed"             => nil
           },
           "Schedule[hourly]" => {
             "skipped"         => nil,
@@ -351,7 +359,8 @@ describe Puppet::Transaction::Report do
             ],
             "file"               => nil,
             "events"             => [],
-            "version"            => 1279826342
+            "version"            => 1279826342,
+            "failed"             => nil
           }
         }
       end
diff --git a/spec/lib/report_transformer_spec.rb 
b/spec/lib/report_transformer_spec.rb
index 01d5c3e..3b61080 100644
--- a/spec/lib/report_transformer_spec.rb
+++ b/spec/lib/report_transformer_spec.rb
@@ -222,5 +222,16 @@ describe ReportTransformer do
         resource_status["skipped"].should == false
       end
     end
+
+    it "should set resource status 'failed' to false if not present" do
+      expected_failure_states = {}
+      @report["resource_statuses"].each do |key, resource_status|
+        expected_failure_states[key] = resource_status["failed"] || false
+      end
+      report = ReportTransformer::OneToTwo.apply(@report)
+      report["resource_statuses"].each do |key, resource_status|
+        resource_status["failed"].should == expected_failure_states[key]
+      end
+    end
   end
 end
diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb
index 62096c6..8bc6a58 100644
--- a/spec/models/report_spec.rb
+++ b/spec/models/report_spec.rb
@@ -132,6 +132,7 @@ describe Report do
         - default
         - &id003 class
       time: 2010-07-22 14:42:39.654436 -04:00
+      failed: false
       events: 
         - !ruby/object:Puppet::Transaction::Event
           default_log_level: !ruby/sym notice
@@ -347,17 +348,18 @@ HEREDOC
           #t.source_description,
           t.tags.sort,
           #t.time,
-          t.change_count
+          t.change_count,
+          t.failed
         ] }.should =~ [
-          [ 'Filebucket' ,  'puppet'  ,  "0.00" ,  nil ,  nil ,  ['filebucket' 
,  'puppet']   ,  0 ],
-          [ 'Schedule'   ,  'puppet'  ,  "0.00" ,  nil ,  nil ,  ['puppet'     
,  'schedule'] ,  0 ],
-          [ 'Schedule'   ,  'weekly'  ,  "0.00" ,  nil ,  nil ,  ['schedule'   
,  'weekly']   ,  0 ],
-          [ 'Schedule'   ,  'daily'   ,  "0.00" ,  nil ,  nil ,  ['daily'      
,  'schedule'] ,  0 ],
-          [ 'Schedule'   ,  'hourly'  ,  "0.00" ,  nil ,  nil ,  ['hourly'     
,  'schedule'] ,  0 ],
-          [ 'Schedule'   ,  'monthly' ,  "0.00" ,  nil ,  nil ,  ['monthly'    
,  'schedule'] ,  0 ],
-          [ 'Schedule'   ,  'never'   ,  "0.00" ,  nil ,  nil ,  ['never'      
,  'schedule'] ,  0 ],
-          [ 'Service'    ,  'mysqld'  ,  "1.56" ,  file,  8   ,  ['class'      
,  'default'   ,  'mysqld' ,  'node' ,  'service'] ,  1 ],
-          [ 'Exec'       ,'/bin/true' ,  "0.10" ,  file ,  9  ,  ['class'      
,  'default'   ,  'exec' ,  'node' ] ,  1 ],
+          [ 'Filebucket' ,  'puppet'  ,  "0.00" ,  nil ,  nil ,  ['filebucket' 
,  'puppet']   ,  0, false ],
+          [ 'Schedule'   ,  'puppet'  ,  "0.00" ,  nil ,  nil ,  ['puppet'     
,  'schedule'] ,  0, false ],
+          [ 'Schedule'   ,  'weekly'  ,  "0.00" ,  nil ,  nil ,  ['schedule'   
,  'weekly']   ,  0, false ],
+          [ 'Schedule'   ,  'daily'   ,  "0.00" ,  nil ,  nil ,  ['daily'      
,  'schedule'] ,  0, false ],
+          [ 'Schedule'   ,  'hourly'  ,  "0.00" ,  nil ,  nil ,  ['hourly'     
,  'schedule'] ,  0, false ],
+          [ 'Schedule'   ,  'monthly' ,  "0.00" ,  nil ,  nil ,  ['monthly'    
,  'schedule'] ,  0, false ],
+          [ 'Schedule'   ,  'never'   ,  "0.00" ,  nil ,  nil ,  ['never'      
,  'schedule'] ,  0, false ],
+          [ 'Service'    ,  'mysqld'  ,  "1.56" ,  file,  8   ,  ['class'      
,  'default'   ,  'mysqld' ,  'node' ,  'service'] ,  1, false ],
+          [ 'Exec'       ,'/bin/true' ,  "0.10" ,  file ,  9  ,  ['class'      
,  'default'   ,  'exec' ,  'node' ] ,  1, true ],
         ]
         report.events.map { |t| [
           t.property,
@@ -428,19 +430,20 @@ HEREDOC
         #t.time,
         t.change_count,
         t.out_of_sync_count,
+        t.failed
       ] }.should =~ [
-        [ 'Filebucket' ,  'puppet'  ,  "0.000" ,  nil ,  nil ,  ['filebucket' 
,  'puppet']   ,  0 , 0 ],
-        [ 'Schedule'   ,  'monthly' ,  "0.000" ,  nil ,  nil ,  ['monthly'    
,  'schedule'] ,  0 , 0 ],
-        [ 'File' , '/tmp/unchanged' ,  "0.001" ,  file,  7   ,  ['class'      
,  'file']     ,  0 , 0 ],
-        [ 'File' , '/tmp/noop'      ,  "0.001" ,  file,  7   ,  ['class'      
,  'file']     ,  0 , 1 ],
-        [ 'Schedule'   ,  'never'   ,  "0.000" ,  nil ,  nil ,  ['never'      
,  'schedule'] ,  0 , 0 ],
-        [ 'Schedule'   ,  'weekly'  ,  "0.000" ,  nil ,  nil ,  ['schedule'   
,  'weekly']   ,  0 , 0 ],
-        [ 'File' , '/tmp/removed'   ,  "0.004" ,  file,  7   ,  ['class'      
,  'file']     ,  1 , 1 ],
-        [ 'File' , '/tmp/created'   ,  "0.001" ,  file,  7   ,  ['class'      
,  'file']     ,  1 , 1 ],
-        [ 'Schedule'   ,  'puppet'  ,  "0.000" ,  nil ,  nil ,  ['puppet'     
,  'schedule'] ,  0 , 0 ],
-        [ 'Schedule'   ,  'daily'   ,  "0.000" ,  nil ,  nil ,  ['daily'      
,  'schedule'] ,  0 , 0 ],
-        [ 'File' , '/tmp/changed'   ,  "0.001" ,  file,  7   ,  ['class'      
,  'file']     ,  1 , 1 ],
-        [ 'Schedule'   ,  'hourly'  ,  "0.000" ,  nil ,  nil ,  ['hourly'     
,  'schedule'] ,  0 , 0 ],
+        [ 'Filebucket' ,  'puppet'  ,  "0.000" ,  nil ,  nil ,  ['filebucket' 
,  'puppet']   ,  0 , 0 , false ],
+        [ 'Schedule'   ,  'monthly' ,  "0.000" ,  nil ,  nil ,  ['monthly'    
,  'schedule'] ,  0 , 0 , false ],
+        [ 'File' , '/tmp/unchanged' ,  "0.001" ,  file,  7   ,  ['class'      
,  'file']     ,  0 , 0 , false ],
+        [ 'File' , '/tmp/noop'      ,  "0.001" ,  file,  7   ,  ['class'      
,  'file']     ,  0 , 1 , false ],
+        [ 'Schedule'   ,  'never'   ,  "0.000" ,  nil ,  nil ,  ['never'      
,  'schedule'] ,  0 , 0 , false ],
+        [ 'Schedule'   ,  'weekly'  ,  "0.000" ,  nil ,  nil ,  ['schedule'   
,  'weekly']   ,  0 , 0 , false ],
+        [ 'File' , '/tmp/removed'   ,  "0.004" ,  file,  7   ,  ['class'      
,  'file']     ,  1 , 1 , false ],
+        [ 'File' , '/tmp/created'   ,  "0.001" ,  file,  7   ,  ['class'      
,  'file']     ,  1 , 1 , false ],
+        [ 'Schedule'   ,  'puppet'  ,  "0.000" ,  nil ,  nil ,  ['puppet'     
,  'schedule'] ,  0 , 0 , false ],
+        [ 'Schedule'   ,  'daily'   ,  "0.000" ,  nil ,  nil ,  ['daily'      
,  'schedule'] ,  0 , 0 , false ],
+        [ 'File' , '/tmp/changed'   ,  "0.001" ,  file,  7   ,  ['class'      
,  'file']     ,  1 , 1 , true  ],
+        [ 'Schedule'   ,  'hourly'  ,  "0.000" ,  nil ,  nil ,  ['hourly'     
,  'schedule'] ,  0 , 0 , false ],
       ]
       report.events.map { |t| [
         t.property,
-- 
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.

Reply via email to