A higher level test of importing report format 2 reports exposed some
bugs when saving the reports to the database.

Paired-with: Nick Lewis

Signed-off-by: Matt Robinson <[email protected]>
---
Local-branch: ticket/next/5743
 .../20110107233911_remove_out_of_sync_column.rb    |    9 +
 db/schema.rb                                       |    3 +-
 lib/puppet/report.rb                               |   31 +-
 spec/fixtures/reports/version2/example.yaml        |  441 ++++++++++++++++++++
 spec/lib/puppet/report_spec.rb                     |   11 +-
 spec/models/report_spec.rb                         |  107 +++++-
 6 files changed, 578 insertions(+), 24 deletions(-)
 create mode 100644 db/migrate/20110107233911_remove_out_of_sync_column.rb
 create mode 100644 spec/fixtures/reports/version2/example.yaml

diff --git a/db/migrate/20110107233911_remove_out_of_sync_column.rb 
b/db/migrate/20110107233911_remove_out_of_sync_column.rb
new file mode 100644
index 0000000..4b963f1
--- /dev/null
+++ b/db/migrate/20110107233911_remove_out_of_sync_column.rb
@@ -0,0 +1,9 @@
+class RemoveOutOfSyncColumn < ActiveRecord::Migration
+  def self.up
+    remove_column :resource_statuses, :out_of_sync
+  end
+
+  def self.down
+    add_column :resource_statuses, :out_of_sync, :boolean
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 67b40f7..6b22416 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 => 20110106002514) do
+ActiveRecord::Schema.define(:version => 20110107233911) do
 
   create_table "assignments", :force => true do |t|
     t.integer  "node_id"
@@ -150,7 +150,6 @@ ActiveRecord::Schema.define(:version => 20110106002514) do
     t.string   "tags"
     t.datetime "time"
     t.integer  "change_count"
-    t.boolean  "out_of_sync"
     t.integer  "out_of_sync_count"
     t.boolean  "skipped"
   end
diff --git a/lib/puppet/report.rb b/lib/puppet/report.rb
index 2182168..1d4b4b7 100644
--- a/lib/puppet/report.rb
+++ b/lib/puppet/report.rb
@@ -52,7 +52,7 @@ module Puppet #:nodoc:
 
   module Util
     class Metric
-      attr_reader :type, :name, :values, :label
+      attr_reader :name, :values
 
       # Return a specific value
       def [](name)
@@ -88,7 +88,7 @@ module Puppet #:nodoc:
     class Status
       attr_reader :evaluation_time, :resource, :tags,
       :file, :events, :time, :line, :changed, :change_count,
-      :out_of_sync, :skipped
+      :skipped
 
       def to_hash
         {
@@ -98,7 +98,6 @@ module Puppet #:nodoc:
           "tags" => tags,
           "time" => time,
           "change_count" => change_count || 0,
-          "out_of_sync" => out_of_sync,
           "events" => events.map(&:to_hash),
           "skipped" => skipped
         }
@@ -151,7 +150,7 @@ module ReportExtensions #:nodoc:
       end
 
       # Attributes in 2.6.x but not 0.25.x
-      attr_reader :external_times, :resource_statuses
+      attr_reader :resource_statuses
 
       def to_hash
         hash = super
@@ -197,10 +196,13 @@ module ReportExtensions #:nodoc:
       attr_reader :report_format
 
       def self.extended(obj)
-        obj.resource_statuses.each{|_, status| status.extend 
ReportFormat2::Resource::Status} if obj.resource_statuses.respond_to?(:each)
+        obj.resource_statuses.each do |_, status| 
+          status.extend ReportFormat2::Resource::Status
+          status.events.each {|event| event.extend 
ReportFormat2::Transaction::Event}
+        end if obj.resource_statuses
       end
 
-      attr_reader :resource_statuses, :kind, :puppet_version, 
:configuration_version
+      attr_reader :resource_statuses, :kind, :puppet_version, 
:configuration_version, :status
 
       def to_hash
         hash = super
@@ -209,6 +211,7 @@ module ReportExtensions #:nodoc:
           hash["resource_statuses"][key] = value.to_hash
         end
         hash["kind"] = kind
+        hash["status"] = status
         hash["puppet_version"] = puppet_version
         hash["configuration_version"] = configuration_version
         hash
@@ -217,15 +220,29 @@ module ReportExtensions #:nodoc:
 
     module Resource
       module Status
-        attr_reader :resource_type, :title
+        attr_reader :resource_type, :title, :out_of_sync_count
 
         def to_hash
           hash = super
           hash["resource_type"] = resource_type
+          hash["out_of_sync_count"] = out_of_sync_count
           hash["title"] = title
           hash
         end
       end
     end
+
+    module Transaction
+      module Event
+        attr_reader :audited, :historical_value
+
+        def to_hash
+          hash = super
+          hash["audited"] = audited
+          hash["historical_value"] = historical_value
+          hash
+        end
+      end
+    end
   end
 end
diff --git a/spec/fixtures/reports/version2/example.yaml 
b/spec/fixtures/reports/version2/example.yaml
new file mode 100644
index 0000000..8df6a40
--- /dev/null
+++ b/spec/fixtures/reports/version2/example.yaml
@@ -0,0 +1,441 @@
+--- !ruby/object:Puppet::Transaction::Report
+  configuration_version: 1293756667
+  host: paul-berrys-macbook-pro-3.local
+  kind: apply
+  logs: 
+    - !ruby/object:Puppet::Util::Log
+      level: !ruby/sym debug
+      message: Using cached certificate for ca
+      source: Puppet
+      tags: 
+        - debug
+      time: 2010-12-30 16:56:37.290413 -08:00
+    - !ruby/object:Puppet::Util::Log
+      level: !ruby/sym debug
+      message: Using cached certificate for paul-berrys-macbook-pro-3.local
+      source: Puppet
+      tags: 
+        - debug
+      time: 2010-12-30 16:56:37.291081 -08:00
+    - !ruby/object:Puppet::Util::Log
+      level: !ruby/sym debug
+      message: Using cached certificate_revocation_list for ca
+      source: Puppet
+      tags: 
+        - debug
+      time: 2010-12-30 16:56:37.292402 -08:00
+    - !ruby/object:Puppet::Util::Log
+      level: !ruby/sym debug
+      message: "catalog supports formats: b64_zlib_yaml dot marshal pson raw 
yaml; using pson"
+      source: Puppet
+      tags: 
+        - debug
+      time: 2010-12-30 16:56:37.293879 -08:00
+    - !ruby/object:Puppet::Util::Log
+      level: !ruby/sym info
+      message: Caching catalog for paul-berrys-macbook-pro-3.local
+      source: Puppet
+      tags: 
+        - info
+      time: 2010-12-30 16:56:37.351517 -08:00
+    - !ruby/object:Puppet::Util::Log
+      level: !ruby/sym debug
+      message: Creating default schedules
+      source: Puppet
+      tags: 
+        - debug
+      time: 2010-12-30 16:56:37.425154 -08:00
+    - !ruby/object:Puppet::Util::Log
+      level: !ruby/sym debug
+      message: Loaded state in 0.00 seconds
+      source: Puppet
+      tags: 
+        - debug
+      time: 2010-12-30 16:56:37.432343 -08:00
+    - !ruby/object:Puppet::Util::Log
+      level: !ruby/sym info
+      message: Applying configuration version '1293756667'
+      source: Puppet
+      tags: 
+        - info
+      time: 2010-12-30 16:56:37.434292 -08:00
+    - !ruby/object:Puppet::Util::Log
+      file: &id001 /Users/pberry/puppet_labs/test_data/master/manifests/site.pp
+      level: !ruby/sym notice
+      line: 7
+      message: &id002 "audit change: previously recorded value pberry has been 
changed to root"
+      source: "/Stage[main]//File[/tmp/unchanged]/owner"
+      tags: 
+        - notice
+        - file
+        - class
+      time: 2010-12-30 16:56:37.436286 -08:00
+    - !ruby/object:Puppet::Util::Log
+      file: *id001
+      level: !ruby/sym notice
+      line: 7
+      message: &id005 mode changed '640' to '644'
+      source: "/Stage[main]//File[/tmp/changed]/mode"
+      tags: 
+        - notice
+        - file
+        - class
+      time: 2010-12-30 16:56:37.438225 -08:00
+    - !ruby/object:Puppet::Util::Log
+      level: !ruby/sym debug
+      message: Finishing transaction 2166421680
+      source: Puppet
+      tags: 
+        - debug
+      time: 2010-12-30 16:56:37.442001 -08:00
+    - !ruby/object:Puppet::Util::Log
+      level: !ruby/sym info
+      message: "FileBucket got a duplicate file /private/tmp/removed 
({md5}d41d8cd98f00b204e9800998ecf8427e)"
+      source: Puppet
+      tags: 
+        - info
+      time: 2010-12-30 16:56:37.442516 -08:00
+    - !ruby/object:Puppet::Util::Log
+      file: *id001
+      level: !ruby/sym info
+      line: 7
+      message: Filebucketed /tmp/removed to puppet with sum 
d41d8cd98f00b204e9800998ecf8427e
+      source: "/Stage[main]//File[/tmp/removed]"
+      tags: 
+        - info
+        - file
+        - class
+      time: 2010-12-30 16:56:37.442920 -08:00
+    - !ruby/object:Puppet::Util::Log
+      file: *id001
+      level: !ruby/sym debug
+      line: 7
+      message: Removing existing file for replacement with absent
+      source: "/Stage[main]//File[/tmp/removed]"
+      tags: 
+        - debug
+        - file
+        - class
+      time: 2010-12-30 16:56:37.443198 -08:00
+    - !ruby/object:Puppet::Util::Log
+      file: *id001
+      level: !ruby/sym notice
+      line: 7
+      message: &id003 removed
+      source: "/Stage[main]//File[/tmp/removed]/ensure"
+      tags: 
+        - notice
+        - file
+        - class
+      time: 2010-12-30 16:56:37.443617 -08:00
+    - !ruby/object:Puppet::Util::Log
+      file: *id001
+      level: !ruby/sym notice
+      line: 7
+      message: &id004 created
+      source: "/Stage[main]//File[/tmp/created]/ensure"
+      tags: 
+        - notice
+        - file
+        - class
+      time: 2010-12-30 16:56:37.445352 -08:00
+  metrics: 
+    time: !ruby/object:Puppet::Util::Metric
+      label: Time
+      name: time
+      values: 
+        - - config_retrieval
+          - Config retrieval
+          - 0.0729589462280273
+        - - schedule
+          - Schedule
+          - 0.001619
+        - - total
+          - Total
+          - 0.0830139462280273
+        - - file
+          - File
+          - 0.008153
+        - - filebucket
+          - Filebucket
+          - 0.000283
+    resources: !ruby/object:Puppet::Util::Metric
+      label: Resources
+      name: resources
+      values: 
+        - - changed
+          - Changed
+          - 3
+        - - total
+          - Total
+          - 12
+        - - out_of_sync
+          - Out of sync
+          - 4
+    events: !ruby/object:Puppet::Util::Metric
+      label: Events
+      name: events
+      values: 
+        - - total
+          - Total
+          - 4
+        - - audit
+          - Audit
+          - 1
+        - - success
+          - Success
+          - 3
+    changes: !ruby/object:Puppet::Util::Metric
+      label: Changes
+      name: changes
+      values: 
+        - - total
+          - Total
+          - 3
+  puppet_version: 2.6.4
+  report_format: 2
+  resource_statuses: 
+    "Filebucket[puppet]": !ruby/object:Puppet::Resource::Status
+      change_count: 0
+      changed: false
+      evaluation_time: 0.000283
+      events: []
+      file: 
+      line: 
+      out_of_sync: false
+      out_of_sync_count: 0
+      resource: "Filebucket[puppet]"
+      resource_type: Filebucket
+      tags: 
+        - filebucket
+        - puppet
+      time: 2010-12-30 16:56:37.445939 -08:00
+      title: puppet
+    "Schedule[monthly]": !ruby/object:Puppet::Resource::Status
+      change_count: 0
+      changed: false
+      evaluation_time: 0.000258
+      events: []
+      file: 
+      line: 
+      out_of_sync: false
+      out_of_sync_count: 0
+      resource: "Schedule[monthly]"
+      resource_type: Schedule
+      tags: 
+        - schedule
+        - monthly
+      time: 2010-12-30 16:56:37.447343 -08:00
+      title: monthly
+    "File[/tmp/unchanged]": !ruby/object:Puppet::Resource::Status
+      change_count: 0
+      changed: false
+      evaluation_time: 0.001123
+      events: 
+        - !ruby/object:Puppet::Transaction::Event
+          audited: true
+          desired_value: 
+          historical_value: 501
+          message: *id002
+          name: !ruby/sym owner_changed
+          previous_value: 0
+          property: owner
+          status: audit
+          time: 2010-12-30 16:56:37.436191 -08:00
+      file: *id001
+      line: 7
+      out_of_sync: false
+      out_of_sync_count: 0
+      resource: "File[/tmp/unchanged]"
+      resource_type: File
+      tags: 
+        - file
+        - class
+      time: 2010-12-30 16:56:37.435405 -08:00
+      title: /tmp/unchanged
+    "File[/tmp/noop]": !ruby/object:Puppet::Resource::Status
+      change_count: 0
+      changed: false
+      evaluation_time: 0.000527
+      events: 
+        - !ruby/object:Puppet::Transaction::Event
+          audited: false
+          desired_value: "644"
+          historical_value: 
+          message: *id001
+          name: !ruby/sym mode_changed
+          previous_value: "640"
+          property: mode
+          status: noop
+          time: 2010-12-30 17:13:28.925582 -08:00
+      file: *id001
+      line: 7
+      out_of_sync: true
+      out_of_sync_count: 1
+      resource: "File[/tmp/noop]"
+      resource_type: File
+      tags: 
+        - file
+        - class
+      time: 2010-12-30 16:56:37.438844 -08:00
+      title: /tmp/noop
+    "Schedule[never]": !ruby/object:Puppet::Resource::Status
+      change_count: 0
+      changed: false
+      evaluation_time: 0.000256
+      events: []
+      file: 
+      line: 
+      out_of_sync: false
+      out_of_sync_count: 0
+      resource: "Schedule[never]"
+      resource_type: Schedule
+      tags: 
+        - schedule
+        - never
+      time: 2010-12-30 16:56:37.446889 -08:00
+      title: never
+    "Schedule[weekly]": !ruby/object:Puppet::Resource::Status
+      change_count: 0
+      changed: false
+      evaluation_time: 0.00027
+      events: []
+      file: 
+      line: 
+      out_of_sync: false
+      out_of_sync_count: 0
+      resource: "Schedule[weekly]"
+      resource_type: Schedule
+      tags: 
+        - schedule
+        - weekly
+      time: 2010-12-30 16:56:37.436824 -08:00
+      title: weekly
+    "File[/tmp/removed]": !ruby/object:Puppet::Resource::Status
+      change_count: 1
+      changed: true
+      evaluation_time: 0.00391
+      events: 
+        - !ruby/object:Puppet::Transaction::Event
+          audited: false
+          desired_value: !ruby/sym absent
+          historical_value: 
+          message: *id003
+          name: !ruby/sym file_removed
+          previous_value: !ruby/sym file
+          property: ensure
+          status: success
+          time: 2010-12-30 16:56:37.440618 -08:00
+      file: *id001
+      line: 7
+      out_of_sync: true
+      out_of_sync_count: 1
+      resource: "File[/tmp/removed]"
+      resource_type: File
+      tags: 
+        - file
+        - class
+      time: 2010-12-30 16:56:37.440078 -08:00
+      title: /tmp/removed
+    "File[/tmp/created]": !ruby/object:Puppet::Resource::Status
+      change_count: 1
+      changed: true
+      evaluation_time: 0.001365
+      events: 
+        - !ruby/object:Puppet::Transaction::Event
+          audited: false
+          desired_value: !ruby/sym present
+          historical_value: 
+          message: *id004
+          name: !ruby/sym file_created
+          previous_value: !ruby/sym absent
+          property: ensure
+          status: success
+          time: 2010-12-30 16:56:37.445044 -08:00
+      file: *id001
+      line: 7
+      out_of_sync: true
+      out_of_sync_count: 1
+      resource: "File[/tmp/created]"
+      resource_type: File
+      tags: 
+        - file
+        - class
+      time: 2010-12-30 16:56:37.444322 -08:00
+      title: /tmp/created
+    "Schedule[puppet]": !ruby/object:Puppet::Resource::Status
+      change_count: 0
+      changed: false
+      evaluation_time: 0.000264
+      events: []
+      file: 
+      line: 
+      out_of_sync: false
+      out_of_sync_count: 0
+      resource: "Schedule[puppet]"
+      resource_type: Schedule
+      tags: 
+        - schedule
+        - puppet
+      time: 2010-12-30 16:56:37.446426 -08:00
+      title: puppet
+    "Schedule[daily]": !ruby/object:Puppet::Resource::Status
+      change_count: 0
+      changed: false
+      evaluation_time: 0.00031
+      events: []
+      file: 
+      line: 
+      out_of_sync: false
+      out_of_sync_count: 0
+      resource: "Schedule[daily]"
+      resource_type: Schedule
+      tags: 
+        - schedule
+        - daily
+      time: 2010-12-30 16:56:37.434845 -08:00
+      title: daily
+    "File[/tmp/changed]": !ruby/object:Puppet::Resource::Status
+      change_count: 1
+      changed: true
+      evaluation_time: 0.001228
+      events: 
+        - !ruby/object:Puppet::Transaction::Event
+          audited: false
+          desired_value: "644"
+          historical_value: 
+          message: *id005
+          name: !ruby/sym mode_changed
+          previous_value: "640"
+          property: mode
+          status: success
+          time: 2010-12-30 16:56:37.438029 -08:00
+      file: *id001
+      line: 7
+      out_of_sync: true
+      out_of_sync_count: 1
+      resource: "File[/tmp/changed]"
+      resource_type: File
+      tags: 
+        - file
+        - class
+      time: 2010-12-30 16:56:37.437332 -08:00
+      title: /tmp/changed
+    "Schedule[hourly]": !ruby/object:Puppet::Resource::Status
+      change_count: 0
+      changed: false
+      evaluation_time: 0.000261
+      events: []
+      file: 
+      line: 
+      out_of_sync: false
+      out_of_sync_count: 0
+      resource: "Schedule[hourly]"
+      resource_type: Schedule
+      tags: 
+        - schedule
+        - hourly
+      time: 2010-12-30 16:56:37.439586 -08:00
+      title: hourly
+  status: changed
+  time: 2010-12-30 16:56:36.718334 -08:00
\ No newline at end of file
diff --git a/spec/lib/puppet/report_spec.rb b/spec/lib/puppet/report_spec.rb
index 21996d6..70ba2fd 100644
--- a/spec/lib/puppet/report_spec.rb
+++ b/spec/lib/puppet/report_spec.rb
@@ -217,7 +217,6 @@ describe Puppet::Transaction::Report do
               "monthly"
             ],
             "file"               => nil,
-            "out_of_sync"        => nil,
             "events"             => [],
             "version"            => 1279826342
           },
@@ -232,7 +231,6 @@ describe Puppet::Transaction::Report do
               "puppet"
             ],
             "file"               => nil,
-            "out_of_sync"        => nil,
             "events"             => [],
             "version"            => 1279826342
           },
@@ -250,7 +248,6 @@ describe Puppet::Transaction::Report do
               "class"
             ],
             "file"               => "/etc/puppet/manifests/site.pp",
-            "out_of_sync"        => true,
             "events"             => [{
               "previous_value"     => :stopped,
               "desired_value"      => :running,
@@ -273,7 +270,6 @@ describe Puppet::Transaction::Report do
               "never"
             ],
             "file"               => nil,
-            "out_of_sync"        => nil,
             "events"             => [],
             "version"            => 1279826342
           },
@@ -288,7 +284,6 @@ describe Puppet::Transaction::Report do
             "weekly"
             ],
             "file"               => nil,
-            "out_of_sync"        => nil,
             "events"             => [],
             "version"            => 1279826342
           },
@@ -305,7 +300,6 @@ describe Puppet::Transaction::Report do
               "class"
             ],
             "file"               => "/etc/puppet/manifests/site.pp",
-            "out_of_sync"        => true,
             "events"             => [{
               "previous_value"     => :notrun,
               "desired_value"      => ["0"],
@@ -328,7 +322,6 @@ describe Puppet::Transaction::Report do
               "puppet"
             ],
             "file"               => nil,
-            "out_of_sync"        => nil,
             "events"             => [],
             "version"            => 1279826342
           },
@@ -343,7 +336,6 @@ describe Puppet::Transaction::Report do
               "daily"
             ],
             "file"               => nil,
-            "out_of_sync"        => nil,
             "events"             => [],
             "version"            => 1279826342
           },
@@ -358,7 +350,6 @@ describe Puppet::Transaction::Report do
               "hourly"
             ],
             "file"               => nil,
-            "out_of_sync"        => nil,
             "events"             => [],
             "version"            => 1279826342
           }
@@ -428,7 +419,7 @@ HEREDOC
       it "should produce a hash of the report" do
         hash = @report.to_hash
         hash.should be_a(Hash)
-        hash.keys.should =~ %w{host time logs metrics resource_statuses kind 
configuration_version puppet_version report_format}
+        hash.keys.should =~ %w{host time logs metrics resource_statuses kind 
configuration_version puppet_version report_format status}
         hash["report_format"].should == 2
         hash["host"].should == "localhost"
         hash["time"].should == Time.parse("2010-07-22 12:19:47.204207 -07:00")
diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb
index acf5054..1e0546f 100644
--- a/spec/models/report_spec.rb
+++ b/spec/models/report_spec.rb
@@ -275,7 +275,7 @@ HEREDOC
   end
 
   describe "#create_from_yaml" do
-    it "should populate report related tables from a 0.25 yaml report" do
+    it "should populate report related tables from a version 0 yaml report" do
       Time.zone = 'UTC'
       @node = Node.generate(:name => 'sample_node')
       @report_yaml = File.read(File.join(RAILS_ROOT, 
"spec/fixtures/reports/puppet25/1_changed_0_failures.yml"))
@@ -320,7 +320,7 @@ HEREDOC
       report.status.should == 'changed'
     end
 
-      it "should populate report related tables from a 2.6 yaml report" do
+      it "should populate report related tables from a version 1 yaml report" 
do
         @node = Node.generate(:name => 'puppet.puppetlabs.vm')
         @report_yaml = File.read(File.join(RAILS_ROOT, 
"spec/fixtures/reports/puppet26/report_ok_service_started_ok.yaml"))
         file = '/etc/puppet/manifests/site.pp'
@@ -334,7 +334,7 @@ HEREDOC
           ['time',      'filebucket'       ,  '0.00'],
           ['time',      'service'          ,  '1.56'],
           ['time',      'exec'             ,  '0.10'],
-          ['time',      'total'       ,  '1.82'],
+          ['time',      'total'            ,  '1.82'],
           ['resources', 'total'            ,  '9.00'],
           ['resources', 'changed'          ,  '2.00'],
           ['resources', 'out_of_sync'      ,  '2.00'],
@@ -361,8 +361,8 @@ HEREDOC
           [ '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 ],
+          [ 'Service'    ,  'mysqld'  ,  "1.56" ,  file,  8   ,  ['class'      
,  'default'   ,  'mysqld' ,  'node' ,  'service'] ,  1 ],
+          [ 'Exec'       ,'/bin/true' ,  "0.10" ,  file ,  9  ,  ['class'      
,  'default'   ,  'exec' ,  'node' ] ,  1 ],
         ]
         report.events.map { |t| [
           t.property,
@@ -394,6 +394,103 @@ HEREDOC
       report.puppet_version.should == '2.6.0'
       report.status.should == 'changed'
     end
+
+    it "should populate report related tables from a version 2 report" do
+      @node = Node.generate(:name => 'paul-berrys-macbook-pro-3.local')
+      @report_yaml = File.read(File.join(RAILS_ROOT, 
"spec/fixtures/reports/version2/example.yaml"))
+      file = '/Users/pberry/puppet_labs/test_data/master/manifests/site.pp'
+      Report.create_from_yaml(@report_yaml)
+      Report.count.should == 1
+
+      report = Report.first
+      report.node.should == @node
+      report.status.should == 'changed'
+      report.configuration_version.should == '1293756667'
+      report.puppet_version.should == '2.6.4'
+
+      report.metrics.map {|t| [t.category, t.name, "%0.2f" % t.value]}.should 
=~ [
+        ['time',      'schedule'         ,  '0.00'],
+        ['time',      'config_retrieval' ,  '0.07'],
+        ['time',      'filebucket'       ,  '0.00'],
+        ['time',      'file'             ,  '0.01'],
+        ['time',      'total'            ,  '0.08'],
+        ['resources', 'total'            , '12.00'],
+        ['resources', 'out_of_sync'      ,  '4.00'],
+        ['resources', 'changed'          ,  '3.00'],
+        ['changes',   'total'            ,  '3.00'],
+        ['events',    'total'            ,  '4.00'],
+        ['events',    'success'          ,  '3.00'],
+        ['events',    'audit'            ,  '1.00']
+      ]
+
+      report.resource_statuses.map { |t| [
+        t.resource_type,
+        t.title,
+        "%0.3f" % t.evaluation_time,
+        t.file,
+        t.line,
+        t.tags.sort,
+        #t.time,
+        t.change_count,
+        t.out_of_sync_count,
+      ] }.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 ],
+      ]
+      report.events.map { |t| [
+        t.property,
+        t.previous_value.to_s,
+        t.desired_value.to_s,
+        t.historical_value.to_s,
+        #t.message,
+        t.name,
+        t.status,
+        t.audited,
+      ] }.should =~ [
+        [ 'owner'  , '0'     , ''       , '501' , 'owner_changed' , 'audit'   
, true  ],
+        [ 'mode'   , '640'   , '644'    , ''    , 'mode_changed'  , 'noop'    
, false ],
+        [ 'ensure' , 'file'  , 'absent' , ''    , 'file_removed'  , 'success' 
, false ],
+        [ 'ensure' , 'absent', 'present', ''    , 'file_created'  , 'success' 
, false ],
+        [ 'mode'   , '640'   , '644'    , ''    , 'mode_changed'  , 'success' 
, false ],
+      ]
+
+      report.logs.map { |t| [
+        t.level,
+        t.message,
+        t.source,
+        t.tags.sort,
+        #t.time,
+        t.file,
+        t.line,
+      ] }.should =~ [
+        ['debug', 'Using cached certificate for ca', 'Puppet', ['debug'], nil, 
nil],
+        ['debug', 'Using cached certificate for 
paul-berrys-macbook-pro-3.local', 'Puppet', ['debug'], nil, nil],
+        ['debug', 'Using cached certificate_revocation_list for ca', 'Puppet', 
['debug'], nil, nil],
+        ['debug', 'catalog supports formats: b64_zlib_yaml dot marshal pson 
raw yaml; using pson', 'Puppet', ['debug'], nil, nil],
+        ['info', 'Caching catalog for paul-berrys-macbook-pro-3.local', 
'Puppet', ['info'], nil, nil],
+        ['debug', 'Creating default schedules', 'Puppet', ['debug'], nil, nil],
+        ['debug', 'Loaded state in 0.00 seconds', 'Puppet', ['debug'], nil, 
nil],
+        ['info', "Applying configuration version '1293756667'", 'Puppet', 
['info'], nil, nil],
+        ['notice', "audit change: previously recorded value pberry has been 
changed to root", "/Stage[main]//File[/tmp/unchanged]/owner", ['class', 'file', 
'notice'], file, 7],
+        ['notice', "mode changed '640' to '644'", 
"/Stage[main]//File[/tmp/changed]/mode", ['class', 'file', 'notice'], file, 7],
+        ['debug', 'Finishing transaction 2166421680', 'Puppet', ['debug'], 
nil, nil],
+        ['info', "FileBucket got a duplicate file /private/tmp/removed 
({md5}d41d8cd98f00b204e9800998ecf8427e)", 'Puppet', ['info'], nil, nil],
+        ['info', 'Filebucketed /tmp/removed to puppet with sum 
d41d8cd98f00b204e9800998ecf8427e', "/Stage[main]//File[/tmp/removed]", 
['class', 'file', 'info'], file, 7],
+        ['debug', 'Removing existing file for replacement with absent', 
"/Stage[main]//File[/tmp/removed]", ['class', 'debug', 'file'], file, 7],
+        ['notice', 'removed', "/Stage[main]//File[/tmp/removed]/ensure", 
['class', 'file', 'notice'], file, 7],
+        ['notice', 'created', "/Stage[main]//File[/tmp/created]/ensure", 
['class', 'file', 'notice'], file, 7],
+      ]
+    end
   end
 
 
-- 
1.7.3.1

-- 
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