diff options
author | Adrien Thebo <adrien@puppetlabs.com> | 2011-03-15 17:29:19 -0700 |
---|---|---|
committer | Adrien Thebo <adrien.thebo@gmail.com> | 2011-04-01 18:20:00 -0700 |
commit | c2ff8330f4d705ded3f251e170df4bd973af3d43 (patch) | |
tree | 262ac8d76a07fc9217f937daa0c4484027cffebe /lib | |
parent | 0c4a98b2271ed5d84f2aa8783398f08502b578ee (diff) | |
download | facter-c2ff8330f4d705ded3f251e170df4bd973af3d43.tar.gz facter-c2ff8330f4d705ded3f251e170df4bd973af3d43.tar.xz facter-c2ff8330f4d705ded3f251e170df4bd973af3d43.zip |
(#5135) Refactored physicalprocessorcount
- Refactored code to make testing simpler
Diffstat (limited to 'lib')
-rw-r--r-- | lib/facter/physicalprocessorcount.rb | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/facter/physicalprocessorcount.rb b/lib/facter/physicalprocessorcount.rb index 144183c..cd5777c 100644 --- a/lib/facter/physicalprocessorcount.rb +++ b/lib/facter/physicalprocessorcount.rb @@ -39,9 +39,11 @@ Facter.add('physicalprocessorcount') do lookup_pattern = "#{sysfs_cpu_directory}" + "/cpu*/topology/physical_package_id" - Facter::Util::Resolution.exec( - "cat #{lookup_pattern}" - ).scan(/\d+/).uniq.size + ids = Dir.glob(lookup_pattern).collect { |f| Facter::Util::Resolution.exec("cat #{f}")} + + ids = ids.join if ids.is_a?(Array) + ids.scan(/\d+/).uniq.size + else # # Try to count number of CPUs using the proc file system next ... @@ -49,9 +51,9 @@ Facter.add('physicalprocessorcount') do # We assume that /proc/cpuinfo has what we need and is so then we need # to make sure that we only count unique entries ... # - Facter::Util::Resolution.exec( - "grep 'physical.\\+:' /proc/cpuinfo" - ).scan(/\d+/).uniq.size + str = Facter::Util::Resolution.exec("grep 'physical.\\+:' /proc/cpuinfo") + + if not str.nil? then str.scan(/\d+/).uniq.size; end end end end |