This patch implements a rudimentary UI to compare two arbitrary "inspect" reports.
A more polished interface is planned for ticket #5173 Paired-With: Matt Robinson <[email protected]> Signed-off-by: Jesse Wolfe <[email protected]> --- Local-branch: ticket/next/5174 app/controllers/reports_controller.rb | 18 ++++++++++++++++++ app/models/report.rb | 7 ++++++- app/views/reports/diff.html.haml | 17 +++++++++++++++++ app/views/reports/diff_summary.html.haml | 11 +++++++++++ config/routes.rb | 6 +++++- db/schema.rb | 4 ++++ spec/models/report_spec.rb | 6 ++++-- 7 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 app/views/reports/diff.html.haml create mode 100644 app/views/reports/diff_summary.html.haml diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 68991f4..7203d55 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -19,6 +19,24 @@ class ReportsController < InheritedResources::Base end end + def diff + @my_report = Report.find(params[:id]) + @baseline_report = Report.find(params[:baseline_id]) + @diff = @baseline_report.diff(@my_report) + end + + def diff_summary + diff + @resources = {} + @baseline_report.resources.each do |resource| + if @diff[resource] + @resources[resource] = :failed + else + @resources[resource] = :pass + end + end + end + private def collection diff --git a/app/models/report.rb b/app/models/report.rb index 39c95b9..5dfd999 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -57,13 +57,18 @@ class Report < ActiveRecord::Base their_properties = events_to_hash( value.events ) my_properties.keys.each do |property| if my_properties[property] != their_properties[property] - diff_stuff[ [name, property.to_sym] ] = [ my_properties[property], their_properties[property] ] + diff_stuff[name] ||= {} + diff_stuff[name][property.to_sym] = [ my_properties[property], their_properties[property] ] end end end diff_stuff end + def resources + self.report.resource_statuses.keys + end + private def events_to_hash(events) diff --git a/app/views/reports/diff.html.haml b/app/views/reports/diff.html.haml new file mode 100644 index 0000000..a55a2b2 --- /dev/null +++ b/app/views/reports/diff.html.haml @@ -0,0 +1,17 @@ +%table.inspector + %thead + %tr + %th Resource + %th Property + %th Expected + %th Actual + %tbody + - @diff.each do |resource, properties_hash| + - properties_hash.each do |property, expected_actual| + - expected, actual = expected_actual + %tr + %td= h resource + %td= h property + %td= h expected + %td= h actual += link_to "Summary", :id => @my_report, :action => "diff_summary", :baseline_id => @baseline_report diff --git a/app/views/reports/diff_summary.html.haml b/app/views/reports/diff_summary.html.haml new file mode 100644 index 0000000..68d1f10 --- /dev/null +++ b/app/views/reports/diff_summary.html.haml @@ -0,0 +1,11 @@ +%table.inspector + %thead + %tr + %th Resource + %th Status + %tbody + - @resources.each do |resource, status| + %tr{:class => status} + %td= h resource + %td= h status += link_to "Details", :id => @my_report, :action => "diff", :baseline_id => @baseline_report diff --git a/config/routes.rb b/config/routes.rb index 7d25854..a79691c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,7 +24,11 @@ ActionController::Routing::Routes.draw do |map| map.resource :account, :controller => "users" map.resources :users - map.resources :reports + map.resources :reports, + :member => { + :diff => :get, + :diff_summary => :get, + } map.release_notes '/release_notes', :controller => :pages, :action => :release_notes diff --git a/db/schema.rb b/db/schema.rb index a2c7460..378bbdd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,6 +11,10 @@ ActiveRecord::Schema.define(:version => 20101118222325) do + create_table "Times", :id => false, :force => true do |t| + t.datetime "time" + end + create_table "assignments", :force => true do |t| t.integer "node_id" t.integer "service_id" diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index 25c7bbc..7110381 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -280,8 +280,10 @@ HEREDOC report1 = Report.create(:report => @report_yaml) report2 = Report.create(:report => @report_yaml2) report1.diff(report2).should == { - ['File[/tmp/foo]', :ensure] => [:file, :directory], - ['File[/tmp/foo]', :content] => ["{md5}foo", "{md5}bar"] + 'File[/tmp/foo]' => { + :ensure => [:file, :directory], + :content => ["{md5}foo", "{md5}bar"], + } } end end -- 1.7.0.4 -- 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.
