[Pkg-puppet-devel] [facter] 05/352: (#22334) Use Facter's logging system for warn

Stig Sandbeck Mathisen ssm at debian.org
Sun Apr 6 22:21:26 UTC 2014


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository facter.

commit 0d1f705ab0ab7d4f06233323bb8c8e814d835e2f
Author: Andrew Parker <andy at puppetlabs.com>
Date:   Wed Aug 28 17:33:34 2013 -0700

    (#22334) Use Facter's logging system for warn
    
    Several points in facter would use ruby's built in warn method, which
    always prints to stderr. This made unstoppable messages show up on the
    stderr such as:
    
      [vagrant at localhost ~]$ facter virtual
      Could not retrieve virtual: Permission denied - /sys/firmware/dmi/entries/1-0/raw
      virtualbox
    
    By using facter's normal logging system, the user has control of these
    showing up and they won't end up in stderr (which might be going nowhere
    in a daemonized process).
---
 lib/facter/util/loader.rb         | 2 +-
 lib/facter/util/resolution.rb     | 6 +++---
 spec/unit/ec2_spec.rb             | 2 +-
 spec/unit/util/loader_spec.rb     | 2 +-
 spec/unit/util/resolution_spec.rb | 6 +++---
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/lib/facter/util/loader.rb b/lib/facter/util/loader.rb
index 87008ff..f0e5fee 100644
--- a/lib/facter/util/loader.rb
+++ b/lib/facter/util/loader.rb
@@ -97,7 +97,7 @@ class Facter::Util::Loader
       # Don't store the path if the file can't be loaded
       # in case it's loadable later on.
       @loaded.delete(file)
-      warn "Error loading fact #{file} #{detail}"
+      Facter.warn "Error loading fact #{file} #{detail}"
     end
   end
 
diff --git a/lib/facter/util/resolution.rb b/lib/facter/util/resolution.rb
index 9205abe..a19b81a 100644
--- a/lib/facter/util/resolution.rb
+++ b/lib/facter/util/resolution.rb
@@ -174,7 +174,7 @@ class Facter::Util::Resolution
         # command not found on Windows
         return nil
       rescue => detail
-        $stderr.puts detail
+        Facter.warn(detail)
         return nil
       end
       
@@ -307,7 +307,7 @@ class Facter::Util::Resolution
         end
       end
     rescue Timeout::Error => detail
-      warn "Timed out seeking value for %s" % self.name
+      Facter.warn "Timed out seeking value for %s" % self.name
 
       # This call avoids zombies -- basically, create a thread that will
       # dezombify all of the child processes that we're ignoring because
@@ -315,7 +315,7 @@ class Facter::Util::Resolution
       Thread.new { Process.waitall }
       return nil
     rescue => details
-      warn "Could not retrieve %s: %s" % [self.name, details]
+      Facter.warn "Could not retrieve %s: %s" % [self.name, details]
       return nil
     end
 
diff --git a/spec/unit/ec2_spec.rb b/spec/unit/ec2_spec.rb
index 3046789..f26a613 100755
--- a/spec/unit/ec2_spec.rb
+++ b/spec/unit/ec2_spec.rb
@@ -136,8 +136,8 @@ describe "ec2 facts" do
     end
 
     it "should return nil if open fails" do
+      Facter.stubs(:warn) # do not pollute test output
       Facter.expects(:warn).with('Could not retrieve ec2 metadata: host unreachable')
-      Facter::Util::Resolution.any_instance.stubs(:warn) # do not pollute test output
 
       Object.any_instance.expects(:open).
         with("#{api_prefix}/2008-02-01/meta-data/").
diff --git a/spec/unit/util/loader_spec.rb b/spec/unit/util/loader_spec.rb
index 63dacb9..d0b8706 100755
--- a/spec/unit/util/loader_spec.rb
+++ b/spec/unit/util/loader_spec.rb
@@ -315,7 +315,7 @@ describe Facter::Util::Loader do
       Dir.expects(:entries).with("/one/dir").returns %w{a.rb}
 
       Kernel.expects(:load).with("/one/dir/a.rb").raises(LoadError)
-      @loader.expects(:warn)
+      Facter.expects(:warn)
 
       lambda { @loader.load_all }.should_not raise_error
     end
diff --git a/spec/unit/util/resolution_spec.rb b/spec/unit/util/resolution_spec.rb
index 53d1083..e0300bf 100755
--- a/spec/unit/util/resolution_spec.rb
+++ b/spec/unit/util/resolution_spec.rb
@@ -240,7 +240,7 @@ describe Facter::Util::Resolution do
     describe "and the code is a block" do
       it "should warn but not fail if the code fails" do
         @resolve.setcode { raise "feh" }
-        @resolve.expects(:warn)
+        Facter.expects(:warn)
         @resolve.value.should be_nil
       end
 
@@ -269,7 +269,7 @@ describe Facter::Util::Resolution do
       end
 
       it "should timeout after the provided timeout" do
-        @resolve.expects(:warn)
+        Facter.expects(:warn)
         @resolve.timeout = 0.1
         @resolve.setcode { sleep 2; raise "This is a test" }
         Thread.expects(:new).yields
@@ -278,7 +278,7 @@ describe Facter::Util::Resolution do
       end
 
       it "should waitall to avoid zombies if the timeout is exceeded" do
-        @resolve.stubs(:warn)
+        Facter.stubs(:warn)
         @resolve.timeout = 0.1
         @resolve.setcode { sleep 2; raise "This is a test" }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git



More information about the Pkg-puppet-devel mailing list