facter 1.6.13 → 1.6.14.rc1

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 (90) hide show
  1. data/Rakefile +1 -5
  2. data/bin/facter +11 -0
  3. data/ext/redhat/facter.spec.erb +16 -15
  4. data/lib/facter/application.rb +0 -1
  5. data/lib/facter/hardwareisa.rb +7 -2
  6. data/lib/facter/physicalprocessorcount.rb +13 -1
  7. data/lib/facter/processor.rb +37 -39
  8. data/lib/facter/util/ip.rb +2 -2
  9. data/lib/facter/util/monkey_patches.rb +32 -0
  10. data/lib/facter/util/processor.rb +74 -23
  11. data/lib/facter/util/uptime.rb +27 -16
  12. data/lib/facter/util/virtual.rb +15 -0
  13. data/lib/facter/version.rb +1 -1
  14. data/lib/facter/virtual.rb +34 -1
  15. data/spec/fixtures/ifconfig/centos_5_5 +1 -1
  16. data/spec/fixtures/ifconfig/centos_5_5_eth0 +1 -1
  17. data/spec/fixtures/ifconfig/darwin_10_3_0 +1 -1
  18. data/spec/fixtures/ifconfig/darwin_10_3_0_en0 +1 -1
  19. data/spec/fixtures/ifconfig/darwin_9_8_0 +1 -1
  20. data/spec/fixtures/ifconfig/darwin_9_8_0_en0 +1 -1
  21. data/spec/fixtures/ifconfig/fedora_10 +1 -1
  22. data/spec/fixtures/ifconfig/fedora_10_eth0 +1 -1
  23. data/spec/fixtures/ifconfig/fedora_13 +1 -1
  24. data/spec/fixtures/ifconfig/fedora_13_eth0 +1 -1
  25. data/spec/fixtures/ifconfig/fedora_8 +1 -1
  26. data/spec/fixtures/ifconfig/fedora_8_eth0 +1 -1
  27. data/spec/fixtures/ifconfig/freebsd_6_0 +1 -1
  28. data/spec/fixtures/ifconfig/open_solaris_10 +1 -1
  29. data/spec/fixtures/ifconfig/open_solaris_b132 +1 -1
  30. data/spec/fixtures/ifconfig/ubuntu_7_04 +1 -1
  31. data/spec/fixtures/ifconfig/ubuntu_7_04_eth0 +1 -1
  32. data/spec/fixtures/netstat/centos_5_5 +1 -1
  33. data/spec/fixtures/netstat/darwin_10_3_0 +1 -1
  34. data/spec/fixtures/netstat/darwin_9_8_0 +1 -1
  35. data/spec/fixtures/netstat/fedora_10 +1 -1
  36. data/spec/fixtures/netstat/open_solaris_10 +1 -1
  37. data/spec/fixtures/netstat/open_solaris_b132 +1 -1
  38. data/spec/fixtures/netstat/ubuntu_7_04 +1 -1
  39. data/spec/fixtures/unit/util/ec2/centos-arp-ec2.out +1 -1
  40. data/spec/fixtures/unit/util/ec2/windows-2008-arp-a.out +1 -1
  41. data/spec/fixtures/unit/util/ip/6.0-STABLE_FreeBSD_ifconfig +1 -1
  42. data/spec/fixtures/unit/util/ip/linux_get_single_interface_ib0 +1 -1
  43. data/spec/fixtures/unit/util/ip/linux_ifconfig_all_with_single_interface +1 -1
  44. data/spec/fixtures/unit/util/ip/linux_ifconfig_ib0 +1 -1
  45. data/spec/fixtures/unit/util/ip/solaris_ifconfig_single_interface +1 -1
  46. data/spec/integration/facter_spec.rb +1 -1
  47. data/spec/unit/architecture_spec.rb +1 -1
  48. data/spec/unit/domain_spec.rb +1 -1
  49. data/spec/unit/ec2_spec.rb +1 -1
  50. data/spec/unit/facter_spec.rb +1 -1
  51. data/spec/unit/hardwareisa_spec.rb +7 -0
  52. data/spec/unit/hostname_spec.rb +1 -1
  53. data/spec/unit/id_spec.rb +1 -1
  54. data/spec/unit/interfaces_spec.rb +1 -1
  55. data/spec/unit/ipaddress6_spec.rb +1 -1
  56. data/spec/unit/lsbdistcodename_spec.rb +1 -1
  57. data/spec/unit/lsbdistdescription_spec.rb +1 -1
  58. data/spec/unit/lsbdistid_spec.rb +1 -1
  59. data/spec/unit/lsbdistrelease_spec.rb +1 -1
  60. data/spec/unit/lsbrelease_spec.rb +1 -1
  61. data/spec/unit/macaddress_spec.rb +1 -1
  62. data/spec/unit/memory_spec.rb +1 -1
  63. data/spec/unit/operatingsystem_spec.rb +1 -1
  64. data/spec/unit/operatingsystemrelease_spec.rb +1 -1
  65. data/spec/unit/physicalprocessorcount_spec.rb +24 -5
  66. data/spec/unit/processor_spec.rb +75 -9
  67. data/spec/unit/selinux_spec.rb +1 -1
  68. data/spec/unit/uptime_spec.rb +1 -1
  69. data/spec/unit/util/collection_spec.rb +1 -1
  70. data/spec/unit/util/config_spec.rb +1 -1
  71. data/spec/unit/util/confine_spec.rb +1 -1
  72. data/spec/unit/util/ec2_spec.rb +1 -1
  73. data/spec/unit/util/fact_spec.rb +1 -1
  74. data/spec/unit/util/ip_spec.rb +3 -3
  75. data/spec/unit/util/loader_spec.rb +1 -1
  76. data/spec/unit/util/macaddress_spec.rb +1 -1
  77. data/spec/unit/util/macosx_spec.rb +1 -1
  78. data/spec/unit/util/manufacturer_spec.rb +1 -1
  79. data/spec/unit/util/monkey_patches_spec.rb +42 -0
  80. data/spec/unit/util/processor_spec.rb +1 -9
  81. data/spec/unit/util/registry_spec.rb +1 -1
  82. data/spec/unit/util/resolution_spec.rb +1 -1
  83. data/spec/unit/util/uptime_spec.rb +61 -20
  84. data/spec/unit/util/virtual_spec.rb +1 -1
  85. data/spec/unit/util/vlans_spec.rb +1 -1
  86. data/spec/unit/util/wmi_spec.rb +1 -1
  87. data/spec/unit/util/xendomains_spec.rb +1 -1
  88. data/spec/unit/virtual_spec.rb +66 -34
  89. metadata +7 -7
  90. data/spec/fixtures/unit/util/uptime/who_b_boottime +0 -1
@@ -1,5 +1,6 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
+ require 'facter/util/processor'
3
4
  require 'spec_helper'
4
5
 
5
6
  def cpuinfo_fixture(filename)
@@ -70,6 +71,7 @@ describe "Processor facts" do
70
71
  before :each do
71
72
  Facter.collection.loader.load(:processor)
72
73
  Facter.fact(:kernel).stubs(:value).returns(:sunos)
74
+ Facter.stubs(:value).with(:kernelrelease).returns("5.10")
73
75
  end
74
76
 
75
77
  it "should detect the correct processor count on x86_64" do
@@ -193,14 +195,6 @@ describe "Processor facts" do
193
195
  Facter.fact(:processorcount).value.should == "2"
194
196
  end
195
197
 
196
- it "should be 6 on six-processor AIX box" do
197
- Facter.fact(:kernel).stubs(:value).returns("AIX")
198
- 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")
199
- Facter::Util::Resolution.stubs(:exec).with("lsattr -El proc0 -a type").returns("type PowerPC_POWER3 Processor type False")
200
-
201
- Facter.fact(:processorcount).value.should == "6"
202
- end
203
-
204
198
  it "should be 2 via sysfs when cpu0 and cpu1 are present" do
205
199
  Facter.fact(:kernel).stubs(:value).returns("Linux")
206
200
  File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true)
@@ -242,5 +236,77 @@ describe "Processor facts" do
242
236
 
243
237
  Facter.fact(:processorcount).value.should == "16"
244
238
  end
239
+
240
+ describe "on solaris" do
241
+ before :all do
242
+ @fixture_kstat_sparc = File.read(fixtures('processorcount','solaris-sparc-kstat-cpu-info'))
243
+ @fixture_kstat_x86_64 = File.read(fixtures('processorcount','solaris-x86_64-kstat-cpu-info'))
244
+ end
245
+
246
+ let(:psrinfo) do
247
+ "0 on-line since 10/16/2012 14:06:12\n" +
248
+ "1 on-line since 10/16/2012 14:06:14\n"
249
+ end
250
+
251
+ let(:kstat_sparc) { @fixture_kstat_sparc }
252
+ let(:kstat_x86_64) { @fixture_kstat_x86_64 }
253
+
254
+ %w{ 5.8 5.9 5.10 5.11 }.each do |release|
255
+ %w{ sparc x86_64 }.each do |arch|
256
+ it "uses kstat on release #{release} (#{arch})" do
257
+ Facter.fact(:kernel).stubs(:value).returns(:sunos)
258
+ Facter.stubs(:value).with(:kernelrelease).returns(release)
259
+
260
+ Facter::Util::Resolution.expects(:exec).with("/usr/bin/kstat cpu_info").returns(self.send("kstat_#{arch}".intern))
261
+ Facter.fact(:processorcount).value.should == 8
262
+ end
263
+ end
264
+ end
265
+
266
+ %w{ 5.5.1 5.6 5.7 }.each do |release|
267
+ it "uses psrinfo on release #{release}" do
268
+ Facter.fact(:kernel).stubs(:value).returns(:sunos)
269
+ Facter.stubs(:value).with(:kernelrelease).returns(release)
270
+
271
+ Facter::Util::Resolution.expects(:exec).with("/usr/sbin/psrinfo").returns(psrinfo)
272
+ Facter.fact(:physicalprocessorcount).value.should == "2"
273
+ end
274
+ end
275
+ end
276
+ end
277
+ end
278
+
279
+ describe "processorX facts" do
280
+ describe "on AIX" do
281
+ def self.lsdev_examples
282
+ examples = []
283
+ examples << "proc0 Available 00-00 Processor\n" +
284
+ "proc4 Available 00-04 Processor\n" +
285
+ "proc8 Defined 00-08 Processor\n" +
286
+ "proc12 Defined 00-12 Processor\n"
287
+ examples
288
+ end
289
+
290
+ let(:lsattr) do
291
+ "type PowerPC_POWER5 Processor type False\n"
292
+ end
293
+
294
+ lsdev_examples.each_with_index do |lsdev_example, i|
295
+ context "lsdev example ##{i}" do
296
+ before :each do
297
+ Facter.fact(:kernel).stubs(:value).returns("AIX")
298
+ Facter::Util::Processor.stubs(:lsdev).returns(lsdev_example)
299
+ Facter::Util::Processor.stubs(:lsattr).returns(lsattr)
300
+ Facter.collection.loader.load(:processor)
301
+ end
302
+
303
+ lsdev_example.split("\n").each_with_index do |line, idx|
304
+ aix_idx = idx * 4
305
+ it "maps proc#{aix_idx} to processor#{idx} (#11609)" do
306
+ Facter.value("processor#{idx}").should == "PowerPC_POWER5"
307
+ end
308
+ end
309
+ end
310
+ end
245
311
  end
246
312
  end
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/uptime'
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/collection'
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/config'
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/confine'
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/ec2'
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/fact'
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/ip'
@@ -228,8 +228,8 @@ describe Facter::Util::IP do
228
228
  it "should return fake macaddress information for infiniband on Linux when neither sysfs or /sbin/ip are available" do
229
229
  ifconfig_interface = my_fixture_read("linux_ifconfig_ib0")
230
230
 
231
- File.stubs(:exists?).with("/sys/class/net/ib0/address").returns(false)
232
- File.stubs(:exists?).with("/sbin/ip").returns(false)
231
+ File.expects(:exists?).with("/sys/class/net/ib0/address").returns(false)
232
+ File.expects(:exists?).with("/sbin/ip").returns(false)
233
233
  Facter::Util::IP.expects(:ifconfig_interface).with("ib0").returns(ifconfig_interface)
234
234
  Facter.stubs(:value).with(:kernel).returns("Linux")
235
235
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/loader'
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/macaddress'
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/macosx'
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/manufacturer'
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ require 'tempfile'
3
+
4
+ describe 'Monkey Patches' do
5
+ let(:subject) { "a b c d e f\ng h i j" }
6
+
7
+ context 'String' do
8
+ it "should respond to lines" do
9
+ subject.lines.to_a.should == ["a b c d e f\n", "g h i j"]
10
+ end
11
+ it "should accept a block" do
12
+ our_lines = []
13
+ subject.lines do |line| our_lines << line end
14
+ our_lines.should == ["a b c d e f\n", "g h i j"]
15
+ end
16
+ end
17
+
18
+ context 'IO' do
19
+ it "should respond to lines" do
20
+ our_lines = nil
21
+ Tempfile.open("lines") do | file |
22
+ file.write(subject)
23
+ file.flush
24
+ file.rewind
25
+ our_lines = file.lines.to_a
26
+ end
27
+ our_lines.should == ["a b c d e f\n", "g h i j"]
28
+ end
29
+ it "should accept a block" do
30
+ our_lines = []
31
+ file = Tempfile.new("lines")
32
+ file.write(subject)
33
+ file.flush
34
+ file.rewind
35
+ file.lines.each do |line| our_lines << line end
36
+ file.unlink
37
+ our_lines.should == ["a b c d e f\n", "g h i j"]
38
+ end
39
+ end
40
+
41
+ end
42
+
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/processor'
@@ -50,14 +50,6 @@ describe Facter::Util::Processor do
50
50
  Facter::Util::Processor.enum_cpuinfo[3].should == "Quad-Core AMD Opteron(tm) Processor 2374 HE"
51
51
  end
52
52
 
53
- it "should get the processor type on AIX box" do
54
- Facter.fact(:kernel).stubs(:value).returns("AIX")
55
- 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")
56
- Facter::Util::Resolution.stubs(:exec).with("lsattr -El proc0 -a type").returns("type PowerPC_POWER3 Processor type False")
57
-
58
- Facter::Util::Processor.enum_lsdev[0].should == "PowerPC_POWER3"
59
- end
60
-
61
53
  it "should get the processor description on Solaris (x86)" do
62
54
  Facter.fact(:kernel).stubs(:value).returns("SunOS")
63
55
  Facter.fact(:architecture).stubs(:value).returns("i86pc")
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
  require 'spec_helper'
3
3
  require 'facter/operatingsystem'
4
4
  require 'facter/util/registry'
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/resolution'
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/uptime'
@@ -41,31 +41,72 @@ describe Facter::Util::Uptime do
41
41
 
42
42
  describe "nor is 'sysctl kern.boottime'" do
43
43
  before :each do
44
- Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat \"#{@nonexistent_file}\"")
44
+ Facter::Util::Uptime.stubs(:uptime_proc_uptime).returns(false)
45
+ Facter::Util::Uptime.stubs(:uptime_sysctl).returns(false)
46
+ Facter.fact(:kernel).stubs(:value).returns('SunOS')
45
47
  end
46
48
 
47
- it "should use 'kstat -p unix:::boot_time'" do
48
- kstat_output_file = my_fixture('kstat_boot_time') # unix:0:system_misc:boot_time 1236919980
49
- Facter::Util::Uptime.stubs(:uptime_kstat_cmd).returns("cat \"#{kstat_output_file}\"")
50
- Time.stubs(:now).returns Time.at(1236923580) #one hour later
51
- Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60
52
- end
53
-
54
- describe "nor is 'kstat -p unix:::boot_time'" do
55
- before :each do
56
- Facter::Util::Uptime.stubs(:uptime_kstat_cmd).returns("cat \"#{@nonexistent_file}\"")
57
- end
49
+ describe "should use 'uptime' command" do
50
+ # Note about uptime variations.
51
+ # Solaris (I have examined 5.6, 5.7, 5.8, 5.9, 5.10 & 5.11) and HP-UX (11.00, 11.11, 11.23, 11.31) have time
52
+ # right justified at at 8 characters, and two spaces before 'up'.
53
+ # Solaris differs from all other Unices (and Linux) in that the plural/singular case of minutes/hours/days are
54
+ # written min(s)/hr(s)/day(s) instead of min/mins/hr/hrs etc., e.g. 1 min(s), 2 min(s) as opposed to
55
+ # 1 min, 2 mins, etc.
56
+ # AIX (4.3.3, 5.2, 5.3, 6.1) differs from other SysV Unices in that times are padded with a leading 0 in the
57
+ # hour column where necessary, and have AM/PM in uppercase, and there are three spaces before 'up'.
58
+ # Tru64 (4.0, 5.1) differs from other SysV Unices in that times are in 24 hour format, and there are no
59
+ # leading spaces.
60
+ # Linux (RHEL, uptime version 2.0.7) differs from the SysV Unices in that only minutes before the first hour
61
+ # are written as 1 min, 2 min, 3 min etc. and after that full hours are rendered 1:00 or 21:00. Time of
62
+ # day was written 5:37pm and right-justified at 8 characters, with 2 spaces before 'up'. A figure in
63
+ # whole days was written as 3 days, 0 min.
64
+ # By version 2.0.17 the time of day was rewritten in 24hr time with seconds, right-justified at 9 characters.
65
+ # By version 3.2.7 one of the spaces before 'up' had been removed.
66
+ test_cases = [
67
+ [' 4:42pm up 1 min(s), 0 users, load average: 0.95, 0.25, 0.09', 1*60],
68
+ ['13:16 up 58 mins, 2 users, load average: 0.00, 0.02, 0.05', 58*60],
69
+ ['13:18 up 1 hr, 1 user, load average: 0.58, 0.23, 0.14', 1*60*60 ],
70
+ [' 10:14pm up 3 hr(s), 0 users, load average: 0.00, 0.00, 0.00', 3*60*60 ],
71
+ ['14:18 up 2 hrs, 0 users, load average: 0.33, 0.27, 0.29', 2*60*60 ],
72
+ [' 9:01pm up 1:47, 0 users, load average: 0.00, 0.00, 0.00', 1*60*60 + 47*60],
73
+ ['13:19 up 1:01, 1 user, load average: 0.10, 0.26, 0.21', 1*60*60 + 1*60],
74
+ ['10:49 up 22:31, 0 users, load average: 0.26, 0.34, 0.27', 22*60*60 + 31*60],
75
+ ['12:18 up 1 day, 0 users, load average: 0.74, 0.20, 0.10', 1*24*60*60 ],
76
+ [' 2:48pm up 1 day(s), 0 users, load average: 0.21, 0.20, 0.17', 1*24*60*60 ],
77
+ ['12:18 up 2 days, 0 users, load average: 0.50, 0.27, 0.16', 2*24*60*60 ],
78
+ [' 1:56pm up 25 day(s), 2 users, load average: 0.59, 0.56, 0.50', 25*24*60*60 ],
79
+ [' 1:29pm up 485 days, 0 users, load average: 0.00, 0.01, 0.01', 485*24*60*60 ],
80
+ [' 18:11:24 up 69 days, 0 min, 0 users, load average: 0.00, 0.00, 0.00', 69*24*60*60 ],
81
+ ['12:19 up 1 day, 1 min, 0 users, load average: 0.07, 0.16, 0.13', 1*24*60*60 + 1*60],
82
+ [' 3:23pm up 25 day(s), 27 min(s), 2 users, load average: 0.49, 0.45, 0.46', 25*24*60*60 + 27*60],
83
+ [' 02:42PM up 1 day, 39 mins, 0 users, load average: 1.49, 1.74, 1.80', 1*24*60*60 + 39*60],
84
+ [' 18:13:13 up 245 days, 44 min, 1 user, load average: 0.00, 0.00, 0.00', 245*24*60*60 + 44*60],
85
+ [' 6:09pm up 350 days, 2 min, 1 user, load average: 0.02, 0.03, 0.00', 350*24*60*60 + 2*60],
86
+ [' 1:07pm up 174 day(s), 16 hr(s), 0 users, load average: 0.05, 0.04, 0.03', 174*24*60*60 + 16*60*60 ],
87
+ [' 02:34PM up 621 days, 18 hrs, 0 users, load average: 2.67, 2.52, 2.56', 621*24*60*60 + 18*60*60 ],
88
+ [' 3:30am up 108 days, 1 hr, 31 users, load average: 0.39, 0.40, 0.41', 108*24*60*60 + 1*60*60 ],
89
+ ['13:18 up 1 day, 1 hr, 0 users, load average: 0.78, 0.33, 0.18', 1*24*60*60 + 1*60*60 ],
90
+ ['14:18 up 1 day, 2 hrs, 0 users, load average: 1.17, 0.48, 0.41', 1*24*60*60 + 2*60*60 ],
91
+ ['15:56 up 152 days, 17 hrs, 0 users, load average: 0.01, 0.06, 0.07', 152*24*60*60 + 17*60*60 ],
92
+ [' 5:37pm up 25 days, 21:00, 0 users, load average: 0.01, 0.02, 0.00', 25*24*60*60 + 21*60*60 ],
93
+ [' 8:59pm up 94 day(s), 3:17, 46 users, load average: 0.66, 0.67, 0.70', 94*24*60*60 + 3*60*60 + 17*60],
94
+ [' 3:01pm up 4496 day(s), 21:19, 32 users, load average: 0.61, 0.62, 0.62', 4496*24*60*60 + 21*60*60 + 19*60],
95
+ [' 02:42PM up 41 days, 2:38, 0 users, load average: 0.38, 0.70, 0.55', 41*24*60*60 + 2*60*60 + 38*60],
96
+ [' 18:13:29 up 25 days, 21:36, 0 users, load average: 0.00, 0.00, 0.00', 25*24*60*60 + 21*60*60 + 36*60],
97
+ [' 13:36:05 up 118 days, 1:15, 1 user, load average: 0.00, 0.00, 0.00', 118*24*60*60 + 1*60*60 + 15*60]
98
+ ]
58
99
 
59
- it "should use 'who -b'" do
60
- who_b_output_file = my_fixture('who_b_boottime') # Aug 1 14:13
61
- Facter::Util::Uptime.stubs(:uptime_who_cmd).returns("cat \"#{who_b_output_file}\"")
62
- Time.stubs(:now).returns Time.parse("Aug 01 15:13") # one hour later
63
- Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60
100
+ test_cases.each do |uptime, expected|
101
+ it "should return #{expected} for #{uptime}" do
102
+ Facter::Util::Resolution.stubs(:exec).with('uptime 2>/dev/null').returns(uptime)
103
+ Facter.fact(:uptime_seconds).value.should == expected
104
+ end
64
105
  end
65
106
 
66
- describe "nor is 'who -b'" do
107
+ describe "nor is 'uptime' command" do
67
108
  before :each do
68
- Facter::Util::Uptime.stubs(:uptime_who_cmd).returns("cat \"#{@nonexistent_file}\"")
109
+ Facter::Util::Uptime.stubs(:uptime_executable_cmd).returns("cat \"#{@nonexistent_file}\"")
69
110
  end
70
111
 
71
112
  it "should return nil" do
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/virtual'
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/vlans'
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/wmi'
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/xendomains'
@@ -1,11 +1,11 @@
1
- #!/usr/bin/env rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/virtual'
5
5
  require 'facter/util/macosx'
6
6
 
7
7
  describe "Virtual fact" do
8
- before do
8
+ before(:each) do
9
9
  Facter::Util::Virtual.stubs(:zone?).returns(false)
10
10
  Facter::Util::Virtual.stubs(:openvz?).returns(false)
11
11
  Facter::Util::Virtual.stubs(:vserver?).returns(false)
@@ -13,6 +13,7 @@ describe "Virtual fact" do
13
13
  Facter::Util::Virtual.stubs(:kvm?).returns(false)
14
14
  Facter::Util::Virtual.stubs(:hpvm?).returns(false)
15
15
  Facter::Util::Virtual.stubs(:zlinux?).returns(false)
16
+ Facter::Util::Virtual.stubs(:virt_what).returns(nil)
16
17
  end
17
18
 
18
19
  it "should be zone on Solaris when a zone" do
@@ -31,16 +32,16 @@ describe "Virtual fact" do
31
32
  end
32
33
 
33
34
  it "should be hpvm on HP-UX when in HP-VM" do
34
- Facter.fact(:kernel).stubs(:value).returns("HP-UX")
35
- Facter::Util::Virtual.stubs(:hpvm?).returns(true)
36
- Facter.fact(:virtual).value.should == "hpvm"
35
+ Facter.fact(:kernel).stubs(:value).returns("HP-UX")
36
+ Facter::Util::Virtual.stubs(:hpvm?).returns(true)
37
+ Facter.fact(:virtual).value.should == "hpvm"
37
38
  end
38
39
 
39
40
  it "should be zlinux on s390x" do
40
- Facter.fact(:kernel).stubs(:value).returns("Linux")
41
- Facter.fact(:architecture).stubs(:value).returns("s390x")
42
- Facter::Util::Virtual.stubs(:zlinux?).returns(true)
43
- Facter.fact(:virtual).value.should == "zlinux"
41
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
42
+ Facter.fact(:architecture).stubs(:value).returns("s390x")
43
+ Facter::Util::Virtual.stubs(:zlinux?).returns(true)
44
+ Facter.fact(:virtual).value.should == "zlinux"
44
45
  end
45
46
 
46
47
  describe "on Darwin" do
@@ -70,26 +71,25 @@ describe "Virtual fact" do
70
71
  end
71
72
 
72
73
  describe "on Linux" do
73
-
74
- before do
75
- Facter::Util::Resolution.stubs(:exec).with("vmware -v").returns false
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
81
- Facter.fact(:architecture).stubs(:value).returns(true)
74
+ before(:each) do
75
+ Facter::Util::Resolution.stubs(:exec).with("vmware -v").returns false
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
81
+ Facter.fact(:architecture).stubs(:value).returns(true)
82
82
  end
83
83
 
84
84
  it "should be parallels with Parallels vendor id from lspci 2>/dev/null" do
85
85
  Facter.fact(:kernel).stubs(:value).returns("Linux")
86
- Facter::Util::Resolution.stubs(:exec).with('lspci 2>/dev/null').returns("01:00.0 VGA compatible controller: Unknown device 1ab8:4005")
86
+ Facter::Util::Virtual.stubs(:lspci).returns("01:00.0 VGA compatible controller: Unknown device 1ab8:4005")
87
87
  Facter.fact(:virtual).value.should == "parallels"
88
88
  end
89
89
 
90
90
  it "should be parallels with Parallels vendor name from lspci 2>/dev/null" do
91
91
  Facter.fact(:kernel).stubs(:value).returns("Linux")
92
- Facter::Util::Resolution.stubs(:exec).with('lspci 2>/dev/null').returns("01:00.0 VGA compatible controller: Parallels Display Adapter")
92
+ Facter::Util::Virtual.stubs(:lspci).returns("01:00.0 VGA compatible controller: Parallels Display Adapter")
93
93
  Facter.fact(:virtual).value.should == "parallels"
94
94
  end
95
95
 
@@ -170,8 +170,8 @@ describe "Virtual fact" do
170
170
  Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("System Information\nManufacturer: Microsoft Corporation\nProduct Name: Virtual Machine")
171
171
  Facter.fact(:virtual).value.should == "hyperv"
172
172
  end
173
-
174
173
  end
174
+
175
175
  describe "on Solaris" do
176
176
  before(:each) do
177
177
  Facter::Util::Resolution.stubs(:exec).with("vmware -v").returns false
@@ -234,32 +234,64 @@ describe "Virtual fact" do
234
234
  Facter.fact(:virtual).value.should == "xenhvm"
235
235
  end
236
236
  end
237
+
238
+ describe "with the virt-what command available (#8210)" do
239
+ describe "when the output of virt-what disagrees with lower weight facts" do
240
+ virt_what_map = {
241
+ 'xen-hvm' => 'xenhvm',
242
+ 'xen-dom0' => 'xen0',
243
+ 'xen-domU' => 'xenu',
244
+ 'ibm_systemz' => 'zlinux',
245
+ }
246
+
247
+ virt_what_map.each do |input,output|
248
+ it "maps #{input} to #{output}" do
249
+ Facter::Util::Virtual.expects(:virt_what).returns(input)
250
+ Facter.value(:virtual).should == output
251
+ end
252
+ end
253
+ end
254
+
255
+ describe "arbitrary outputs of virt-what" do
256
+ it "returns the last line output from virt-what" do
257
+ Facter::Util::Virtual.expects(:virt_what).returns("one\ntwo\nthree space\n")
258
+ Facter.value(:virtual).should == "three space"
259
+ end
260
+ end
261
+
262
+ describe "when virt-what returns linux_vserver" do
263
+ it "delegates to Facter::Util::Virtual.vserver_type" do
264
+ Facter::Util::Virtual.expects(:virt_what).returns("linux_vserver")
265
+ Facter::Util::Virtual.expects(:vserver_type).returns("fake_vserver_type")
266
+ Facter.value(:virtual).should == "fake_vserver_type"
267
+ end
268
+ end
269
+ end
237
270
  end
238
271
 
239
272
  describe "is_virtual fact" do
240
-
241
273
  it "should be virtual when running on xen" do
242
- Facter.fact(:kernel).stubs(:value).returns("Linux")
243
- Facter.fact(:virtual).stubs(:value).returns("xenu")
244
- Facter.fact(:is_virtual).value.should == "true"
274
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
275
+ Facter.fact(:virtual).stubs(:value).returns("xenu")
276
+ Facter.fact(:is_virtual).value.should == "true"
245
277
  end
246
278
 
247
279
  it "should be false when running on xen0" do
248
- Facter.fact(:kernel).stubs(:value).returns("Linux")
249
- Facter.fact(:virtual).stubs(:value).returns("xen0")
250
- Facter.fact(:is_virtual).value.should == "false"
280
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
281
+ Facter.fact(:virtual).stubs(:value).returns("xen0")
282
+ Facter.fact(:is_virtual).value.should == "false"
251
283
  end
252
284
 
253
285
  it "should be true when running on xenhvm" do
254
- Facter.fact(:kernel).stubs(:value).returns("Linux")
255
- Facter.fact(:virtual).stubs(:value).returns("xenhvm")
256
- Facter.fact(:is_virtual).value.should == "true"
286
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
287
+ Facter.fact(:virtual).stubs(:value).returns("xenhvm")
288
+ Facter.fact(:is_virtual).value.should == "true"
257
289
  end
258
290
 
259
291
  it "should be false when running on physical" do
260
- Facter.fact(:kernel).stubs(:value).returns("Linux")
261
- Facter.fact(:virtual).stubs(:value).returns("physical")
262
- Facter.fact(:is_virtual).value.should == "false"
292
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
293
+ Facter.fact(:virtual).stubs(:value).returns("physical")
294
+ Facter.fact(:is_virtual).value.should == "false"
263
295
  end
264
296
 
265
297
  it "should be true when running on vmware" do