facter 1.6.18 → 1.7.0.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 (126) hide show
  1. data/Gemfile +23 -8
  2. data/bin/facter +4 -1
  3. data/ext/build_defaults.yaml +1 -1
  4. data/ext/debian/changelog.erb +4 -22
  5. data/ext/debian/control +2 -2
  6. data/ext/project_data.yaml +1 -1
  7. data/ext/redhat/facter.spec.erb +10 -9
  8. data/install.rb +27 -53
  9. data/lib/facter.rb +23 -5
  10. data/lib/facter/application.rb +21 -0
  11. data/lib/facter/blockdevices.rb +105 -0
  12. data/lib/facter/domain.rb +19 -7
  13. data/lib/facter/filesystems.rb +38 -0
  14. data/lib/facter/hardwaremodel.rb +3 -2
  15. data/lib/facter/ipaddress6.rb +1 -2
  16. data/lib/facter/kernelrelease.rb +10 -2
  17. data/lib/facter/ldom.rb +47 -0
  18. data/lib/facter/macaddress.rb +1 -1
  19. data/lib/facter/manufacturer.rb +7 -1
  20. data/lib/facter/memory.rb +58 -160
  21. data/lib/facter/operatingsystem.rb +17 -2
  22. data/lib/facter/operatingsystemmajrelease.rb +33 -0
  23. data/lib/facter/operatingsystemrelease.rb +88 -37
  24. data/lib/facter/osfamily.rb +6 -2
  25. data/lib/facter/processor.rb +2 -2
  26. data/lib/facter/ps.rb +5 -0
  27. data/lib/facter/ssh.rb +50 -12
  28. data/lib/facter/util/cfpropertylist.rb +6 -0
  29. data/lib/facter/util/cfpropertylist/LICENSE +19 -0
  30. data/lib/facter/util/cfpropertylist/README +44 -0
  31. data/lib/facter/util/cfpropertylist/Rakefile +44 -0
  32. data/lib/facter/util/cfpropertylist/THANKS +7 -0
  33. data/lib/facter/util/cfpropertylist/lib/cfpropertylist.rb +6 -0
  34. data/lib/facter/util/cfpropertylist/lib/rbBinaryCFPropertyList.rb +562 -0
  35. data/lib/facter/util/cfpropertylist/lib/rbCFPlistError.rb +26 -0
  36. data/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb +402 -0
  37. data/lib/facter/util/cfpropertylist/lib/rbCFTypes.rb +244 -0
  38. data/lib/facter/util/cfpropertylist/lib/rbLibXMLParser.rb +135 -0
  39. data/lib/facter/util/cfpropertylist/lib/rbNokogiriParser.rb +140 -0
  40. data/lib/facter/util/cfpropertylist/lib/rbREXMLParser.rb +136 -0
  41. data/lib/facter/util/collection.rb +36 -14
  42. data/lib/facter/util/composite_loader.rb +12 -0
  43. data/lib/facter/util/config.rb +36 -0
  44. data/lib/facter/util/confine.rb +1 -6
  45. data/lib/facter/util/directory_loader.rb +83 -0
  46. data/lib/facter/util/fact.rb +49 -42
  47. data/lib/facter/util/file_read.rb +32 -0
  48. data/lib/facter/util/ip.rb +2 -9
  49. data/lib/facter/util/loader.rb +16 -2
  50. data/lib/facter/util/macosx.rb +15 -2
  51. data/lib/facter/util/memory.rb +154 -27
  52. data/lib/facter/util/nothing_loader.rb +15 -0
  53. data/lib/facter/util/parser.rb +141 -0
  54. data/lib/facter/util/processor.rb +27 -35
  55. data/lib/facter/util/resolution.rb +97 -26
  56. data/lib/facter/util/solaris_zones.rb +153 -0
  57. data/lib/facter/util/virtual.rb +32 -3
  58. data/lib/facter/version.rb +72 -2
  59. data/lib/facter/virtual.rb +56 -3
  60. data/lib/facter/zfs_version.rb +10 -0
  61. data/lib/facter/zonename.rb +6 -0
  62. data/lib/facter/zones.rb +17 -0
  63. data/lib/facter/zpool_version.rb +10 -0
  64. data/spec/fixtures/ifconfig/ifconfig_net_tools_1.60.txt +19 -0
  65. data/spec/fixtures/ifconfig/ifconfig_ubuntu_1204.txt +16 -0
  66. data/spec/fixtures/ldom/ldom_v1 +6 -0
  67. data/spec/fixtures/unit/filesystems/linux +28 -0
  68. data/spec/fixtures/unit/util/manufacturer/intel_linux_dmidecode +549 -0
  69. data/spec/fixtures/unit/virtual/sysfs_dmi_entries_raw.txt +0 -0
  70. data/spec/fixtures/unit/zfs_version/freebsd_8.2 +14 -0
  71. data/spec/fixtures/unit/zfs_version/freebsd_9.0 +13 -0
  72. data/spec/fixtures/unit/zfs_version/linux-fuse_0.6.9 +14 -0
  73. data/spec/fixtures/unit/zfs_version/solaris_10 +10 -0
  74. data/spec/fixtures/unit/zfs_version/solaris_11 +12 -0
  75. data/spec/fixtures/unit/zpool_version/freebsd_8.2 +26 -0
  76. data/spec/fixtures/unit/zpool_version/freebsd_9.0 +38 -0
  77. data/spec/fixtures/unit/zpool_version/linux-fuse_0.6.9 +35 -0
  78. data/spec/fixtures/unit/zpool_version/solaris_10 +31 -0
  79. data/spec/fixtures/unit/zpool_version/solaris_11 +43 -0
  80. data/spec/integration/facter_spec.rb +12 -0
  81. data/spec/spec_helper.rb +9 -0
  82. data/spec/unit/architecture_spec.rb +1 -1
  83. data/spec/unit/blockdevices_spec.rb +109 -0
  84. data/spec/unit/domain_spec.rb +189 -81
  85. data/spec/unit/ec2_spec.rb +15 -8
  86. data/spec/unit/filesystems_spec.rb +50 -0
  87. data/spec/unit/hardwaremodel_spec.rb +8 -1
  88. data/spec/unit/id_spec.rb +6 -5
  89. data/spec/unit/ipaddress6_spec.rb +14 -2
  90. data/spec/unit/ipaddress_spec.rb +1 -1
  91. data/spec/unit/kernel_spec.rb +24 -0
  92. data/spec/unit/kernelmajversion_spec.rb +17 -0
  93. data/spec/unit/kernelrelease_spec.rb +53 -0
  94. data/spec/unit/kernelversion_spec.rb +32 -0
  95. data/spec/unit/ldom_spec.rb +74 -0
  96. data/spec/unit/macaddress_spec.rb +3 -1
  97. data/spec/unit/manufacturer_spec.rb +115 -0
  98. data/spec/unit/memory_spec.rb +442 -75
  99. data/spec/unit/operatingsystem_spec.rb +16 -2
  100. data/spec/unit/operatingsystemmajrelease_spec.rb +16 -0
  101. data/spec/unit/operatingsystemrelease_spec.rb +110 -1
  102. data/spec/unit/processor_spec.rb +22 -7
  103. data/spec/unit/ps_spec.rb +42 -0
  104. data/spec/unit/ssh_spec.rb +76 -0
  105. data/spec/unit/util/collection_spec.rb +94 -118
  106. data/spec/unit/util/config_spec.rb +36 -5
  107. data/spec/unit/util/confine_spec.rb +31 -43
  108. data/spec/unit/util/directory_loader_spec.rb +87 -0
  109. data/spec/unit/util/fact_spec.rb +37 -25
  110. data/spec/unit/util/file_read_spec.rb +29 -0
  111. data/spec/unit/util/ip_spec.rb +4 -2
  112. data/spec/unit/util/loader_spec.rb +102 -45
  113. data/spec/unit/util/macosx_spec.rb +40 -9
  114. data/spec/unit/util/manufacturer_spec.rb +12 -1
  115. data/spec/unit/util/parser_spec.rb +135 -0
  116. data/spec/unit/util/resolution_spec.rb +136 -4
  117. data/spec/unit/util/solaris_zones_spec.rb +127 -0
  118. data/spec/unit/util/virtual_spec.rb +54 -0
  119. data/spec/unit/version_spec.rb +42 -0
  120. data/spec/unit/virtual_spec.rb +102 -27
  121. data/spec/unit/zfs_version_spec.rb +76 -0
  122. data/spec/unit/zonename_spec.rb +14 -0
  123. data/spec/unit/zones_spec.rb +55 -0
  124. data/spec/unit/zpool_version_spec.rb +76 -0
  125. metadata +113 -11
  126. data/lib/facter/arp.rb +0 -28
@@ -0,0 +1,127 @@
1
+ require 'spec_helper'
2
+ require 'facter/util/solaris_zones'
3
+
4
+ describe Facter::Util::SolarisZones do
5
+ let :zone_list do
6
+ zone_list = <<-EOF
7
+ 0:global:running:/::native:shared
8
+ -:local:configured:/::native:shared
9
+ -:zoneA:stopped:/::native:shared
10
+ EOF
11
+ end
12
+
13
+ let :zone_list2 do
14
+ zone_list = <<-EOF
15
+ 0:global:running:/::native:shared
16
+ -:local:configured:/::native:shared
17
+ -:zoneB:stopped:/::native:shared
18
+ -:zoneC:stopped:/::native:shared
19
+ EOF
20
+ end
21
+
22
+ subject do
23
+ described_class.new(:zoneadm_output => zone_list)
24
+ end
25
+
26
+ describe '.add_facts' do
27
+ before :each do
28
+ zones = described_class.new(:zoneadm_output => zone_list)
29
+ zones.send(:parse!)
30
+ zones.stubs(:refresh)
31
+ described_class.stubs(:new).returns(zones)
32
+ end
33
+
34
+ it 'defines the zones fact' do
35
+ described_class.add_facts
36
+ Facter.fact(:zones).value.should == 3
37
+ end
38
+
39
+ it 'defines a fact for each attribute of a zone' do
40
+ described_class.add_facts
41
+ [:id, :name, :status, :path, :uuid, :brand, :iptype].each do |attr|
42
+ Facter.fact("zone_local_#{attr}".intern).
43
+ should be_a_kind_of Facter::Util::Fact
44
+ end
45
+ end
46
+ end
47
+
48
+ describe '#refresh' do
49
+ it 'executes the zoneadm_cmd' do
50
+ Facter::Util::Resolution.expects(:exec).with(subject.zoneadm_cmd).returns(zone_list)
51
+ subject.refresh
52
+ end
53
+ end
54
+
55
+ describe 'multiple facts sharing a single model' do
56
+ context 'when zones is resolved for the first time' do
57
+ it 'counts the number of zones' do
58
+ given_initial_zone_facts
59
+ Facter.fact(:zones).value.should == 3
60
+ end
61
+ it 'defines facts for zoneA' do
62
+ given_initial_zone_facts
63
+ Facter.fact(:zone_zoneA_id).value.should == '-'
64
+ end
65
+ it 'does not define facts for zoneB' do
66
+ given_initial_zone_facts
67
+ Facter.fact(:zone_zoneB_id).should be_nil
68
+ end
69
+ it 'uses a single read of the system information for all of the dynamically generated zone facts' do
70
+ given_initial_zone_facts # <= single read happens here
71
+
72
+ Facter::Util::Resolution.expects(:exec).never
73
+ Facter.fact(:zone_zoneA_id).value
74
+ Facter.fact(:zone_local_id).value
75
+ end
76
+ end
77
+ context 'when all facts have been flushed after zones was resolved once' do
78
+ it 'updates the number of zones' do
79
+ given_initial_zone_facts
80
+ when_facts_have_been_resolved_then_flushed
81
+
82
+ Facter.fact(:zones).value.should == 4
83
+ end
84
+ it 'stops resolving a value for a zone that no longer exists' do
85
+ given_initial_zone_facts
86
+ when_facts_have_been_resolved_then_flushed
87
+
88
+ Facter.fact(:zone_zoneA_id).value.should be_nil
89
+ Facter.fact(:zone_zoneA_status).value.should be_nil
90
+ Facter.fact(:zone_zoneA_path).value.should be_nil
91
+ end
92
+ it 'defines facts for new zones' do
93
+ given_initial_zone_facts
94
+ when_facts_have_been_resolved_then_flushed
95
+
96
+ Facter.fact(:zone_zoneB_id).should be_nil
97
+ Facter.fact(:zones).value
98
+ Facter.fact(:zone_zoneB_id).value.should be_a_kind_of String
99
+ end
100
+ it 'uses a single read of the system information for all of the dynamically generated zone facts' do
101
+ given_initial_zone_facts
102
+ when_facts_have_been_resolved_then_flushed
103
+
104
+ Facter::Util::Resolution.expects(:exec).once.returns(zone_list2)
105
+ Facter.fact(:zones).value
106
+ Facter.fact(:zone_zoneA_id).value
107
+ Facter.fact(:zone_local_id).value
108
+ end
109
+
110
+ end
111
+ end
112
+
113
+ def given_initial_zone_facts
114
+ Facter::Util::Resolution.stubs(:exec).
115
+ with(subject.zoneadm_cmd).
116
+ returns(zone_list)
117
+ described_class.add_facts
118
+ end
119
+
120
+ def when_facts_have_been_resolved_then_flushed
121
+ Facter.fact(:zones).value
122
+ Facter.fact(:zone_zoneA_id).value
123
+ Facter.fact(:zone_local_id).value
124
+ Facter::Util::Resolution.stubs(:exec).returns(zone_list2)
125
+ Facter.flush
126
+ end
127
+ end
@@ -81,6 +81,44 @@ describe Facter::Util::Virtual do
81
81
  Facter::Util::Virtual.should_not be_vserver
82
82
  end
83
83
 
84
+ it "should identify kvm" do
85
+ Facter::Util::Virtual.stubs(:kvm?).returns(true)
86
+ Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("something")
87
+ Facter::Util::Virtual.kvm_type().should == "kvm"
88
+ end
89
+
90
+ it "should be able to detect RHEV via sysfs on Linux" do
91
+ # Fake files are always hard to stub. :/
92
+ File.stubs(:read).with("/sys/devices/virtual/dmi/id/product_name").
93
+ returns("RHEV Hypervisor")
94
+
95
+ Facter::Util::Virtual.should be_rhev
96
+ end
97
+
98
+ it "should be able to detect RHEV via sysfs on Linux improperly" do
99
+ # Fake files are always hard to stub. :/
100
+ File.stubs(:read).with("/sys/devices/virtual/dmi/id/product_name").
101
+ returns("something else")
102
+
103
+ Facter::Util::Virtual.should_not be_rhev
104
+ end
105
+
106
+ it "should be able to detect ovirt via sysfs on Linux" do
107
+ # Fake files are always hard to stub. :/
108
+ File.stubs(:read).with("/sys/devices/virtual/dmi/id/product_name").
109
+ returns("oVirt Node")
110
+
111
+ Facter::Util::Virtual.should be_ovirt
112
+ end
113
+
114
+ it "should be able to detect ovirt via sysfs on Linux improperly" do
115
+ # Fake files are always hard to stub. :/
116
+ File.stubs(:read).with("/sys/devices/virtual/dmi/id/product_name").
117
+ returns("something else")
118
+
119
+ Facter::Util::Virtual.should_not be_ovirt
120
+ end
121
+
84
122
  fixture_path = fixtures('virtual', 'proc_self_status')
85
123
 
86
124
  test_cases = [
@@ -181,4 +219,20 @@ describe Facter::Util::Virtual do
181
219
  Facter::Util::Resolution.stubs(:exec).with("/usr/bin/getconf MACHINE_MODEL").returns('ia64 hp server rx660')
182
220
  Facter::Util::Virtual.should_not be_hpvm
183
221
  end
222
+
223
+ it "should be able to detect virtualbox via sysfs on Linux" do
224
+ # Fake files are always hard to stub. :/
225
+ File.stubs(:read).with("/sys/devices/virtual/dmi/id/product_name").
226
+ returns("VirtualBox")
227
+
228
+ Facter::Util::Virtual.should be_virtualbox
229
+ end
230
+
231
+ it "should be able to detect virtualbox via sysfs on Linux improperly" do
232
+ # Fake files are always hard to stub. :/
233
+ File.stubs(:read).with("/sys/devices/virtual/dmi/id/product_name").
234
+ returns("HP-Oracle-Sun-VMWare-funky-town")
235
+
236
+ Facter::Util::Virtual.should_not be_virtualbox
237
+ end
184
238
  end
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+ require "facter/version"
3
+ require 'pathname'
4
+
5
+ describe "Facter.version Public API" do
6
+ before :each do
7
+ Facter.instance_eval do
8
+ if @facter_version
9
+ @facter_version = nil
10
+ end
11
+ end
12
+ end
13
+
14
+ context "without a VERSION file" do
15
+ before :each do
16
+ Facter.stubs(:read_version_file).returns(nil)
17
+ end
18
+
19
+ it "is Facter::FACTERVERSION" do
20
+ Facter.version.should == Facter::FACTERVERSION
21
+ end
22
+ it "respects the version= setter" do
23
+ Facter.version = '1.2.3'
24
+ Facter.version.should == '1.2.3'
25
+ end
26
+ end
27
+
28
+ context "with a VERSION file" do
29
+ it "is the content of the file" do
30
+ Facter.expects(:read_version_file).with() do |path|
31
+ pathname = Pathname.new(path)
32
+ pathname.basename.to_s == "VERSION"
33
+ end.returns('1.6.14-6-gea42046')
34
+
35
+ Facter.version.should == '1.6.14-6-gea42046'
36
+ end
37
+ it "respects the version= setter" do
38
+ Facter.version = '1.2.3'
39
+ Facter.version.should == '1.2.3'
40
+ end
41
+ end
42
+ end
@@ -14,6 +14,8 @@ describe "Virtual fact" do
14
14
  Facter::Util::Virtual.stubs(:hpvm?).returns(false)
15
15
  Facter::Util::Virtual.stubs(:zlinux?).returns(false)
16
16
  Facter::Util::Virtual.stubs(:virt_what).returns(nil)
17
+ Facter::Util::Virtual.stubs(:rhev?).returns(false)
18
+ Facter::Util::Virtual.stubs(:ovirt?).returns(false)
17
19
  Facter::Util::Virtual.stubs(:virtualbox?).returns(false)
18
20
  end
19
21
 
@@ -46,26 +48,26 @@ describe "Virtual fact" do
46
48
  end
47
49
 
48
50
  describe "on Darwin" do
49
- it "should be parallels with Parallels vendor id" do
51
+ before do
50
52
  Facter.fact(:kernel).stubs(:value).returns("Darwin")
53
+ end
54
+
55
+ it "should be parallels with Parallels vendor id" do
51
56
  Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor-id" => "0x1ab8" })
52
57
  Facter.fact(:virtual).value.should == "parallels"
53
58
  end
54
59
 
55
60
  it "should be parallels with Parallels vendor name" do
56
- Facter.fact(:kernel).stubs(:value).returns("Darwin")
57
61
  Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor" => "Parallels" })
58
62
  Facter.fact(:virtual).value.should == "parallels"
59
63
  end
60
64
 
61
65
  it "should be vmware with VMWare vendor id" do
62
- Facter.fact(:kernel).stubs(:value).returns("Darwin")
63
66
  Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor-id" => "0x15ad" })
64
67
  Facter.fact(:virtual).value.should == "vmware"
65
68
  end
66
69
 
67
70
  it "should be vmware with VMWare vendor name" do
68
- Facter.fact(:kernel).stubs(:value).returns("Darwin")
69
71
  Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor" => "VMWare" })
70
72
  Facter.fact(:virtual).value.should == "vmware"
71
73
  end
@@ -73,9 +75,11 @@ describe "Virtual fact" do
73
75
 
74
76
  describe "on Linux" do
75
77
  before(:each) do
78
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
79
+ Facter.fact(:operatingsystem).stubs(:value).returns("Linux")
80
+
76
81
  Facter::Util::Resolution.stubs(:exec).with("vmware -v").returns false
77
- Facter.fact(:operatingsystem).stubs(:value).returns(true)
78
- # Ensure the tests don't fail on Xen
82
+
79
83
  FileTest.stubs(:exists?).with("/proc/sys/xen").returns false
80
84
  FileTest.stubs(:exists?).with("/sys/bus/xen").returns false
81
85
  FileTest.stubs(:exists?).with("/proc/xen").returns false
@@ -83,103 +87,133 @@ describe "Virtual fact" do
83
87
  end
84
88
 
85
89
  it "should be parallels with Parallels vendor id from lspci 2>/dev/null" do
86
- Facter.fact(:kernel).stubs(:value).returns("Linux")
87
90
  Facter::Util::Virtual.stubs(:lspci).returns("01:00.0 VGA compatible controller: Unknown device 1ab8:4005")
88
91
  Facter.fact(:virtual).value.should == "parallels"
89
92
  end
90
93
 
91
94
  it "should be parallels with Parallels vendor name from lspci 2>/dev/null" do
92
- Facter.fact(:kernel).stubs(:value).returns("Linux")
93
95
  Facter::Util::Virtual.stubs(:lspci).returns("01:00.0 VGA compatible controller: Parallels Display Adapter")
94
96
  Facter.fact(:virtual).value.should == "parallels"
95
97
  end
96
98
 
97
99
  it "should be vmware with VMware vendor name from lspci 2>/dev/null" do
98
- Facter.fact(:kernel).stubs(:value).returns("Linux")
99
100
  Facter::Util::Resolution.stubs(:exec).with('lspci 2>/dev/null').returns("00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter")
100
101
  Facter.fact(:virtual).value.should == "vmware"
101
102
  end
102
103
 
103
104
  it "should be virtualbox with VirtualBox vendor name from lspci 2>/dev/null" do
104
- Facter.fact(:kernel).stubs(:value).returns("Linux")
105
105
  Facter::Util::Resolution.stubs(:exec).with('lspci 2>/dev/null').returns("00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter")
106
106
  Facter.fact(:virtual).value.should == "virtualbox"
107
107
  end
108
108
 
109
109
  it "should be vmware with VMWare vendor name from dmidecode" do
110
- Facter.fact(:kernel).stubs(:value).returns("Linux")
111
110
  Facter::Util::Resolution.stubs(:exec).with('lspci 2>/dev/null').returns(nil)
112
111
  Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("On Board Device 1 Information\nType: Video\nStatus: Disabled\nDescription: VMware SVGA II")
113
112
  Facter.fact(:virtual).value.should == "vmware"
114
113
  end
115
114
 
116
115
  it "should be xen0 with xen dom0 files in /proc" do
117
- Facter.fact(:kernel).stubs(:value).returns("Linux")
118
- Facter.fact(:operatingsystem).stubs(:value).returns("Linux")
119
116
  Facter.fact(:hardwaremodel).stubs(:value).returns("i386")
120
117
  Facter::Util::Virtual.expects(:xen?).returns(true)
121
- FileTest.expects(:exists?).with("/proc/xen/xsd_kva").returns(true)
118
+ FileTest.expects(:exists?).with("/dev/xen/evtchn").returns(true)
122
119
  Facter.fact(:virtual).value.should == "xen0"
123
120
  end
124
121
 
125
122
  it "should be xenu with xen domU files in /proc" do
126
- Facter.fact(:kernel).stubs(:value).returns("Linux")
127
- Facter.fact(:operatingsystem).stubs(:value).returns("Linux")
128
123
  Facter.fact(:hardwaremodel).stubs(:value).returns("i386")
129
124
  Facter::Util::Virtual.expects(:xen?).returns(true)
130
- FileTest.expects(:exists?).with("/proc/xen/xsd_kva").returns(false)
131
- FileTest.expects(:exists?).with("/proc/xen/capabilities").returns(true)
125
+ FileTest.expects(:exists?).with("/dev/xen/evtchn").returns(false)
126
+ FileTest.expects(:exists?).with("/proc/xen").returns(true)
132
127
  Facter.fact(:virtual).value.should == "xenu"
133
128
  end
134
129
 
135
130
  it "should be xenhvm with Xen HVM vendor name from lspci 2>/dev/null" do
136
- Facter.fact(:kernel).stubs(:value).returns("Linux")
137
131
  Facter::Util::Resolution.stubs(:exec).with('lspci 2>/dev/null').returns("00:03.0 Unassigned class [ff80]: XenSource, Inc. Xen Platform Device (rev 01)")
138
132
  Facter.fact(:virtual).value.should == "xenhvm"
139
133
  end
140
134
 
141
135
  it "should be xenhvm with Xen HVM vendor name from dmidecode" do
142
- Facter.fact(:kernel).stubs(:value).returns("Linux")
143
136
  Facter::Util::Resolution.stubs(:exec).with('lspci 2>/dev/null').returns(nil)
144
137
  Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("System Information\nManufacturer: Xen\nProduct Name: HVM domU")
145
138
  Facter.fact(:virtual).value.should == "xenhvm"
146
139
  end
147
140
 
148
141
  it "should be parallels with Parallels vendor name from dmidecode" do
149
- Facter.fact(:kernel).stubs(:value).returns("Linux")
150
142
  Facter::Util::Resolution.stubs(:exec).with('lspci 2>/dev/null').returns(nil)
151
143
  Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("On Board Device Information\nType: Video\nStatus: Disabled\nDescription: Parallels Video Adapter")
152
144
  Facter.fact(:virtual).value.should == "parallels"
153
145
  end
154
146
 
155
147
  it "should be virtualbox with VirtualBox vendor name from dmidecode" do
156
- Facter.fact(:kernel).stubs(:value).returns("Linux")
157
148
  Facter::Util::Resolution.stubs(:exec).with('lspci 2>/dev/null').returns(nil)
158
149
  Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("BIOS Information\nVendor: innotek GmbH\nVersion: VirtualBox\n\nSystem Information\nManufacturer: innotek GmbH\nProduct Name: VirtualBox\nFamily: Virtual Machine")
159
150
  Facter.fact(:virtual).value.should == "virtualbox"
160
151
  end
161
152
 
162
- it "should be hyperv with Microsoft vendor name from lspci 2>/dev/null" do
153
+ it "should be rhev with RHEV Hypervisor product name from dmidecode" do
154
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
155
+ Facter::Util::Resolution.stubs(:exec).with('lspci 2>/dev/null').returns(nil)
156
+ Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("Product Name: RHEV Hypervisor")
157
+ Facter.fact(:virtual).value.should == "rhev"
158
+ end
159
+
160
+ it "should be ovirt with oVirt Node product name from dmidecode" do
163
161
  Facter.fact(:kernel).stubs(:value).returns("Linux")
162
+ Facter::Util::Resolution.stubs(:exec).with('lspci 2>/dev/null').returns(nil)
163
+ Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("Product Name: oVirt Node")
164
+ Facter.fact(:virtual).value.should == "ovirt"
165
+ end
166
+
167
+ it "should be hyperv with Microsoft vendor name from lspci 2>/dev/null" do
164
168
  Facter::Util::Resolution.stubs(:exec).with('lspci 2>/dev/null').returns("00:08.0 VGA compatible controller: Microsoft Corporation Hyper-V virtual VGA")
165
169
  Facter.fact(:virtual).value.should == "hyperv"
166
170
  end
167
171
 
168
172
  it "should be hyperv with Microsoft vendor name from dmidecode" do
169
- Facter.fact(:kernel).stubs(:value).returns("Linux")
170
173
  Facter::Util::Resolution.stubs(:exec).with('lspci 2>/dev/null').returns(nil)
171
174
  Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns("System Information\nManufacturer: Microsoft Corporation\nProduct Name: Virtual Machine")
172
175
  Facter.fact(:virtual).value.should == "hyperv"
173
176
  end
177
+
178
+ context "In Google Compute Engine" do
179
+ before :each do
180
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
181
+ end
182
+
183
+ context "Without /sys/firmware/dmi/entries/1-0/raw" do
184
+ before :each do
185
+ Facter::Util::Virtual.stubs(:read_sysfs_dmi_entries).returns(nil)
186
+ end
187
+
188
+ it "should be gce with gce vendor name from lspci 2>/dev/null" do
189
+ Facter::Util::Resolution.stubs(:exec).with('lspci 2>/dev/null').returns("00:05.0 Class 8007: Google, Inc. Device 6442")
190
+ Facter.fact(:virtual).value.should == "gce"
191
+ end
192
+ end
193
+
194
+ context "With /sys/firmware/dmi/entries/1-0/raw" do
195
+ let :sysfs_dmi_raw do
196
+ my_fixture_read('sysfs_dmi_entries_raw.txt')
197
+ end
198
+
199
+ before :each do
200
+ Facter::Util::Virtual.stubs(:read_sysfs_dmi_entries).returns(sysfs_dmi_raw)
201
+ end
202
+
203
+ it "(#17612) is 'gce'" do
204
+ Facter.fact(:virtual).value.should == "gce"
205
+ end
206
+ end
207
+ end
174
208
  end
175
209
 
176
210
  describe "on Solaris" do
177
211
  before(:each) do
178
212
  Facter::Util::Resolution.stubs(:exec).with("vmware -v").returns false
213
+ Facter.fact(:kernel).stubs(:value).returns("SunOS")
179
214
  end
180
215
 
181
216
  it "should be vmware with VMWare vendor name from prtdiag" do
182
- Facter.fact(:kernel).stubs(:value).returns("SunOS")
183
217
  Facter.fact(:hardwaremodel).stubs(:value).returns(nil)
184
218
  Facter::Util::Resolution.stubs(:exec).with('lspci 2>/dev/null').returns(nil)
185
219
  Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil)
@@ -188,7 +222,6 @@ describe "Virtual fact" do
188
222
  end
189
223
 
190
224
  it "should be parallels with Parallels vendor name from prtdiag" do
191
- Facter.fact(:kernel).stubs(:value).returns("SunOS")
192
225
  Facter.fact(:hardwaremodel).stubs(:value).returns(nil)
193
226
  Facter::Util::Resolution.stubs(:exec).with('lspci 2>/dev/null').returns(nil)
194
227
  Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil)
@@ -197,7 +230,6 @@ describe "Virtual fact" do
197
230
  end
198
231
 
199
232
  it "should be virtualbox with VirtualBox vendor name from prtdiag" do
200
- Facter.fact(:kernel).stubs(:value).returns("SunOS")
201
233
  Facter.fact(:hardwaremodel).stubs(:value).returns(nil)
202
234
  Facter::Util::Resolution.stubs(:exec).with('lspci 2>/dev/null').returns(nil)
203
235
  Facter::Util::Resolution.stubs(:exec).with('dmidecode').returns(nil)
@@ -236,6 +268,37 @@ describe "Virtual fact" do
236
268
  end
237
269
  end
238
270
 
271
+ describe "on Windows" do
272
+ require 'facter/util/wmi'
273
+ before do
274
+ Facter.fact(:kernel).stubs(:value).returns("windows")
275
+ end
276
+
277
+ it "should be kvm with KVM model name from Win32_ComputerSystem" do
278
+ computersystem = mock('computersystem', :model => 'KVM')
279
+ Facter::Util::WMI.expects(:execquery).returns([computersystem])
280
+ Facter.fact(:virtual).value.should == "kvm"
281
+ end
282
+
283
+ it "should be hyperv with Virtual Machine model name and Microsoft Corporation manufacturer from Win32_ComputerSystem" do
284
+ computersystem = mock('computersystem', :manufacturer => 'Microsoft Corporation', :model => 'Virtual Machine')
285
+ Facter::Util::WMI.expects(:execquery).returns([computersystem])
286
+ Facter.fact(:virtual).value.should == "hyperv"
287
+ end
288
+
289
+ it "should be virtualbox with VirtualBox model name from Win32_ComputerSystem" do
290
+ computersystem = mock('computersystem', :model => 'VirtualBox')
291
+ Facter::Util::WMI.expects(:execquery).returns([computersystem])
292
+ Facter.fact(:virtual).value.should == "virtualbox"
293
+ end
294
+
295
+ it "should be vmware with VMware like model name from Win32_ComputerSystem" do
296
+ computersystem = mock('computersystem', :model => 'VMware Virtual Platform')
297
+ Facter::Util::WMI.expects(:execquery).returns([computersystem])
298
+ Facter.fact(:virtual).value.should == "vmware"
299
+ end
300
+ end
301
+
239
302
  describe "with the virt-what command available (#8210)" do
240
303
  describe "when the output of virt-what disagrees with lower weight facts" do
241
304
  virt_what_map = {
@@ -367,4 +430,16 @@ describe "is_virtual fact" do
367
430
  Facter.fact(:virtual).stubs(:value).returns("hyperv")
368
431
  Facter.fact(:is_virtual).value.should == "true"
369
432
  end
433
+
434
+ it "should be true when running on rhev" do
435
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
436
+ Facter.fact(:virtual).stubs(:value).returns("rhev")
437
+ Facter.fact(:is_virtual).value.should == "true"
438
+ end
439
+
440
+ it "should be true when running on ovirt" do
441
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
442
+ Facter.fact(:virtual).stubs(:value).returns("ovirt")
443
+ Facter.fact(:is_virtual).value.should == "true"
444
+ end
370
445
  end