If no baseline is specified, this will still diff each node in the group against its individual baseline. If a baseline is specified, it will diff each node in the group against that particular baseline.
Paired-With: Jesse Wolfe Signed-off-by: Nick Lewis <[email protected]> --- Local-branch: ticket/next/5867 app/controllers/node_groups_controller.rb | 11 ++- app/views/node_groups/show.html.haml | 8 ++- spec/controllers/node_groups_controller_spec.rb | 75 +++++++++++++++++++++-- 3 files changed, 82 insertions(+), 12 deletions(-) diff --git a/app/controllers/node_groups_controller.rb b/app/controllers/node_groups_controller.rb index 8848f95..7676dbb 100644 --- a/app/controllers/node_groups_controller.rb +++ b/app/controllers/node_groups_controller.rb @@ -8,22 +8,25 @@ class NodeGroupsController < InheritedResources::Base def diff @node_group = NodeGroup.find(params[:id]) + @baseline = Report.find(params[:against]) unless params[:against] == "self" || params[:against].nil? + @nodes_without_latest_inspect_reports = [] @nodes_without_baselines = [] @nodes_without_differences = [] @nodes_with_differences = [] - @node_group.all_nodes.each do |node| + @node_group.all_nodes.sort_by(&:name).each do |node| + baseline = @baseline || node.baseline_report @nodes_without_latest_inspect_reports << node and next unless node.last_inspect_report - @nodes_without_baselines << node and next unless node.baseline_report + @nodes_without_baselines << node and next unless baseline - report_diff = node.baseline_report.diff(node.last_inspect_report) + report_diff = baseline.diff(node.last_inspect_report) resource_statuses = Report.divide_diff_into_pass_and_fail(report_diff) if resource_statuses[:failure].empty? @nodes_without_differences << node else @nodes_with_differences << { - :baseline_report => node.baseline_report, + :baseline_report => baseline, :last_inspect_report => node.last_inspect_report, :report_diff => report_diff, :resource_statuses => resource_statuses, diff --git a/app/views/node_groups/show.html.haml b/app/views/node_groups/show.html.haml index 9cd86c1..4507e94 100644 --- a/app/views/node_groups/show.html.haml +++ b/app/views/node_groups/show.html.haml @@ -42,8 +42,12 @@ .section .header %h2 Nodes for this group - %ul.actions - %li= link_to "Diffs against own baselines", diff_node_group_path(@node_group), :class => 'button' + - if Report.baselines.any? + %h3= "Compare with baselines" + - form_tag(diff_node_group_path(@node_group), :method => :get) do + %p + = select_tag( "against", options_for_select({"individual baselines" => :self}) + options_from_collection_for_select( Report.baselines.order("name ASC"), :id, :long_name ) ) + = submit_tag("compare") - if @node_group.all_nodes.present? = render 'nodes/nodes', :nodes => @node_group.all_nodes, :container => @node_group - else diff --git a/spec/controllers/node_groups_controller_spec.rb b/spec/controllers/node_groups_controller_spec.rb index c9633aa..7f8c8e8 100644 --- a/spec/controllers/node_groups_controller_spec.rb +++ b/spec/controllers/node_groups_controller_spec.rb @@ -15,12 +15,6 @@ describe NodeGroupsController do @node_group = NodeGroup.generate! @node = Node.generate! :name => "node_it_all" @node_group.nodes << @node - - @child_node_group = NodeGroup.generate! - @child_node = Node.generate! :name => "nema_node" - @child_node_group.nodes << @node - - @node_group.node_group_children << @child_node_group end describe "the node has no inspect reports" do @@ -119,5 +113,74 @@ describe NodeGroupsController do }] end end + + describe "when diffing against a single baseline" do + it "should diff each node against the given baseline" do + @child_node_group = NodeGroup.generate! + @child_node = Node.generate! :name => "nema_node" + @child_node_group.nodes << @child_node + + @node_group.node_group_children << @child_node_group + @baseline = Report.generate!(:host => @node.name, :kind => 'inspect', :time => 2.hours.ago) + @baseline_status = ResourceStatus.generate!( + :report => @baseline, + :resource_type => 'File', + :title => '/tmp/test', + :events_attributes => [{:property => 'content', :previous_value => '{md5}abcd'}] + ) + + @latest = Report.generate!(:host => @node.name, :kind => 'inspect', :time => 1.hour.ago) + @latest_status = ResourceStatus.generate!( + :report => @latest, + :resource_type => 'File', + :title => '/tmp/test', + :events_attributes => [{:property => 'content', :previous_value => '{md5}efgh'}] + ) + + @child_baseline = Report.generate!(:host => @child_node.name, :kind => 'inspect', :time => 2.hours.ago) + @child_baseline_status = ResourceStatus.generate!( + :report => @child_baseline, + :resource_type => 'File', + :title => '/tmp/test', + :events_attributes => [{:property => 'content', :previous_value => '{md5}hijk'}] + ) + + @child_latest = Report.generate!(:host => @child_node.name, :kind => 'inspect', :time => 1.hour.ago) + @child_latest_status = ResourceStatus.generate!( + :report => @child_latest, + :resource_type => 'File', + :title => '/tmp/test', + :events_attributes => [{:property => 'content', :previous_value => '{md5}hijk'}] + ) + + @node.reports = [@baseline, @latest] + @child_node.reports = [@child_baseline, @child_latest] + @baseline.baseline! + @child_baseline.baseline! + @node.last_inspect_report = @latest + @child_node.last_inspect_report = @child_latest + + get :diff, :id => @node_group.id, :against => @baseline.id + + @node_group.all_nodes.should =~ [@node, @child_node] + assigns[:nodes_without_latest_inspect_reports].should be_empty + assigns[:nodes_without_baselines].should be_empty + assigns[:nodes_without_differences].should be_empty + assigns[:nodes_with_differences].should =~ [ + { + :baseline_report => @baseline, + :last_inspect_report => @node.last_inspect_report, + :report_diff => {"File[/tmp/test]"=>{:content=>["{md5}abcd", "{md5}efgh"]}}, + :resource_statuses => {:pass =>[], :failure=>["File[/tmp/test]"]} + }, + { + :baseline_report => @baseline, + :last_inspect_report => @child_node.last_inspect_report, + :report_diff => {"File[/tmp/test]"=>{:content=>["{md5}abcd", "{md5}hijk"]}}, + :resource_statuses => {:pass =>[], :failure=>["File[/tmp/test]"]} + } + ] + end + end end end -- 1.7.3.5 -- 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.
