facter 2.1.0 → 2.2.0

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 +652 -589
  139. checksums.yaml +0 -7
@@ -5,15 +5,19 @@ require 'facter'
5
5
 
6
6
  describe "Partition facts" do
7
7
 
8
- describe "on non-Linux OS" do
8
+ describe "on unsupported platforms" do
9
9
 
10
- it "should not exist when kernel isn't Linux" do
10
+ it "should not exist" do
11
11
  Facter.fact(:kernel).stubs(:value).returns("SunOS")
12
12
  Facter.fact(:partitions).value.should == nil
13
13
  end
14
14
  end
15
15
 
16
16
  describe "on Linux" do
17
+ before do
18
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
19
+ end
20
+
17
21
  it "should return a structured fact with uuid, size, mount point and filesytem for each partition" do
18
22
  partitions = {
19
23
  'sda1' => {
@@ -30,7 +34,7 @@ describe "Partition facts" do
30
34
  },
31
35
  }
32
36
 
33
- Facter::Util::Partitions.stubs(:list).returns( partitions.keys )
37
+ Facter::Util::Partitions.stubs(:list).returns(partitions.keys)
34
38
 
35
39
  partitions.each do |part,vals|
36
40
  Facter::Util::Partitions.stubs(:uuid).with(part).returns(vals['uuid'])
@@ -45,4 +49,38 @@ describe "Partition facts" do
45
49
  }
46
50
  end
47
51
  end
52
+
53
+ describe "on OpenBSD" do
54
+ before do
55
+ Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
56
+ end
57
+
58
+ it "should return a structured fact with size, mount point and filesystem for each partition" do
59
+ partitions = {
60
+ 'sd2a' => {
61
+ 'size' => '1234',
62
+ 'mount' => '/',
63
+ 'filesystem' => 'ffs',
64
+ },
65
+ 'sd2d' => {
66
+ 'size' => '4321',
67
+ 'mount' => '/usr',
68
+ 'filesystem' => 'ffs2',
69
+ },
70
+ }
71
+
72
+ Facter::Util::Partitions.stubs(:list).returns(partitions.keys)
73
+
74
+ partitions.each do |part,vals|
75
+ Facter::Util::Partitions.stubs(:size).with(part).returns(vals['size'])
76
+ Facter::Util::Partitions.stubs(:mount).with(part).returns(vals['mount'])
77
+ Facter::Util::Partitions.stubs(:filesystem).with(part).returns(vals['filesystem'])
78
+ end
79
+
80
+ Facter.fact(:partitions).value.should == {
81
+ 'sd2a' => { 'size' => '1234', 'mount' => '/', 'filesystem' => 'ffs' },
82
+ 'sd2d' => { 'size' => '4321', 'mount' => '/usr', 'filesystem' => 'ffs2' },
83
+ }
84
+ end
85
+ end
48
86
  end
@@ -1,85 +1,13 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
- require 'facter/util/posix'
5
4
 
6
- describe "Physical processor count facts" do
7
-
8
- describe "on linux" do
9
- before :each do
10
- Facter.fact(:kernel).stubs(:value).returns("Linux")
11
- File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true)
12
- end
13
-
14
- it "should return one physical CPU" do
15
- Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns(["/sys/devices/system/cpu/cpu0/topology/physical_package_id"])
16
- Facter::Core::Execution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu0/topology/physical_package_id").returns("0")
17
-
18
- Facter.fact(:physicalprocessorcount).value.should == "1"
19
- end
20
-
21
- it "should return four physical CPUs" do
22
- Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns(%w{
23
- /sys/devices/system/cpu/cpu0/topology/physical_package_id
24
- /sys/devices/system/cpu/cpu1/topology/physical_package_id
25
- /sys/devices/system/cpu/cpu2/topology/physical_package_id
26
- /sys/devices/system/cpu/cpu3/topology/physical_package_id
27
- })
28
-
29
- Facter::Core::Execution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu0/topology/physical_package_id").returns("0")
30
- Facter::Core::Execution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu1/topology/physical_package_id").returns("1")
31
- Facter::Core::Execution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu2/topology/physical_package_id").returns("2")
32
- Facter::Core::Execution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu3/topology/physical_package_id").returns("3")
33
-
34
- Facter.fact(:physicalprocessorcount).value.should == "4"
35
- end
36
- end
37
-
38
- describe "on windows" do
39
- it "should return 4 physical CPUs" do
40
- Facter.fact(:kernel).stubs(:value).returns("windows")
41
-
42
- require 'facter/util/wmi'
43
- ole = stub 'WIN32OLE'
44
- Facter::Util::WMI.expects(:execquery).with("select Name from Win32_Processor").returns(ole)
45
- ole.stubs(:Count).returns(4)
46
-
47
- Facter.fact(:physicalprocessorcount).value.should == "4"
48
- end
49
- end
50
-
51
- describe "on solaris" do
52
- let(:psrinfo) do
53
- "0 on-line since 10/16/2012 14:06:12\n" +
54
- "1 on-line since 10/16/2012 14:06:14\n"
55
- end
56
-
57
- %w{ 5.8 5.9 5.10 5.11 }.each do |release|
58
- it "should use the output of psrinfo -p on #{release}" do
59
- Facter.fact(:kernel).stubs(:value).returns(:sunos)
60
- Facter.stubs(:value).with(:kernelrelease).returns(release)
61
-
62
- Facter::Core::Execution.expects(:exec).with("/usr/sbin/psrinfo -p").returns("1")
63
- Facter.fact(:physicalprocessorcount).value.should == "1"
64
- end
65
- end
66
-
67
- %w{ 5.5.1 5.6 5.7 }.each do |release|
68
- it "uses psrinfo with no -p for kernelrelease #{release}" do
69
- Facter.fact(:kernel).stubs(:value).returns(:sunos)
70
- Facter.stubs(:value).with(:kernelrelease).returns(release)
71
-
72
- Facter::Core::Execution.expects(:exec).with("/usr/sbin/psrinfo").returns(psrinfo)
73
- Facter.fact(:physicalprocessorcount).value.should == "2"
74
- end
75
- end
76
- end
77
-
78
- describe "on openbsd" do
79
- it "should return 4 physical CPUs" do
80
- Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
81
- Facter::Util::POSIX.expects(:sysctl).with("hw.ncpufound").returns("4")
82
- Facter.fact(:physicalprocessorcount).value.should == "4"
5
+ describe "Physical processor count fact" do
6
+ ["linux", "windows", "sunos", "openbsd"].each do |kernel|
7
+ it "should return the value of the 'physicalcount' key of the 'processors' fact on #{kernel}" do
8
+ Facter.fact(:kernel).stubs(:value).returns("#{kernel}")
9
+ Facter.fact("processors").stubs(:value).returns({"physicalcount" => 2, "count" => 4})
10
+ Facter.fact("physicalprocessorcount").value.should eq "2"
83
11
  end
84
12
  end
85
13
  end
@@ -1,401 +1,38 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
- require 'facter/util/posix'
4
- require 'facter/util/processor'
5
3
  require 'spec_helper'
6
- require 'facter_spec/cpuinfo'
7
4
 
8
5
  describe "Processor facts" do
9
- describe "on Windows" do
10
- before :each do
11
- Facter.clear
12
- Facter.fact(:kernel).stubs(:value).returns("windows")
13
- end
14
-
15
- def load(procs)
16
- require 'facter/util/wmi'
17
- Facter::Util::WMI.stubs(:execquery).with("select * from Win32_Processor").returns(procs)
18
- # This is to workaround #14674
19
- Facter.fact(:architecture).stubs(:value).returns("x64")
20
-
21
- # processor facts belong to a file with a different name,
22
- # so load the file explicitly (after stubbing kernel),
23
- # but we have to stub execquery first
24
- Facter.collection.internal_loader.load(:processor)
25
- end
26
-
27
- describe "2003" do
28
- before :each do
29
- proc = stubs 'proc'
30
- proc.stubs(:Name).returns("Intel(R) Celeron(R) processor")
31
-
32
- load(Array.new(2, proc))
33
- end
34
-
35
- it "should count 2 processors" do
36
- proc.expects(:NumberOfLogicalProcessors).never
37
-
38
- Facter.fact(:processorcount).value.should == "2"
39
- end
40
-
41
- it "should squeeze the processor name 2 times" do
42
- 2.times do |i|
43
- Facter.fact("processor#{i}".to_sym).value.should == "Intel(R) Celeron(R) processor"
44
- end
45
- end
46
- end
47
-
48
- describe "2008" do
49
- before :each do
50
- proc = stubs 'proc'
51
- proc.stubs(:NumberOfLogicalProcessors).returns(2)
52
- proc.stubs(:Name).returns("Intel(R) Celeron(R) processor")
53
-
54
- load(Array.new(2, proc))
55
- end
6
+ describe "processorX facts" do
7
+ expected_proc_list = ["Intel(R) Xeon(R) CPU E5-2609 0 @ 2.40GHz", "Intel(R) Xeon(R) CPU E5-2609 0 @ 2.40GHz"]
56
8
 
57
- it "should count 4 processors" do
58
- Facter.fact(:processorcount).value.should == "4"
59
- end
60
-
61
- it "should squeeze the processor name 4 times" do
62
- 4.times do |i|
63
- Facter.fact("processor#{i}".to_sym).value.should == "Intel(R) Celeron(R) processor"
64
- end
65
- end
66
- end
67
- end
68
-
69
- describe "on Linux" do
70
- include FacterSpec::Cpuinfo
71
-
72
- shared_context 'Linux processor stubs' do
73
- before :each do
9
+ ["aix", "hp-ux", "sunos", "linux", "gnu/kfreebsd"].each do |kernel|
10
+ it "should use the 'models' key from the 'processors' fact on #{kernel}" do
11
+ Facter.fact(:kernel).stubs(:value).returns("#{kernel}")
12
+ Facter.fact("processors").stubs(:value).returns({"count" => 8, "physicalcount" => 4, "models" => expected_proc_list})
74
13
  Facter.collection.internal_loader.load(:processor)
75
-
76
- Facter.fact(:kernel).stubs(:value).returns 'Linux'
77
- Facter.fact(:operatingsystem).stubs(:value).returns 'Linux'
78
- File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
79
- end
80
- end
81
-
82
- shared_examples_for 'a /proc/cpuinfo based processor fact' do |processor_fact|
83
- include_context 'Linux processor stubs'
84
-
85
- it "should be 1 in SPARC fixture" do
86
- Facter.fact(:architecture).stubs(:value).returns("sparc")
87
- File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture_readlines("sparc"))
88
-
89
- Facter.fact(processor_fact).value.should == "1"
90
- end
91
-
92
- it "should be 2 in ppc64 fixture on Linux" do
93
- Facter.fact(:architecture).stubs(:value).returns("ppc64")
94
- File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture_readlines("ppc64"))
95
-
96
- Facter.fact(processor_fact).value.should == "2"
97
- end
98
-
99
- it "should be 2 in panda-armel fixture on Linux" do
100
- Facter.fact(:architecture).stubs(:value).returns("arm")
101
- File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture_readlines("panda-armel"))
102
-
103
- Facter.fact(processor_fact).value.should == "2"
104
- end
105
-
106
- it "should be 1 in bbg3-armel fixture on Linux" do
107
- Facter.fact(:architecture).stubs(:value).returns("arm")
108
- File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture_readlines("bbg3-armel"))
109
-
110
- Facter.fact(processor_fact).value.should == "1"
111
- end
112
-
113
- it "should be 1 in beaglexm-armel fixture on Linux" do
114
- Facter.fact(:architecture).stubs(:value).returns("arm")
115
- File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture_readlines("beaglexm-armel"))
116
-
117
- Facter.fact(processor_fact).value.should == "1"
118
- end
119
-
120
- it "should be 1 in amd64solo fixture on Linux" do
121
- Facter.fact(:architecture).stubs(:value).returns("amd64")
122
- File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture_readlines("amd64solo"))
123
-
124
- Facter.fact(processor_fact).value.should == "1"
125
- end
126
-
127
- it "should be 2 in amd64dual fixture on Linux" do
128
- Facter.fact(:architecture).stubs(:value).returns("amd64")
129
- File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture_readlines("amd64dual"))
130
-
131
- Facter.fact(processor_fact).value.should == "2"
132
- end
133
-
134
- it "should be 3 in amd64tri fixture on Linux" do
135
- Facter.fact(:architecture).stubs(:value).returns("amd64")
136
- File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture_readlines("amd64tri"))
137
-
138
- Facter.fact(processor_fact).value.should == "3"
139
- end
140
-
141
- it "should be 4 in amd64quad fixture on Linux" do
142
- Facter.fact(:architecture).stubs(:value).returns("amd64")
143
- File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture_readlines("amd64quad"))
144
-
145
- Facter.fact(processor_fact).value.should == "4"
146
- end
147
- end
148
-
149
- it_behaves_like 'a /proc/cpuinfo based processor fact', :processorcount
150
-
151
- def sysfs_cpu_stubs(count)
152
- (0...count).map { |index| "/sys/devices/system/cpu/cpu#{index}" }
153
- end
154
-
155
- describe 'when /proc/cpuinfo returns 0 processors (#2945)' do
156
- include_context 'Linux processor stubs'
157
-
158
- before do
159
- File.stubs(:readlines).with("/proc/cpuinfo").returns([])
160
- File.stubs(:exists?).with("/sys/devices/system/cpu").returns(true)
161
- end
162
-
163
- it "should be 2 via sysfs when cpu0 and cpu1 are present" do
164
- Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu[0-9]*").returns(
165
- sysfs_cpu_stubs(2)
166
- )
167
-
168
- Facter.fact(:processorcount).value.should == "2"
169
- end
170
-
171
- it "should be 16 via sysfs when cpu0 through cpu15 are present" do
172
- Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu[0-9]*").returns(
173
- sysfs_cpu_stubs(16)
174
- )
175
-
176
- Facter.fact(:processorcount).value.should == "16"
14
+ expected_proc_list.each_with_index do |processor, i|
15
+ Facter.fact("processor#{i}").value.should eq processor
16
+ end
177
17
  end
178
18
  end
179
19
  end
180
20
 
181
-
182
- describe "on Unixes" do
183
- before :each do
21
+ describe "processorcount" do
22
+ it "should use the 'processorcount' key from the 'processors' fact" do
23
+ Facter.fact(:kernel).stubs(:value).returns("linux")
24
+ Facter.fact("processors").stubs(:value).returns({"count" => 8, "physicalcount" => 4 })
184
25
  Facter.collection.internal_loader.load(:processor)
26
+ Facter.fact(:processorcount).value.should eq "8"
185
27
  end
28
+ end
186
29
 
187
- it "should be 2 on dual-processor Darwin box" do
188
- Facter.fact(:kernel).stubs(:value).returns("Darwin")
189
- Facter::Util::POSIX.stubs(:sysctl).with("hw.ncpu").returns('2')
190
-
191
- Facter.fact(:processorcount).value.should == "2"
192
- end
193
-
194
- it "should be 2 on dual-processor OpenBSD box" do
195
- Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
196
- Facter::Util::POSIX.stubs(:sysctl).with("hw.ncpu").returns('2')
197
-
198
- Facter.fact(:processorcount).value.should == "2"
199
- end
200
-
30
+ describe "processor" do
201
31
  it "should print the correct CPU Model on OpenBSD" do
32
+ Facter.collection.internal_loader.load(:processor)
202
33
  Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
203
34
  Facter::Util::POSIX.stubs(:sysctl).with("hw.model").returns('SomeVendor CPU 4.2GHz')
204
-
205
- Facter.fact(:processor).value.should == "SomeVendor CPU 4.2GHz"
206
- end
207
-
208
- it "should be 2 on dual-processor FreeBSD box" do
209
- Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
210
- Facter::Util::POSIX.stubs(:sysctl).with("hw.ncpu").returns('2')
211
-
212
- Facter.fact(:processorcount).value.should == "2"
213
- end
214
-
215
- it "should print the correct CPU Model on FreeBSD" do
216
- Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
217
- Facter::Util::POSIX.stubs(:sysctl).with("hw.model").returns('SomeVendor CPU 3GHz')
218
-
219
- Facter.fact(:processor).value.should == "SomeVendor CPU 3GHz"
220
- end
221
-
222
- it "should be 2 on dual-processor DragonFly box" do
223
- Facter.fact(:kernel).stubs(:value).returns("DragonFly")
224
- Facter::Util::POSIX.stubs(:sysctl).with("hw.ncpu").returns('2')
225
-
226
- Facter.fact(:processorcount).value.should == "2"
227
- end
228
- end
229
-
230
- describe "on solaris" do
231
- before :each do
232
- Facter::Util::Processor.stubs(:kernel_fact_value).returns :sunos
233
- Facter.fact(:kernel).stubs(:value).returns(:sunos)
234
- Facter.collection.internal_loader.load(:processor)
235
- end
236
-
237
- before :all do
238
- @fixture_kstat_sparc = File.read(fixtures('processorcount','solaris-sparc-kstat-cpu-info'))
239
- @fixture_kstat_x86_64 = File.read(fixtures('processorcount','solaris-x86_64-kstat-cpu-info'))
240
- end
241
-
242
- let(:kstat_sparc) { @fixture_kstat_sparc }
243
- let(:kstat_x86_64) { @fixture_kstat_x86_64 }
244
-
245
- %w{ 5.5.1 5.6 5.7 }.each do |release|
246
- %w{ sparc x86_64 }.each do |arch|
247
- it "uses kstat on release #{release} (#{arch})" do
248
- Facter.stubs(:value).with(:kernelrelease).returns(release)
249
-
250
- Facter::Core::Execution.expects(:exec).with("/usr/sbin/psrinfo").never
251
- Facter::Core::Execution.expects(:exec).with("/usr/bin/kstat cpu_info").returns(self.send("kstat_#{arch}".intern))
252
- Facter.fact(:processorcount).value.should == '8'
253
- end
254
- end
255
- end
256
-
257
- %w{ 5.8 5.9 5.10 5.11 }.each do |release|
258
- it "uses psrinfo on release #{release}" do
259
- Facter.stubs(:value).with(:kernelrelease).returns(release)
260
-
261
- fixture_data = File.read(fixtures('processorcount','solaris-psrinfo'))
262
- Facter::Core::Execution.expects(:exec).with("/usr/bin/kstat cpu_info").never
263
- Facter::Core::Execution.expects(:exec).with("/usr/sbin/psrinfo").returns(fixture_data)
264
- Facter.fact(:processorcount).value.should == '24'
265
- end
266
- end
267
- end
268
- end
269
-
270
- describe "processorX facts" do
271
- describe "on AIX" do
272
- def self.lsdev_examples
273
- examples = []
274
- examples << "proc0 Available 00-00 Processor\n" +
275
- "proc4 Available 00-04 Processor\n" +
276
- "proc8 Defined 00-08 Processor\n" +
277
- "proc12 Defined 00-12 Processor\n"
278
- examples
279
- end
280
-
281
- let(:lsattr) do
282
- "type PowerPC_POWER5 Processor type False\n"
283
- end
284
-
285
- lsdev_examples.each_with_index do |lsdev_example, i|
286
- context "lsdev example ##{i}" do
287
- before :each do
288
- Facter.fact(:kernel).stubs(:value).returns("AIX")
289
- Facter::Util::Processor.stubs(:lsdev).returns(lsdev_example)
290
- Facter::Util::Processor.stubs(:lsattr).returns(lsattr)
291
- Facter.collection.internal_loader.load(:processor)
292
- end
293
-
294
- lsdev_example.split("\n").each_with_index do |line, idx|
295
- aix_idx = idx * 4
296
- it "maps proc#{aix_idx} to processor#{idx} (#11609)" do
297
- Facter.value("processor#{idx}").should == "PowerPC_POWER5"
298
- end
299
- end
300
- end
301
- end
302
- end
303
-
304
- describe "on HP-UX" do
305
- def self.machinfo_examples
306
- examples = []
307
- examples << [File.read(fixtures('hpux','machinfo','ia64-rx2620')), "Intel(R) Itanium 2 processor"]
308
- examples << [File.read(fixtures('hpux','machinfo','ia64-rx6600')), "Intel(R) Itanium 2 9100 series processor (1.59 GHz, 18 MB)"]
309
- examples << [File.read(fixtures('hpux','machinfo','ia64-rx8640')), "Intel(R) Itanium 2 9100 series"]
310
- examples << [File.read(fixtures('hpux','machinfo','hppa-rp4440')), "PA-RISC 8800 processor (1000 MHz, 64 MB)"]
311
- examples << [File.read(fixtures('hpux','machinfo','superdome-server-SD32B')), "Intel(R) Itanium 2 9000 series"]
312
- examples << [File.read(fixtures('hpux','machinfo','superdome2-16s')), "Intel(R) Itanium(R) Processor 9340 (1.6 GHz, 15 MB)"]
313
- examples
314
- end
315
-
316
- let(:ioscan) do
317
- "Class I H/W Path Driver S/W State H/W Type Description\n" +
318
- "===================================================================\n" +
319
- "processor 0 0/120 processor CLAIMED PROCESSOR Processor\n" +
320
- "processor 1 0/123 processor CLAIMED PROCESSOR Processor\n"
321
- end
322
-
323
- describe "when machinfo is available" do
324
- machinfo_examples.each_with_index do |example, i|
325
- machinfo_example, expected_cpu = example
326
- context "machinfo example ##{i}" do
327
- before :each do
328
- Facter.fact(:kernel).stubs(:value).returns("HP-UX")
329
- Facter::Util::Processor.stubs(:ioscan).returns(ioscan)
330
- Facter::Util::Processor.stubs(:machinfo).returns(machinfo_example)
331
- Facter.collection.internal_loader.load(:processor)
332
- end
333
-
334
- %w{ 0 1 }.each do |j|
335
- it "should find #{expected_cpu}" do
336
- Facter.value("processor#{j}").should == expected_cpu
337
- end
338
- end
339
- end
340
- end
341
- end
342
-
343
- def self.model_and_getconf_examples
344
- examples = []
345
- examples << ["9000/800/L3000-5x", "sched.models_present", "unistd.h_present", "532", "616", "PA-RISC 8600 processor"]
346
- examples << ["9000/800/L3000-5x", "", "unistd.h_present", "532", "616", "HP PA-RISC2.0 CHIP TYPE #616"]
347
- examples << ["9000/800/L3000-5x", "", "", "532", "616", "CPU v532 CHIP TYPE #616"]
348
- examples << ["ia64 hp server rx2660", "sched.models_present", "unistd.h_present", "768", "536936708", "IA-64 archrev 0 CHIP TYPE #536936708"]
349
- examples << ["ia64 hp server rx2660", "", "unistd.h_present", "768", "536936708", "IA-64 archrev 0 CHIP TYPE #536936708"]
350
- examples << ["ia64 hp server rx2660", "", "", "768", "536936708", "CPU v768 CHIP TYPE #536936708"]
351
- examples
352
- end
353
-
354
- sched_models = File.readlines(fixtures('hpux','sched.models'))
355
- unistd_h = File.readlines(fixtures('hpux','unistd.h'))
356
-
357
- describe "when machinfo is not available" do
358
- model_and_getconf_examples.each_with_index do |example, i|
359
- model_example, sm, unistd, getconf_cpu_ver, getconf_chip_type, expected_cpu = example
360
- context "and model and getconf example ##{i}" do
361
- before :each do
362
- Facter.fact(:kernel).stubs(:value).returns("HP-UX")
363
- Facter::Util::Processor.stubs(:ioscan).returns(ioscan)
364
- Facter::Util::Processor.stubs(:getconf_cpu_version).returns(getconf_cpu_ver)
365
- Facter::Util::Processor.stubs(:getconf_cpu_chip_type).returns(getconf_chip_type)
366
- Facter::Util::Processor.stubs(:machinfo).returns(nil)
367
- Facter::Util::Processor.stubs(:model).returns(model_example)
368
- end
369
-
370
- if unistd == "unistd.h_present" then
371
- before :each do
372
- Facter::Util::Processor.stubs(:read_unistd_h).returns(unistd_h)
373
- end
374
- else
375
- before :each do
376
- Facter::Util::Processor.stubs(:read_unistd_h).returns(nil)
377
- end
378
- end
379
-
380
- if sm == "sched.models_present" then
381
- before :each do
382
- Facter::Util::Processor.stubs(:read_sched_models).returns(sched_models)
383
- Facter.collection.internal_loader.load(:processor)
384
- end
385
- else
386
- before :each do
387
- Facter::Util::Processor.stubs(:read_sched_models).returns(nil)
388
- Facter.collection.internal_loader.load(:processor)
389
- end
390
- end
391
-
392
- %w{ 0 1 }.each do |j|
393
- it "should find #{expected_cpu}" do
394
- Facter.value("processor#{j}").should == expected_cpu
395
- end
396
- end
397
- end
398
- end
35
+ Facter.fact(:processor).value.should eq "SomeVendor CPU 4.2GHz"
399
36
  end
400
37
  end
401
38
  end