[Pkg-puppet-devel] [facter] 239/352: (maint) Add more context when resolutions fail to evaluate

Stig Sandbeck Mathisen ssm at debian.org
Sun Apr 6 22:21:49 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 928282afbcb18f2216ed2047588ab8515f90197e
Author: Adrien Thebo <git at somethingsinistral.net>
Date:   Tue Feb 11 15:26:22 2014 -0800

    (maint) Add more context when resolutions fail to evaluate
---
 lib/facter/core/resolvable.rb            | 12 ++++++++----
 spec/unit/core/resolvable_spec.rb        | 10 +++++++---
 spec/unit/operatingsystemrelease_spec.rb |  7 ++-----
 3 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/lib/facter/core/resolvable.rb b/lib/facter/core/resolvable.rb
index 7228262..84459a5 100644
--- a/lib/facter/core/resolvable.rb
+++ b/lib/facter/core/resolvable.rb
@@ -66,7 +66,7 @@ module Facter::Core::Resolvable
 
     Facter::Util::Normalization.normalize(result)
   rescue Timeout::Error => detail
-    Facter.warn "Timed out seeking value for #{self.name}"
+    Facter.warn "Timed out after #{limit} seconds while resolving #{qualified_name}"
 
     # This call avoids zombies -- basically, create a thread that will
     # dezombify all of the child processes that we're ignoring because
@@ -74,10 +74,10 @@ module Facter::Core::Resolvable
     Thread.new { Process.waitall }
     return nil
   rescue Facter::Util::Normalization::NormalizationError => e
-    Facter.warn "Fact resolution #{self.name} resolved to an invalid value: #{e.message}"
+    Facter.warn "Fact resolution #{qualified_name} resolved to an invalid value: #{e.message}"
     return nil
   rescue => details
-    Facter.warn "Could not retrieve #{self.name}: #{details.message}"
+    Facter.warn "Could not retrieve #{qualified_name}: #{details.message}"
     return nil
   end
 
@@ -90,6 +90,10 @@ module Facter::Core::Resolvable
 
     finishtime = Time.now.to_f
     ms = (finishtime - starttime) * 1000
-    Facter.show_time "#{self.name}: #{"%.2f" % ms}ms"
+    Facter.show_time "#{qualified_name}: #{"%.2f" % ms}ms"
+  end
+
+  def qualified_name
+    "fact='#{@fact.name.to_s}', resolution='#{@name || '<anonymous>'}'"
   end
 end
diff --git a/spec/unit/core/resolvable_spec.rb b/spec/unit/core/resolvable_spec.rb
index e2ed98e..1b877f0 100644
--- a/spec/unit/core/resolvable_spec.rb
+++ b/spec/unit/core/resolvable_spec.rb
@@ -6,8 +6,10 @@ describe Facter::Core::Resolvable do
   class ResolvableClass
     def initialize(name)
       @name = name
+      @fact = Facter::Util::Fact.new("stub fact")
     end
     attr_accessor :name, :resolve_value
+    attr_reader :fact
     include Facter::Core::Resolvable
   end
 
@@ -36,7 +38,7 @@ describe Facter::Core::Resolvable do
 
     it "logs a warning if an exception was raised" do
       subject.expects(:resolve_value).raises RuntimeError, "kaboom!"
-      Facter.expects(:warn).with('Could not retrieve resolvable: kaboom!')
+      Facter.expects(:warn).with(regexp_matches(/Could not retrieve .*: kaboom!/))
       expect(subject.value).to eq nil
     end
   end
@@ -51,9 +53,11 @@ describe Facter::Core::Resolvable do
     end
 
     it "returns nil if the timeout was reached" do
-      Facter.expects(:warn).with("Timed out seeking value for resolvable")
+      Facter.expects(:warn).with(regexp_matches(/Timed out after 0\.1 seconds while resolving/))
       Timeout.expects(:timeout).raises Timeout::Error
 
+      subject.timeout = 0.1
+
       expect(subject.value).to be_nil
     end
 
@@ -62,7 +66,7 @@ describe Facter::Core::Resolvable do
       Thread.expects(:new).yields
       Process.expects(:waitall)
 
-      Facter.expects(:warn).with("Timed out seeking value for resolvable")
+      Facter.stubs(:warn)
       Timeout.expects(:timeout).raises Timeout::Error
 
       subject.value
diff --git a/spec/unit/operatingsystemrelease_spec.rb b/spec/unit/operatingsystemrelease_spec.rb
index e929f97..781ee98 100755
--- a/spec/unit/operatingsystemrelease_spec.rb
+++ b/spec/unit/operatingsystemrelease_spec.rb
@@ -127,13 +127,10 @@ describe "Operating System Release fact" do
     end
 
     context "malformed /etc/release files" do
-      before :each do
-        Facter::Util::Resolution.any_instance.stubs(:warn)
-      end
       it "should fallback to the kernelrelease fact if /etc/release is empty" do
         Facter::Util::FileRead.stubs(:read).with('/etc/release').
           raises EOFError
-        Facter.expects(:warn).with("Could not retrieve operatingsystemrelease: EOFError")
+        Facter.expects(:warn).with(regexp_matches(/Could not retrieve fact='operatingsystemrelease'.*EOFError/))
         Facter.fact(:operatingsystemrelease).value.
           should == Facter.fact(:kernelrelease).value
       end
@@ -141,7 +138,7 @@ describe "Operating System Release fact" do
       it "should fallback to the kernelrelease fact if /etc/release is not present" do
         Facter::Util::FileRead.stubs(:read).with('/etc/release').
           raises Errno::ENOENT
-        Facter.expects(:warn).with("Could not retrieve operatingsystemrelease: No such file or directory")
+        Facter.expects(:warn).with(regexp_matches(/Could not retrieve fact='operatingsystemrelease'.*No such file or directory/))
         Facter.fact(:operatingsystemrelease).value.
           should == Facter.fact(:kernelrelease).value
       end

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