facter 1.6.1 → 1.6.2

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 (88) hide show
  1. data/CHANGELOG +31 -0
  2. data/Rakefile +41 -36
  3. data/conf/redhat/facter.spec +11 -4
  4. data/conf/solaris/pkginfo +1 -1
  5. data/install.rb +286 -286
  6. data/lib/facter.rb +211 -211
  7. data/lib/facter/Cfkey.rb +24 -24
  8. data/lib/facter/application.rb +1 -0
  9. data/lib/facter/architecture.rb +21 -29
  10. data/lib/facter/domain.rb +34 -34
  11. data/lib/facter/facterversion.rb +1 -1
  12. data/lib/facter/fqdn.rb +8 -8
  13. data/lib/facter/hardwareisa.rb +2 -2
  14. data/lib/facter/hardwaremodel.rb +12 -12
  15. data/lib/facter/hostname.rb +14 -14
  16. data/lib/facter/id.rb +3 -3
  17. data/lib/facter/interfaces.rb +13 -13
  18. data/lib/facter/ipaddress.rb +101 -101
  19. data/lib/facter/iphostnumber.rb +12 -12
  20. data/lib/facter/kernel.rb +7 -7
  21. data/lib/facter/kernelmajversion.rb +3 -3
  22. data/lib/facter/kernelrelease.rb +12 -12
  23. data/lib/facter/kernelversion.rb +5 -5
  24. data/lib/facter/lsb.rb +14 -14
  25. data/lib/facter/lsbmajdistrelease.rb +8 -8
  26. data/lib/facter/macaddress.rb +44 -44
  27. data/lib/facter/macosx.rb +21 -21
  28. data/lib/facter/manufacturer.rb +28 -28
  29. data/lib/facter/memory.rb +143 -115
  30. data/lib/facter/netmask.rb +4 -4
  31. data/lib/facter/network.rb +4 -4
  32. data/lib/facter/operatingsystem.rb +73 -69
  33. data/lib/facter/operatingsystemrelease.rb +85 -79
  34. data/lib/facter/osfamily.rb +31 -0
  35. data/lib/facter/path.rb +3 -3
  36. data/lib/facter/physicalprocessorcount.rb +8 -0
  37. data/lib/facter/processor.rb +91 -72
  38. data/lib/facter/ps.rb +3 -3
  39. data/lib/facter/puppetversion.rb +7 -7
  40. data/lib/facter/rubysitedir.rb +5 -5
  41. data/lib/facter/rubyversion.rb +1 -1
  42. data/lib/facter/ssh.rb +16 -16
  43. data/lib/facter/timezone.rb +3 -3
  44. data/lib/facter/uniqueid.rb +2 -2
  45. data/lib/facter/util/collection.rb +96 -96
  46. data/lib/facter/util/confine.rb +30 -30
  47. data/lib/facter/util/fact.rb +95 -95
  48. data/lib/facter/util/ip.rb +173 -173
  49. data/lib/facter/util/loader.rb +88 -88
  50. data/lib/facter/util/macosx.rb +46 -46
  51. data/lib/facter/util/manufacturer.rb +78 -78
  52. data/lib/facter/util/memory.rb +63 -63
  53. data/lib/facter/util/netmask.rb +34 -34
  54. data/lib/facter/util/plist.rb +1 -1
  55. data/lib/facter/util/plist/generator.rb +177 -177
  56. data/lib/facter/util/plist/parser.rb +166 -166
  57. data/lib/facter/util/processor.rb +88 -0
  58. data/lib/facter/util/resolution.rb +154 -154
  59. data/lib/facter/util/uptime.rb +42 -42
  60. data/lib/facter/util/values.rb +9 -9
  61. data/lib/facter/util/virtual.rb +68 -58
  62. data/lib/facter/util/vlans.rb +17 -17
  63. data/lib/facter/virtual.rb +105 -110
  64. data/lib/facter/vlans.rb +6 -6
  65. data/spec/fixtures/cpuinfo/amd64dual +57 -0
  66. data/spec/fixtures/cpuinfo/amd64quad +79 -0
  67. data/spec/fixtures/cpuinfo/amd64solo +23 -0
  68. data/spec/fixtures/cpuinfo/amd64tri +86 -0
  69. data/spec/fixtures/cpuinfo/bbg3-armel +12 -0
  70. data/spec/fixtures/cpuinfo/beaglexm-armel +12 -0
  71. data/spec/fixtures/cpuinfo/panda-armel +17 -0
  72. data/spec/fixtures/cpuinfo/ppc64 +19 -0
  73. data/spec/fixtures/cpuinfo/sparc +10 -0
  74. data/spec/fixtures/processorcount/solaris-sparc-kstat-cpu-info +1216 -0
  75. data/spec/fixtures/processorcount/solaris-x86_64-kstat-cpu-info +225 -0
  76. data/spec/integration/facter_spec.rb +18 -18
  77. data/spec/spec_helper.rb +10 -1
  78. data/spec/unit/architecture_spec.rb +54 -0
  79. data/spec/unit/domain_spec.rb +23 -0
  80. data/spec/unit/memory_spec.rb +78 -1
  81. data/spec/unit/physicalprocessorcount_spec.rb +41 -35
  82. data/spec/unit/processor_spec.rb +183 -2
  83. data/spec/unit/util/processor_spec.rb +62 -0
  84. data/spec/unit/util/uptime_spec.rb +4 -4
  85. data/spec/unit/util/virtual_spec.rb +26 -5
  86. data/spec/unit/virtual_spec.rb +47 -2
  87. data/spec/watchr.rb +125 -0
  88. metadata +20 -4
@@ -1,51 +1,57 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env rspec
2
2
 
3
3
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
4
 
5
- require 'facter'
6
-
7
5
  describe "Physical processor count facts" do
8
- before do
9
- Facter.loadfacts
10
- end
11
- before do
12
- Facter.clear
6
+
7
+ describe "on linux" do
8
+ before :each do
9
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
10
+ File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true)
13
11
  end
12
+
14
13
  it "should return one physical CPU" do
15
- Facter.fact(:kernel).stubs(:value).returns("Linux")
16
- File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true)
17
- Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns(["/sys/devices/system/cpu/cpu0/topology/physical_package_id"])
18
- Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu0/topology/physical_package_id").returns("0")
14
+ Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns(["/sys/devices/system/cpu/cpu0/topology/physical_package_id"])
15
+ Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu0/topology/physical_package_id").returns("0")
19
16
 
20
- Facter.fact(:physicalprocessorcount).value.should == 1
17
+ Facter.fact(:physicalprocessorcount).value.should == 1
21
18
  end
22
19
 
23
20
  it "should return four physical CPUs" do
24
- Facter.fact(:kernel).stubs(:value).returns("Linux")
25
- File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true)
26
- Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns(%w{
27
- /sys/devices/system/cpu/cpu0/topology/physical_package_id
28
- /sys/devices/system/cpu/cpu1/topology/physical_package_id
29
- /sys/devices/system/cpu/cpu2/topology/physical_package_id
30
- /sys/devices/system/cpu/cpu3/topology/physical_package_id
31
- })
32
-
33
- Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu0/topology/physical_package_id").returns("0")
34
- Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu1/topology/physical_package_id").returns("1")
35
- Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu2/topology/physical_package_id").returns("2")
36
- Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu3/topology/physical_package_id").returns("3")
37
-
38
- Facter.fact(:physicalprocessorcount).value.should == 4
21
+ Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns(%w{
22
+ /sys/devices/system/cpu/cpu0/topology/physical_package_id
23
+ /sys/devices/system/cpu/cpu1/topology/physical_package_id
24
+ /sys/devices/system/cpu/cpu2/topology/physical_package_id
25
+ /sys/devices/system/cpu/cpu3/topology/physical_package_id
26
+ })
27
+
28
+ Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu0/topology/physical_package_id").returns("0")
29
+ Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu1/topology/physical_package_id").returns("1")
30
+ Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu2/topology/physical_package_id").returns("2")
31
+ Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu3/topology/physical_package_id").returns("3")
32
+
33
+ Facter.fact(:physicalprocessorcount).value.should == 4
39
34
  end
35
+ end
36
+
37
+ describe "on windows" do
38
+ it "should return 4 physical CPUs" do
39
+ Facter.fact(:kernel).stubs(:value).returns("windows")
40
40
 
41
- it "should return 4 physical CPUs on Windows" do
42
- Facter.fact(:kernel).stubs(:value).returns("windows")
41
+ require 'facter/util/wmi'
42
+ ole = stub 'WIN32OLE'
43
+ Facter::Util::WMI.expects(:execquery).with("select Name from Win32_Processor").returns(ole)
44
+ ole.stubs(:Count).returns(4)
43
45
 
44
- require 'facter/util/wmi'
45
- ole = stub 'WIN32OLE'
46
- Facter::Util::WMI.expects(:execquery).with("select Name from Win32_Processor").returns(ole)
47
- ole.stubs(:Count).returns(4)
46
+ Facter.fact(:physicalprocessorcount).value.should == 4
47
+ end
48
+ end
48
49
 
49
- Facter.fact(:physicalprocessorcount).value.should == 4
50
+ describe "on solaris" do
51
+ it "should use the output of psrinfo" do
52
+ Facter.fact(:kernel).stubs(:value).returns(:sunos)
53
+ Facter::Util::Resolution.expects(:exec).with("/usr/sbin/psrinfo -p").returns(1)
54
+ Facter.fact(:physicalprocessorcount).value.should == 1
50
55
  end
56
+ end
51
57
  end
@@ -1,9 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
+ $basedir = File.expand_path(File.dirname(__FILE__) + '/..')
4
+ require File.join($basedir, 'spec_helper')
4
5
 
5
6
  require 'facter'
6
7
 
8
+ def cpuinfo_fixture(filename)
9
+ cpuinfo = File.open(File.join($basedir, 'fixtures', 'cpuinfo', filename)).readlines
10
+ end
11
+
7
12
  describe "Processor facts" do
8
13
  describe "on Windows" do
9
14
  before :each do
@@ -61,6 +66,182 @@ describe "Processor facts" do
61
66
  end
62
67
  end
63
68
  end
64
- end
65
69
 
70
+ describe "on Solaris" do
71
+ before :each do
72
+ Facter.collection.loader.load(:processor)
73
+ Facter.fact(:kernel).stubs(:value).returns(:sunos)
74
+ end
75
+
76
+ it "should detect the correct processor count on x86_64" do
77
+ fixture_data = File.read(File.expand_path(File.dirname(__FILE__) + '/../fixtures/processorcount/solaris-x86_64-kstat-cpu-info'))
78
+ Facter::Util::Resolution.expects(:exec).with("/usr/bin/kstat cpu_info").returns(fixture_data)
79
+ Facter.fact(:processorcount).value.should == 8
80
+ end
81
+
82
+ it "should detect the correct processor count on sparc" do
83
+ fixture_data = File.read(File.expand_path(File.dirname(__FILE__) + '/../fixtures/processorcount/solaris-sparc-kstat-cpu-info'))
84
+ Facter::Util::Resolution.expects(:exec).with("/usr/bin/kstat cpu_info").returns(fixture_data)
85
+ Facter.fact(:processorcount).value.should == 8
86
+ end
87
+ end
88
+
89
+ describe "on Unixes" do
90
+ before :each do
91
+ Facter.collection.loader.load(:processor)
92
+ end
93
+
94
+ it "should be 1 in SPARC fixture" do
95
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
96
+ Facter.fact(:operatingsystem).stubs(:value).returns("Linux")
97
+ Facter.fact(:architecture).stubs(:value).returns("sparc")
98
+ File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
99
+ File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("sparc"))
100
+
101
+ Facter.fact(:processorcount).value.should == "1"
102
+ end
103
+
104
+ it "should be 2 in ppc64 fixture on Linux" do
105
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
106
+ Facter.fact(:architecture).stubs(:value).returns("ppc64")
107
+ File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
108
+ File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("ppc64"))
109
+
110
+ Facter.fact(:processorcount).value.should == "2"
111
+ end
112
+
113
+ it "should be 2 in panda-armel fixture on Linux" do
114
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
115
+ Facter.fact(:architecture).stubs(:value).returns("arm")
116
+ File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
117
+ File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("panda-armel"))
118
+
119
+ Facter.fact(:processorcount).value.should == "2"
120
+ end
121
+
122
+ it "should be 1 in bbg3-armel fixture on Linux" do
123
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
124
+ Facter.fact(:architecture).stubs(:value).returns("arm")
125
+ File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
126
+ File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("bbg3-armel"))
127
+
128
+ Facter.fact(:processorcount).value.should == "1"
129
+ end
130
+
131
+ it "should be 1 in beaglexm-armel fixture on Linux" do
132
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
133
+ Facter.fact(:architecture).stubs(:value).returns("arm")
134
+ File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
135
+ File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("beaglexm-armel"))
136
+
137
+ Facter.fact(:processorcount).value.should == "1"
138
+ end
139
+
140
+ it "should be 1 in amd64solo fixture on Linux" do
141
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
142
+ Facter.fact(:architecture).stubs(:value).returns("amd64")
143
+ File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
144
+ File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64solo"))
145
+
146
+ Facter.fact(:processorcount).value.should == "1"
147
+ end
148
+
149
+ it "should be 2 in amd64dual fixture on Linux" do
150
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
151
+ Facter.fact(:architecture).stubs(:value).returns("amd64")
152
+ File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
153
+ File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64dual"))
154
+
155
+ Facter.fact(:processorcount).value.should == "2"
156
+ end
157
+
158
+ it "should be 3 in amd64tri fixture on Linux" do
159
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
160
+ Facter.fact(:architecture).stubs(:value).returns("amd64")
161
+ File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
162
+ File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64tri"))
163
+
164
+ Facter.fact(:processorcount).value.should == "3"
165
+ end
166
+
167
+ it "should be 4 in amd64quad fixture on Linux" do
168
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
169
+ Facter.fact(:architecture).stubs(:value).returns("amd64")
170
+ File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
171
+ File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64quad"))
172
+
173
+ Facter.fact(:processorcount).value.should == "4"
174
+ end
175
+
176
+ it "should be 2 on dual-processor Darwin box" do
177
+ Facter.fact(:kernel).stubs(:value).returns("Darwin")
178
+ Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
179
+
180
+ Facter.fact(:processorcount).value.should == "2"
181
+ end
182
+
183
+ it "should be 2 on dual-processor OpenBSD box" do
184
+ Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
185
+ Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
186
+
187
+ Facter.fact(:processorcount).value.should == "2"
188
+ end
66
189
 
190
+ it "should be 2 on dual-processor DragonFly box" do
191
+ Facter.fact(:kernel).stubs(:value).returns("DragonFly")
192
+ Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
193
+
194
+ Facter.fact(:processorcount).value.should == "2"
195
+ end
196
+
197
+ it "should be 6 on six-processor AIX box" do
198
+ Facter.fact(:kernel).stubs(:value).returns("AIX")
199
+ Facter::Util::Resolution.stubs(:exec).with("lsdev -Cc processor").returns("proc0 Available 00-00 Processor\nproc2 Available 00-02 Processor\nproc4 Available 00-04 Processor\nproc6 Available 00-06 Processor\nproc8 Available 00-08 Processor\nproc10 Available 00-10 Processor")
200
+ Facter::Util::Resolution.stubs(:exec).with("lsattr -El proc0 -a type").returns("type PowerPC_POWER3 Processor type False")
201
+
202
+ Facter.fact(:processorcount).value.should == "6"
203
+ end
204
+
205
+ it "should be 2 via sysfs when cpu0 and cpu1 are present" do
206
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
207
+ File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true)
208
+ ## sysfs method is only used if cpuinfo method returned no processors
209
+ File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
210
+ File.stubs(:readlines).with("/proc/cpuinfo").returns("")
211
+ Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu[0-9]*").returns(%w{
212
+ /sys/devices/system/cpu/cpu0
213
+ /sys/devices/system/cpu/cpu1
214
+ })
215
+
216
+ Facter.fact(:processorcount).value.should == "2"
217
+ end
218
+
219
+ it "should be 16 via sysfs when cpu0 through cpu15 are present" do
220
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
221
+ File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true)
222
+ ## sysfs method is only used if cpuinfo method returned no processors
223
+ File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
224
+ File.stubs(:readlines).with("/proc/cpuinfo").returns("")
225
+ Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu[0-9]*").returns(%w{
226
+ /sys/devices/system/cpu/cpu0
227
+ /sys/devices/system/cpu/cpu1
228
+ /sys/devices/system/cpu/cpu2
229
+ /sys/devices/system/cpu/cpu3
230
+ /sys/devices/system/cpu/cpu4
231
+ /sys/devices/system/cpu/cpu5
232
+ /sys/devices/system/cpu/cpu6
233
+ /sys/devices/system/cpu/cpu7
234
+ /sys/devices/system/cpu/cpu8
235
+ /sys/devices/system/cpu/cpu9
236
+ /sys/devices/system/cpu/cpu10
237
+ /sys/devices/system/cpu/cpu11
238
+ /sys/devices/system/cpu/cpu12
239
+ /sys/devices/system/cpu/cpu13
240
+ /sys/devices/system/cpu/cpu14
241
+ /sys/devices/system/cpu/cpu15
242
+ })
243
+
244
+ Facter.fact(:processorcount).value.should == "16"
245
+ end
246
+ end
247
+ end
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $basedir = File.expand_path(File.dirname(__FILE__) + '/../..')
4
+ require File.join($basedir, 'spec_helper')
5
+
6
+ require 'facter/util/processor'
7
+
8
+ def cpuinfo_fixture(filename)
9
+ cpuinfo = File.open(File.join($basedir, 'fixtures', 'cpuinfo', filename)).readlines
10
+ end
11
+
12
+ describe Facter::Util::Processor do
13
+ it "should get the processor description from the amd64solo fixture" do
14
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
15
+ Facter.fact(:architecture).stubs(:value).returns("amd64")
16
+ File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
17
+ File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64solo"))
18
+
19
+ Facter::Util::Processor.enum_cpuinfo[0].should == "Intel(R) Core(TM)2 Duo CPU P8700 @ 2.53GHz"
20
+ end
21
+
22
+ it "should get the processor descriptions from the amd64dual fixture" do
23
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
24
+ Facter.fact(:architecture).stubs(:value).returns("amd64")
25
+ File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
26
+ File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64dual"))
27
+
28
+ Facter::Util::Processor.enum_cpuinfo[0].should == "Intel(R) Core(TM)2 Duo CPU P8700 @ 2.53GHz"
29
+ Facter::Util::Processor.enum_cpuinfo[1].should == "Intel(R) Core(TM)2 Duo CPU P8700 @ 2.53GHz"
30
+ end
31
+
32
+ it "should get the processor descriptions from the amd64tri fixture" do
33
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
34
+ Facter.fact(:architecture).stubs(:value).returns("amd64")
35
+ File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
36
+ File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64tri"))
37
+
38
+ Facter::Util::Processor.enum_cpuinfo[0].should == "Intel(R) Core(TM)2 Duo CPU P8700 @ 2.53GHz"
39
+ Facter::Util::Processor.enum_cpuinfo[1].should == "Intel(R) Core(TM)2 Duo CPU P8700 @ 2.53GHz"
40
+ Facter::Util::Processor.enum_cpuinfo[2].should == "Intel(R) Core(TM)2 Duo CPU P8700 @ 2.53GHz"
41
+ end
42
+
43
+ it "should get the processor descriptions from the amd64quad fixture" do
44
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
45
+ Facter.fact(:architecture).stubs(:value).returns("amd64")
46
+ File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
47
+ File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64quad"))
48
+
49
+ Facter::Util::Processor.enum_cpuinfo[0].should == "Quad-Core AMD Opteron(tm) Processor 2374 HE"
50
+ Facter::Util::Processor.enum_cpuinfo[1].should == "Quad-Core AMD Opteron(tm) Processor 2374 HE"
51
+ Facter::Util::Processor.enum_cpuinfo[2].should == "Quad-Core AMD Opteron(tm) Processor 2374 HE"
52
+ Facter::Util::Processor.enum_cpuinfo[3].should == "Quad-Core AMD Opteron(tm) Processor 2374 HE"
53
+ end
54
+
55
+ it "should get the processor type on AIX box" do
56
+ Facter.fact(:kernel).stubs(:value).returns("AIX")
57
+ Facter::Util::Resolution.stubs(:exec).with("lsdev -Cc processor").returns("proc0 Available 00-00 Processor\nproc2 Available 00-02 Processor\nproc4 Available 00-04 Processor\nproc6 Available 00-06 Processor\nproc8 Available 00-08 Processor\nproc10 Available 00-10 Processor")
58
+ Facter::Util::Resolution.stubs(:exec).with("lsattr -El proc0 -a type").returns("type PowerPC_POWER3 Processor type False")
59
+
60
+ Facter::Util::Processor.enum_lsdev[0].should == "PowerPC_POWER3"
61
+ end
62
+ end
@@ -28,10 +28,10 @@ describe Facter::Util::Uptime do
28
28
 
29
29
  it "should use 'sysctl kern.boottime'" do
30
30
  if [1].pack("L") == [1].pack("V") # Determine endianness
31
- sysctl_output_filename = 'sysctl_kern_boottime_little_endian'
32
- else
33
- sysctl_output_filename = 'sysctl_kern_boottime_big_endian'
34
- end
31
+ sysctl_output_filename = 'sysctl_kern_boottime_little_endian'
32
+ else
33
+ sysctl_output_filename = 'sysctl_kern_boottime_big_endian'
34
+ end
35
35
  sysctl_output_file = File.join(SPECDIR, 'fixtures', 'uptime', sysctl_output_filename) # Aug 01 14:13:47 -0700 2010
36
36
  Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat \"#{sysctl_output_file}\"")
37
37
  Time.stubs(:now).returns Time.parse("Aug 01 15:13:47 -0700 2010") # one hour later
@@ -9,22 +9,43 @@ describe Facter::Util::Virtual do
9
9
  end
10
10
  it "should detect openvz" do
11
11
  FileTest.stubs(:directory?).with("/proc/vz").returns(true)
12
- FileTest.stubs(:exists?).with("/proc/vz/veinfo").returns(true)
12
+ Dir.stubs(:glob).with("/proc/vz/*").returns(['vzquota'])
13
13
  Facter::Util::Virtual.should be_openvz
14
14
  end
15
15
 
16
- it "should identify openvzhn when version file exists" do
16
+ it "should not detect openvz when /proc/lve/list is present" do
17
+ FileTest.stubs(:file?).with("/proc/lve/list").returns(true)
18
+ Facter::Util::Virtual.should_not be_openvz
19
+ end
20
+
21
+ it "should not detect openvz when /proc/vz/ is empty" do
22
+ FileTest.stubs(:file?).with("/proc/lve/list").returns(false)
23
+ FileTest.stubs(:directory?).with("/proc/vz").returns(true)
24
+ Dir.stubs(:glob).with("/proc/vz/*").returns([])
25
+ Facter::Util::Virtual.should_not be_openvz
26
+ end
27
+
28
+ it "should identify openvzhn when /proc/self/status has envID of 0" do
17
29
  Facter::Util::Virtual.stubs(:openvz?).returns(true)
18
- FileTest.stubs(:exists?).with("/proc/vz/version").returns(true)
30
+ FileTest.stubs(:exists?).with("/proc/self/status").returns(true)
31
+ Facter::Util::Resolution.stubs(:exec).with('grep "envID" /proc/self/status').returns("envID: 0")
19
32
  Facter::Util::Virtual.openvz_type().should == "openvzhn"
20
33
  end
21
34
 
22
- it "should identify openvzve when no version file exists" do
35
+ it "should identify openvzve when /proc/self/status has envID of 0" do
23
36
  Facter::Util::Virtual.stubs(:openvz?).returns(true)
24
- FileTest.stubs(:exists?).with("/proc/vz/version").returns(false)
37
+ FileTest.stubs(:exists?).with('/proc/self/status').returns(true)
38
+ Facter::Util::Resolution.stubs(:exec).with('grep "envID" /proc/self/status').returns("envID: 666")
25
39
  Facter::Util::Virtual.openvz_type().should == "openvzve"
26
40
  end
27
41
 
42
+ it "should not attempt to identify openvz when /proc/self/status has no envID" do
43
+ Facter::Util::Virtual.stubs(:openvz?).returns(true)
44
+ FileTest.stubs(:exists?).with('/proc/self/status').returns(true)
45
+ Facter::Util::Resolution.stubs(:exec).with('grep "envID" /proc/self/status').returns("")
46
+ Facter::Util::Virtual.openvz_type().should be_nil
47
+ end
48
+
28
49
  it "should identify Solaris zones when non-global zone" do
29
50
  Facter::Util::Resolution.stubs(:exec).with("/sbin/zonename").returns("somezone")
30
51
  Facter::Util::Virtual.should be_zone
@@ -72,8 +72,12 @@ describe "Virtual fact" do
72
72
  describe "on Linux" do
73
73
 
74
74
  before do
75
- Facter::Util::Resolution.expects(:exec).with("vmware -v").returns false
75
+ Facter::Util::Resolution.stubs(:exec).with("vmware -v").returns false
76
76
  Facter.fact(:operatingsystem).stubs(:value).returns(true)
77
+ # Ensure the tests don't fail on Xen
78
+ FileTest.stubs(:exists?).with("/proc/sys/xen").returns false
79
+ FileTest.stubs(:exists?).with("/sys/bus/xen").returns false
80
+ FileTest.stubs(:exists?).with("/proc/xen").returns false
77
81
  Facter.fact(:architecture).stubs(:value).returns(true)
78
82
  end
79
83
 
@@ -135,14 +139,28 @@ describe "Virtual fact" do
135
139
  Facter.fact(:virtual).value.should == "virtualbox"
136
140
  end
137
141
 
142
+ it "should be hyperv with Microsoft vendor name from lspci" do
143
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
144
+ Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:08.0 VGA compatible controller: Microsoft Corporation Hyper-V virtual VGA")
145
+ Facter.fact(:virtual).value.should == "hyperv"
146
+ end
147
+
148
+ it "should be hyperv with Microsoft vendor name from dmidecode" do
149
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
150
+ Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
151
+ Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("System Information\nManufacturer: Microsoft Corporation\nProduct Name: Virtual Machine")
152
+ Facter.fact(:virtual).value.should == "hyperv"
153
+ end
154
+
138
155
  end
139
156
  describe "on Solaris" do
140
157
  before(:each) do
141
- Facter::Util::Resolution.expects(:exec).with("vmware -v").returns false
158
+ Facter::Util::Resolution.stubs(:exec).with("vmware -v").returns false
142
159
  end
143
160
 
144
161
  it "should be vmware with VMWare vendor name from prtdiag" do
145
162
  Facter.fact(:kernel).stubs(:value).returns("SunOS")
163
+ Facter.fact(:hardwaremodel).stubs(:value).returns(nil)
146
164
  Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
147
165
  Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil)
148
166
  Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: VMware, Inc. VMware Virtual Platform")
@@ -151,6 +169,7 @@ describe "Virtual fact" do
151
169
 
152
170
  it "should be parallels with Parallels vendor name from prtdiag" do
153
171
  Facter.fact(:kernel).stubs(:value).returns("SunOS")
172
+ Facter.fact(:hardwaremodel).stubs(:value).returns(nil)
154
173
  Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
155
174
  Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil)
156
175
  Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: Parallels Virtual Platform")
@@ -159,11 +178,31 @@ describe "Virtual fact" do
159
178
 
160
179
  it "should be virtualbox with VirtualBox vendor name from prtdiag" do
161
180
  Facter.fact(:kernel).stubs(:value).returns("SunOS")
181
+ Facter.fact(:hardwaremodel).stubs(:value).returns(nil)
162
182
  Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
163
183
  Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil)
164
184
  Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: innotek GmbH VirtualBox")
165
185
  Facter.fact(:virtual).value.should == "virtualbox"
166
186
  end
187
+
188
+ it "should be xen0 with xen dom0 files in /proc" do
189
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
190
+ Facter.fact(:operatingsystem).stubs(:value).returns("Linux")
191
+ Facter.fact(:hardwaremodel).stubs(:value).returns("i386")
192
+ Facter::Util::Virtual.expects(:xen?).returns(true)
193
+ FileTest.expects(:exists?).with("/proc/xen/xsd_kva").returns(true)
194
+ Facter.fact(:virtual).value.should == "xen0"
195
+ end
196
+
197
+ it "should be xenu with xen domU files in /proc" do
198
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
199
+ Facter.fact(:operatingsystem).stubs(:value).returns("Linux")
200
+ Facter.fact(:hardwaremodel).stubs(:value).returns("i386")
201
+ Facter::Util::Virtual.expects(:xen?).returns(true)
202
+ FileTest.expects(:exists?).with("/proc/xen/xsd_kva").returns(false)
203
+ FileTest.expects(:exists?).with("/proc/xen/capabilities").returns(true)
204
+ Facter.fact(:virtual).value.should == "xenu"
205
+ end
167
206
  end
168
207
  end
169
208
 
@@ -259,4 +298,10 @@ describe "is_virtual fact" do
259
298
  Facter.fact(:virtual).stubs(:value).returns("openvzhn")
260
299
  Facter.fact(:is_virtual).value.should == "false"
261
300
  end
301
+
302
+ it "should be true when running on hyperv" do
303
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
304
+ Facter.fact(:virtual).stubs(:value).returns("hyperv")
305
+ Facter.fact(:is_virtual).value.should == "true"
306
+ end
262
307
  end