From: Brice Figureau <[email protected]>

Yet, only the store reports has an implementation.

Signed-off-by: Brice Figureau <[email protected]>
Signed-off-by: Peter Meier <[email protected]>
---
 lib/puppet/indirector/report/processor.rb     |   10 +++++-
 lib/puppet/reports/log.rb                     |    3 ++
 lib/puppet/reports/rrdgraph.rb                |    3 ++
 lib/puppet/reports/store.rb                   |   16 +++++++++++
 lib/puppet/reports/tagmail.rb                 |    4 +++
 lib/puppet/transaction/report.rb              |    3 +-
 spec/unit/indirector/report/processor_spec.rb |   37 +++++++++++++++++++++++-
 test/other/report.rb                          |    6 ++++
 8 files changed, 77 insertions(+), 5 deletions(-)

diff --git a/lib/puppet/indirector/report/processor.rb 
b/lib/puppet/indirector/report/processor.rb
index 88fe4b4..9aedc72 100644
--- a/lib/puppet/indirector/report/processor.rb
+++ b/lib/puppet/indirector/report/processor.rb
@@ -14,12 +14,18 @@ class Puppet::Transaction::Report::Processor < 
Puppet::Indirector::Code
     process(request.instance)
   end
 
+  def destroy(request)
+    dummy = Puppet::Transaction::Report.new
+    dummy.host = request.key
+    process(dummy, :destroy)
+  end
+
   private
 
   # Process the report with each of the configured report types.
   # LAK:NOTE This isn't necessarily the best design, but it's backward
   # compatible and that's good enough for now.
-  def process(report)
+  def process(report, method = :process)
     return if Puppet[:reports] == "none"
 
     reports.each do |name|
@@ -29,7 +35,7 @@ class Puppet::Transaction::Report::Processor < 
Puppet::Indirector::Code
         newrep = report.dup
         begin
           newrep.extend(mod)
-          newrep.process
+          newrep.send(method)
         rescue => detail
           puts detail.backtrace if Puppet[:trace]
           Puppet.err "Report #{name} failed: #{detail}"
diff --git a/lib/puppet/reports/log.rb b/lib/puppet/reports/log.rb
index 1fc6876..2d65f17 100644
--- a/lib/puppet/reports/log.rb
+++ b/lib/puppet/reports/log.rb
@@ -10,5 +10,8 @@ Puppet::Reports.register_report(:log) do
       Puppet::Util::Log.newmessage(log)
     end
   end
+
+  def destroy
+  end
 end
 
diff --git a/lib/puppet/reports/rrdgraph.rb b/lib/puppet/reports/rrdgraph.rb
index 517fa8f..b605f0e 100644
--- a/lib/puppet/reports/rrdgraph.rb
+++ b/lib/puppet/reports/rrdgraph.rb
@@ -124,5 +124,8 @@ Puppet::Reports.register_report(:rrdgraph) do
   def timeclean(metric)
     metric.values = metric.values.find_all { |name, label, value| ['total', 
'config_retrieval'].include?(name.to_s) }
   end
+
+  def destroy
+  end
 end
 
diff --git a/lib/puppet/reports/store.rb b/lib/puppet/reports/store.rb
index 30f2459..9cb38d5 100644
--- a/lib/puppet/reports/store.rb
+++ b/lib/puppet/reports/store.rb
@@ -56,5 +56,21 @@ Puppet::Reports.register_report(:store) do
     # Only testing cares about the return value
     file
   end
+
+  # removes all reports for a given host
+  def destroy
+    client = self.host.gsub("..",".")
+
+    dir = File.join(Puppet[:reportdir], client)
+
+    if FileTest.exists?(dir)
+      Dir.entries(dir).each do |file|
+        next if file == '.' or file == '..'
+        file = File.join(dir, file)
+        File.unlink(file) if FileTest.file?(file)
+      end
+      Dir.rmdir(dir)
+    end
+  end
 end
 
diff --git a/lib/puppet/reports/tagmail.rb b/lib/puppet/reports/tagmail.rb
index e17143e..23e218d 100644
--- a/lib/puppet/reports/tagmail.rb
+++ b/lib/puppet/reports/tagmail.rb
@@ -164,5 +164,9 @@ Puppet::Reports.register_report(:tagmail) do
     # Don't bother waiting for the pid to return.
     Process.detach(pid)
   end
+
+  def destroy
+  end
+
 end
 
diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb
index e6d1e05..3fdd52b 100644
--- a/lib/puppet/transaction/report.rb
+++ b/lib/puppet/transaction/report.rb
@@ -10,7 +10,8 @@ class Puppet::Transaction::Report
 
   indirects :report, :terminus_class => :processor
 
-  attr_reader :resource_statuses, :logs, :metrics, :host, :time
+  attr_reader :resource_statuses, :logs, :metrics, :time
+  attr_accessor :host 
 
   # This is necessary since Marshall doesn't know how to
   # dump hash with default proc (see below @records)
diff --git a/spec/unit/indirector/report/processor_spec.rb 
b/spec/unit/indirector/report/processor_spec.rb
index 5602a27..1523934 100755
--- a/spec/unit/indirector/report/processor_spec.rb
+++ b/spec/unit/indirector/report/processor_spec.rb
@@ -15,6 +15,11 @@ describe Puppet::Transaction::Report::Processor do
   it "should provide a method for saving reports" do
     Puppet::Transaction::Report::Processor.new.should respond_to(:save)
   end
+
+  it "should provide a method for cleaning reports" do
+    Puppet::Transaction::Report::Processor.new.should respond_to(:destroy)
+  end
+
 end
 
 describe Puppet::Transaction::Report::Processor, " when saving a report" do
@@ -38,6 +43,24 @@ describe Puppet::Transaction::Report::Processor, " when 
saving a report" do
   end
 end
 
+describe Puppet::Transaction::Report::Processor, " when destroying a node 
reports" do
+  before do
+    Puppet.settings.stubs(:use)
+    @reporter = Puppet::Transaction::Report::Processor.new
+    @reporter.stubs(:process)
+  end
+
+  it "should create a dummy report" do
+    dummy = stub 'report'
+    request = stub 'request', :key => 'host'
+
+    Puppet::Transaction::Report.expects(:new).returns(dummy)
+    dummy.expects(:host=).with('host')
+
+    @reporter.destroy(request)
+  end
+end
+
 describe Puppet::Transaction::Report::Processor, " when processing a report" do
   before do
     Puppet.settings.stubs(:value).with(:reports).returns("one")
@@ -47,10 +70,11 @@ describe Puppet::Transaction::Report::Processor, " when 
processing a report" do
     @report_type = mock 'one'
     @dup_report = mock 'dupe report'
     @dup_report.stubs(:process)
+    @dup_report.stubs(:destroy)
     @report = mock 'report'
     @report.expects(:dup).returns(@dup_report)
 
-    @request = stub 'request', :instance => @report
+    @request = stub 'request', :instance => @report, :key => 'host'
 
     Puppet::Reports.expects(:report).with("one").returns(@report_type)
 
@@ -68,11 +92,20 @@ describe Puppet::Transaction::Report::Processor, " when 
processing a report" do
     @reporter.save(@request)
   end
 
-  it "should call the report type's :process method" do
+  it "should call the report type's :process method when saving" do
     @dup_report.expects(:process)
     @reporter.save(@request)
   end
 
+  it "should call the report type's :destroy method when destroying" do
+    Puppet::Transaction::Report.stubs(:new).returns(@report)
+    @report.stubs(:host=).with('host')
+
+    @dup_report.expects(:destroy)
+    @reporter.destroy(@request)
+  end
+
+
   it "should not raise exceptions" do
     Puppet.settings.stubs(:value).with(:trace).returns(false)
     @dup_report.expects(:process).raises(ArgumentError)
diff --git a/test/other/report.rb b/test/other/report.rb
index 8a909b4..bc1db11 100755
--- a/test/other/report.rb
+++ b/test/other/report.rb
@@ -82,6 +82,12 @@ class TestReports < Test::Unit::TestCase
 
     assert_nothing_raised do
       report.extend(Puppet::Reports.report(:store))
+        assert(FileTest.exists?(file), "report file did not get created")
+        assert_equal(yaml, File.read(file), "File did not get written")
+
+        # test report destroying
+        report.destroy
+        assert(!FileTest.exists?(file), "report file still exist after 
destroy")
     end
 
     yaml = YAML.dump(report)
-- 
1.7.2.3

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