Codebase list facter / b5cb1ef
(#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. Josh Cooper authored 11 years ago Matthaus Owens committed 11 years ago
2 changed file(s) with 4 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
116116 # get each physical processor
117117 Facter::Util::WMI.execquery("select * from Win32_Processor").each do |proc|
118118 # not supported before 2008
119 begin
119 if proc.respond_to?(:NumberOfLogicalProcessors)
120120 processor_num = proc.NumberOfLogicalProcessors
121 rescue RuntimeError => e
121 else
122122 processor_num = 1
123123 end
124124
2828 describe "2003" do
2929 before :each do
3030 proc = stubs 'proc'
31 proc.stubs(:NumberOfLogicalProcessors).raises(RuntimeError)
3231 proc.stubs(:Name).returns("Intel(R) Celeron(R) processor")
3332
3433 load(Array.new(2, proc))
3534 end
3635
3736 it "should count 2 processors" do
37 proc.expects(:NumberOfLogicalProcessors).never
38
3839 Facter.fact(:processorcount).value.should == "2"
3940 end
4041