From: Nick Lewis <[email protected]>

A node is pending if it a) has noop events, and b) is not failed.

Paired-With: Daniel Pittman

Signed-off-by: Pieter van de Bruggen <[email protected]>
---
Local-branch: tickets/next/6991
 app/models/node.rb       |    7 +++++++
 spec/models/node_spec.rb |   24 ++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/app/models/node.rb b/app/models/node.rb
index cb79380..f0a0105 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -57,6 +57,13 @@ class Node < ActiveRecord::Base
     end
   }
 
+  named_scope :pending,
+    :conditions => ["resource_events.status = 'noop' and reports.status != 
'failed'"],
+    :joins => "join reports on nodes.last_apply_report_id = reports.id
+    join resource_statuses on resource_statuses.report_id = reports.id
+    join resource_events on resource_events.resource_status_id = 
resource_statuses.id",
+    :group => 'nodes.id'
+
   named_scope :reported, :conditions => ["reported_at IS NOT NULL"]
 
   # Return nodes that have never reported.
diff --git a/spec/models/node_spec.rb b/spec/models/node_spec.rb
index b492820..90a96df 100644
--- a/spec/models/node_spec.rb
+++ b/spec/models/node_spec.rb
@@ -87,6 +87,30 @@ describe Node do
     end
   end
 
+  describe "::pending" do
+    before :each do
+      @node = Node.generate!
+      @report = Report.generate!(:status => "unchanged", :host => @node.name)
+      @resource_status = @report.resource_statuses.generate!(:resource_type => 
"file", :title => "/tmp/foo", :failed => false)
+      @resource_status.events.generate!(:status => "noop")
+    end
+
+    it "should find nodes with noop events" do
+      Node.pending.should == [@node]
+    end
+
+    it "should exclude nodes which are failed" do
+      @report.status = 'failed'
+      @report.save
+      Node.pending.should == []
+    end
+
+    it "should only consider the latest report for a node" do
+      @new_report = Report.generate!(:status => "unchanged", :host => 
@node.name)
+      Node.pending.should == []
+    end
+  end
+
   describe "::find_from_inventory_search" do
     before :each do
       @foo = Node.generate :name => "foo"
-- 
1.7.5.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