From: Daniel Pittman <[email protected]>

We now emit timing and output a status message at the end of a successful
inspect run.

Paired-With: Nick Lewis <[email protected]>
Signed-Off-By: Daniel Pittman <[email protected]>
---
 lib/puppet/application/inspect.rb     |  116 +++++++++++++++++----------------
 spec/unit/application/inspect_spec.rb |    2 +-
 2 files changed, 60 insertions(+), 58 deletions(-)
 mode change 100644 => 100755 spec/unit/application/inspect_spec.rb

diff --git a/lib/puppet/application/inspect.rb 
b/lib/puppet/application/inspect.rb
index 52ef975..764c8c4 100644
--- a/lib/puppet/application/inspect.rb
+++ b/lib/puppet/application/inspect.rb
@@ -98,79 +98,81 @@ Licensed under the GNU General Public License version 2
   end
 
   def run_command
-    retrieval_starttime = Time.now
+    benchmark(:notice, "Finished inspection") do
+      retrieval_starttime = Time.now
 
-    unless catalog = Puppet::Resource::Catalog.find(Puppet[:certname])
-      raise "Could not find catalog for #{Puppet[:certname]}"
-    end
+      unless catalog = Puppet::Resource::Catalog.find(Puppet[:certname])
+        raise "Could not find catalog for #{Puppet[:certname]}"
+      end
 
-    @report.configuration_version = catalog.version
+      @report.configuration_version = catalog.version
 
-    inspect_starttime = Time.now
-    @report.add_times("config_retrieval", inspect_starttime - 
retrieval_starttime)
+      inspect_starttime = Time.now
+      @report.add_times("config_retrieval", inspect_starttime - 
retrieval_starttime)
 
-    if Puppet[:archive_files]
-      dipper = Puppet::FileBucket::Dipper.new(:Server => 
Puppet[:archive_file_server])
-    end
+      if Puppet[:archive_files]
+        dipper = Puppet::FileBucket::Dipper.new(:Server => 
Puppet[:archive_file_server])
+      end
 
-    catalog.to_ral.resources.each do |ral_resource|
-      audited_attributes = ral_resource[:audit]
-      next unless audited_attributes
+      catalog.to_ral.resources.each do |ral_resource|
+        audited_attributes = ral_resource[:audit]
+        next unless audited_attributes
 
-      status = Puppet::Resource::Status.new(ral_resource)
+        status = Puppet::Resource::Status.new(ral_resource)
 
-      begin
-        audited_resource = ral_resource.to_resource
-      rescue StandardError => detail
-        puts detail.backtrace if Puppet[:trace]
-        ral_resource.err "Could not inspect #{ral_resource}; skipping: 
#{detail}"
-        audited_attributes.each do |name|
-          event = ral_resource.event(
-            :property => name,
-            :status   => "failure",
-            :audited  => true,
-            :message  => "failed to inspect #{name}"
-          )
-          status.add_event(event)
-        end
-      else
-        audited_attributes.each do |name|
-          next if audited_resource[name].nil?
-          # Skip :absent properties of :absent resources. Really, it would be 
nicer if the RAL returned nil for those, but it doesn't. ~JW
-          if name == :ensure or audited_resource[:ensure] != :absent or 
audited_resource[name] != :absent
+        begin
+          audited_resource = ral_resource.to_resource
+        rescue StandardError => detail
+          puts detail.backtrace if Puppet[:trace]
+          ral_resource.err "Could not inspect #{ral_resource}; skipping: 
#{detail}"
+          audited_attributes.each do |name|
             event = ral_resource.event(
-              :previous_value => audited_resource[name],
-              :property       => name,
-              :status         => "audit",
-              :audited        => true,
-              :message        => "inspected value is 
#{audited_resource[name].inspect}"
-            )
+                                       :property => name,
+                                       :status   => "failure",
+                                       :audited  => true,
+                                       :message  => "failed to inspect #{name}"
+                                       )
             status.add_event(event)
           end
+        else
+          audited_attributes.each do |name|
+            next if audited_resource[name].nil?
+            # Skip :absent properties of :absent resources. Really, it would 
be nicer if the RAL returned nil for those, but it doesn't. ~JW
+            if name == :ensure or audited_resource[:ensure] != :absent or 
audited_resource[name] != :absent
+              event = ral_resource.event(
+                                         :previous_value => 
audited_resource[name],
+                                         :property       => name,
+                                         :status         => "audit",
+                                         :audited        => true,
+                                         :message        => "inspected value 
is #{audited_resource[name].inspect}"
+                                         )
+              status.add_event(event)
+            end
+          end
         end
-      end
-      if Puppet[:archive_files] and ral_resource.type == :file and 
audited_attributes.include?(:content)
-        path = ral_resource[:path]
-        if File.readable?(path)
-          begin
-            dipper.backup(path)
-          rescue StandardError => detail
-            Puppet.warning detail
+        if Puppet[:archive_files] and ral_resource.type == :file and 
audited_attributes.include?(:content)
+          path = ral_resource[:path]
+          if File.readable?(path)
+            begin
+              dipper.backup(path)
+            rescue StandardError => detail
+              Puppet.warning detail
+            end
           end
         end
+        @report.add_resource_status(status)
       end
-      @report.add_resource_status(status)
-    end
 
-    finishtime = Time.now
-    @report.add_times("inspect", finishtime - inspect_starttime)
-    @report.finalize_report
+      finishtime = Time.now
+      @report.add_times("inspect", finishtime - inspect_starttime)
+      @report.finalize_report
 
-    begin
-      @report.save
-    rescue => detail
-      puts detail.backtrace if Puppet[:trace]
-      Puppet.err "Could not send report: #{detail}"
+      begin
+        @report.save
+      rescue => detail
+        puts detail.backtrace if Puppet[:trace]
+        Puppet.err "Could not send report: #{detail}"
+      end
     end
   end
 end
diff --git a/spec/unit/application/inspect_spec.rb 
b/spec/unit/application/inspect_spec.rb
old mode 100644
new mode 100755
index 1d99c6c..d334a87
--- a/spec/unit/application/inspect_spec.rb
+++ b/spec/unit/application/inspect_spec.rb
@@ -174,7 +174,7 @@ describe Puppet::Application::Inspect do
 
           @inspect.run_command
 
-          @report.logs.count.should == 1
+          @report.logs.first.should_not == nil
           @report.logs.first.message.should =~ /Could not back up/
         end
       end
-- 
1.7.4.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