[Pkg-puppet-devel] [facter] 19/46: (#20301) Handle different error in ruby 1.9

Stig Sandbeck Mathisen ssm at debian.org
Sun Sep 1 10:47:29 UTC 2013


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

ssm pushed a commit to branch master
in repository facter.

commit 0da8bd75c482466f1212f2cbd3d24d35532416dd
Author: Josh Cooper <josh at puppetlabs.com>
Date:   Thu Apr 18 22:59:31 2013 -0700

    (#20301) Handle different error in ruby 1.9
    
    The NumberOfLogicalProcessor property of the Win32_Processor WMI class
    does not exist in the base win2003 install. Previously, we were trying
    to access the property, and then catching the resulting error if the
    property did not exist.
    
    In ruby 1.8, it would raise a RuntimeError, but in ruby 1.9, it raises a
    StandardError, causing the fact to blow up on ruby 1.9.
    
    This commit checks to see if the process object responds to that method,
    and only then does it try to call it.
---
 lib/facter/processor.rb     |    4 ++--
 spec/unit/processor_spec.rb |    3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/facter/processor.rb b/lib/facter/processor.rb
index 1d409eb..1d11d07 100644
--- a/lib/facter/processor.rb
+++ b/lib/facter/processor.rb
@@ -117,9 +117,9 @@ if Facter.value(:kernel) == "windows"
     # get each physical processor
     Facter::Util::WMI.execquery("select * from Win32_Processor").each do |proc|
       # not supported before 2008
-      begin
+      if proc.respond_to?(:NumberOfLogicalProcessors)
         processor_num = proc.NumberOfLogicalProcessors
-      rescue RuntimeError => e
+      else
         processor_num = 1
       end
 
diff --git a/spec/unit/processor_spec.rb b/spec/unit/processor_spec.rb
index 31b336d..1ed6935 100755
--- a/spec/unit/processor_spec.rb
+++ b/spec/unit/processor_spec.rb
@@ -29,13 +29,14 @@ describe "Processor facts" do
     describe "2003" do
       before :each do
         proc = stubs 'proc'
-        proc.stubs(:NumberOfLogicalProcessors).raises(RuntimeError)
         proc.stubs(:Name).returns("Intel(R)    Celeron(R)   processor")
 
         load(Array.new(2, proc))
       end
 
       it "should count 2 processors" do
+        proc.expects(:NumberOfLogicalProcessors).never
+
         Facter.fact(:processorcount).value.should == "2"
       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