facter 2.1.0-x86-mingw32 → 2.2.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of facter might be problematic. Click here for more details.

Files changed (139) hide show
  1. data/COMMITTERS.md +25 -34
  2. data/CONTRIBUTING.md +27 -5
  3. data/README.md +32 -0
  4. data/ext/build_defaults.yaml +1 -1
  5. data/ext/debian/control +3 -2
  6. data/ext/osx/file_mapping.yaml +5 -0
  7. data/ext/redhat/facter.spec.erb +4 -1
  8. data/lib/facter/Cfkey.rb +2 -2
  9. data/lib/facter/architecture.rb +2 -2
  10. data/lib/facter/augeasversion.rb +2 -2
  11. data/lib/facter/blockdevices.rb +12 -12
  12. data/lib/facter/dhcp_servers.rb +4 -4
  13. data/lib/facter/domain.rb +4 -4
  14. data/lib/facter/ec2.rb +17 -0
  15. data/lib/facter/ec2/rest.rb +2 -2
  16. data/lib/facter/facterversion.rb +2 -2
  17. data/lib/facter/filesystems.rb +10 -3
  18. data/lib/facter/fqdn.rb +1 -1
  19. data/lib/facter/gid.rb +16 -0
  20. data/lib/facter/hardwareisa.rb +3 -3
  21. data/lib/facter/hardwaremodel.rb +3 -3
  22. data/lib/facter/hostname.rb +1 -1
  23. data/lib/facter/id.rb +4 -4
  24. data/lib/facter/interfaces.rb +3 -0
  25. data/lib/facter/ipaddress6.rb +9 -9
  26. data/lib/facter/kernel.rb +2 -2
  27. data/lib/facter/kernelmajversion.rb +2 -2
  28. data/lib/facter/kernelrelease.rb +4 -4
  29. data/lib/facter/kernelversion.rb +3 -3
  30. data/lib/facter/ldom.rb +11 -0
  31. data/lib/facter/lsbdistcodename.rb +8 -4
  32. data/lib/facter/lsbdistdescription.rb +6 -10
  33. data/lib/facter/lsbdistid.rb +8 -4
  34. data/lib/facter/lsbdistrelease.rb +8 -4
  35. data/lib/facter/lsbmajdistrelease.rb +7 -12
  36. data/lib/facter/lsbminordistrelease.rb +22 -0
  37. data/lib/facter/lsbrelease.rb +8 -4
  38. data/lib/facter/macaddress.rb +1 -0
  39. data/lib/facter/macosx.rb +1 -1
  40. data/lib/facter/manufacturer.rb +3 -3
  41. data/lib/facter/memory.rb +8 -8
  42. data/lib/facter/netmask.rb +2 -1
  43. data/lib/facter/network.rb +3 -3
  44. data/lib/facter/operatingsystem.rb +9 -126
  45. data/lib/facter/operatingsystem/base.rb +61 -0
  46. data/lib/facter/operatingsystem/cumuluslinux.rb +27 -0
  47. data/lib/facter/operatingsystem/implementation.rb +30 -0
  48. data/lib/facter/operatingsystem/linux.rb +467 -0
  49. data/lib/facter/operatingsystem/sunos.rb +54 -0
  50. data/lib/facter/operatingsystem/vmkernel.rb +11 -0
  51. data/lib/facter/operatingsystem/windows.rb +37 -0
  52. data/lib/facter/operatingsystemmajrelease.rb +14 -33
  53. data/lib/facter/operatingsystemrelease.rb +14 -235
  54. data/lib/facter/os.rb +69 -0
  55. data/lib/facter/osfamily.rb +4 -23
  56. data/lib/facter/partitions.rb +4 -3
  57. data/lib/facter/path.rb +2 -2
  58. data/lib/facter/physicalprocessorcount.rb +10 -74
  59. data/lib/facter/processor.rb +13 -129
  60. data/lib/facter/processors.rb +60 -0
  61. data/lib/facter/processors/os.rb +234 -0
  62. data/lib/facter/ps.rb +5 -4
  63. data/lib/facter/puppetversion.rb +1 -1
  64. data/lib/facter/rackspace.rb +34 -0
  65. data/lib/facter/rubysitedir.rb +3 -0
  66. data/lib/facter/rubyversion.rb +2 -2
  67. data/lib/facter/selinux.rb +57 -2
  68. data/lib/facter/ssh.rb +1 -0
  69. data/lib/facter/system_uptime.rb +42 -0
  70. data/lib/facter/timezone.rb +1 -1
  71. data/lib/facter/uptime.rb +5 -23
  72. data/lib/facter/uptime_days.rb +4 -6
  73. data/lib/facter/uptime_hours.rb +4 -6
  74. data/lib/facter/uptime_seconds.rb +5 -9
  75. data/lib/facter/util/formatter.rb +1 -1
  76. data/lib/facter/util/manufacturer.rb +1 -1
  77. data/lib/facter/util/partitions.rb +3 -1
  78. data/lib/facter/util/partitions/linux.rb +1 -1
  79. data/lib/facter/util/partitions/openbsd.rb +35 -0
  80. data/lib/facter/util/uptime.rb +4 -3
  81. data/lib/facter/util/virtual.rb +3 -1
  82. data/lib/facter/util/xendomains.rb +12 -3
  83. data/lib/facter/version.rb +1 -1
  84. data/lib/facter/virtual.rb +24 -23
  85. data/lib/facter/vlans.rb +1 -1
  86. data/lib/facter/xendomains.rb +1 -1
  87. data/lib/facter/zfs_version.rb +6 -2
  88. data/lib/facter/zones.rb +6 -5
  89. data/lib/facter/zpool_version.rb +1 -1
  90. data/spec/fixtures/cpuinfo/amd64dual-grep +2 -0
  91. data/spec/fixtures/cpuinfo/amd64twentyfour-grep +24 -0
  92. data/spec/fixtures/cpuinfo/two_multicore-grep +4 -0
  93. data/spec/fixtures/cpuinfo/two_singlecore-grep +2 -0
  94. data/spec/fixtures/unit/processors/os/darwin-system-profiler +287 -0
  95. data/spec/fixtures/unit/zfs_version/zfs_new +61 -0
  96. data/spec/fixtures/unit/zfs_version/zfs_old +43 -0
  97. data/spec/fixtures/unit/zfs_version/zfsonlinux_0.6.1 +13 -0
  98. data/spec/fixtures/unit/zpool_version/zfsonlinux_0.6.1 +48 -0
  99. data/spec/unit/ec2/rest_spec.rb +6 -6
  100. data/spec/unit/gid_spec.rb +22 -0
  101. data/spec/unit/hardwaremodel_spec.rb +2 -0
  102. data/spec/unit/lsbdistcodename_spec.rb +22 -17
  103. data/spec/unit/lsbdistdescription_spec.rb +22 -17
  104. data/spec/unit/lsbdistid_spec.rb +23 -18
  105. data/spec/unit/lsbdistrelease_spec.rb +22 -17
  106. data/spec/unit/lsbmajdistrelease_spec.rb +23 -6
  107. data/spec/unit/lsbminordistrelease_spec.rb +31 -0
  108. data/spec/unit/lsbrelease_spec.rb +22 -17
  109. data/spec/unit/macaddress_spec.rb +3 -0
  110. data/spec/unit/operatingsystem/base_spec.rb +76 -0
  111. data/spec/unit/operatingsystem/cumuluslinux_spec.rb +40 -0
  112. data/spec/unit/operatingsystem/implementation_spec.rb +49 -0
  113. data/spec/unit/operatingsystem/linux_spec.rb +538 -0
  114. data/spec/unit/operatingsystem/sunos_spec.rb +144 -0
  115. data/spec/unit/operatingsystem/vmkernel_spec.rb +13 -0
  116. data/spec/unit/operatingsystem/windows_spec.rb +68 -0
  117. data/spec/unit/operatingsystem_spec.rb +10 -153
  118. data/spec/unit/operatingsystemmajrelease_spec.rb +14 -31
  119. data/spec/unit/operatingsystemrelease_spec.rb +13 -229
  120. data/spec/unit/os_spec.rb +131 -0
  121. data/spec/unit/osfamily_spec.rb +9 -54
  122. data/spec/unit/partitions_spec.rb +41 -3
  123. data/spec/unit/physicalprocessorcount_spec.rb +6 -78
  124. data/spec/unit/processor_spec.rb +18 -381
  125. data/spec/unit/processors/os_spec.rb +446 -0
  126. data/spec/unit/processors_spec.rb +203 -0
  127. data/spec/unit/rackspace_spec.rb +40 -0
  128. data/spec/unit/system_uptime_spec.rb +80 -0
  129. data/spec/unit/util/formatter_spec.rb +5 -0
  130. data/spec/unit/util/macaddress_spec.rb +2 -0
  131. data/spec/unit/util/processor_spec.rb +120 -0
  132. data/spec/unit/util/uptime_spec.rb +3 -4
  133. data/spec/unit/util/virtual_spec.rb +8 -0
  134. data/spec/unit/util/xendomains_spec.rb +54 -9
  135. data/spec/unit/virtual_spec.rb +8 -1
  136. data/spec/unit/zfs_version_spec.rb +20 -8
  137. data/spec/unit/zpool_version_spec.rb +5 -0
  138. metadata +660 -589
  139. checksums.yaml +0 -7
@@ -0,0 +1,446 @@
1
+ require 'spec_helper'
2
+ require 'facter/processors/os'
3
+ require 'facter/util/wmi'
4
+ require 'facter_spec/cpuinfo'
5
+
6
+ shared_context "processor list" do
7
+ let(:proc_list_array) { ["Intel(R) Xeon(R) CPU E5-2609 0 @ 2.40GHz", "Intel(R) Xeon(R) CPU E5-2609 0 @ 2.40GHz"] }
8
+ end
9
+
10
+ describe Facter::Processors::Linux do
11
+ include FacterSpec::Cpuinfo
12
+ subject { described_class.new }
13
+ include_context "processor list"
14
+ describe "getting the processor list" do
15
+ it "should delegate to the enum_cpuinfo utility" do
16
+ Facter::Util::Processor.expects(:enum_cpuinfo).once.returns(proc_list_array)
17
+ list = subject.get_processor_list
18
+ expect(list).to eq proc_list_array
19
+ end
20
+ end
21
+
22
+ describe "getting the processor count" do
23
+ describe "when enum_cpuinfo is available" do
24
+
25
+ before :each do
26
+ File.expects(:exists?).with("/proc/cpuinfo").returns(true)
27
+ end
28
+
29
+ it "should be 1 in SPARC fixture" do
30
+ Facter.fact(:architecture).stubs(:value).returns("sparc")
31
+ File.expects(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture_readlines("sparc"))
32
+ count = subject.get_processor_count
33
+ expect(count).to eq 1
34
+ end
35
+
36
+ it "should be 2 in ppc64 fixture on Linux" do
37
+ Facter.fact(:architecture).stubs(:value).returns("ppc64")
38
+ File.expects(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture_readlines("ppc64"))
39
+ count = subject.get_processor_count
40
+ expect(count).to eq 2
41
+ end
42
+
43
+ it "should be 2 in panda-armel fixture on Linux" do
44
+ Facter.fact(:architecture).stubs(:value).returns("arm")
45
+ File.expects(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture_readlines("panda-armel"))
46
+ count = subject.get_processor_count
47
+ expect(count).to eq 2
48
+ end
49
+
50
+ it "should be 1 in bbg3-armel fixture on Linux" do
51
+ Facter.fact(:architecture).stubs(:value).returns("arm")
52
+ File.expects(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture_readlines("bbg3-armel"))
53
+ count = subject.get_processor_count
54
+ expect(count).to eq 1
55
+ end
56
+
57
+ it "should be 1 in beaglexm-armel fixture on Linux" do
58
+ Facter.fact(:architecture).stubs(:value).returns("arm")
59
+ File.expects(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture_readlines("beaglexm-armel"))
60
+ count = subject.get_processor_count
61
+ expect(count).to eq 1
62
+ end
63
+
64
+ it "should be 1 in amd64solo fixture on Linux" do
65
+ Facter.fact(:architecture).stubs(:value).returns("amd64")
66
+ File.expects(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture_readlines("amd64solo"))
67
+ count = subject.get_processor_count
68
+ expect(count).to eq 1
69
+ end
70
+
71
+ it "should be 2 in amd64dual fixture on Linux" do
72
+ Facter.fact(:architecture).stubs(:value).returns("amd64")
73
+ File.expects(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture_readlines("amd64dual"))
74
+ count = subject.get_processor_count
75
+ expect(count).to eq 2
76
+ end
77
+
78
+ it "should be 3 in amd64tri fixture on Linux" do
79
+ Facter.fact(:architecture).stubs(:value).returns("amd64")
80
+ File.expects(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture_readlines("amd64tri"))
81
+ count = subject.get_processor_count
82
+ expect(count).to eq 3
83
+ end
84
+
85
+ it "should be 4 in amd64quad fixture on Linux" do
86
+ Facter.fact(:architecture).stubs(:value).returns("amd64")
87
+ File.expects(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture_readlines("amd64quad"))
88
+ count = subject.get_processor_count
89
+ expect(count).to eq 4
90
+ end
91
+ end
92
+
93
+ describe "when enum_cpuinfo returns 0 processors (#2945)" do
94
+
95
+ def sysfs_cpu_stubs(count)
96
+ (0...count).map { |index| "/sys/devices/system/cpu/cpu#{index}" }
97
+ end
98
+
99
+ before :each do
100
+ subject.expects(:get_processor_list).returns([])
101
+ File.expects(:exists?).with("/sys/devices/system/cpu").returns(true)
102
+ end
103
+
104
+ it "should be 2 via sysfs when cpu0 and cpu1 are present" do
105
+ Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu[0-9]*").returns(sysfs_cpu_stubs(2))
106
+ count = subject.get_processor_count
107
+ expect(count).to eq 2
108
+ end
109
+
110
+ it "should be 16 via sysfs when cpu0 through cpu15 are present" do
111
+ Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu[0-9]*").returns(sysfs_cpu_stubs(16))
112
+ count = subject.get_processor_count
113
+ expect(count).to eq 16
114
+ end
115
+ end
116
+ end
117
+
118
+ describe "getting the physical processor count" do
119
+
120
+ def sysfs_cpu_stubs(count)
121
+ (0...count).map { |index| "/sys/devices/system/cpu/cpu#{index}/topology/physical_package_id" }
122
+ end
123
+
124
+ describe "when /sys/devices/system/cpu is available" do
125
+ before :each do
126
+ File.expects(:exists?).with("/sys/devices/system/cpu").returns(true)
127
+ end
128
+
129
+ it "should return 1 when there is 1 CPU with 1 core" do
130
+ Dir.expects(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns(sysfs_cpu_stubs(1))
131
+ Facter::Core::Execution.expects(:exec).with("cat /sys/devices/system/cpu/cpu0/topology/physical_package_id").returns("0")
132
+ count = subject.get_physical_processor_count
133
+ expect(count).to eq 1
134
+ end
135
+
136
+ it "should return 1 when there is 1 CPU with 4 cores" do
137
+ Dir.expects(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns(sysfs_cpu_stubs(4))
138
+ sysfs_cpu_stubs(4).each do |file|
139
+ Facter::Core::Execution.expects(:exec).with("cat #{file}").returns("0")
140
+ end
141
+ count = subject.get_physical_processor_count
142
+ expect(count).to eq 1
143
+ end
144
+
145
+ it "returns 4 when there are 4 CPUs each with one core" do
146
+ Dir.expects(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns(sysfs_cpu_stubs(4))
147
+ sysfs_cpu_stubs(4).each_with_index do |file, i|
148
+ Facter::Core::Execution.expects(:exec).with("cat #{file}").returns(i)
149
+ end
150
+ count = subject.get_physical_processor_count
151
+ expect(count).to eq 4
152
+ end
153
+
154
+ it "returns 4 when there are 4 CPUs each with two cores" do
155
+ Dir.expects(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns(sysfs_cpu_stubs(8))
156
+ sysfs_cpu_stubs(8).each_with_index do |file, i|
157
+ Facter::Core::Execution.expects(:exec).with("cat #{file}").returns((i / 2).floor)
158
+ end
159
+ count = subject.get_physical_processor_count
160
+ expect(count).to eq 4
161
+ end
162
+ end
163
+
164
+ describe "when the sysfs cpu directory is not available" do
165
+ include FacterSpec::Cpuinfo
166
+ before :each do
167
+ File.stubs(:exists?).with("/sys/devices/system/cpu").returns false
168
+ end
169
+
170
+ it "returns 1 when there is 1 amd64 CPU with 2 cores" do
171
+ Facter::Core::Execution.expects(:exec).with("grep 'physical.\+:' /proc/cpuinfo").returns(cpuinfo_fixture_read("amd64dual-grep"))
172
+ count = subject.get_physical_processor_count
173
+ expect(count).to eq 1
174
+ end
175
+
176
+ it "returns 2 when there are 2 CPUs each with 1 core" do
177
+ Facter::Core::Execution.expects(:exec).with("grep 'physical.\+:' /proc/cpuinfo").returns(cpuinfo_fixture_read("two_singlecore-grep"))
178
+ count = subject.get_physical_processor_count
179
+ expect(count).to eq 2
180
+ end
181
+
182
+ it "returns 2 when there are 2 CPUS each with 2 cores" do
183
+ Facter::Core::Execution.expects(:exec).with("grep 'physical.\+:' /proc/cpuinfo").returns(cpuinfo_fixture_read("two_multicore-grep"))
184
+ count = subject.get_physical_processor_count
185
+ expect(count).to eq 2
186
+ end
187
+
188
+ it "returns 2 when there are 2 CPUs each with 12 cores" do
189
+ Facter::Core::Execution.expects(:exec).with("grep 'physical.\+:' /proc/cpuinfo").returns(cpuinfo_fixture_read("amd64twentyfour-grep"))
190
+ count = subject.get_physical_processor_count
191
+ expect(count).to eq 2
192
+ end
193
+ end
194
+ end
195
+ end
196
+
197
+ describe Facter::Processors::Windows do
198
+ subject { described_class.new }
199
+ include_context "processor list"
200
+
201
+ def load(procs)
202
+ require 'facter/util/wmi'
203
+ Facter::Util::WMI.stubs(:execquery).with("select * from Win32_Processor").returns(procs)
204
+ # This is to workaround #14674
205
+ Facter.fact(:architecture).stubs(:value).returns("x64")
206
+ end
207
+
208
+ before :each do
209
+ Facter.fact(:kernel).stubs(:value).returns("windows")
210
+ end
211
+
212
+ describe "getting the processor list" do
213
+ describe "2003" do
214
+ before :each do
215
+ proc = stubs 'proc'
216
+ proc.stubs(:Name).returns("Intel(R) Celeron(R) processor")
217
+ load(Array.new(2, proc))
218
+ end
219
+
220
+ it "should squeeze the processor name 2 times" do
221
+ 2.times do |i|
222
+ subject.get_processor_list[i].should == "Intel(R) Celeron(R) processor"
223
+ end
224
+ end
225
+ end
226
+
227
+ describe "2008" do
228
+ before :each do
229
+ proc = stubs 'proc'
230
+ proc.stubs(:NumberOfLogicalProcessors).returns(2)
231
+ proc.stubs(:Name).returns("Intel(R) Celeron(R) processor")
232
+ load(Array.new(2, proc))
233
+ end
234
+
235
+ it "should squeeze the processor name 4 times" do
236
+ 4.times do |i|
237
+ subject.get_processor_list[i].should == "Intel(R) Celeron(R) processor"
238
+ end
239
+ end
240
+ end
241
+ end
242
+
243
+ describe "getting the processor count" do
244
+ it "should use the length of its processor list" do
245
+ subject.expects(:get_processor_list).returns(proc_list_array)
246
+ count = subject.get_processor_count
247
+ expect(count).to eq 2
248
+ end
249
+ end
250
+
251
+ describe "getting the physical processor count" do
252
+ it "should delegate to the execquery utility" do
253
+ ole = stub 'WIN32OLE'
254
+ Facter::Util::WMI.expects(:execquery).with("select Name from Win32_Processor").returns(ole)
255
+ ole.stubs(:Count).returns(4)
256
+ count = subject.get_physical_processor_count
257
+ expect(count).to eq 4
258
+ end
259
+ end
260
+ end
261
+
262
+ describe Facter::Processors::Darwin, :unless => Facter::Util::Config.is_windows? do
263
+ subject { described_class.new }
264
+ include_context "processor list"
265
+
266
+ before :each do
267
+ Facter::Core::Execution.expects(:exec).with("/usr/sbin/system_profiler -xml SPHardwareDataType").returns(my_fixture_read("darwin-system-profiler"))
268
+ subject.stubs(:query_system_profiler).returns({"number_processors" => 4, "current_processor_speed" => "2.3 GHz"})
269
+ subject.instance_variable_set :@system_hardware_data, {"number_processors" => 4, "current_processor_speed" => "2.3 GHz"}
270
+ end
271
+
272
+ describe "getting the processor list" do
273
+ it "should delegate to the enum_cpuinfo utility" do
274
+ Facter::Util::Processor.expects(:enum_cpuinfo).once.returns(proc_list_array)
275
+ list = subject.get_processor_list
276
+ expect(list).to eq proc_list_array
277
+ end
278
+ end
279
+
280
+ describe "getting the processor count" do
281
+ it "should delegate to the sysctl utility" do
282
+ Facter::Util::POSIX.expects(:sysctl).with("hw.ncpu").once.returns("2")
283
+ count = subject.get_processor_count
284
+ expect(count).to eq 2
285
+ end
286
+ end
287
+
288
+ describe "getting the processor speed" do
289
+ it "should use system_profiler" do
290
+ subject.instance_variable_set :@system_hardware_data, {"number_processors" => 4, "current_processor_speed" => "2.4 GHz"}
291
+ speed = subject.get_processor_speed
292
+ expect(speed).to eq "2.4 GHz"
293
+ end
294
+ end
295
+ end
296
+
297
+ describe Facter::Processors::AIX do
298
+ subject { described_class.new }
299
+ include_context "processor list"
300
+
301
+ describe "getting the processor list" do
302
+ it "should delegate to the aix_processor_list utility" do
303
+ Facter::Util::Processor.expects(:aix_processor_list).returns(proc_list_array)
304
+ list = subject.get_processor_list
305
+ expect(list).to eq proc_list_array
306
+ end
307
+ end
308
+
309
+ describe "getting the processor count" do
310
+ it "should use the length of its processor list" do
311
+ subject.expects(:get_processor_list).once.returns(proc_list_array)
312
+ count = subject.get_processor_count
313
+ expect(count).to eq 2
314
+ end
315
+ end
316
+ end
317
+
318
+ describe Facter::Processors::HP_UX do
319
+ subject { described_class.new }
320
+ include_context "processor list"
321
+
322
+ describe "getting the processor list" do
323
+ it "should delegate to the hpux_processor_list utility" do
324
+ Facter::Util::Processor.expects(:hpux_processor_list).once.returns(proc_list_array)
325
+ list = subject.get_processor_list
326
+ expect(list).to eq proc_list_array
327
+ end
328
+ end
329
+
330
+ describe "getting the processor count" do
331
+ it "should use the length of its processor list" do
332
+ subject.expects(:get_processor_list).once.returns(proc_list_array)
333
+ count = subject.get_processor_count
334
+ expect(count).to eq 2
335
+ end
336
+ end
337
+ end
338
+
339
+ describe Facter::Processors::BSD do
340
+ subject { described_class.new }
341
+ include_context "processor list"
342
+
343
+ describe "getting the processor list" do
344
+ it "should delegate to the enum_cpuinfo utility" do
345
+ Facter::Util::Processor.expects(:enum_cpuinfo).once.returns(proc_list_array)
346
+ list = subject.get_processor_list
347
+ expect(list).to eq proc_list_array
348
+ end
349
+ end
350
+
351
+ describe "getting the processor count" do
352
+ it "should delegate to the sysctl utility" do
353
+ Facter::Util::POSIX.expects(:sysctl).with("hw.ncpu").once.returns("2")
354
+ count = subject.get_processor_count
355
+ expect(count).to eq 2
356
+ end
357
+ end
358
+ end
359
+
360
+ describe Facter::Processors::OpenBSD do
361
+ subject { described_class.new }
362
+ include_context "processor list"
363
+
364
+ describe "getting the physical processor count" do
365
+ it "should delegate to the sysctl utility" do
366
+ Facter::Util::POSIX.expects(:sysctl).with("hw.ncpufound").once.returns("2")
367
+ count = subject.get_physical_processor_count
368
+ expect(count).to eq 2
369
+ end
370
+ end
371
+ end
372
+
373
+ describe Facter::Processors::SunOS do
374
+ subject { described_class.new }
375
+ include_context "processor list"
376
+
377
+ describe "getting the processor list" do
378
+ it "should delegate to the enum_kstat utility" do
379
+ Facter::Util::Processor.expects(:enum_kstat).once.returns(proc_list_array)
380
+ list = subject.get_processor_list
381
+ expect(list).to eq proc_list_array
382
+ end
383
+ end
384
+
385
+ describe "getting the processor count" do
386
+ before :all do
387
+ @fixture_kstat_sparc = File.read(fixtures('processorcount','solaris-sparc-kstat-cpu-info'))
388
+ @fixture_kstat_x86_64 = File.read(fixtures('processorcount','solaris-x86_64-kstat-cpu-info'))
389
+ @fixture_psrinfo = File.read(fixtures('processorcount','solaris-psrinfo'))
390
+ end
391
+
392
+ describe "with version 5.7 or older" do
393
+ before :each do
394
+ Facter.fact(:kernelrelease).stubs(:value).returns("5.7")
395
+ end
396
+
397
+ it "should count processors returned from kstat" do
398
+ Facter::Core::Execution.expects(:exec).with("/usr/sbin/psrinfo").never
399
+ Facter::Core::Execution.expects(:exec).with("/usr/bin/kstat cpu_info").returns(@fixture_kstat_sparc)
400
+ count = subject.get_processor_count
401
+ expect(count).to eq 8
402
+ end
403
+
404
+ it "should fall back to psrinfo if kstat returns nil" do
405
+ Facter::Core::Execution.expects(:exec).with("/usr/bin/kstat cpu_info").returns(nil)
406
+ Facter::Core::Execution.expects(:exec).with("/usr/sbin/psrinfo").returns(@fixture_psrinfo)
407
+ count = subject.get_processor_count
408
+ expect(count).to eq 24
409
+ end
410
+ end
411
+
412
+ describe "with version 5.8 or newer" do
413
+ it "should count processors using psrinfo" do
414
+ Facter.fact(:kernelrelease).stubs(:value).returns("5.8")
415
+ Facter::Core::Execution.expects(:exec).with("/usr/bin/kstat cpu_info").never
416
+ Facter::Core::Execution.expects(:exec).with("/usr/sbin/psrinfo").returns(@fixture_psrinfo)
417
+ count = subject.get_processor_count
418
+ expect(count).to eq 24
419
+ end
420
+ end
421
+ end
422
+
423
+ describe "getting the physical processor count" do
424
+ before :all do
425
+ @fixture_psrinfo = File.read(fixtures('processorcount','solaris-psrinfo'))
426
+ end
427
+
428
+ describe "with version 5.7 or older" do
429
+ it "should use psrinfo without the 'p' flag" do
430
+ Facter.fact(:kernelrelease).stubs(:value).returns("5.7")
431
+ Facter::Core::Execution.expects(:exec).with("/usr/sbin/psrinfo").once.returns(@fixture_psrinfo)
432
+ count = subject.get_physical_processor_count
433
+ expect(count).to eq 24
434
+ end
435
+ end
436
+
437
+ describe "with version 5.8 or newer" do
438
+ it "should use psrinfo with the 'p' flag" do
439
+ Facter.fact(:kernelrelease).stubs(:value).returns("5.8")
440
+ Facter::Core::Execution.expects(:exec).with("/usr/sbin/psrinfo -p").once.returns("2")
441
+ count = subject.get_physical_processor_count
442
+ expect(count).to eq 2
443
+ end
444
+ end
445
+ end
446
+ end
@@ -0,0 +1,203 @@
1
+ require 'spec_helper'
2
+ require 'facter/processors/os'
3
+ require 'facter/util/processor'
4
+
5
+ describe "processors" do
6
+ subject { Facter.fact(:processors) }
7
+ let(:os) { stub('OS Object') }
8
+ let(:proc_list_array) { ["Intel(R) Xeon(R) CPU E5-2609 0 @ 2.40GHz", "Intel(R) Xeon(R) CPU E5-2609 0 @ 2.40GHz"] }
9
+
10
+ shared_examples "all operating systems" do
11
+ it "should include a models key with all processors" do
12
+ expect(subject.value["models"]).to eq proc_list_array
13
+ end
14
+
15
+ it "should include a count key with the number of processors" do
16
+ expect(subject.value["count"]).to eq 8
17
+ end
18
+ end
19
+
20
+ describe "In OSX" do
21
+ before do
22
+ Facter::Processors::Darwin.stubs(:new).returns os
23
+ end
24
+
25
+ before :each do
26
+ Facter.clear
27
+ Facter.fact(:kernel).stubs(:value).returns("Darwin")
28
+ os.stubs(:get_processor_list).returns(proc_list_array)
29
+ os.stubs(:get_processor_count).returns(8)
30
+ os.stubs(:get_physical_processor_count).returns(nil)
31
+ os.stubs(:get_processor_speed).returns("2.4 GHz")
32
+ end
33
+
34
+ it_behaves_like "all operating systems"
35
+
36
+ it "should include a speed key with the processor speed" do
37
+ expect(subject.value["speed"]).to eq "2.4 GHz"
38
+ end
39
+ end
40
+
41
+ describe "In Linux" do
42
+ before do
43
+ Facter::Processors::Linux.stubs(:new).returns os
44
+ end
45
+
46
+ before :each do
47
+ Facter.clear
48
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
49
+ os.stubs(:get_processor_list).returns(proc_list_array)
50
+ os.stubs(:get_processor_count).returns(8)
51
+ os.stubs(:get_physical_processor_count).returns(4)
52
+ os.stubs(:get_processor_speed).returns(nil)
53
+ end
54
+
55
+ it_behaves_like "all operating systems"
56
+
57
+ it "should include a physicalcount key with the number of physical processors" do
58
+ expect(subject.value["physicalcount"]).to eq 4
59
+ end
60
+ end
61
+
62
+ describe "In Windows" do
63
+ before do
64
+ Facter::Processors::Windows.stubs(:new).returns os
65
+ end
66
+
67
+ before :each do
68
+ Facter.clear
69
+ Facter.fact(:kernel).stubs(:value).returns("windows")
70
+ os.stubs(:get_processor_list).returns(proc_list_array)
71
+ os.stubs(:get_processor_count).returns(8)
72
+ os.stubs(:get_physical_processor_count).returns(4)
73
+ os.stubs(:get_processor_speed).returns(nil)
74
+ end
75
+
76
+ it_behaves_like "all operating systems"
77
+
78
+ it "should include a physicalcount key with the number of physical processors" do
79
+ expect(subject.value["physicalcount"]).to eq 4
80
+ end
81
+ end
82
+
83
+ describe "In SunOS" do
84
+ before do
85
+ Facter::Processors::SunOS.stubs(:new).returns os
86
+ end
87
+
88
+ before :each do
89
+ Facter.clear
90
+ Facter.fact(:kernel).stubs(:value).returns("SunOS")
91
+ os.stubs(:get_processor_list).returns(proc_list_array)
92
+ os.stubs(:get_processor_count).returns(8)
93
+ os.stubs(:get_physical_processor_count).returns(4)
94
+ os.stubs(:get_processor_speed).returns(nil)
95
+ end
96
+
97
+ it_behaves_like "all operating systems"
98
+
99
+ it "should include a physicalcount key with the number of physical processors" do
100
+ expect(subject.value["physicalcount"]).to eq 4
101
+ end
102
+ end
103
+
104
+ describe "In Dragonfly and FreeBSD" do
105
+ before do
106
+ Facter::Processors::BSD.stubs(:new).returns os
107
+ end
108
+
109
+ before :each do
110
+ Facter.clear
111
+ Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
112
+ os.stubs(:get_processor_list).returns(proc_list_array)
113
+ os.stubs(:get_processor_count).returns(8)
114
+ os.stubs(:get_physical_processor_count).returns(nil)
115
+ os.stubs(:get_processor_speed).returns(nil)
116
+ end
117
+
118
+ it_behaves_like "all operating systems"
119
+ end
120
+
121
+ describe "OpenBSD" do
122
+ before do
123
+ Facter::Processors::OpenBSD.stubs(:new).returns os
124
+ end
125
+
126
+ before :each do
127
+ Facter.clear
128
+ Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
129
+ os.stubs(:get_processor_list).returns(proc_list_array)
130
+ os.stubs(:get_processor_count).returns(8)
131
+ os.stubs(:get_physical_processor_count).returns(4)
132
+ os.stubs(:get_processor_speed).returns(nil)
133
+ end
134
+
135
+ it_behaves_like "all operating systems"
136
+
137
+ it "should include a physicalcount key with the number of physical processors" do
138
+ expect(subject.value["physicalcount"]).to eq 4
139
+ end
140
+ end
141
+
142
+ describe "In GNU/kFreeBSD" do
143
+ before do
144
+ Facter::Processors::GNU.stubs(:new).returns os
145
+ end
146
+
147
+ before :each do
148
+ Facter.clear
149
+ Facter.fact(:kernel).stubs(:value).returns("GNU/kFreeBSD")
150
+ os.stubs(:get_processor_list).returns(proc_list_array)
151
+ os.stubs(:get_processor_count).returns(8)
152
+ os.stubs(:get_physical_processor_count).returns(nil)
153
+ os.stubs(:get_processor_speed).returns(nil)
154
+ end
155
+
156
+ it_behaves_like "all operating systems"
157
+ end
158
+
159
+ describe "In AIX" do
160
+ before do
161
+ Facter::Processors::AIX.stubs(:new).returns os
162
+ end
163
+
164
+ before :each do
165
+ Facter.clear
166
+ Facter.fact(:kernel).stubs(:value).returns("AIX")
167
+ os.stubs(:get_processor_list).returns(proc_list_array)
168
+ os.stubs(:get_processor_count).returns(8)
169
+ os.stubs(:get_physical_processor_count).returns(nil)
170
+ os.stubs(:get_processor_speed).returns(nil)
171
+ end
172
+
173
+ it_behaves_like "all operating systems"
174
+ end
175
+
176
+ describe "In HP-UX" do
177
+ before do
178
+ Facter::Processors::HP_UX.stubs(:new).returns os
179
+ end
180
+
181
+ before :each do
182
+ Facter.clear
183
+ Facter.fact(:kernel).stubs(:value).returns("HP-UX")
184
+ os.stubs(:get_processor_list).returns(proc_list_array)
185
+ os.stubs(:get_processor_count).returns(8)
186
+ os.stubs(:get_physical_processor_count).returns(nil)
187
+ os.stubs(:get_processor_speed).returns(nil)
188
+ end
189
+
190
+ it_behaves_like "all operating systems"
191
+ end
192
+
193
+ describe "In non-supported kernels" do
194
+ before do
195
+ Facter.fact(:kernel).stubs(:value).returns("Foo")
196
+ end
197
+
198
+ it "should not resolve the processors fact" do
199
+ Facter::Processors.expects(:implementation).returns(nil)
200
+ expect(subject.value).to be_nil
201
+ end
202
+ end
203
+ end