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
@@ -27,6 +27,17 @@ describe "The netmask fact" do
27
27
  "ifconfig_ubuntu_1204.txt"
28
28
  end
29
29
 
30
+ context "on AIX" do
31
+ before :each do
32
+ Facter.fact(:kernel).stubs(:value).returns("AIX")
33
+ end
34
+
35
+ example_behavior_for "netmask from ifconfig output",
36
+ "AIX 7", "255.255.255.0",
37
+ "ifconfig_aix_7.txt"
38
+
39
+ end
40
+
30
41
  context "on Darwin" do
31
42
  before :each do
32
43
  Facter.fact(:kernel).stubs(:value).returns("Darwin")
@@ -58,6 +58,7 @@ describe "Operating System fact" do
58
58
  "Debian" => "/etc/debian_version",
59
59
  "Gentoo" => "/etc/gentoo-release",
60
60
  "Fedora" => "/etc/fedora-release",
61
+ "Mageia" => "/etc/mageia-release",
61
62
  "Mandriva" => "/etc/mandriva-release",
62
63
  "Mandrake" => "/etc/mandrake-release",
63
64
  "MeeGo" => "/etc/meego-release",
@@ -89,6 +90,13 @@ describe "Operating System fact" do
89
90
  Facter.fact(:operatingsystem).value.should == "Ubuntu"
90
91
  end
91
92
 
93
+ it "on LinuxMint should use the lsbdistid fact" do
94
+ FileUtils.stubs(:exists?).with("/etc/debian_version").returns true
95
+
96
+ Facter.stubs(:value).with(:lsbdistid).returns("LinuxMint")
97
+ Facter.fact(:operatingsystem).value.should == "LinuxMint"
98
+ end
99
+
92
100
  end
93
101
 
94
102
 
@@ -137,5 +145,16 @@ describe "Operating System fact" do
137
145
  File.expects(:read).with("/etc/redhat-release").returns("Scientific Linux CERN SLC 5.7 (Boron)")
138
146
  Facter.fact(:operatingsystem).value.should == "SLC"
139
147
  end
148
+
149
+ it "should identify Cumulus Linux" do
150
+ Facter::Util::Operatingsystem.expects(:os_release).returns({'NAME' => 'Cumulus Linux'})
151
+ Facter.fact(:operatingsystem).value.should == "CumulusLinux"
152
+ end
153
+
154
+ it "should not use '/etc/os-release' on platforms other than Cumulus Linux" do
155
+ Facter::Util::Operatingsystem.expects(:os_release).returns({'NAME' => 'Debian GNU/Linux'})
156
+ FileTest.expects(:exists?).with('/etc/debian_version').returns true
157
+ Facter.fact(:operatingsystem).value.should == "Debian"
158
+ end
140
159
  end
141
160
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  require 'facter'
4
4
 
5
5
  describe "OS Major Release fact" do
6
- ['Amazon','CentOS','CloudLinux','Debian','Fedora','OEL','OracleLinux','OVS','RedHat','Scientific','SLC'].each do |operatingsystem|
6
+ ['Amazon','CentOS','CloudLinux','Debian','Fedora','OEL','OracleLinux','OVS','RedHat','Scientific','SLC','CumulusLinux'].each do |operatingsystem|
7
7
  context "on #{operatingsystem} operatingsystems" do
8
8
  it "should be derived from operatingsystemrelease" do
9
9
  Facter.fact(:kernel).stubs(:value).returns("Linux")
@@ -17,6 +17,7 @@ describe "Operating System Release fact" do
17
17
  "OpenWrt" => "/etc/openwrt_version",
18
18
  "CentOS" => "/etc/redhat-release",
19
19
  "RedHat" => "/etc/redhat-release",
20
+ "LinuxMint" => "/etc/linuxmint/info",
20
21
  "Scientific" => "/etc/redhat-release",
21
22
  "Fedora" => "/etc/fedora-release",
22
23
  "MeeGo" => "/etc/meego-release",
@@ -225,4 +226,11 @@ describe "Operating System Release fact" do
225
226
  Facter.fact(:operatingsystemrelease).value.should == "10.04"
226
227
  end
227
228
  end
229
+
230
+ it "uses '/etc/os-release for Cumulus Linux" do
231
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
232
+ Facter.fact(:operatingsystem).stubs(:value).returns("CumulusLinux")
233
+ Facter::Util::Operatingsystem.expects(:os_release).returns({'VERSION_ID' => '1.5.0'})
234
+ Facter.fact(:operatingsystemrelease).value.should == "1.5.0"
235
+ end
228
236
  end
@@ -0,0 +1,62 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'spec_helper'
4
+
5
+ describe "OS Family fact" do
6
+
7
+ {
8
+ 'Archlinux' => 'Archlinux',
9
+ 'SmartOS' => 'Solaris',
10
+ 'OpenIndiana' => 'Solaris',
11
+ 'OmniOS' => 'Solaris',
12
+ 'Nexenta' => 'Solaris',
13
+ 'Solaris' => 'Solaris',
14
+ 'Ubuntu' => 'Debian',
15
+ 'Debian' => 'Debian',
16
+ 'LinuxMint' => 'Debian',
17
+ 'Gentoo' => 'Gentoo',
18
+ 'Fedora' => 'RedHat',
19
+ 'Amazon' => 'RedHat',
20
+ 'OracleLinux' => 'RedHat',
21
+ 'OVS' => 'RedHat',
22
+ 'OEL' => 'RedHat',
23
+ 'CentOS' => 'RedHat',
24
+ 'SLC' => 'RedHat',
25
+ 'Scientific' => 'RedHat',
26
+ 'CloudLinux' => 'RedHat',
27
+ 'PSBM' => 'RedHat',
28
+ 'Ascendos' => 'RedHat',
29
+ 'XenServer' => 'RedHat',
30
+ 'RedHat' => 'RedHat',
31
+ 'SLES' => 'Suse',
32
+ 'SLED' => 'Suse',
33
+ 'OpenSuSE' => 'Suse',
34
+ 'SuSE' => 'Suse',
35
+ 'Mageia' => 'Mandrake',
36
+ 'Mandriva' => 'Mandrake',
37
+ 'Mandrake' => 'Mandrake',
38
+ }.each do |os,family|
39
+ it "should return #{family} on operatingsystem #{os}" do
40
+ Facter.fact(:operatingsystem).stubs(:value).returns os
41
+ Facter.fact(:osfamily).value.should == family
42
+ end
43
+ end
44
+
45
+ [
46
+ 'MeeGo',
47
+ 'VMWareESX',
48
+ 'Bluewhite64',
49
+ 'Slamd64',
50
+ 'Slackware',
51
+ 'Alpine',
52
+ 'ESXi',
53
+ 'windows',
54
+ 'HP-UX'
55
+ ].each do |os|
56
+ it "should return the kernel fact on operatingsystem #{os}" do
57
+ Facter.fact(:operatingsystem).stubs(:value).returns os
58
+ Facter.fact(:kernel).stubs(:value).returns 'random_kernel_fact'
59
+ Facter.fact(:osfamily).value.should == 'random_kernel_fact'
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'spec_helper'
4
+ require 'facter'
5
+
6
+ describe "Partition facts" do
7
+
8
+ describe "on non-Linux OS" do
9
+
10
+ it "should not exist when kernel isn't Linux" do
11
+ Facter.fact(:kernel).stubs(:value).returns("SunOS")
12
+ Facter.fact(:partitions).value.should == nil
13
+ end
14
+ end
15
+
16
+ describe "on Linux" do
17
+ it "should return a structured fact with uuid, size, mount point and filesytem for each partition" do
18
+ partitions = {
19
+ 'sda1' => {
20
+ 'uuid' => '13459663-22cc-47b4-a9e6-21dea9906e03',
21
+ 'size' => '1234',
22
+ 'mount' => '/',
23
+ 'filesystem' => 'ext4',
24
+ },
25
+ 'sdb2' => {
26
+ 'uuid' => '98043570-eb10-457f-9718-0b85a26e66bf',
27
+ 'size' => '5678',
28
+ 'mount' => '/home',
29
+ 'filesystem' => 'xfs',
30
+ },
31
+ }
32
+
33
+ Facter::Util::Partitions.stubs(:list).returns( partitions.keys )
34
+
35
+ partitions.each do |part,vals|
36
+ Facter::Util::Partitions.stubs(:uuid).with(part).returns(vals['uuid'])
37
+ Facter::Util::Partitions.stubs(:size).with(part).returns(vals['size'])
38
+ Facter::Util::Partitions.stubs(:mount).with(part).returns(vals['mount'])
39
+ Facter::Util::Partitions.stubs(:filesystem).with(part).returns(vals['filesystem'])
40
+ end
41
+
42
+ Facter.fact(:partitions).value.should == {
43
+ 'sda1' => { 'uuid' => '13459663-22cc-47b4-a9e6-21dea9906e03', 'size' => '1234', 'mount' => '/', 'filesystem' => 'ext4' },
44
+ 'sdb2' => { 'uuid' => '98043570-eb10-457f-9718-0b85a26e66bf', 'size' => '5678', 'mount' => '/home', 'filesystem' => 'xfs' },
45
+ }
46
+ end
47
+ end
48
+ end
@@ -1,6 +1,7 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
+ require 'facter/util/posix'
4
5
 
5
6
  describe "Physical processor count facts" do
6
7
 
@@ -73,4 +74,12 @@ describe "Physical processor count facts" do
73
74
  end
74
75
  end
75
76
  end
77
+
78
+ describe "on openbsd" do
79
+ it "should return 4 physical CPUs" do
80
+ Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
81
+ Facter::Util::POSIX.expects(:sysctl).with("hw.ncpufound").returns("4")
82
+ Facter.fact(:physicalprocessorcount).value.should == "4"
83
+ end
84
+ end
76
85
  end
@@ -1,5 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
+ require 'facter/util/posix'
3
4
  require 'facter/util/processor'
4
5
  require 'spec_helper'
5
6
  require 'facter_spec/cpuinfo'
@@ -185,35 +186,42 @@ describe "Processor facts" do
185
186
 
186
187
  it "should be 2 on dual-processor Darwin box" do
187
188
  Facter.fact(:kernel).stubs(:value).returns("Darwin")
188
- Facter::Core::Execution.stubs(:execute).with("sysctl -n hw.ncpu", anything).returns('2')
189
+ Facter::Util::POSIX.stubs(:sysctl).with("hw.ncpu").returns('2')
189
190
 
190
191
  Facter.fact(:processorcount).value.should == "2"
191
192
  end
192
193
 
193
194
  it "should be 2 on dual-processor OpenBSD box" do
194
195
  Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
195
- Facter::Core::Execution.stubs(:execute).with("sysctl -n hw.ncpu", anything).returns('2')
196
+ Facter::Util::POSIX.stubs(:sysctl).with("hw.ncpu").returns('2')
196
197
 
197
198
  Facter.fact(:processorcount).value.should == "2"
198
199
  end
199
200
 
201
+ it "should print the correct CPU Model on OpenBSD" do
202
+ Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
203
+ Facter::Util::POSIX.stubs(:sysctl).with("hw.model").returns('SomeVendor CPU 4.2GHz')
204
+
205
+ Facter.fact(:processor).value.should == "SomeVendor CPU 4.2GHz"
206
+ end
207
+
200
208
  it "should be 2 on dual-processor FreeBSD box" do
201
209
  Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
202
- Facter::Core::Execution.stubs(:execute).with("sysctl -n hw.ncpu", anything).returns('2')
210
+ Facter::Util::POSIX.stubs(:sysctl).with("hw.ncpu").returns('2')
203
211
 
204
212
  Facter.fact(:processorcount).value.should == "2"
205
213
  end
206
214
 
207
215
  it "should print the correct CPU Model on FreeBSD" do
208
216
  Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
209
- Facter::Core::Execution.stubs(:execute).with("sysctl -n hw.model", anything).returns('SomeVendor CPU 3GHz')
217
+ Facter::Util::POSIX.stubs(:sysctl).with("hw.model").returns('SomeVendor CPU 3GHz')
210
218
 
211
219
  Facter.fact(:processor).value.should == "SomeVendor CPU 3GHz"
212
220
  end
213
221
 
214
222
  it "should be 2 on dual-processor DragonFly box" do
215
223
  Facter.fact(:kernel).stubs(:value).returns("DragonFly")
216
- Facter::Core::Execution.stubs(:execute).with("sysctl -n hw.ncpu", anything).returns('2')
224
+ Facter::Util::POSIX.stubs(:sysctl).with("hw.ncpu").returns('2')
217
225
 
218
226
  Facter.fact(:processorcount).value.should == "2"
219
227
  end
@@ -234,7 +242,7 @@ describe "Processor facts" do
234
242
  let(:kstat_sparc) { @fixture_kstat_sparc }
235
243
  let(:kstat_x86_64) { @fixture_kstat_x86_64 }
236
244
 
237
- %w{ 5.8 5.9 5.10 5.11 }.each do |release|
245
+ %w{ 5.5.1 5.6 5.7 }.each do |release|
238
246
  %w{ sparc x86_64 }.each do |arch|
239
247
  it "uses kstat on release #{release} (#{arch})" do
240
248
  Facter.stubs(:value).with(:kernelrelease).returns(release)
@@ -246,7 +254,7 @@ describe "Processor facts" do
246
254
  end
247
255
  end
248
256
 
249
- %w{ 5.5.1 5.6 5.7 }.each do |release|
257
+ %w{ 5.8 5.9 5.10 5.11 }.each do |release|
250
258
  it "uses psrinfo on release #{release}" do
251
259
  Facter.stubs(:value).with(:kernelrelease).returns(release)
252
260
 
@@ -5,6 +5,19 @@ require 'spec_helper'
5
5
  describe Facter::Util::Config do
6
6
  include PuppetlabsSpec::Files
7
7
 
8
+ describe "ENV['HOME'] is unset", :unless => Facter::Util::Root.root? do
9
+ around do |example|
10
+ Facter::Core::Execution.with_env('HOME' => nil) do
11
+ example.run
12
+ end
13
+ end
14
+
15
+ it "should not set @external_facts_dirs" do
16
+ Facter::Util::Config.setup_default_ext_facts_dirs
17
+ Facter::Util::Config.external_facts_dirs.should be_empty
18
+ end
19
+ end
20
+
8
21
  describe "is_windows? function" do
9
22
  it "should detect windows if Ruby RbConfig::CONFIG['host_os'] returns a windows OS" do
10
23
  host_os = ["mswin","win32","dos","mingw","cygwin"]
@@ -0,0 +1,63 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'spec_helper'
4
+ require 'facter/util/dhcp_servers'
5
+
6
+ describe Facter::Util::DHCPServers do
7
+
8
+ describe "retrieving the gateway device" do
9
+ it "returns nil when there are no default routes" do
10
+ Facter::Util::FileRead.stubs(:read).with('/proc/net/route').returns(my_fixture_read('route_nogw'))
11
+ described_class.gateway_device.should be_nil
12
+ end
13
+
14
+ it "returns the interface associated with the first default route" do
15
+ Facter::Util::FileRead.stubs(:read).with('/proc/net/route').returns(my_fixture_read('route'))
16
+ described_class.gateway_device.should eq "eth0"
17
+ end
18
+ end
19
+
20
+ describe "nmcli_version" do
21
+ {
22
+ 'nmcli tool, version 0.9.8.0' => [0, 9, 8, 0],
23
+ 'nmcli tool, version 0.9.8.10' => [0, 9, 8, 10],
24
+ 'nmcli tool, version 0.9.8.9' => [0, 9, 8, 9],
25
+ 'nmcli tool, version 0.9.9.0' => [0, 9, 9, 0],
26
+ 'nmcli tool, version 0.9.9.9' => [0, 9, 9, 9],
27
+ 'version 0.9.9.0-20.git20131003.fc20' => [0, 9, 9, 0],
28
+ 'nmcli tool, version 0.9.9' => [0, 9, 9, 0],
29
+ 'nmcli tool, version 0.9' => [0, 9, 0, 0],
30
+ 'nmcli tool, version 1' => [1, 0, 0, 0]
31
+ }.each do |version, expected|
32
+ it "should turn #{version} into the integer #{expected}" do
33
+ Facter::Core::Execution.stubs(:which).with('nmcli').returns('/usr/bin/nmcli')
34
+ Facter::Core::Execution.stubs(:exec).with('nmcli --version').returns(version)
35
+
36
+ result = Facter::Util::DHCPServers.nmcli_version
37
+ result.is_a?(Array).should be true
38
+ result.should == expected
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "device_dhcp_server" do
44
+ {
45
+ '0.1.2.3' => false,
46
+ '0.9.8.10' => false,
47
+ '0.9.9.0' => true,
48
+ '0.9.10.0' => true,
49
+ '0.10.0.0' => true,
50
+ '1.0.0.0' => true
51
+ }.each do |version, uses_show|
52
+ it "should use #{if uses_show then 'show' else 'list' end} for version #{version}" do
53
+ command = if uses_show then 'nmcli -f all d show eth0' else 'nmcli -f all d list iface eth0' end
54
+ Facter::Core::Execution.stubs(:which).with('nmcli').returns('/usr/bin/nmcli')
55
+ Facter::Core::Execution.stubs(:exec).with('nmcli --version').returns "nmcli tool, version #{version}"
56
+ Facter::Core::Execution.stubs(:exec).with(command).returns 'DHCP4.OPTION[1]: dhcp_server_identifier = 192.168.1.1'
57
+ Facter::Util::DHCPServers.device_dhcp_server('eth0').should == '192.168.1.1'
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+
@@ -4,6 +4,10 @@ require 'spec_helper'
4
4
  require 'facter/util/ec2'
5
5
 
6
6
  describe Facter::Util::EC2 do
7
+ before do
8
+ # Squelch deprecation notices
9
+ Facter.stubs(:warnonce)
10
+ end
7
11
  # This is the standard prefix for making an API call in EC2 (or fake)
8
12
  # environments.
9
13
  let(:api_prefix) { "http://169.254.169.254" }
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require 'facter/util/formatter'
3
+
4
+ describe Facter::Util::Formatter do
5
+ describe "formatting as json" do
6
+ it "formats the text as json when json is available", :if => Facter.json? do
7
+ JSON.expects(:pretty_generate).with({"hello" => "world"}).returns(%Q({"hello": "world"}))
8
+ expect(described_class.format_json({"hello" => "world"})).to eq %Q({"hello": "world"})
9
+ end
10
+
11
+ it "raises an error when JSON is not available" do
12
+ Facter.stubs(:json?).returns false
13
+ expect {
14
+ described_class.format_json({"hello" => "world"})
15
+ }.to raise_error(/'json' library is not present/)
16
+ end
17
+ end
18
+
19
+ describe "formatting as yaml" do
20
+ it "dumps the text as YAML" do
21
+ expect(described_class.format_yaml({"hello" => "world"})).to match(/hello: world/)
22
+ end
23
+ end
24
+
25
+ describe "formatting as plaintext" do
26
+ it "formats a single string value without quotes" do
27
+ expect(described_class.format_plaintext({"foo" => "bar"})).to eq "bar"
28
+ end
29
+
30
+ it "formats a structured value with #inspect" do
31
+ value = ["bar"]
32
+ value.expects(:inspect).returns %Q(["bar"])
33
+ hash = {"foo" => value, "baz" => "quux"}
34
+ expect(described_class.format_plaintext(hash)).to match(%Q([bar]))
35
+ end
36
+ it "formats multiple string values as key/value pairs" do
37
+ hash = {"foo" => "bar", "baz" => "quux"}
38
+ expect(described_class.format_plaintext(hash)).to match(/foo => bar/)
39
+ expect(described_class.format_plaintext(hash)).to match(/baz => quux/)
40
+ end
41
+
42
+ it "formats multiple structured values with #inspect" do
43
+ value = ["bar"]
44
+ value.expects(:inspect).twice.returns %Q(["bar"])
45
+ hash = {"foo" => value, "baz" => "quux"}
46
+ expect(described_class.format_plaintext(hash)).to match(/foo => \["bar"\]/)
47
+ expect(described_class.format_plaintext(hash)).to match(/baz => quux/)
48
+ end
49
+ end
50
+ end
@@ -277,10 +277,10 @@ describe Facter::Util::Loader do
277
277
  end
278
278
 
279
279
  it "should load facts on the facter search path only once" do
280
- facterlibdir = File.expand_path(File.dirname(__FILE__) + '../../../fixtures/unit/util/loader')
280
+ loader = loader_from(:env => {})
281
+ loader.load_all
281
282
 
282
- Facter::Util::Loader.new('FACTERLIB' => facterlibdir).load_all
283
-
284
- Facter.value(:nosuchfact).should be_nil
283
+ loader.expects(:kernel_load).with(regexp_matches(/ec2/)).never
284
+ loader.load(:ec2)
285
285
  end
286
286
  end