(#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
116 | 116 |
# get each physical processor
|
117 | 117 |
Facter::Util::WMI.execquery("select * from Win32_Processor").each do |proc|
|
118 | 118 |
# not supported before 2008
|
119 | |
begin
|
|
119 |
if proc.respond_to?(:NumberOfLogicalProcessors)
|
120 | 120 |
processor_num = proc.NumberOfLogicalProcessors
|
121 | |
rescue RuntimeError => e
|
|
121 |
else
|
122 | 122 |
processor_num = 1
|
123 | 123 |
end
|
124 | 124 |
|
28 | 28 |
describe "2003" do
|
29 | 29 |
before :each do
|
30 | 30 |
proc = stubs 'proc'
|
31 | |
proc.stubs(:NumberOfLogicalProcessors).raises(RuntimeError)
|
32 | 31 |
proc.stubs(:Name).returns("Intel(R) Celeron(R) processor")
|
33 | 32 |
|
34 | 33 |
load(Array.new(2, proc))
|
35 | 34 |
end
|
36 | 35 |
|
37 | 36 |
it "should count 2 processors" do
|
|
37 |
proc.expects(:NumberOfLogicalProcessors).never
|
|
38 |
|
38 | 39 |
Facter.fact(:processorcount).value.should == "2"
|
39 | 40 |
end
|
40 | 41 |
|