facter 2.0.2-x86-mingw32 → 2.1.0-x86-mingw32

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 (120) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +14 -0
  3. data/ext/project_data.yaml +9 -6
  4. data/lib/facter/core/execution/base.rb +3 -3
  5. data/lib/facter/core/suitable.rb +1 -5
  6. data/lib/facter/dhcp_servers.rb +39 -0
  7. data/lib/facter/ec2.rb +33 -26
  8. data/lib/facter/ec2/rest.rb +130 -0
  9. data/lib/facter/fqdn.rb +2 -0
  10. data/lib/facter/gce.rb +16 -0
  11. data/lib/facter/gce/metadata.rb +87 -0
  12. data/lib/facter/kernelmajversion.rb +8 -0
  13. data/lib/facter/kernelrelease.rb +8 -0
  14. data/lib/facter/memory.rb +21 -15
  15. data/lib/facter/netmask.rb +1 -1
  16. data/lib/facter/operatingsystem.rb +20 -0
  17. data/lib/facter/operatingsystemmajrelease.rb +2 -1
  18. data/lib/facter/operatingsystemrelease.rb +19 -0
  19. data/lib/facter/osfamily.rb +3 -1
  20. data/lib/facter/partitions.rb +35 -0
  21. data/lib/facter/physicalprocessorcount.rb +9 -0
  22. data/lib/facter/processor.rb +25 -25
  23. data/lib/facter/util/config.rb +3 -1
  24. data/lib/facter/util/dhcp_servers.rb +43 -0
  25. data/lib/facter/util/ec2.rb +5 -0
  26. data/lib/facter/util/formatter.rb +2 -1
  27. data/lib/facter/util/ip.rb +1 -1
  28. data/lib/facter/util/loader.rb +10 -1
  29. data/lib/facter/util/manufacturer.rb +15 -16
  30. data/lib/facter/util/memory.rb +12 -12
  31. data/lib/facter/util/netmask.rb +1 -1
  32. data/lib/facter/util/operatingsystem.rb +21 -0
  33. data/lib/facter/util/partitions.rb +41 -0
  34. data/lib/facter/util/partitions/linux.rb +65 -0
  35. data/lib/facter/util/posix.rb +16 -0
  36. data/lib/facter/util/processor.rb +8 -10
  37. data/lib/facter/util/resolution.rb +4 -0
  38. data/lib/facter/util/values.rb +29 -0
  39. data/lib/facter/util/virtual.rb +32 -3
  40. data/lib/facter/util/windows_root.rb +2 -32
  41. data/lib/facter/version.rb +1 -1
  42. data/lib/facter/virtual.rb +53 -12
  43. data/spec/fixtures/ifconfig/openbsd_bridge_rules +11 -0
  44. data/spec/fixtures/unit/dhcp_servers/nmcli_devices +4 -0
  45. data/spec/fixtures/unit/dhcp_servers/nmcli_devices_disconnected +4 -0
  46. data/spec/fixtures/unit/dhcp_servers/nmcli_eth0_dhcp +36 -0
  47. data/spec/fixtures/unit/dhcp_servers/nmcli_eth0_static +24 -0
  48. data/spec/fixtures/unit/dhcp_servers/nmcli_wlan0_dhcp +49 -0
  49. data/spec/fixtures/unit/dhcp_servers/nmcli_wlan0_static +37 -0
  50. data/spec/fixtures/unit/dhcp_servers/route +3 -0
  51. data/spec/fixtures/unit/dhcp_servers/route_nogw +1 -0
  52. data/spec/fixtures/unit/ec2/rest/meta-data/root +20 -0
  53. data/spec/fixtures/unit/gce/metadata/metadata.json +69 -0
  54. data/spec/fixtures/unit/kernelrelease/openbsd-5.3 +2 -0
  55. data/spec/fixtures/unit/kernelrelease/openbsd-5.3-current +3 -0
  56. data/spec/fixtures/unit/memory/aix-svmon +9 -0
  57. data/spec/fixtures/unit/memory/aix-swap_l +2 -0
  58. data/spec/fixtures/unit/memory/darwin-swapinfo-multiple +3 -0
  59. data/spec/fixtures/unit/memory/darwin-swapinfo-single +2 -0
  60. data/spec/fixtures/unit/memory/darwin-vm_stat +13 -0
  61. data/spec/fixtures/unit/memory/dragonfly-vmstat +3 -0
  62. data/spec/fixtures/unit/memory/freebsd-vmstat +3 -0
  63. data/spec/fixtures/unit/memory/linux-proc_meminfo +10 -0
  64. data/spec/fixtures/unit/memory/openbsd-vmstat +3 -0
  65. data/spec/fixtures/unit/memory/smartos_zone_swap_l-single +2 -0
  66. data/spec/fixtures/unit/memory/solaris-prtconf +4 -0
  67. data/spec/fixtures/unit/memory/solaris-swap_l-multiple +3 -0
  68. data/spec/fixtures/unit/memory/solaris-swap_l-single +2 -0
  69. data/spec/fixtures/unit/memory/solaris-vmstat +3 -0
  70. data/spec/fixtures/unit/netmask/ifconfig_aix_7.txt +3 -0
  71. data/spec/fixtures/unit/util/dhcp_servers/route +3 -0
  72. data/spec/fixtures/unit/util/dhcp_servers/route_nogw +1 -0
  73. data/spec/fixtures/unit/util/manufacturer/smartos_smbios +533 -0
  74. data/spec/fixtures/unit/util/operatingsystem/cumuluslinux.txt +8 -0
  75. data/spec/fixtures/unit/util/operatingsystem/redhat-7.txt +12 -0
  76. data/spec/fixtures/unit/util/operatingsystem/sabayon.txt +7 -0
  77. data/spec/fixtures/unit/util/operatingsystem/wheezy.txt +9 -0
  78. data/spec/fixtures/unit/util/partitions/partitions/mount +9 -0
  79. data/spec/fixtures/virtual/proc_1_cgroup/in_a_container +9 -0
  80. data/spec/fixtures/virtual/proc_1_cgroup/in_a_docker_container +8 -0
  81. data/spec/fixtures/virtual/proc_1_cgroup/not_in_a_container +9 -0
  82. data/spec/spec_helper.rb +1 -1
  83. data/spec/unit/core/execution/base_spec.rb +3 -5
  84. data/spec/unit/core/execution/posix_spec.rb +2 -2
  85. data/spec/unit/core/suitable_spec.rb +10 -0
  86. data/spec/unit/dhcp_servers_spec.rb +152 -0
  87. data/spec/unit/ec2/rest_spec.rb +145 -0
  88. data/spec/unit/ec2_spec.rb +87 -147
  89. data/spec/unit/fqdn_spec.rb +16 -0
  90. data/spec/unit/gce/metadata_spec.rb +49 -0
  91. data/spec/unit/gce_spec.rb +34 -0
  92. data/spec/unit/interfaces_spec.rb +9 -9
  93. data/spec/unit/kernelmajversion_spec.rb +14 -9
  94. data/spec/unit/kernelrelease_spec.rb +16 -0
  95. data/spec/unit/macaddress_spec.rb +12 -0
  96. data/spec/unit/memory_spec.rb +53 -122
  97. data/spec/unit/netmask_spec.rb +11 -0
  98. data/spec/unit/operatingsystem_spec.rb +19 -0
  99. data/spec/unit/operatingsystemmajrelease_spec.rb +1 -1
  100. data/spec/unit/operatingsystemrelease_spec.rb +8 -0
  101. data/spec/unit/osfamily_spec.rb +62 -0
  102. data/spec/unit/partitions_spec.rb +48 -0
  103. data/spec/unit/physicalprocessorcount_spec.rb +9 -0
  104. data/spec/unit/processor_spec.rb +15 -7
  105. data/spec/unit/util/config_spec.rb +13 -0
  106. data/spec/unit/util/dhcp_servers_spec.rb +63 -0
  107. data/spec/unit/util/ec2_spec.rb +4 -0
  108. data/spec/unit/util/formatter_spec.rb +50 -0
  109. data/spec/unit/util/loader_spec.rb +4 -4
  110. data/spec/unit/util/macosx_spec.rb +3 -2
  111. data/spec/unit/util/manufacturer_spec.rb +44 -0
  112. data/spec/unit/util/operatingsystem_spec.rb +92 -0
  113. data/spec/unit/util/partitions/partitions_spec.rb +67 -0
  114. data/spec/unit/util/partitions_spec.rb +19 -0
  115. data/spec/unit/util/posix_spec.rb +11 -0
  116. data/spec/unit/util/values_spec.rb +40 -0
  117. data/spec/unit/util/virtual_spec.rb +72 -2
  118. data/spec/unit/virtual_spec.rb +67 -18
  119. metadata +124 -54
  120. data/spec/fixtures/unit/util/loader/nosuchfact.rb +0 -1
@@ -1,9 +1,10 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
- require 'facter/util/macosx'
4
+ require 'facter/util/config'
5
+ require 'facter/util/macosx' unless Facter::Util::Config.is_windows?
5
6
 
6
- describe Facter::Util::Macosx do
7
+ describe "Facter::Util::Macosx", :unless => Facter::Util::Config.is_windows? do
7
8
  let(:badplist) do
8
9
  '<?xml version="1.0" encoding="UTF-8"?>
9
10
  <!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
@@ -63,6 +63,17 @@ describe Facter::Manufacturer do
63
63
  Facter.value(:reldate).should == "12/01/2006"
64
64
  end
65
65
 
66
+ it "can parse smbios output that contains non-UTF8 characters" do
67
+ smbios_output = my_fixture_read("smartos_smbios")
68
+ Facter::Core::Execution.stubs(:exec).with('/usr/sbin/smbios 2>/dev/null').returns(smbios_output)
69
+ Facter.fact(:kernel).stubs(:value).returns("SunOS")
70
+
71
+ query = { 'BIOS information' => [ { 'Release Date:' => 'reldate' } ] }
72
+
73
+ Facter::Manufacturer.dmi_find_system_info(query)
74
+ Facter.value(:reldate).should == "06/11/2007"
75
+ end
76
+
66
77
  it "should not split on dmi keys containing the string Handle" do
67
78
  dmidecode_output = <<-eos
68
79
  Handle 0x1000, DMI type 16, 15 bytes
@@ -176,4 +187,37 @@ Handle 0x001F
176
187
  Facter.value(:serialnumber).should == "56 4d 40 2b 4d 81 94 d6-e6 c5 56 a4 56 0c 9e 9f"
177
188
  Facter.value(:productname).should == "VMware Virtual Platform"
178
189
  end
190
+
191
+ describe "using sysctl to look up manufacturer information" do
192
+ before do
193
+ Facter.fact(:kernel).stubs(:value).returns 'OpenBSD'
194
+ end
195
+
196
+ let(:mfg_keys) do
197
+ {
198
+ 'hw.vendor' => 'manufacturer',
199
+ 'hw.product' => 'productname',
200
+ 'hw.serialno' => 'serialnumber'
201
+ }
202
+ end
203
+
204
+ it "creates a new fact for the each hash key" do
205
+ mfg_keys.values.each do |value|
206
+ Facter.expects(:add).with(value)
207
+ end
208
+ described_class.sysctl_find_system_info(mfg_keys)
209
+ end
210
+
211
+ it "uses sysctl to determine the value for that fact" do
212
+ mfg_keys.keys.each do |sysctl|
213
+ Facter::Util::POSIX.expects(:sysctl).with(sysctl).returns "sysctl #{sysctl}"
214
+ end
215
+
216
+ described_class.sysctl_find_system_info(mfg_keys)
217
+
218
+ mfg_keys.invert.each_pair do |factname, value|
219
+ expect(Facter.value(factname)).to eq "sysctl #{value}"
220
+ end
221
+ end
222
+ end
179
223
  end
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+ require 'facter/util/operatingsystem'
3
+
4
+ describe Facter::Util::Operatingsystem do
5
+ describe "reading the os-release file" do
6
+
7
+ it "correctly parses the file on Cumulus Linux" do
8
+ values = described_class.os_release(my_fixture('cumuluslinux.txt'))
9
+
10
+ expect(values).to eq({
11
+ 'NAME' => "Cumulus Linux",
12
+ 'VERSION_ID' => "1.5.2",
13
+ 'VERSION' => "1.5.2-28283a7-201311181623-final",
14
+ 'PRETTY_NAME' => "Cumulus Linux",
15
+ 'ID' => "cumulus-linux",
16
+ 'ID_LIKE' => "debian",
17
+ 'CPE_NAME' => "cpe:/o:cumulusnetworks:cumulus_linux:1.5.2-28283a7-201311181623-final",
18
+ 'HOME_URL' => "http://www.cumulusnetworks.com/",
19
+ })
20
+ end
21
+
22
+ it "correctly parses the file on Sabayon" do
23
+ values = described_class.os_release(my_fixture('sabayon.txt'))
24
+
25
+ expect(values).to eq({
26
+ "NAME" => "Sabayon",
27
+ "ID" => "sabayon",
28
+ "PRETTY_NAME" => "Sabayon/Linux",
29
+ "ANSI_COLOR" => "1;32",
30
+ "HOME_URL" => "http://www.sabayon.org/",
31
+ "SUPPORT_URL" => "http://forum.sabayon.org/",
32
+ "BUG_REPORT_URL" => "https://bugs.sabayon.org/",
33
+ })
34
+ end
35
+
36
+ it "correctly parses the file on Debian Wheezy" do
37
+ values = described_class.os_release(my_fixture('wheezy.txt'))
38
+
39
+ expect(values).to eq({
40
+ "PRETTY_NAME" => "Debian GNU/Linux 7 (wheezy)",
41
+ "NAME" => "Debian GNU/Linux",
42
+ "VERSION_ID" => "7",
43
+ "VERSION" => "7 (wheezy)",
44
+ "ID" => "debian",
45
+ "ANSI_COLOR" => "1;31",
46
+ "HOME_URL" => "http://www.debian.org/",
47
+ "SUPPORT_URL" => "http://www.debian.org/support/",
48
+ "BUG_REPORT_URL" => "http://bugs.debian.org/",
49
+ })
50
+ end
51
+
52
+ it "correctly parses the file on Debian Wheezy" do
53
+ values = described_class.os_release(my_fixture('wheezy.txt'))
54
+
55
+ expect(values).to eq({
56
+ "PRETTY_NAME" => "Debian GNU/Linux 7 (wheezy)",
57
+ "NAME" => "Debian GNU/Linux",
58
+ "VERSION_ID" => "7",
59
+ "VERSION" => "7 (wheezy)",
60
+ "ID" => "debian",
61
+ "ANSI_COLOR" => "1;31",
62
+ "HOME_URL" => "http://www.debian.org/",
63
+ "SUPPORT_URL" => "http://www.debian.org/support/",
64
+ "BUG_REPORT_URL" => "http://bugs.debian.org/",
65
+ })
66
+ end
67
+
68
+
69
+ it "correctly parses the file on RedHat 7" do
70
+ values = described_class.os_release(my_fixture('redhat-7.txt'))
71
+ expect(values).to eq({
72
+ "NAME" => "Red Hat Enterprise Linux Everything",
73
+ "VERSION" => "7.0 (Maipo)",
74
+ "ID" => "rhel",
75
+ "VERSION_ID" => "7.0",
76
+ "PRETTY_NAME" => "Red Hat Enterprise Linux Everything 7.0 (Maipo)",
77
+ "ANSI_COLOR" => "0;31",
78
+ "CPE_NAME" => "cpe:/o:redhat:enterprise_linux:7.0:beta:everything",
79
+ "REDHAT_BUGZILLA_PRODUCT" => "Red Hat Enterprise Linux 7",
80
+ "REDHAT_BUGZILLA_PRODUCT_VERSION" => "7.0",
81
+ "REDHAT_SUPPORT_PRODUCT" => "Red Hat Enterprise Linux",
82
+ "REDHAT_SUPPORT_PRODUCT_VERSION" => "7.0",
83
+ })
84
+ end
85
+
86
+ it "does not try to read an unreadable '/etc/os-release' file" do
87
+ File.expects(:readable?).with('/some/nonexistent/file').returns false
88
+
89
+ expect(described_class.os_release('/some/nonexistent/file')).to be_empty
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+ require 'facter'
3
+ require 'facter/util/partitions/linux'
4
+
5
+ describe 'Facter::Util::Partitions::Linux' do
6
+ describe 'on Linux OS' do
7
+ before :each do
8
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
9
+
10
+ File.stubs(:exist?).with('/sys/block/').returns(true)
11
+ File.stubs(:exist?).with("/sys/block/./device").returns(false)
12
+ File.stubs(:exist?).with("/sys/block/../device").returns(false)
13
+ File.stubs(:exist?).with('/dev/disk/by-uuid/').returns(true)
14
+
15
+ devices = [".", "..", "sda", "sdb", "sdc"]
16
+ Dir.stubs(:entries).with('/sys/block/').returns(devices)
17
+
18
+ Facter::Core::Execution.stubs(:which).with('mount').returns(true)
19
+ Facter::Core::Execution.stubs(:which).with('blkid').returns(true)
20
+
21
+ test_parts = {
22
+ 'sda1' => '13459663-22cc-47b4-a9e6-21dea9906e03',
23
+ 'sdb2' => '98043570-eb10-457f-9718-0b85a26e66bf',
24
+ 'sdc3' => 'a35fb506-e831-4752-9899-dff6c601214b',
25
+ }
26
+
27
+ Dir.stubs(:entries).with('/dev/disk/by-uuid/').returns(test_parts.values)
28
+ test_parts.each do |part,uuid|
29
+ device = part.match(/(\D+)/)[1]
30
+ File.stubs(:exist?).with("/sys/block/#{device}/device").returns(true)
31
+ File.stubs(:symlink?).with("/dev/disk/by-uuid/#{uuid}").returns(true)
32
+ File.stubs(:readlink).with("/dev/disk/by-uuid/#{uuid}").returns("/dev/#{part}")
33
+ Dir.stubs(:glob).with("/sys/block/#{device}/#{device}*").returns(["/sys/block/#{device}/#{part}"])
34
+ Facter::Util::Partitions::Linux.stubs(:read_size).returns('12345')
35
+ Facter::Core::Execution.stubs(:exec).with("blkid /dev/#{part}").returns("/dev/#{part}: UUID=\"#{uuid}\" TYPE=\"ext4\"")
36
+ end
37
+
38
+ Facter::Core::Execution.stubs(:exec).with('mount').returns(my_fixture_read("mount"))
39
+ end
40
+
41
+ it '.list should return a list of partitions' do
42
+ Facter::Util::Partitions::Linux.list.should == ['sda1', 'sdb2', 'sdc3']
43
+ end
44
+
45
+ it '.uuid should return a string containing the uuid' do
46
+ Facter::Util::Partitions::Linux.uuid('sda1').should == '13459663-22cc-47b4-a9e6-21dea9906e03'
47
+ Facter::Util::Partitions::Linux.uuid('sdb2').should == '98043570-eb10-457f-9718-0b85a26e66bf'
48
+ Facter::Util::Partitions::Linux.uuid('sdc3').should == 'a35fb506-e831-4752-9899-dff6c601214b'
49
+ end
50
+
51
+ it '.size should return a string containing the size' do
52
+ Facter::Util::Partitions::Linux.size('sda1').should == '12345'
53
+ end
54
+
55
+ it '.mount should return a string containing the mount point of the partition' do
56
+ Facter::Util::Partitions::Linux.mount('sda1').should == '/home'
57
+ Facter::Util::Partitions::Linux.mount('sdb2').should == '/'
58
+ Facter::Util::Partitions::Linux.mount('sdc3').should == '/var'
59
+ end
60
+
61
+ it '.filesystem should return a string containing the filesystem on the partition' do
62
+ Facter::Util::Partitions::Linux.filesystem('sda1').should == 'ext4'
63
+ Facter::Util::Partitions::Linux.filesystem('sdb2').should == 'ext4'
64
+ Facter::Util::Partitions::Linux.filesystem('sdc3').should == 'ext4'
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'facter'
3
+ require 'facter/util/partitions'
4
+
5
+ describe 'Facter::Util::Partitions' do
6
+ describe 'on unsupported OSs' do
7
+ before :each do
8
+ Facter.fact(:kernel).stubs(:value).returns("SunOS")
9
+ end
10
+
11
+ it 'list should return empty array' do
12
+ Facter::Util::Partitions.list.should == []
13
+ end
14
+
15
+ it 'available? should return false' do
16
+ Facter::Util::Partitions.available?.should == false
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ require 'facter/util/posix'
3
+
4
+ describe Facter::Util::POSIX do
5
+ describe "retrieving values via sysctl" do
6
+ it "returns the result of the sysctl command" do
7
+ Facter::Util::Resolution.expects(:exec).with("sysctl -n hw.pagesize 2>/dev/null").returns("somevalue")
8
+ expect(described_class.sysctl("hw.pagesize")).to eq "somevalue"
9
+ end
10
+ end
11
+ end
@@ -128,4 +128,44 @@ describe Facter::Util::Values do
128
128
  end
129
129
  end
130
130
  end
131
+
132
+ describe "flatten_structure" do
133
+ it "converts a string to a hash containing that string" do
134
+ input = "foo"
135
+ output = described_class.flatten_structure("path", input)
136
+ expect(output).to eq({"path" => "foo"})
137
+ end
138
+
139
+ it "converts an array to a hash with the array elements with indexes" do
140
+ input = ["foo"]
141
+ output = described_class.flatten_structure("path", input)
142
+ expect(output).to eq({"path_0" => "foo"})
143
+ end
144
+
145
+ it "prefixes a non-nested hash with the given path" do
146
+ input = {"foo" => "bar"}
147
+ output = described_class.flatten_structure("path", input)
148
+ expect(output).to eq({"path_foo" => "bar"})
149
+ end
150
+
151
+ it "flattens elements till it reaches the first non-flattenable structure" do
152
+ input = {
153
+ "first" => "second",
154
+ "arr" => ["zero", "one"],
155
+ "nested_array" => [
156
+ "hash" => "string",
157
+ ],
158
+ "top" => {"middle" => ['bottom']},
159
+ }
160
+ output = described_class.flatten_structure("path", input)
161
+
162
+ expect(output).to eq({
163
+ "path_first" => "second",
164
+ "path_arr_0" => "zero",
165
+ "path_arr_1" => "one",
166
+ "path_nested_array_0_hash" => "string",
167
+ "path_top_middle_0" => "bottom"
168
+ })
169
+ end
170
+ end
131
171
  end
@@ -127,6 +127,16 @@ describe Facter::Util::Virtual do
127
127
  Facter::Util::Virtual.should_not be_ovirt
128
128
  end
129
129
 
130
+ it "detects GCE if the DMI product name is Google" do
131
+ File.stubs(:read).with("/sys/devices/virtual/dmi/id/product_name").returns("Google")
132
+ expect(Facter::Util::Virtual.gce?).to be_true
133
+ end
134
+
135
+ it "does not detect GCE if the DMI product name is not Google" do
136
+ File.stubs(:read).with("/sys/devices/virtual/dmi/id/product_name").returns('')
137
+ expect(Facter::Util::Virtual.gce?).to be_false
138
+ end
139
+
130
140
  fixture_path = fixtures('virtual', 'proc_self_status')
131
141
 
132
142
  test_cases = [
@@ -202,14 +212,14 @@ describe Facter::Util::Virtual do
202
212
  it "should detect kvm on FreeBSD" do
203
213
  FileTest.stubs(:exists?).with("/proc/cpuinfo").returns(false)
204
214
  Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
205
- Facter::Core::Execution.stubs(:exec).with("/sbin/sysctl -n hw.model").returns("QEMU Virtual CPU version 0.12.4")
215
+ Facter::Util::POSIX.stubs(:sysctl).with("hw.model").returns("QEMU Virtual CPU version 0.12.4")
206
216
  Facter::Util::Virtual.should be_kvm
207
217
  end
208
218
 
209
219
  it "should detect kvm on OpenBSD" do
210
220
  FileTest.stubs(:exists?).with("/proc/cpuinfo").returns(false)
211
221
  Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
212
- Facter::Core::Execution.stubs(:exec).with("/sbin/sysctl -n hw.model").returns('QEMU Virtual CPU version (cpu64-rhel6) ("AuthenticAMD" 686-class, 512KB L2 cache)')
222
+ Facter::Util::POSIX.stubs(:sysctl).with("hw.model").returns('QEMU Virtual CPU version (cpu64-rhel6) ("AuthenticAMD" 686-class, 512KB L2 cache)')
213
223
  Facter::Util::Virtual.should be_kvm
214
224
  end
215
225
 
@@ -291,4 +301,64 @@ describe Facter::Util::Virtual do
291
301
  context "on windows" do
292
302
  it_should_behave_like "virt-what", "windows", 'c:\windows\system32\virt-what', "NUL"
293
303
  end
304
+
305
+ describe '.lxc?' do
306
+ subject do
307
+ Facter::Util::Virtual.lxc?
308
+ end
309
+
310
+ fixture_path = fixtures('virtual', 'proc_1_cgroup')
311
+
312
+ context '/proc/1/cgroup has at least one hierarchy rooted in /lxc/' do
313
+ before :each do
314
+ fakepath = Pathname.new(File.join(fixture_path, 'in_a_container'))
315
+ Pathname.stubs(:new).with('/proc/1/cgroup').returns(fakepath)
316
+ end
317
+
318
+ it 'is true' do
319
+ subject.should be_true
320
+ end
321
+ end
322
+
323
+ context '/proc/1/cgroup has no hierarchies rooted in /lxc/' do
324
+ before :each do
325
+ fakepath = Pathname.new(File.join(fixture_path, 'not_in_a_container'))
326
+ Pathname.stubs(:new).with('/proc/1/cgroup').returns(fakepath)
327
+ end
328
+
329
+ it 'is false' do
330
+ subject.should be_false
331
+ end
332
+ end
333
+ end
334
+
335
+ describe '.docker?' do
336
+ subject do
337
+ Facter::Util::Virtual.docker?
338
+ end
339
+
340
+ fixture_path = fixtures('virtual', 'proc_1_cgroup')
341
+
342
+ context '/proc/1/cgroup has at least one hierarchy rooted in /docker/' do
343
+ before :each do
344
+ fakepath = Pathname.new(File.join(fixture_path, 'in_a_docker_container'))
345
+ Pathname.stubs(:new).with('/proc/1/cgroup').returns(fakepath)
346
+ end
347
+
348
+ it 'is true' do
349
+ subject.should be_true
350
+ end
351
+ end
352
+
353
+ context '/proc/1/cgroup has no hierarchies rooted in /docker/' do
354
+ before :each do
355
+ fakepath = Pathname.new(File.join(fixture_path, 'not_in_a_container'))
356
+ Pathname.stubs(:new).with('/proc/1/cgroup').returns(fakepath)
357
+ end
358
+
359
+ it 'is false' do
360
+ subject.should be_false
361
+ end
362
+ end
363
+ end
294
364
  end
@@ -2,10 +2,12 @@
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/virtual'
5
- require 'facter/util/macosx'
5
+ require 'facter/util/macosx' unless Facter::Util::Config.is_windows?
6
6
 
7
7
  describe "Virtual fact" do
8
8
  before(:each) do
9
+ Facter::Util::Virtual.stubs(:docker?).returns(false)
10
+ Facter::Util::Virtual.stubs(:lxc?).returns(false)
9
11
  Facter::Util::Virtual.stubs(:zone?).returns(false)
10
12
  Facter::Util::Virtual.stubs(:openvz?).returns(false)
11
13
  Facter::Util::Virtual.stubs(:vserver?).returns(false)
@@ -16,6 +18,7 @@ describe "Virtual fact" do
16
18
  Facter::Util::Virtual.stubs(:virt_what).returns(nil)
17
19
  Facter::Util::Virtual.stubs(:rhev?).returns(false)
18
20
  Facter::Util::Virtual.stubs(:ovirt?).returns(false)
21
+ Facter::Util::Virtual.stubs(:gce?).returns(false)
19
22
  Facter::Util::Virtual.stubs(:virtualbox?).returns(false)
20
23
  end
21
24
 
@@ -47,28 +50,23 @@ describe "Virtual fact" do
47
50
  Facter.fact(:virtual).value.should == "zlinux"
48
51
  end
49
52
 
50
- describe "on Darwin" do
53
+ describe "on Darwin", :unless => Facter::Util::Config.is_windows? do
51
54
  before do
52
55
  Facter.fact(:kernel).stubs(:value).returns("Darwin")
53
56
  end
54
57
 
55
- it "should be parallels with Parallels vendor id" do
56
- Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor-id" => "0x1ab8" })
58
+ it "should be parallels with Parallels ethernet vendor id" do
59
+ Facter::Util::Macosx.stubs(:profiler_data).returns({ "spethernet_subsystem-vendor-id" => "0x1ab8" })
57
60
  Facter.fact(:virtual).value.should == "parallels"
58
61
  end
59
62
 
60
- it "should be parallels with Parallels vendor name" do
61
- Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor" => "Parallels" })
62
- Facter.fact(:virtual).value.should == "parallels"
63
- end
64
-
65
- it "should be vmware with VMWare vendor id" do
66
- Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor-id" => "0x15ad" })
67
- Facter.fact(:virtual).value.should == "vmware"
63
+ it "should be virtualbox with VirtualBox boot rom name" do
64
+ Facter::Util::Macosx.stubs(:profiler_data).returns({ "boot_rom_version" => "VirtualBox" })
65
+ Facter.fact(:virtual).value.should == "virtualbox"
68
66
  end
69
67
 
70
- it "should be vmware with VMWare vendor name" do
71
- Facter::Util::Macosx.stubs(:profiler_data).returns({ "spdisplays_vendor" => "VMWare" })
68
+ it "should be vmware with VMware machine model" do
69
+ Facter::Util::Macosx.stubs(:profiler_data).returns({ "machine_model" => "VMware7,1" })
72
70
  Facter.fact(:virtual).value.should == "vmware"
73
71
  end
74
72
  end
@@ -164,6 +162,12 @@ describe "Virtual fact" do
164
162
  Facter.fact(:virtual).value.should == "ovirt"
165
163
  end
166
164
 
165
+ it "is gce based on DMI info" do
166
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
167
+ Facter::Util::Virtual.stubs(:gce?).returns(true)
168
+ Facter.fact(:virtual).value.should == "gce"
169
+ end
170
+
167
171
  it "should be hyperv with Microsoft vendor name from lspci 2>/dev/null" do
168
172
  Facter::Core::Execution.stubs(:exec).with('lspci 2>/dev/null').returns("00:08.0 VGA compatible controller: Microsoft Corporation Hyper-V virtual VGA")
169
173
  Facter.fact(:virtual).value.should == "hyperv"
@@ -175,6 +179,28 @@ describe "Virtual fact" do
175
179
  Facter.fact(:virtual).value.should == "hyperv"
176
180
  end
177
181
 
182
+ context "In a Linux Container (LXC)" do
183
+ before :each do
184
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
185
+ end
186
+
187
+ it 'is "lxc" when Facter::Util::Virtual.lxc? is true' do
188
+ Facter::Util::Virtual.stubs(:lxc?).returns(true)
189
+ Facter.fact(:virtual).value.should == 'lxc'
190
+ end
191
+ end
192
+
193
+ context "In a Docker Container (docker)" do
194
+ before :each do
195
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
196
+ end
197
+
198
+ it 'is "docker" when Facter::Util::Virtual.docker? is true' do
199
+ Facter::Util::Virtual.stubs(:docker?).returns(true)
200
+ Facter.fact(:virtual).value.should == 'docker'
201
+ end
202
+ end
203
+
178
204
  context "In Google Compute Engine" do
179
205
  before :each do
180
206
  Facter.fact(:kernel).stubs(:value).returns("Linux")
@@ -254,24 +280,29 @@ describe "Virtual fact" do
254
280
  end
255
281
 
256
282
  it "should be parallels with Parallels product name from sysctl" do
257
- Facter::Core::Execution.stubs(:exec).with('sysctl -n hw.product 2>/dev/null').returns("Parallels Virtual Platform")
283
+ Facter::Util::POSIX.stubs(:sysctl).with('hw.product').returns("Parallels Virtual Platform")
258
284
  Facter.fact(:virtual).value.should == "parallels"
259
285
  end
260
286
 
261
287
  it "should be vmware with VMware product name from sysctl" do
262
- Facter::Core::Execution.stubs(:exec).with('sysctl -n hw.product 2>/dev/null').returns("VMware Virtual Platform")
288
+ Facter::Util::POSIX.stubs(:sysctl).with('hw.product').returns("VMware Virtual Platform")
263
289
  Facter.fact(:virtual).value.should == "vmware"
264
290
  end
265
291
 
266
292
  it "should be virtualbox with VirtualBox product name from sysctl" do
267
- Facter::Core::Execution.stubs(:exec).with('sysctl -n hw.product 2>/dev/null').returns("VirtualBox")
293
+ Facter::Util::POSIX.stubs(:sysctl).with('hw.product').returns("VirtualBox")
268
294
  Facter.fact(:virtual).value.should == "virtualbox"
269
295
  end
270
296
 
271
297
  it "should be xenhvm with Xen HVM product name from sysctl" do
272
- Facter::Core::Execution.stubs(:exec).with('sysctl -n hw.product 2>/dev/null').returns("HVM domU")
298
+ Facter::Util::POSIX.stubs(:sysctl).with('hw.product').returns("HVM domU")
273
299
  Facter.fact(:virtual).value.should == "xenhvm"
274
300
  end
301
+
302
+ it "should be ovirt with oVirt Node product name from sysctl" do
303
+ Facter::Util::POSIX.stubs(:sysctl).with('hw.product').returns("oVirt Node")
304
+ Facter.fact(:virtual).value.should == "ovirt"
305
+ end
275
306
  end
276
307
 
277
308
  describe "on Windows" do
@@ -467,4 +498,22 @@ describe "is_virtual fact" do
467
498
  Facter.fact(:virtual).stubs(:value).returns("ovirt")
468
499
  Facter.fact(:is_virtual).value.should == "true"
469
500
  end
501
+
502
+ it "should be true when running on ovirt" do
503
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
504
+ Facter.fact(:virtual).stubs(:value).returns("gce")
505
+ Facter.fact(:is_virtual).value.should == "true"
506
+ end
507
+
508
+ it "should be true when running in LXC" do
509
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
510
+ Facter.fact(:virtual).stubs(:value).returns("lxc")
511
+ Facter.fact(:is_virtual).value.should == "true"
512
+ end
513
+
514
+ it "should be true when running in docker" do
515
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
516
+ Facter.fact(:virtual).stubs(:value).returns("docker")
517
+ Facter.fact(:is_virtual).value.should == "true"
518
+ end
470
519
  end