facter 1.5.8 → 1.5.9
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.
- data/CHANGELOG +94 -0
- data/INSTALL +1 -1
- data/README +1 -1
- data/README.rst +3 -3
- data/Rakefile +9 -6
- data/bin/facter +18 -123
- data/conf/redhat/facter.spec +21 -3
- data/conf/solaris/pkginfo +2 -2
- data/install.rb +18 -10
- data/lib/facter.rb +27 -1
- data/lib/facter/application.rb +123 -0
- data/lib/facter/arp.rb +28 -0
- data/lib/facter/ec2.rb +32 -11
- data/lib/facter/hardwareisa.rb +1 -1
- data/lib/facter/id.rb +2 -9
- data/lib/facter/interfaces.rb +1 -1
- data/lib/facter/ipaddress.rb +2 -33
- data/lib/facter/ipaddress6.rb +68 -0
- data/lib/facter/lsb.rb +5 -5
- data/lib/facter/lsbmajdistrelease.rb +1 -1
- data/lib/facter/macaddress.rb +4 -14
- data/lib/facter/manufacturer.rb +9 -0
- data/lib/facter/memory.rb +110 -6
- data/lib/facter/netmask.rb +1 -1
- data/lib/facter/operatingsystem.rb +17 -2
- data/lib/facter/operatingsystemrelease.rb +34 -0
- data/lib/facter/processor.rb +8 -5
- data/lib/facter/selinux.rb +37 -4
- data/lib/facter/uniqueid.rb +1 -1
- data/lib/facter/util/#uptime.rb# +64 -0
- data/lib/facter/util/ip.rb +23 -15
- data/lib/facter/util/loader.rb +2 -2
- data/lib/facter/util/macaddress.rb +28 -0
- data/lib/facter/util/manufacturer.rb +39 -2
- data/lib/facter/util/memory.rb +43 -0
- data/lib/facter/util/netmask.rb +1 -1
- data/lib/facter/util/resolution.rb +7 -0
- data/lib/facter/util/uptime.rb +11 -1
- data/lib/facter/util/virtual.rb +13 -2
- data/lib/facter/util/vlans.rb +2 -2
- data/lib/facter/util/xendomains.rb +10 -0
- data/lib/facter/virtual.rb +45 -13
- data/lib/facter/xendomains.rb +10 -0
- data/spec/fixtures/ifconfig/bsd_ifconfig_all_with_multiple_interfaces +18 -0
- data/spec/fixtures/ifconfig/centos_5_5 +17 -0
- data/spec/fixtures/ifconfig/centos_5_5_eth0 +8 -0
- data/spec/fixtures/ifconfig/darwin_10_3_0 +26 -0
- data/spec/fixtures/ifconfig/darwin_10_3_0_en0 +6 -0
- data/spec/fixtures/ifconfig/darwin_10_6_4 +28 -0
- data/spec/fixtures/ifconfig/darwin_10_6_4_en1 +6 -0
- data/spec/fixtures/ifconfig/darwin_10_6_6_dualstack +8 -0
- data/spec/fixtures/ifconfig/darwin_10_6_6_dualstack_en1 +7 -0
- data/spec/fixtures/ifconfig/darwin_9_8_0 +26 -0
- data/spec/fixtures/ifconfig/darwin_9_8_0_en0 +6 -0
- data/spec/fixtures/ifconfig/darwin_ifconfig_all_with_multiple_interfaces +23 -0
- data/spec/fixtures/ifconfig/fedora_10 +36 -0
- data/spec/fixtures/ifconfig/fedora_10_eth0 +9 -0
- data/spec/fixtures/ifconfig/fedora_13 +18 -0
- data/spec/fixtures/ifconfig/fedora_13_eth0 +9 -0
- data/spec/fixtures/ifconfig/fedora_8 +38 -0
- data/spec/fixtures/ifconfig/fedora_8_eth0 +9 -0
- data/spec/fixtures/ifconfig/freebsd_6_0 +12 -0
- data/spec/fixtures/ifconfig/linux_ifconfig_all_with_multiple_interfaces +19 -0
- data/spec/fixtures/ifconfig/open_solaris_10 +12 -0
- data/spec/fixtures/ifconfig/open_solaris_b132 +20 -0
- data/spec/fixtures/ifconfig/sunos_ifconfig_all_with_multiple_interfaces +10 -0
- data/spec/fixtures/ifconfig/ubuntu_7_04 +38 -0
- data/spec/fixtures/ifconfig/ubuntu_7_04_eth0 +9 -0
- data/spec/fixtures/netstat/centos_5_5 +5 -0
- data/spec/fixtures/netstat/darwin_10_3_0 +35 -0
- data/spec/fixtures/netstat/darwin_10_6_4 +29 -0
- data/spec/fixtures/netstat/darwin_10_6_6_dualstack +34 -0
- data/spec/fixtures/netstat/darwin_9_8_0 +28 -0
- data/spec/fixtures/netstat/fedora_10 +7 -0
- data/spec/fixtures/netstat/open_solaris_10 +16 -0
- data/spec/fixtures/netstat/open_solaris_b132 +17 -0
- data/spec/fixtures/netstat/ubuntu_7_04 +7 -0
- data/spec/fixtures/uptime/kstat_boot_time +1 -0
- data/spec/fixtures/virtual/proc_self_status/vserver_2_1/guest +37 -0
- data/spec/fixtures/virtual/proc_self_status/vserver_2_1/host +36 -0
- data/spec/fixtures/virtual/proc_self_status/vserver_2_3/guest +39 -0
- data/spec/fixtures/virtual/proc_self_status/vserver_2_3/host +39 -0
- data/spec/integration/{facter.rb → facter_spec.rb} +1 -1
- data/spec/spec_helper.rb +8 -3
- data/spec/unit/data/debian_kfreebsd_ifconfig +40 -0
- data/spec/unit/data/hpux_netstat_all_interfaces +3 -6
- data/spec/unit/data/selinux_sestatus +6 -0
- data/spec/unit/data/xendomains +4 -0
- data/spec/unit/{facter.rb → facter_spec.rb} +28 -1
- data/spec/unit/id_spec.rb +27 -0
- data/spec/unit/{interfaces.rb → interfaces_spec.rb} +1 -1
- data/spec/unit/ipaddress6_spec.rb +36 -0
- data/spec/unit/memory_spec.rb +45 -0
- data/spec/unit/{operatingsystem.rb → operatingsystem_spec.rb} +22 -8
- data/spec/unit/operatingsystemrelease_spec.rb +49 -0
- data/spec/unit/selinux_spec.rb +89 -0
- data/spec/unit/{uptime.rb → uptime_spec.rb} +4 -4
- data/spec/unit/util/{collection.rb → collection_spec.rb} +1 -1
- data/spec/unit/util/{confine.rb → confine_spec.rb} +1 -1
- data/spec/unit/util/{fact.rb → fact_spec.rb} +1 -1
- data/spec/unit/util/{ip.rb → ip_spec.rb} +47 -12
- data/spec/unit/util/{loader.rb → loader_spec.rb} +51 -1
- data/spec/unit/util/macaddress_spec.rb +68 -0
- data/spec/unit/util/{macosx.rb → macosx_spec.rb} +1 -1
- data/spec/unit/util/{manufacturer.rb → manufacturer_spec.rb} +15 -4
- data/spec/unit/util/{resolution.rb → resolution_spec.rb} +1 -1
- data/spec/unit/util/uptime_spec.rb +73 -0
- data/spec/unit/util/{virtual.rb → virtual_spec.rb} +37 -3
- data/spec/unit/util/{vlans.rb → vlans_spec.rb} +1 -1
- data/spec/unit/util/xendomains_spec.rb +23 -0
- data/spec/unit/virtual_spec.rb +196 -0
- metadata +149 -98
- data/spec/Rakefile +0 -18
- data/spec/unit/data/hpux_ifconfig +0 -3
- data/spec/unit/data/hpux_netscan +0 -4
- data/spec/unit/operatingsystemrelease.rb +0 -39
- data/spec/unit/selinux.rb +0 -48
- data/spec/unit/util/uptime.rb +0 -53
- data/spec/unit/virtual.rb +0 -71
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
4
|
+
|
5
|
+
require 'facter/util/macaddress'
|
6
|
+
|
7
|
+
describe "Darwin" do
|
8
|
+
test_cases = [
|
9
|
+
# version, iface, real macaddress, fallback macaddress
|
10
|
+
["9.8.0", 'en0', "00:17:f2:06:e4:2e", "00:17:f2:06:e4:2e"],
|
11
|
+
["10.3.0", 'en0', "00:17:f2:06:e3:c2", "00:17:f2:06:e3:c2"],
|
12
|
+
["10.6.4", 'en1', "58:b0:35:7f:25:b3", "58:b0:35:fa:08:b1"],
|
13
|
+
["10.6.6_dualstack", "en1", "00:25:00:48:19:ef", "00:25:4b:ca:56:72"]
|
14
|
+
]
|
15
|
+
|
16
|
+
test_cases.each do |version, default_iface, macaddress, fallback_macaddress|
|
17
|
+
netstat_file = File.join(SPECDIR, "fixtures", "netstat", "darwin_#{version.tr('.', '_')}")
|
18
|
+
ifconfig_file_no_iface = File.join(SPECDIR, "fixtures", "ifconfig", "darwin_#{version.tr('.', '_')}")
|
19
|
+
ifconfig_file = "#{ifconfig_file_no_iface}_#{default_iface}"
|
20
|
+
|
21
|
+
describe "version #{version}" do
|
22
|
+
describe Facter::Util::Macaddress::Darwin do
|
23
|
+
describe ".default_interface" do
|
24
|
+
describe "when netstat has a default interface" do
|
25
|
+
before do
|
26
|
+
Facter::Util::Macaddress::Darwin.stubs(:netstat_command).returns("cat \"#{netstat_file}\"")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return the default interface name" do
|
30
|
+
Facter::Util::Macaddress::Darwin.default_interface.should == default_iface
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".macaddress" do
|
36
|
+
describe "when netstat has a default interface" do
|
37
|
+
before do
|
38
|
+
Facter.stubs(:warn)
|
39
|
+
Facter::Util::Macaddress::Darwin.stubs(:default_interface).returns('')
|
40
|
+
Facter::Util::Macaddress::Darwin.stubs(:ifconfig_command).returns("cat \"#{ifconfig_file}\"")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return the macaddress of the default interface" do
|
44
|
+
Facter::Util::Macaddress::Darwin.macaddress.should == macaddress
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "when netstat does not have a default interface" do
|
49
|
+
before do
|
50
|
+
Facter::Util::Macaddress::Darwin.stubs(:default_interface).returns("")
|
51
|
+
Facter::Util::Macaddress::Darwin.stubs(:ifconfig_command).returns("cat \"#{ifconfig_file_no_iface}\"")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should warn about the lack of default" do
|
55
|
+
Facter.expects(:warn).with("Could not find a default route. Using first non-loopback interface")
|
56
|
+
Facter::Util::Macaddress::Darwin.stubs(:default_interface).returns('')
|
57
|
+
Facter::Util::Macaddress::Darwin.macaddress
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return the macaddress of the first non-loopback interface" do
|
61
|
+
Facter::Util::Macaddress::Darwin.macaddress.should == fallback_macaddress
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,8 +1,12 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
2
|
|
3
3
|
require 'facter/util/manufacturer'
|
4
4
|
|
5
5
|
describe Facter::Manufacturer do
|
6
|
+
before :each do
|
7
|
+
Facter.clear
|
8
|
+
end
|
9
|
+
|
6
10
|
it "should return the system DMI table" do
|
7
11
|
Facter::Manufacturer.should respond_to(:get_dmi_table)
|
8
12
|
end
|
@@ -12,6 +16,13 @@ describe Facter::Manufacturer do
|
|
12
16
|
Facter::Manufacturer.get_dmi_table().should be_nil
|
13
17
|
end
|
14
18
|
|
19
|
+
it "should parse prtdiag output" do
|
20
|
+
Facter::Util::Resolution.stubs(:exec).returns("System Configuration: Sun Microsystems sun4u Sun SPARC Enterprise M3000 Server")
|
21
|
+
Facter::Manufacturer.prtdiag_sparc_find_system_info()
|
22
|
+
Facter.value(:manufacturer).should == "Sun Microsystems"
|
23
|
+
Facter.value(:productname).should == "Sun SPARC Enterprise M3000 Server"
|
24
|
+
end
|
25
|
+
|
15
26
|
it "should strip white space on dmi output with spaces" do
|
16
27
|
sample_output_file = File.dirname(__FILE__) + "/../data/linux_dmidecode_with_spaces"
|
17
28
|
dmidecode_output = File.new(sample_output_file).read()
|
@@ -23,7 +34,7 @@ describe Facter::Manufacturer do
|
|
23
34
|
Facter::Manufacturer.dmi_find_system_info(query)
|
24
35
|
Facter.value(:productname).should == "MS-6754"
|
25
36
|
end
|
26
|
-
|
37
|
+
|
27
38
|
it "should handle output from smbios when run under sunos" do
|
28
39
|
sample_output_file = File.dirname(__FILE__) + "/../data/opensolaris_smbios"
|
29
40
|
smbios_output = File.new(sample_output_file).read()
|
@@ -98,8 +109,8 @@ Handle 0x001F
|
|
98
109
|
|
99
110
|
def find_product_name(os)
|
100
111
|
output_file = case os
|
101
|
-
when "FreeBSD"
|
102
|
-
when "SunOS"
|
112
|
+
when "FreeBSD" then File.dirname(__FILE__) + "/../data/freebsd_dmidecode"
|
113
|
+
when "SunOS" then File.dirname(__FILE__) + "/../data/opensolaris_smbios"
|
103
114
|
end
|
104
115
|
|
105
116
|
output = File.new(output_file).read()
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
4
|
+
|
5
|
+
require 'facter/util/uptime'
|
6
|
+
|
7
|
+
describe Facter::Util::Uptime do
|
8
|
+
|
9
|
+
describe ".get_uptime_seconds_unix" do
|
10
|
+
describe "when /proc/uptime is available" do
|
11
|
+
before do
|
12
|
+
uptime_file = File.join(SPECDIR, "fixtures", "uptime", "ubuntu_proc_uptime")
|
13
|
+
Facter::Util::Uptime.stubs(:uptime_file).returns("\"#{uptime_file}\"")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return the uptime in seconds as an integer" do
|
17
|
+
Facter::Util::Uptime.get_uptime_seconds_unix.should == 5097686
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "when /proc/uptime is not available" do
|
23
|
+
before :each do
|
24
|
+
@nonexistent_file = '/non/existent/file'
|
25
|
+
File.exists?(@nonexistent_file).should == false
|
26
|
+
Facter::Util::Uptime.stubs(:uptime_file).returns(@nonexistent_file)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should use 'sysctl kern.boottime'" do
|
30
|
+
sysctl_output_file = File.join(SPECDIR, 'fixtures', 'uptime', 'sysctl_kern_boottime') # Aug 01 14:13:47 -0700 2010
|
31
|
+
Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat \"#{sysctl_output_file}\"")
|
32
|
+
Time.stubs(:now).returns Time.parse("Aug 01 15:13:47 -0700 2010") # one hour later
|
33
|
+
Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "nor is 'sysctl kern.boottime'" do
|
37
|
+
before :each do
|
38
|
+
Facter::Util::Uptime.stubs(:uptime_sysctl_cmd).returns("cat \"#{@nonexistent_file}\"")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should use 'kstat -p unix:::boot_time'" do
|
42
|
+
kstat_output_file = File.join(SPECDIR, 'fixtures', 'uptime', 'kstat_boot_time') # unix:0:system_misc:boot_time 1236919980
|
43
|
+
Facter::Util::Uptime.stubs(:uptime_kstat_cmd).returns("cat \"#{kstat_output_file}\"")
|
44
|
+
Time.stubs(:now).returns Time.at(1236923580) #one hour later
|
45
|
+
Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "nor is 'kstat -p unix:::boot_time'" do
|
49
|
+
before :each do
|
50
|
+
Facter::Util::Uptime.stubs(:uptime_kstat_cmd).returns("cat \"#{@nonexistent_file}\"")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should use 'who -b'" do
|
54
|
+
who_b_output_file = File.join(SPECDIR, 'fixtures', 'uptime', 'who_b_boottime') # Aug 1 14:13
|
55
|
+
Facter::Util::Uptime.stubs(:uptime_who_cmd).returns("cat \"#{who_b_output_file}\"")
|
56
|
+
Time.stubs(:now).returns Time.parse("Aug 01 15:13") # one hour later
|
57
|
+
Facter::Util::Uptime.get_uptime_seconds_unix.should == 60 * 60
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "nor is 'who -b'" do
|
61
|
+
before :each do
|
62
|
+
Facter::Util::Uptime.stubs(:uptime_who_cmd).returns("cat \"#{@nonexistent_file}\"")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return nil" do
|
66
|
+
Facter::Util::Uptime.get_uptime_seconds_unix.should == nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
2
|
|
3
3
|
require 'facter/util/virtual'
|
4
4
|
|
@@ -57,6 +57,26 @@ describe Facter::Util::Virtual do
|
|
57
57
|
Facter::Util::Virtual.should_not be_vserver
|
58
58
|
end
|
59
59
|
|
60
|
+
fixture_path = File.join(SPECDIR, 'fixtures', 'virtual', 'proc_self_status')
|
61
|
+
|
62
|
+
test_cases = [
|
63
|
+
[File.join(fixture_path, 'vserver_2_1', 'guest'), true, 'vserver 2.1 guest'],
|
64
|
+
[File.join(fixture_path, 'vserver_2_1', 'host'), true, 'vserver 2.1 host'],
|
65
|
+
[File.join(fixture_path, 'vserver_2_3', 'guest'), true, 'vserver 2.3 guest'],
|
66
|
+
[File.join(fixture_path, 'vserver_2_3', 'host'), true, 'vserver 2.3 host']
|
67
|
+
]
|
68
|
+
|
69
|
+
test_cases.each do |status_file, expected, description|
|
70
|
+
describe "with /proc/self/status from #{description}" do
|
71
|
+
it "should detect vserver as #{expected.inspect}" do
|
72
|
+
status = File.read(status_file)
|
73
|
+
FileTest.stubs(:exists?).with("/proc/self/status").returns(true)
|
74
|
+
File.stubs(:read).with("/proc/self/status").returns(status)
|
75
|
+
Facter::Util::Virtual.vserver?.should == expected
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
60
80
|
it "should identify vserver_host when /proc/virtual exists" do
|
61
81
|
Facter::Util::Virtual.expects(:vserver?).returns(true)
|
62
82
|
FileTest.stubs(:exists?).with("/proc/virtual").returns(true)
|
@@ -101,19 +121,33 @@ describe Facter::Util::Virtual do
|
|
101
121
|
end
|
102
122
|
|
103
123
|
it "should detect kvm on FreeBSD" do
|
124
|
+
FileTest.stubs(:exists?).with("/proc/cpuinfo").returns(false)
|
104
125
|
Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
|
105
126
|
Facter::Util::Resolution.stubs(:exec).with("/sbin/sysctl -n hw.model").returns("QEMU Virtual CPU version 0.12.4")
|
106
127
|
Facter::Util::Virtual.should be_kvm
|
107
128
|
end
|
108
129
|
|
109
130
|
it "should identify FreeBSD jail when in jail" do
|
131
|
+
Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
|
110
132
|
Facter::Util::Resolution.stubs(:exec).with("/sbin/sysctl -n security.jail.jailed").returns("1")
|
111
133
|
Facter::Util::Virtual.should be_jail
|
112
134
|
end
|
113
135
|
|
114
|
-
it "should not identify
|
115
|
-
Facter
|
136
|
+
it "should not identify GNU/kFreeBSD jail when not in jail" do
|
137
|
+
Facter.fact(:kernel).stubs(:value).returns("GNU/kFreeBSD")
|
138
|
+
Facter::Util::Resolution.stubs(:exec).with("/bin/sysctl -n security.jail.jailed").returns("0")
|
116
139
|
Facter::Util::Virtual.should_not be_jail
|
117
140
|
end
|
118
141
|
|
142
|
+
it "should detect hpvm on HP-UX" do
|
143
|
+
Facter.fact(:kernel).stubs(:value).returns("HP-UX")
|
144
|
+
Facter::Util::Resolution.stubs(:exec).with("/usr/bin/getconf MACHINE_MODEL").returns('ia64 hp server Integrity Virtual Machine')
|
145
|
+
Facter::Util::Virtual.should be_hpvm
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should not detect hpvm on HP-UX when not in hpvm" do
|
149
|
+
Facter.fact(:kernel).stubs(:value).returns("HP-UX")
|
150
|
+
Facter::Util::Resolution.stubs(:exec).with("/usr/bin/getconf MACHINE_MODEL").returns('ia64 hp server rx660')
|
151
|
+
Facter::Util::Virtual.should_not be_hpvm
|
152
|
+
end
|
119
153
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
4
|
+
|
5
|
+
require 'facter/util/xendomains'
|
6
|
+
|
7
|
+
describe Facter::Util::Xendomains do
|
8
|
+
describe ".get_domains" do
|
9
|
+
it "should return a list of running Xen Domains on Xen0" do
|
10
|
+
sample_output_file = File.dirname(__FILE__) + '/../data/xendomains'
|
11
|
+
xen0_domains = File.read(sample_output_file)
|
12
|
+
Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/xm list 2>/dev/null').returns(xen0_domains)
|
13
|
+
Facter::Util::Xendomains.get_domains.should == %{web01,mailserver}
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "when xm list isn't executable" do
|
17
|
+
it "should be nil" do
|
18
|
+
Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/xm list 2>/dev/null').returns(nil)
|
19
|
+
Facter::Util::Xendomains.get_domains.should == nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,196 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
require 'facter'
|
4
|
+
require 'facter/util/virtual'
|
5
|
+
require 'facter/util/macosx'
|
6
|
+
|
7
|
+
describe "Virtual fact" do
|
8
|
+
before do
|
9
|
+
Facter::Util::Virtual.stubs(:zone?).returns(false)
|
10
|
+
Facter::Util::Virtual.stubs(:openvz?).returns(false)
|
11
|
+
Facter::Util::Virtual.stubs(:vserver?).returns(false)
|
12
|
+
Facter::Util::Virtual.stubs(:xen?).returns(false)
|
13
|
+
Facter::Util::Virtual.stubs(:kvm?).returns(false)
|
14
|
+
Facter::Util::Virtual.stubs(:hpvm?).returns(false)
|
15
|
+
Facter::Util::Virtual.stubs(:zlinux?).returns(false)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be zone on Solaris when a zone" do
|
19
|
+
Facter.fact(:kernel).stubs(:value).returns("SunOS")
|
20
|
+
Facter::Util::Virtual.stubs(:zone?).returns(true)
|
21
|
+
Facter::Util::Virtual.stubs(:vserver?).returns(false)
|
22
|
+
Facter::Util::Virtual.stubs(:xen?).returns(false)
|
23
|
+
Facter.fact(:virtual).value.should == "zone"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be jail on FreeBSD when a jail in kvm" do
|
27
|
+
Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
|
28
|
+
Facter::Util::Virtual.stubs(:jail?).returns(true)
|
29
|
+
Facter::Util::Virtual.stubs(:kvm?).returns(true)
|
30
|
+
Facter.fact(:virtual).value.should == "jail"
|
31
|
+
end
|
32
|
+
|
33
|
+
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"
|
37
|
+
end
|
38
|
+
|
39
|
+
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"
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "on Darwin" do
|
47
|
+
it "should be parallels with Parallels vendor id" do
|
48
|
+
Facter.fact(:kernel).stubs(:value).returns("Darwin")
|
49
|
+
Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor-id" => "0x1ab8" })
|
50
|
+
Facter.fact(:virtual).value.should == "parallels"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should be parallels with Parallels vendor name" do
|
54
|
+
Facter.fact(:kernel).stubs(:value).returns("Darwin")
|
55
|
+
Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor" => "Parallels" })
|
56
|
+
Facter.fact(:virtual).value.should == "parallels"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should be vmware with VMWare vendor id" do
|
60
|
+
Facter.fact(:kernel).stubs(:value).returns("Darwin")
|
61
|
+
Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor-id" => "0x15ad" })
|
62
|
+
Facter.fact(:virtual).value.should == "vmware"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should be vmware with VMWare vendor name" do
|
66
|
+
Facter.fact(:kernel).stubs(:value).returns("Darwin")
|
67
|
+
Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor" => "VMWare" })
|
68
|
+
Facter.fact(:virtual).value.should == "vmware"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "on Linux" do
|
73
|
+
|
74
|
+
before do
|
75
|
+
FileTest.expects(:exists?).with("/usr/lib/vmware/bin/vmware-vmx").returns false
|
76
|
+
Facter.fact(:architecture).stubs(:value).returns(true)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should be parallels with Parallels vendor id from lspci" do
|
80
|
+
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
81
|
+
Facter::Util::Resolution.stubs(:exec).with('lspci').returns("01:00.0 VGA compatible controller: Unknown device 1ab8:4005")
|
82
|
+
Facter.fact(:virtual).value.should == "parallels"
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should be parallels with Parallels vendor name from lspci" do
|
86
|
+
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
87
|
+
Facter::Util::Resolution.stubs(:exec).with('lspci').returns("01:00.0 VGA compatible controller: Parallels Display Adapter")
|
88
|
+
Facter.fact(:virtual).value.should == "parallels"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should be vmware with VMware vendor name from lspci" do
|
92
|
+
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
93
|
+
Facter::Util::Resolution.stubs(:exec).with('lspci').returns("00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter")
|
94
|
+
Facter.fact(:virtual).value.should == "vmware"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should be vmware with VMWare vendor name from dmidecode" do
|
98
|
+
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
99
|
+
Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
|
100
|
+
Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("On Board Device 1 Information\nType: Video\nStatus: Disabled\nDescription: VMware SVGA II")
|
101
|
+
Facter.fact(:virtual).value.should == "vmware"
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should be parallels with Parallels vendor name from dmidecode" do
|
105
|
+
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
106
|
+
Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
|
107
|
+
Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("On Board Device Information\nType: Video\nStatus: Disabled\nDescription: Parallels Video Adapter")
|
108
|
+
Facter.fact(:virtual).value.should == "parallels"
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should be vmware with VMWare vendor name from prtdiag" do
|
112
|
+
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
113
|
+
Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
|
114
|
+
Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil)
|
115
|
+
Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: VMware, Inc. VMware Virtual Platform")
|
116
|
+
Facter.fact(:virtual).value.should == "vmware"
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should be parallels with Parallels vendor name from prtdiag" do
|
120
|
+
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
121
|
+
Facter::Util::Resolution.stubs(:exec).with('lspci').returns(nil)
|
122
|
+
Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil)
|
123
|
+
Facter::Util::Resolution.stubs(:exec).with('prtdiag').returns("System Configuration: Parallels Virtual Platform")
|
124
|
+
Facter.fact(:virtual).value.should == "parallels"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "is_virtual fact" do
|
130
|
+
|
131
|
+
it "should be virtual when running on xen" do
|
132
|
+
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
133
|
+
Facter.fact(:virtual).stubs(:value).returns("xenu")
|
134
|
+
Facter.fact(:is_virtual).value.should == "true"
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should be false when running on xen0" do
|
138
|
+
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
139
|
+
Facter.fact(:virtual).stubs(:value).returns("xen0")
|
140
|
+
Facter.fact(:is_virtual).value.should == "false"
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should be false when running on physical" do
|
144
|
+
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
145
|
+
Facter.fact(:virtual).stubs(:value).returns("physical")
|
146
|
+
Facter.fact(:is_virtual).value.should == "false"
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should be true when running on vmware" do
|
150
|
+
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
151
|
+
Facter.fact(:virtual).stubs(:value).returns("vmware")
|
152
|
+
Facter.fact(:is_virtual).value.should == "true"
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should be true when running on openvz" do
|
156
|
+
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
157
|
+
Facter.fact(:virtual).stubs(:value).returns("openvzve")
|
158
|
+
Facter.fact(:is_virtual).value.should == "true"
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should be true when running on kvm" do
|
162
|
+
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
163
|
+
Facter.fact(:virtual).stubs(:value).returns("kvm")
|
164
|
+
Facter.fact(:is_virtual).value.should == "true"
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should be true when running in jail" do
|
168
|
+
Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
|
169
|
+
Facter.fact(:virtual).stubs(:value).returns("jail")
|
170
|
+
Facter.fact(:is_virtual).value.should == "true"
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should be true when running in zone" do
|
174
|
+
Facter.fact(:kernel).stubs(:value).returns("SunOS")
|
175
|
+
Facter.fact(:virtual).stubs(:value).returns("zone")
|
176
|
+
Facter.fact(:is_virtual).value.should == "true"
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should be true when running on hp-vm" do
|
180
|
+
Facter.fact(:kernel).stubs(:value).returns("HP-UX")
|
181
|
+
Facter.fact(:virtual).stubs(:value).returns("hpvm")
|
182
|
+
Facter.fact(:is_virtual).value.should == "true"
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should be true when running on S390" do
|
186
|
+
Facter.fact(:architecture).stubs(:value).returns("s390x")
|
187
|
+
Facter.fact(:virtual).stubs(:value).returns("zlinux")
|
188
|
+
Facter.fact(:is_virtual).value.should == "true"
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should be true when running on parallels" do
|
192
|
+
Facter.fact(:kernel).stubs(:value).returns("Darwin")
|
193
|
+
Facter.fact(:virtual).stubs(:value).returns("parallels")
|
194
|
+
Facter.fact(:is_virtual).value.should == "true"
|
195
|
+
end
|
196
|
+
end
|