facter 1.7.6 → 2.0.1.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 (155) hide show
  1. checksums.yaml +7 -0
  2. data/COMMITTERS.md +194 -0
  3. data/CONTRIBUTING.md +63 -235
  4. data/Gemfile +12 -8
  5. data/README.md +1 -2
  6. data/Rakefile +1 -1
  7. data/bin/facter +0 -4
  8. data/ext/build_defaults.yaml +2 -2
  9. data/ext/project_data.yaml +18 -0
  10. data/install.rb +1 -16
  11. data/lib/facter.rb +171 -171
  12. data/lib/facter/application.rb +65 -54
  13. data/lib/facter/core/aggregate.rb +220 -0
  14. data/lib/facter/core/directed_graph.rb +46 -0
  15. data/lib/facter/core/execution.rb +100 -0
  16. data/lib/facter/core/execution/base.rb +73 -0
  17. data/lib/facter/core/execution/posix.rb +50 -0
  18. data/lib/facter/core/execution/windows.rb +57 -0
  19. data/lib/facter/core/logging.rb +169 -0
  20. data/lib/facter/core/resolvable.rb +94 -0
  21. data/lib/facter/core/suitable.rb +117 -0
  22. data/lib/facter/domain.rb +15 -9
  23. data/lib/facter/filesystems.rb +1 -1
  24. data/lib/facter/hardwaremodel.rb +1 -1
  25. data/lib/facter/hostname.rb +3 -3
  26. data/lib/facter/interfaces.rb +6 -1
  27. data/lib/facter/ipaddress.rb +2 -2
  28. data/lib/facter/kernel.rb +1 -1
  29. data/lib/facter/kernelrelease.rb +1 -1
  30. data/lib/facter/ldom.rb +1 -1
  31. data/lib/facter/lsbdistcodename.rb +1 -1
  32. data/lib/facter/lsbdistdescription.rb +1 -1
  33. data/lib/facter/lsbdistid.rb +1 -1
  34. data/lib/facter/lsbdistrelease.rb +1 -1
  35. data/lib/facter/lsbrelease.rb +1 -1
  36. data/lib/facter/macaddress.rb +1 -14
  37. data/lib/facter/macosx.rb +2 -2
  38. data/lib/facter/memory.rb +8 -19
  39. data/lib/facter/operatingsystem.rb +1 -1
  40. data/lib/facter/operatingsystemrelease.rb +34 -1
  41. data/lib/facter/physicalprocessorcount.rb +6 -6
  42. data/lib/facter/processor.rb +11 -10
  43. data/lib/facter/selinux.rb +4 -15
  44. data/lib/facter/ssh.rb +5 -2
  45. data/lib/facter/util/architecture.rb +2 -2
  46. data/lib/facter/util/collection.rb +42 -38
  47. data/lib/facter/util/config.rb +19 -9
  48. data/lib/facter/util/confine.rb +34 -4
  49. data/lib/facter/util/ec2.rb +1 -1
  50. data/lib/facter/util/fact.rb +108 -36
  51. data/lib/facter/util/file_read.rb +7 -6
  52. data/lib/facter/util/formatter.rb +38 -0
  53. data/lib/facter/util/ip.rb +3 -3
  54. data/lib/facter/util/loader.rb +62 -42
  55. data/lib/facter/util/macosx.rb +7 -8
  56. data/lib/facter/util/manufacturer.rb +3 -3
  57. data/lib/facter/util/memory.rb +13 -13
  58. data/lib/facter/util/monkey_patches.rb +0 -31
  59. data/lib/facter/util/netmask.rb +3 -3
  60. data/lib/facter/util/normalization.rb +94 -0
  61. data/lib/facter/util/nothing_loader.rb +3 -6
  62. data/lib/facter/util/parser.rb +3 -5
  63. data/lib/facter/util/plist/generator.rb +1 -1
  64. data/lib/facter/util/processor.rb +15 -15
  65. data/lib/facter/util/resolution.rb +112 -289
  66. data/lib/facter/util/solaris_zones.rb +4 -4
  67. data/lib/facter/util/uptime.rb +8 -3
  68. data/lib/facter/util/values.rb +67 -1
  69. data/lib/facter/util/virtual.rb +10 -10
  70. data/lib/facter/util/xendomains.rb +1 -1
  71. data/lib/facter/version.rb +42 -39
  72. data/lib/facter/virtual.rb +6 -7
  73. data/lib/facter/zfs_version.rb +3 -3
  74. data/lib/facter/zpool_version.rb +3 -3
  75. data/spec/fixtures/unit/netmask/darwin_10_8_5.txt +30 -0
  76. data/spec/unit/application_spec.rb +46 -1
  77. data/spec/unit/core/aggregate_spec.rb +125 -0
  78. data/spec/unit/core/directed_graph_spec.rb +79 -0
  79. data/spec/unit/core/execution/base_spec.rb +119 -0
  80. data/spec/unit/core/execution/posix_spec.rb +86 -0
  81. data/spec/unit/core/execution/windows_spec.rb +106 -0
  82. data/spec/unit/core/execution_spec.rb +37 -0
  83. data/spec/unit/core/logging_spec.rb +104 -0
  84. data/spec/unit/core/resolvable_spec.rb +81 -0
  85. data/spec/unit/core/suitable_spec.rb +96 -0
  86. data/spec/unit/domain_spec.rb +5 -5
  87. data/spec/unit/facter_spec.rb +61 -222
  88. data/spec/unit/filesystems_spec.rb +2 -2
  89. data/spec/unit/hardwareisa_spec.rb +5 -5
  90. data/spec/unit/hardwaremodel_spec.rb +1 -1
  91. data/spec/unit/hostname_spec.rb +4 -4
  92. data/spec/unit/id_spec.rb +3 -3
  93. data/spec/unit/interfaces_spec.rb +10 -0
  94. data/spec/unit/ipaddress6_spec.rb +4 -4
  95. data/spec/unit/ipaddress_spec.rb +1 -1
  96. data/spec/unit/kernel_spec.rb +2 -2
  97. data/spec/unit/kernelmajversion_spec.rb +1 -1
  98. data/spec/unit/kernelrelease_spec.rb +4 -4
  99. data/spec/unit/kernelversion_spec.rb +2 -2
  100. data/spec/unit/ldom_spec.rb +2 -2
  101. data/spec/unit/lsbdistcodename_spec.rb +2 -2
  102. data/spec/unit/lsbdistdescription_spec.rb +2 -2
  103. data/spec/unit/lsbdistid_spec.rb +2 -2
  104. data/spec/unit/lsbdistrelease_spec.rb +2 -2
  105. data/spec/unit/lsbrelease_spec.rb +2 -2
  106. data/spec/unit/manufacturer_spec.rb +1 -1
  107. data/spec/unit/memory_spec.rb +24 -31
  108. data/spec/unit/netmask_spec.rb +9 -0
  109. data/spec/unit/operatingsystem_spec.rb +1 -1
  110. data/spec/unit/operatingsystemrelease_spec.rb +62 -4
  111. data/spec/unit/physicalprocessorcount_spec.rb +10 -10
  112. data/spec/unit/processor_spec.rb +11 -11
  113. data/spec/unit/selinux_spec.rb +2 -8
  114. data/spec/unit/ssh_spec.rb +3 -2
  115. data/spec/unit/uniqueid_spec.rb +3 -3
  116. data/spec/unit/util/collection_spec.rb +37 -35
  117. data/spec/unit/util/config_spec.rb +20 -0
  118. data/spec/unit/util/confine_spec.rb +21 -0
  119. data/spec/unit/util/directory_loader_spec.rb +1 -0
  120. data/spec/unit/util/ec2_spec.rb +6 -6
  121. data/spec/unit/util/fact_spec.rb +92 -90
  122. data/spec/unit/util/ip_spec.rb +2 -2
  123. data/spec/unit/util/loader_spec.rb +127 -186
  124. data/spec/unit/util/macaddress_spec.rb +2 -2
  125. data/spec/unit/util/macosx_spec.rb +8 -8
  126. data/spec/unit/util/manufacturer_spec.rb +3 -3
  127. data/spec/unit/util/normalization_spec.rb +113 -0
  128. data/spec/unit/util/parser_spec.rb +25 -3
  129. data/spec/unit/util/processor_spec.rb +2 -2
  130. data/spec/unit/util/resolution_spec.rb +60 -631
  131. data/spec/unit/util/solaris_zones_spec.rb +5 -5
  132. data/spec/unit/util/uptime_spec.rb +1 -1
  133. data/spec/unit/util/values_spec.rb +131 -0
  134. data/spec/unit/util/virtual_spec.rb +16 -16
  135. data/spec/unit/util/xendomains_spec.rb +2 -2
  136. data/spec/unit/virtual_spec.rb +39 -39
  137. data/spec/unit/zfs_version_spec.rb +11 -11
  138. data/spec/unit/zonename_spec.rb +2 -2
  139. data/spec/unit/zones_spec.rb +1 -1
  140. data/spec/unit/zpool_version_spec.rb +11 -11
  141. metadata +466 -447
  142. data/lib/facter/util/cfpropertylist.rb +0 -6
  143. data/lib/facter/util/cfpropertylist/LICENSE +0 -19
  144. data/lib/facter/util/cfpropertylist/README +0 -44
  145. data/lib/facter/util/cfpropertylist/Rakefile +0 -44
  146. data/lib/facter/util/cfpropertylist/THANKS +0 -7
  147. data/lib/facter/util/cfpropertylist/lib/cfpropertylist.rb +0 -6
  148. data/lib/facter/util/cfpropertylist/lib/rbBinaryCFPropertyList.rb +0 -562
  149. data/lib/facter/util/cfpropertylist/lib/rbCFPlistError.rb +0 -26
  150. data/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb +0 -407
  151. data/lib/facter/util/cfpropertylist/lib/rbCFTypes.rb +0 -244
  152. data/lib/facter/util/cfpropertylist/lib/rbLibXMLParser.rb +0 -135
  153. data/lib/facter/util/cfpropertylist/lib/rbNokogiriParser.rb +0 -140
  154. data/lib/facter/util/cfpropertylist/lib/rbREXMLParser.rb +0 -136
  155. data/spec/unit/util/monkey_patches_spec.rb +0 -42
@@ -27,6 +27,15 @@ describe "The netmask fact" do
27
27
  "ifconfig_ubuntu_1204.txt"
28
28
  end
29
29
 
30
+ context "on Darwin" do
31
+ before :each do
32
+ Facter.fact(:kernel).stubs(:value).returns("Darwin")
33
+ end
34
+
35
+ example_behavior_for "netmask from ifconfig output",
36
+ "Darwin 10.8.5", "255.255.252.0", "darwin_10_8_5.txt"
37
+ end
38
+
30
39
  context "on Windows" do
31
40
  require 'facter/util/wmi'
32
41
  require 'facter/util/registry'
@@ -40,7 +40,7 @@ describe "Operating System fact" do
40
40
  "OpenIndiana" => "oi_151a",
41
41
  }.each_pair do |distribution, string|
42
42
  it "should be #{distribution} if uname -v is '#{string}'" do
43
- Facter::Util::Resolution.stubs(:exec).with('uname -v').returns(string)
43
+ Facter::Core::Execution.stubs(:exec).with('uname -v').returns(string)
44
44
  Facter.fact(:operatingsystem).value.should == distribution
45
45
  end
46
46
  end
@@ -51,7 +51,7 @@ describe "Operating System Release fact" do
51
51
  Facter.fact(:kernelrelease).stubs(:value).returns("4.1.0")
52
52
  Facter.fact(:operatingsystem).stubs(:value).returns("VMwareESX")
53
53
 
54
- Facter::Util::Resolution.stubs(:exec).with('vmware -v').returns('foo')
54
+ Facter::Core::Execution.stubs(:exec).with('vmware -v').returns('foo')
55
55
 
56
56
  Facter.fact(:operatingsystemrelease).value
57
57
  end
@@ -127,12 +127,10 @@ describe "Operating System Release fact" do
127
127
  end
128
128
 
129
129
  context "malformed /etc/release files" do
130
- before :each do
131
- Facter::Util::Resolution.any_instance.stubs(:warn)
132
- end
133
130
  it "should fallback to the kernelrelease fact if /etc/release is empty" do
134
131
  Facter::Util::FileRead.stubs(:read).with('/etc/release').
135
132
  raises EOFError
133
+ Facter.expects(:warn).with(regexp_matches(/Could not retrieve fact='operatingsystemrelease'.*EOFError/))
136
134
  Facter.fact(:operatingsystemrelease).value.
137
135
  should == Facter.fact(:kernelrelease).value
138
136
  end
@@ -140,6 +138,7 @@ describe "Operating System Release fact" do
140
138
  it "should fallback to the kernelrelease fact if /etc/release is not present" do
141
139
  Facter::Util::FileRead.stubs(:read).with('/etc/release').
142
140
  raises Errno::ENOENT
141
+ Facter.expects(:warn).with(regexp_matches(/Could not retrieve fact='operatingsystemrelease'.*No such file or directory/))
143
142
  Facter.fact(:operatingsystemrelease).value.
144
143
  should == Facter.fact(:kernelrelease).value
145
144
  end
@@ -153,6 +152,65 @@ describe "Operating System Release fact" do
153
152
  end
154
153
  end
155
154
 
155
+ describe "with operatingsystem reported as Windows" do
156
+ require 'facter/util/wmi'
157
+ before do
158
+ Facter.fact(:kernel).stubs(:value).returns("windows")
159
+ end
160
+
161
+ {
162
+ ['5.2.3790', 1] => "XP",
163
+ ['6.0.6002', 1] => "Vista",
164
+ ['6.0.6002', 2] => "2008",
165
+ ['6.0.6002', 3] => "2008",
166
+ ['6.1.7601', 1] => "7",
167
+ ['6.1.7601', 2] => "2008 R2",
168
+ ['6.1.7601', 3] => "2008 R2",
169
+ ['6.2.9200', 1] => "8",
170
+ ['6.2.9200', 2] => "2012",
171
+ ['6.2.9200', 3] => "2012",
172
+ }.each do |os_values, expected_output|
173
+ it "should be #{expected_output} with Version #{os_values[0]} and ProductType #{os_values[1]}" do
174
+ os = mock('os', :version => os_values[0], :producttype => os_values[1])
175
+ Facter::Util::WMI.expects(:execquery).returns([os])
176
+ Facter.fact(:operatingsystemrelease).value.should == expected_output
177
+ end
178
+ end
179
+
180
+ {
181
+ ['5.2.3790', 2, ""] => "2003",
182
+ ['5.2.3790', 2, "R2"] => "2003 R2",
183
+ ['5.2.3790', 3, ""] => "2003",
184
+ ['5.2.3790', 3, "R2"] => "2003 R2",
185
+ }.each do |os_values, expected_output|
186
+ it "should be #{expected_output} with Version #{os_values[0]} and ProductType #{os_values[1]} and OtherTypeDescription #{os_values[2]}" do
187
+ os = mock('os', :version => os_values[0], :producttype => os_values[1], :othertypedescription => os_values[2])
188
+ Facter::Util::WMI.expects(:execquery).returns([os])
189
+ Facter.fact(:operatingsystemrelease).value.should == expected_output
190
+ end
191
+ end
192
+
193
+ it "reports '2003' if the WMI method othertypedescription does not exist" do
194
+ os = mock('os', :version => '5.2.3790', :producttype => 2)
195
+ os.stubs(:othertypedescription).raises(NoMethodError)
196
+
197
+ Facter::Util::WMI.expects(:execquery).returns([os])
198
+ Facter.fact(:operatingsystemrelease).value.should == '2003'
199
+ end
200
+
201
+ context "Unknown Windows version" do
202
+ before :each do
203
+ Facter.fact(:kernelrelease).stubs(:value).returns("X.Y.ZZZZ")
204
+ end
205
+
206
+ it "should be kernel version value with unknown values " do
207
+ os = mock('os', :version => "X.Y.ZZZZ")
208
+ Facter::Util::WMI.expects(:execquery).returns([os])
209
+ Facter.fact(:operatingsystemrelease).value.should == "X.Y.ZZZZ"
210
+ end
211
+ end
212
+ end
213
+
156
214
  context "Ubuntu" do
157
215
  let(:lsbrelease) { 'DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=10.04\nDISTRIB_CODENAME=lucid\nDISTRIB_DESCRIPTION="Ubuntu 10.04.4 LTS"'}
158
216
  before :each do
@@ -12,9 +12,9 @@ describe "Physical processor count facts" do
12
12
 
13
13
  it "should return one physical CPU" do
14
14
  Dir.stubs(:glob).with("/sys/devices/system/cpu/cpu*/topology/physical_package_id").returns(["/sys/devices/system/cpu/cpu0/topology/physical_package_id"])
15
- Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu0/topology/physical_package_id").returns("0")
15
+ Facter::Core::Execution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu0/topology/physical_package_id").returns("0")
16
16
 
17
- Facter.fact(:physicalprocessorcount).value.should == 1
17
+ Facter.fact(:physicalprocessorcount).value.should == "1"
18
18
  end
19
19
 
20
20
  it "should return four physical CPUs" do
@@ -25,12 +25,12 @@ describe "Physical processor count facts" do
25
25
  /sys/devices/system/cpu/cpu3/topology/physical_package_id
26
26
  })
27
27
 
28
- Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu0/topology/physical_package_id").returns("0")
29
- Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu1/topology/physical_package_id").returns("1")
30
- Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu2/topology/physical_package_id").returns("2")
31
- Facter::Util::Resolution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu3/topology/physical_package_id").returns("3")
28
+ Facter::Core::Execution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu0/topology/physical_package_id").returns("0")
29
+ Facter::Core::Execution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu1/topology/physical_package_id").returns("1")
30
+ Facter::Core::Execution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu2/topology/physical_package_id").returns("2")
31
+ Facter::Core::Execution.stubs(:exec).with("cat /sys/devices/system/cpu/cpu3/topology/physical_package_id").returns("3")
32
32
 
33
- Facter.fact(:physicalprocessorcount).value.should == 4
33
+ Facter.fact(:physicalprocessorcount).value.should == "4"
34
34
  end
35
35
  end
36
36
 
@@ -43,7 +43,7 @@ describe "Physical processor count facts" do
43
43
  Facter::Util::WMI.expects(:execquery).with("select Name from Win32_Processor").returns(ole)
44
44
  ole.stubs(:Count).returns(4)
45
45
 
46
- Facter.fact(:physicalprocessorcount).value.should == 4
46
+ Facter.fact(:physicalprocessorcount).value.should == "4"
47
47
  end
48
48
  end
49
49
 
@@ -58,7 +58,7 @@ describe "Physical processor count facts" do
58
58
  Facter.fact(:kernel).stubs(:value).returns(:sunos)
59
59
  Facter.stubs(:value).with(:kernelrelease).returns(release)
60
60
 
61
- Facter::Util::Resolution.expects(:exec).with("/usr/sbin/psrinfo -p").returns("1")
61
+ Facter::Core::Execution.expects(:exec).with("/usr/sbin/psrinfo -p").returns("1")
62
62
  Facter.fact(:physicalprocessorcount).value.should == "1"
63
63
  end
64
64
  end
@@ -68,7 +68,7 @@ describe "Physical processor count facts" do
68
68
  Facter.fact(:kernel).stubs(:value).returns(:sunos)
69
69
  Facter.stubs(:value).with(:kernelrelease).returns(release)
70
70
 
71
- Facter::Util::Resolution.expects(:exec).with("/usr/sbin/psrinfo").returns(psrinfo)
71
+ Facter::Core::Execution.expects(:exec).with("/usr/sbin/psrinfo").returns(psrinfo)
72
72
  Facter.fact(:physicalprocessorcount).value.should == "2"
73
73
  end
74
74
  end
@@ -185,35 +185,35 @@ describe "Processor facts" do
185
185
 
186
186
  it "should be 2 on dual-processor Darwin box" do
187
187
  Facter.fact(:kernel).stubs(:value).returns("Darwin")
188
- Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
188
+ Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
189
189
 
190
190
  Facter.fact(:processorcount).value.should == "2"
191
191
  end
192
192
 
193
193
  it "should be 2 on dual-processor OpenBSD box" do
194
194
  Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
195
- Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
195
+ Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
196
196
 
197
197
  Facter.fact(:processorcount).value.should == "2"
198
198
  end
199
199
 
200
200
  it "should be 2 on dual-processor FreeBSD box" do
201
201
  Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
202
- Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
202
+ Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
203
203
 
204
204
  Facter.fact(:processorcount).value.should == "2"
205
205
  end
206
206
 
207
207
  it "should print the correct CPU Model on FreeBSD" do
208
208
  Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
209
- Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.model").returns('SomeVendor CPU 3GHz')
209
+ Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.model").returns('SomeVendor CPU 3GHz')
210
210
 
211
211
  Facter.fact(:processor).value.should == "SomeVendor CPU 3GHz"
212
212
  end
213
213
 
214
214
  it "should be 2 on dual-processor DragonFly box" do
215
215
  Facter.fact(:kernel).stubs(:value).returns("DragonFly")
216
- Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
216
+ Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
217
217
 
218
218
  Facter.fact(:processorcount).value.should == "2"
219
219
  end
@@ -239,9 +239,9 @@ describe "Processor facts" do
239
239
  it "uses kstat on release #{release} (#{arch})" do
240
240
  Facter.stubs(:value).with(:kernelrelease).returns(release)
241
241
 
242
- Facter::Util::Resolution.expects(:exec).with("/usr/sbin/psrinfo").never
243
- Facter::Util::Resolution.expects(:exec).with("/usr/bin/kstat cpu_info").returns(self.send("kstat_#{arch}".intern))
244
- Facter.fact(:processorcount).value.should == 8
242
+ Facter::Core::Execution.expects(:exec).with("/usr/sbin/psrinfo").never
243
+ Facter::Core::Execution.expects(:exec).with("/usr/bin/kstat cpu_info").returns(self.send("kstat_#{arch}".intern))
244
+ Facter.fact(:processorcount).value.should == '8'
245
245
  end
246
246
  end
247
247
  end
@@ -251,9 +251,9 @@ describe "Processor facts" do
251
251
  Facter.stubs(:value).with(:kernelrelease).returns(release)
252
252
 
253
253
  fixture_data = File.read(fixtures('processorcount','solaris-psrinfo'))
254
- Facter::Util::Resolution.expects(:exec).with("/usr/bin/kstat cpu_info").never
255
- Facter::Util::Resolution.expects(:exec).with("/usr/sbin/psrinfo").returns(fixture_data)
256
- Facter.fact(:processorcount).value.should == 24
254
+ Facter::Core::Execution.expects(:exec).with("/usr/bin/kstat cpu_info").never
255
+ Facter::Core::Execution.expects(:exec).with("/usr/sbin/psrinfo").returns(fixture_data)
256
+ Facter.fact(:processorcount).value.should == '24'
257
257
  end
258
258
  end
259
259
  end
@@ -96,16 +96,10 @@ describe "SELinux facts" do
96
96
 
97
97
  Facter.fact(:selinux_config_policy).value.should == "targeted"
98
98
  end
99
-
100
- it "should ensure legacy selinux_mode facts returns same value as selinux_config_policy fact" do
101
- Facter.fact(:selinux_config_policy).stubs(:value).returns("targeted")
102
-
103
- Facter.fact(:selinux_mode).value.should == "targeted"
104
- end
105
99
  end
106
100
 
107
101
  def sestatus_is(status)
108
- Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(status)
102
+ Facter::Core::Execution.stubs(:exec).with('/usr/sbin/sestatus').returns(status)
109
103
  end
110
104
 
111
105
  def mounts_does_not_exist
@@ -114,7 +108,7 @@ describe "SELinux facts" do
114
108
 
115
109
  def mounts_contains(*lines)
116
110
  FileTest.expects(:exists?).with("/proc/self/mounts").returns true
117
- Facter::Util::Resolution.expects(:exec).with("cat /proc/self/mounts").returns(lines.join("\n"))
111
+ Facter::Core::Execution.expects(:exec).with("cat /proc/self/mounts").returns(lines.join("\n"))
118
112
  end
119
113
 
120
114
  end
@@ -1,4 +1,4 @@
1
- #! /usr/bin/env ruby -S rspec
1
+ #! /usr/bin/env ruby
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/ssh'
@@ -22,7 +22,8 @@ describe "SSH fact" do
22
22
  # fingerprints extracted from ssh-keygen -r '' -f /etc/ssh/ssh_host_dsa_key.pub
23
23
  { 'SSHRSAKey' => [ 'ssh_host_rsa_key.pub' , "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDrs+KtR8hjasELsyCiiBplUeIi77hEHzTSQt1ALG7N4IgtMg27ZAcq0tl2/O9ZarQuClc903pgionbM9Q98CtAIoqgJwdtsor7ETRmzwrcY/mvI7ne51UzQy4Eh9WrplfpNyg+EVO0FUC7mBcay6JY30QKasePp+g4MkwK5cuTzOCzd9up9KELonlH7tTm2L0YI4HhZugwVoTFulCAZvPICxSk1B/fEKyGSZVfY/UxZNqg9g2Wyvq5u40xQ5eO882UwhB3w4IbmRnPKcyotAcqOJxA7hToMKtEmFct+vjHE8T37w8axE/1X9mdvy8IZbkEBL1cupqqb8a8vU1QTg1z", "SSHFP 1 1 1e4f163a1747d0d1a08a29972c9b5d94ee5705d0\nSSHFP 1 2 4e834c91e423d6085ed6dfb880a59e2f1b04f17c1dc17da07708af67c5ab6045" ],
24
24
  'SSHDSAKey' => [ 'ssh_host_dsa_key.pub' , "ssh-dss AAAAB3NzaC1kc3MAAACBAKjmRez14aZT6OKhHrsw19s7u30AdghwHFQbtC+L781YjJ3UV0/WQoZ8NaDL4ovuvW23RuO49tsqSNcVHg+PtRiN2iTVAS2h55TFhaPKhTs+i0NH3p3Ze8LNSYuz8uK7a+nTxysz47GYTHiE1ke8KXe5wGKDO1TO/MUgpDbwx72LAAAAFQD9yMJCnZMiKzA7J1RNkwvgCyBKSQAAAIAtWBAsuRM0F2fdCe+F/JmgyryQmRIT5vP8E1ww3t3ywdLHklN7UMkaEKBW/TN/jj1JOGXtZ2v5XI+0VNoNKD/7dnCGzNViRT/jjfyVi6l5UMg4Q52Gv0RXJoBJpxNqFOU2niSsy8hioyE39W6LJYWJtQozGpH/KKgkCSvxBn5hlAAAAIB1yo/YD0kQICOO0KE+UMMaKtV7FwyedFJsxsWYwZfHXGwWskf0d2+lPhd9qwdbmSvySE8Qrlvu+W+X8AipwGkItSnj16ORF8kO3lfABa+7L4BLDtumt7ybjBPcHOy3n28dd07TmMtyWvLjOb0mcxPo+TwDLtHd3L/3C1Dh41jRPg==\n", "SSHFP 2 1 f63dfe8da99f50ffbcfa40a61161cee29d109f70\nSSHFP 2 2 5f57aa6be9baddd71b6049ed5d8639664a7ddf92ce293e3887f16ad0f2d459d9" ],
25
- 'SSHECDSAKey' => [ 'ssh_host_ecdsa_key.pub' , 'ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIuKHtgXQUIrXSVNKC7uY+ZOF7jjfqYNU7Cb/IncDOZ7jW44dxsfBzRJwS5sTHERjBinJskY87mmwY07NFF5GoE=', "SSHFP 3 1 091a088fd3500ad9e35ce201c5101646cbf6ff98\nSSHFP 3 2 1dd2aa8f29b539337316e2862b28c196c68ffe0af78fccf9e50625635677e50f"]
25
+ 'SSHECDSAKey' => [ 'ssh_host_ecdsa_key.pub' , 'ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIuKHtgXQUIrXSVNKC7uY+ZOF7jjfqYNU7Cb/IncDOZ7jW44dxsfBzRJwS5sTHERjBinJskY87mmwY07NFF5GoE=', "SSHFP 3 1 091a088fd3500ad9e35ce201c5101646cbf6ff98\nSSHFP 3 2 1dd2aa8f29b539337316e2862b28c196c68ffe0af78fccf9e50625635677e50f"],
26
+ 'SSHED25519Key' => [ 'ssh_host_ed25519_key.pub' , 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAkxkUMKV0H7Z0KDgfMs+iKQFwJhKUDg8GImV/BwN48X', "SSHFP 4 1 216d49ff3581a42c7a2d4064f2356b375367d493\nSSHFP 4 2 95e3aa6f86bc2dcc46f1e9e5ea930c790afc0669fcf237c4d7b0c8e386ef2790"]
26
27
  }.each_pair do |fact, data|
27
28
  describe "#{fact}" do
28
29
  let(:filename) { data[0] }
@@ -6,21 +6,21 @@ require 'facter'
6
6
  describe "Uniqueid fact" do
7
7
  it "should match hostid on Solaris" do
8
8
  Facter.fact(:kernel).stubs(:value).returns("SunOS")
9
- Facter::Util::Resolution.stubs(:exec).with("hostid").returns("Larry")
9
+ Facter::Core::Execution.stubs(:exec).with("hostid").returns("Larry")
10
10
 
11
11
  Facter.fact(:uniqueid).value.should == "Larry"
12
12
  end
13
13
 
14
14
  it "should match hostid on Linux" do
15
15
  Facter.fact(:kernel).stubs(:value).returns("Linux")
16
- Facter::Util::Resolution.stubs(:exec).with("hostid").returns("Curly")
16
+ Facter::Core::Execution.stubs(:exec).with("hostid").returns("Curly")
17
17
 
18
18
  Facter.fact(:uniqueid).value.should == "Curly"
19
19
  end
20
20
 
21
21
  it "should match hostid on AIX" do
22
22
  Facter.fact(:kernel).stubs(:value).returns("AIX")
23
- Facter::Util::Resolution.stubs(:exec).with("hostid").returns("Moe")
23
+ Facter::Core::Execution.stubs(:exec).with("hostid").returns("Moe")
24
24
 
25
25
  Facter.fact(:uniqueid).value.should == "Moe"
26
26
  end
@@ -27,47 +27,22 @@ describe Facter::Util::Collection do
27
27
  end
28
28
 
29
29
  it "should accept options" do
30
- collection.add(:myname, :ldapname => "whatever") { }
30
+ collection.add(:myname, :timeout => 1) { }
31
31
  end
32
32
 
33
- it "should set any appropriate options on the fact instances" do
34
- # Use a real fact instance, because we're using respond_to?
33
+ it "passes resolution specific options to the fact" do
35
34
  fact = Facter::Util::Fact.new(:myname)
35
+ Facter::Util::Fact.expects(:new).with(:myname, {:timeout => 'myval'}).returns fact
36
36
 
37
- collection.add(:myname, :ldapname => "testing")
38
- collection.fact(:myname).ldapname.should == "testing"
39
- end
40
-
41
- it "should set appropriate options on the resolution instance" do
42
- fact = Facter::Util::Fact.new(:myname)
43
- Facter::Util::Fact.expects(:new).with(:myname).returns fact
44
-
45
- resolve = Facter::Util::Resolution.new(:myname) {}
46
- fact.expects(:add).returns resolve
37
+ fact.expects(:add).with({:timeout => 'myval'})
47
38
 
48
39
  collection.add(:myname, :timeout => "myval") {}
49
40
  end
50
41
 
51
- it "should not pass fact-specific options to resolutions" do
52
- fact = Facter::Util::Fact.new(:myname)
53
- Facter::Util::Fact.expects(:new).with(:myname).returns fact
54
-
55
- resolve = Facter::Util::Resolution.new(:myname) {}
56
- fact.expects(:add).returns resolve
57
-
58
- fact.expects(:ldapname=).with("foo")
59
- resolve.expects(:timeout=).with("myval")
60
-
61
- collection.add(:myname, :timeout => "myval", :ldapname => "foo") {}
62
- end
63
-
64
- it "should fail if invalid options are provided" do
65
- lambda { collection.add(:myname, :foo => :bar) }.should raise_error(ArgumentError)
66
- end
67
-
68
42
  describe "and a block is provided" do
69
43
  it "should use the block to add a resolution to the fact" do
70
44
  fact = mock 'fact'
45
+ fact.stubs(:extract_ldapname_option!)
71
46
  Facter::Util::Fact.expects(:new).returns fact
72
47
 
73
48
  fact.expects(:add)
@@ -76,13 +51,40 @@ describe Facter::Util::Collection do
76
51
  end
77
52
 
78
53
  it "should discard resolutions that throw an exception when added" do
79
- lambda {
54
+ Facter.expects(:warn).with(regexp_matches(/Unable to add resolve .* kaboom!/))
55
+ expect {
80
56
  collection.add('yay') do
81
- raise
82
- setcode { 'yay' }
57
+ raise "kaboom!"
83
58
  end
84
- }.should_not raise_error
85
- collection.value('yay').should be_nil
59
+ }.to_not raise_error
60
+ expect(collection.value('yay')).to be_nil
61
+ end
62
+ end
63
+ end
64
+
65
+ describe "when only defining facts" do
66
+ it "creates a new fact if no such fact exists" do
67
+ fact = Facter::Util::Fact.new(:newfact)
68
+ Facter::Util::Fact.expects(:new).with(:newfact, {}).returns fact
69
+ expect(collection.define_fact(:newfact)).to equal fact
70
+ end
71
+
72
+ it "returns an existing fact if the fact has already been defined" do
73
+ fact = collection.define_fact(:newfact)
74
+ expect(collection.define_fact(:newfact)).to equal fact
75
+ end
76
+
77
+ it "passes options to newly generated facts" do
78
+ Facter.stubs(:warnonce)
79
+ fact = collection.define_fact(:newfact, :ldapname => 'NewFact')
80
+ expect(fact.ldapname).to eq 'NewFact'
81
+ end
82
+
83
+ it "logs a warning if the fact could not be defined" do
84
+ Facter.expects(:warn).with("Unable to add fact newfact: kaboom!")
85
+
86
+ collection.define_fact(:newfact) do
87
+ raise "kaboom!"
86
88
  end
87
89
  end
88
90
  end
@@ -41,24 +41,44 @@ describe Facter::Util::Config do
41
41
  it "should return the default value for linux" do
42
42
  Facter::Util::Config.stubs(:is_windows?).returns(false)
43
43
  Facter::Util::Config.stubs(:windows_data_dir).returns(nil)
44
+ Facter::Util::Config.setup_default_ext_facts_dirs
44
45
  Facter::Util::Config.external_facts_dirs.should == ["/etc/facter/facts.d", "/etc/puppetlabs/facter/facts.d"]
45
46
  end
46
47
 
47
48
  it "should return the default value for windows 2008" do
48
49
  Facter::Util::Config.stubs(:is_windows?).returns(true)
49
50
  Facter::Util::Config.stubs(:windows_data_dir).returns("C:\\ProgramData")
51
+ Facter::Util::Config.setup_default_ext_facts_dirs
50
52
  Facter::Util::Config.external_facts_dirs.should == [File.join("C:\\ProgramData", 'PuppetLabs', 'facter', 'facts.d')]
51
53
  end
52
54
 
53
55
  it "should return the default value for windows 2003R2" do
54
56
  Facter::Util::Config.stubs(:is_windows?).returns(true)
55
57
  Facter::Util::Config.stubs(:windows_data_dir).returns("C:\\Documents")
58
+ Facter::Util::Config.setup_default_ext_facts_dirs
56
59
  Facter::Util::Config.external_facts_dirs.should == [File.join("C:\\Documents", 'PuppetLabs', 'facter', 'facts.d')]
57
60
  end
58
61
 
59
62
  it "returns the users home directory when not root" do
60
63
  Facter::Util::Root.stubs(:root?).returns(false)
64
+ Facter::Util::Config.setup_default_ext_facts_dirs
61
65
  Facter::Util::Config.external_facts_dirs.should == [File.expand_path(File.join("~", ".facter", "facts.d"))]
62
66
  end
67
+
68
+ it "includes additional values when user appends to the list" do
69
+ Facter::Util::Config.setup_default_ext_facts_dirs
70
+ original_values = Facter::Util::Config.external_facts_dirs.dup
71
+ new_value = '/usr/share/newdir'
72
+ Facter::Util::Config.external_facts_dirs << new_value
73
+ Facter::Util::Config.external_facts_dirs.should == original_values + [new_value]
74
+ end
75
+
76
+ it "should only output new values when explicitly set" do
77
+ Facter::Util::Config.setup_default_ext_facts_dirs
78
+ new_value = ['/usr/share/newdir']
79
+ Facter::Util::Config.external_facts_dirs = new_value
80
+ Facter::Util::Config.external_facts_dirs.should == new_value
81
+ end
82
+
63
83
  end
64
84
  end