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
@@ -29,9 +29,21 @@ describe "Operating System fact" do
29
29
  Facter.fact(:operatingsystem).value.should == "Nexenta"
30
30
  end
31
31
 
32
- it "should be Solaris for SunOS if no other variants match" do
32
+ it "should be Solaris if /etc/debian_version is missing and uname -v failed to match" do
33
+ FileTest.expects(:exists?).with("/etc/debian_version").returns false
33
34
  Facter.fact(:operatingsystem).value.should == "Solaris"
34
35
  end
36
+
37
+ {
38
+ "SmartOS" => "joyent_20120629T002039Z",
39
+ "OmniOS" => "omnios-dda4bb3",
40
+ "OpenIndiana" => "oi_151a",
41
+ }.each_pair do |distribution, string|
42
+ it "should be #{distribution} if uname -v is '#{string}'" do
43
+ Facter::Util::Resolution.stubs(:exec).with('uname -v').returns(string)
44
+ Facter.fact(:operatingsystem).value.should == distribution
45
+ end
46
+ end
35
47
  end
36
48
 
37
49
  describe "on Linux" do
@@ -51,6 +63,7 @@ describe "Operating System fact" do
51
63
  "MeeGo" => "/etc/meego-release",
52
64
  "Archlinux" => "/etc/arch-release",
53
65
  "OracleLinux" => "/etc/oracle-release",
66
+ "OpenWrt" => "/etc/openwrt_release",
54
67
  "Alpine" => "/etc/alpine-release",
55
68
  "VMWareESX" => "/etc/vmware-release",
56
69
  "Bluewhite64" => "/etc/bluewhite64-version",
@@ -66,7 +79,7 @@ describe "Operating System fact" do
66
79
 
67
80
  describe "depending on LSB release information" do
68
81
  before :each do
69
- Facter.collection.loader.load(:lsb)
82
+ Facter.collection.internal_loader.load(:lsb)
70
83
  end
71
84
 
72
85
  it "on Ubuntu should use the lsbdistid fact" do
@@ -87,6 +100,7 @@ describe "Operating System fact" do
87
100
  "SLC" => "Scientific Linux CERN SLC release 5.7 (Boron)",
88
101
  "Ascendos" => "Ascendos release 6.0 (Nameless)",
89
102
  "CloudLinux" => "CloudLinux Server release 5.5",
103
+ "XenServer" => "XenServer release 5.6.0-31188p (xenenterprise)",
90
104
  }.each_pair do |operatingsystem, string|
91
105
  it "should be #{operatingsystem} based on /etc/redhat-release contents #{string}" do
92
106
  FileTest.expects(:exists?).with("/etc/redhat-release").returns true
@@ -0,0 +1,16 @@
1
+ #! /usr/bin/env ruby -S rspec
2
+ require 'spec_helper'
3
+ require 'facter'
4
+
5
+ describe "OS Major Release fact" do
6
+ ['Amazon','CentOS','CloudLinux','Debian','Fedora','OEL','OracleLinux','OVS','RedHat','Scientific','SLC'].each do |operatingsystem|
7
+ context "on #{operatingsystem} operatingsystems" do
8
+ it "should be derived from operatingsystemrelease" do
9
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
10
+ Facter.fact(:operatingsystem).stubs(:value).returns(operatingsystem)
11
+ Facter.fact(:operatingsystemrelease).stubs(:value).returns("6.3")
12
+ Facter.fact(:operatingsystemmajrelease).value.should == "6"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
+ require 'facter/util/file_read'
3
4
  require 'spec_helper'
4
5
 
5
6
  describe "Operating System Release fact" do
@@ -13,6 +14,7 @@ describe "Operating System Release fact" do
13
14
  end
14
15
 
15
16
  test_cases = {
17
+ "OpenWrt" => "/etc/openwrt_version",
16
18
  "CentOS" => "/etc/redhat-release",
17
19
  "RedHat" => "/etc/redhat-release",
18
20
  "Scientific" => "/etc/redhat-release",
@@ -31,13 +33,19 @@ describe "Operating System Release fact" do
31
33
  it "should read the #{file.inspect} file" do
32
34
  Facter.fact(:operatingsystem).stubs(:value).returns(system)
33
35
 
34
- File.expects(:open).with(file, "r").at_least(1)
36
+ Facter::Util::FileRead.expects(:read).with(file).at_least(1)
35
37
 
36
38
  Facter.fact(:operatingsystemrelease).value
37
39
  end
38
40
  end
39
41
  end
40
42
 
43
+ it "does not include trailing whitespace on Debian" do
44
+ Facter.fact(:operatingsystem).stubs(:value).returns("Debian")
45
+ Facter::Util::FileRead.stubs(:read).returns("6.0.6\n")
46
+ Facter.fact(:operatingsystemrelease).value.should == "6.0.6"
47
+ end
48
+
41
49
  it "for VMWareESX it should run the vmware -v command" do
42
50
  Facter.fact(:kernel).stubs(:value).returns("VMkernel")
43
51
  Facter.fact(:kernelrelease).stubs(:value).returns("4.1.0")
@@ -56,4 +64,105 @@ describe "Operating System Release fact" do
56
64
 
57
65
  Facter.fact(:operatingsystemrelease).value.should == "foo"
58
66
  end
67
+
68
+ describe "with operatingsystem reported as Solaris" do
69
+
70
+ before :each do
71
+ Facter.fact(:kernel).stubs(:value).returns('SunOS')
72
+ Facter.fact(:osfamily).stubs(:value).returns('Solaris')
73
+ end
74
+
75
+ {
76
+ 'Solaris 8 s28_38shwp2 SPARC' => '28',
77
+ 'Solaris 8 6/00 s28s_u1wos_08 SPARC' => '28_u1',
78
+ 'Solaris 8 10/00 s28s_u2wos_11b SPARC' => '28_u2',
79
+ 'Solaris 8 1/01 s28s_u3wos_08 SPARC' => '28_u3',
80
+ 'Solaris 8 4/01 s28s_u4wos_08 SPARC' => '28_u4',
81
+ 'Solaris 8 7/01 s28s_u5wos_08 SPARC' => '28_u5',
82
+ 'Solaris 8 10/01 s28s_u6wos_08a SPARC' => '28_u6',
83
+ 'Solaris 8 2/02 s28s_u7wos_08a SPARC' => '28_u7',
84
+ 'Solaris 8 HW 12/02 s28s_hw1wos_06a SPARC' => '28',
85
+ 'Solaris 8 HW 5/03 s28s_hw2wos_06a SPARC' => '28',
86
+ 'Solaris 8 HW 7/03 s28s_hw3wos_05a SPARC' => '28',
87
+ 'Solaris 8 2/04 s28s_hw4wos_05a SPARC' => '28',
88
+ 'Solaris 9 s9_58shwpl3 SPARC' => '9',
89
+ 'Solaris 9 9/02 s9s_u1wos_08b SPARC' => '9_u1',
90
+ 'Solaris 9 12/02 s9s_u2wos_10 SPARC' => '9_u2',
91
+ 'Solaris 9 4/03 s9s_u3wos_08 SPARC' => '9_u3',
92
+ 'Solaris 9 8/03 s9s_u4wos_08a SPARC' => '9_u4',
93
+ 'Solaris 9 12/03 s9s_u5wos_08b SPARC' => '9_u5',
94
+ 'Solaris 9 4/04 s9s_u6wos_08a SPARC' => '9_u6',
95
+ 'Solaris 9 9/04 s9s_u7wos_09 SPARC' => '9_u7',
96
+ 'Solaris 9 9/05 s9s_u8wos_05 SPARC' => '9_u8',
97
+ 'Solaris 9 9/05 HW s9s_u9wos_06b SPARC' => '9_u9',
98
+ 'Solaris 10 3/05 s10_74L2a SPARC' => '10',
99
+ 'Solaris 10 3/05 HW1 s10s_wos_74L2a SPARC' => '10',
100
+ 'Solaris 10 3/05 HW2 s10s_hw2wos_05 SPARC' => '10',
101
+ 'Solaris 10 1/06 s10s_u1wos_19a SPARC' => '10_u1',
102
+ 'Solaris 10 6/06 s10s_u2wos_09a SPARC' => '10_u2',
103
+ 'Solaris 10 11/06 s10s_u3wos_10 SPARC' => '10_u3',
104
+ 'Solaris 10 8/07 s10s_u4wos_12b SPARC' => '10_u4',
105
+ 'Solaris 10 5/08 s10s_u5wos_10 SPARC' => '10_u5',
106
+ 'Solaris 10 10/08 s10s_u6wos_07b SPARC' => '10_u6',
107
+ 'Solaris 10 5/09 s10s_u7wos_08 SPARC' => '10_u7',
108
+ 'Solaris 10 10/09 s10s_u8wos_08a SPARC' => '10_u8',
109
+ 'Oracle Solaris 10 9/10 s10s_u9wos_14a SPARC' => '10_u9',
110
+ 'Oracle Solaris 10 8/11 s10s_u10wos_17b SPARC' => '10_u10',
111
+ 'Solaris 10 3/05 HW1 s10x_wos_74L2a X86' => '10',
112
+ 'Solaris 10 1/06 s10x_u1wos_19a X86' => '10_u1',
113
+ 'Solaris 10 6/06 s10x_u2wos_09a X86' => '10_u2',
114
+ 'Solaris 10 11/06 s10x_u3wos_10 X86' => '10_u3',
115
+ 'Solaris 10 8/07 s10x_u4wos_12b X86' => '10_u4',
116
+ 'Solaris 10 5/08 s10x_u5wos_10 X86' => '10_u5',
117
+ 'Solaris 10 10/08 s10x_u6wos_07b X86' => '10_u6',
118
+ 'Solaris 10 5/09 s10x_u7wos_08 X86' => '10_u7',
119
+ 'Solaris 10 10/09 s10x_u8wos_08a X86' => '10_u8',
120
+ 'Oracle Solaris 10 9/10 s10x_u9wos_14a X86' => '10_u9',
121
+ 'Oracle Solaris 10 8/11 s10x_u10wos_17b X86' => '10_u10',
122
+ }.each do |fakeinput,expected_output|
123
+ it "should be able to parse a release of #{fakeinput}" do
124
+ Facter::Util::FileRead.stubs(:read).with('/etc/release').returns fakeinput
125
+ Facter.fact(:operatingsystemrelease).value.should == expected_output
126
+ end
127
+ end
128
+
129
+ context "malformed /etc/release files" do
130
+ before :each do
131
+ Facter::Util::Resolution.any_instance.stubs(:warn)
132
+ end
133
+ it "should fallback to the kernelrelease fact if /etc/release is empty" do
134
+ Facter::Util::FileRead.stubs(:read).with('/etc/release').
135
+ raises EOFError
136
+ Facter.fact(:operatingsystemrelease).value.
137
+ should == Facter.fact(:kernelrelease).value
138
+ end
139
+
140
+ it "should fallback to the kernelrelease fact if /etc/release is not present" do
141
+ Facter::Util::FileRead.stubs(:read).with('/etc/release').
142
+ raises Errno::ENOENT
143
+ Facter.fact(:operatingsystemrelease).value.
144
+ should == Facter.fact(:kernelrelease).value
145
+ end
146
+
147
+ it "should fallback to the kernelrelease fact if /etc/release cannot be parsed" do
148
+ Facter::Util::FileRead.stubs(:read).with('/etc/release').
149
+ returns 'some future release string'
150
+ Facter.fact(:operatingsystemrelease).value.
151
+ should == Facter.fact(:kernelrelease).value
152
+ end
153
+ end
154
+ end
155
+
156
+ context "Ubuntu" do
157
+ let(:issue) { "Ubuntu 10.04.4 LTS \\n \\l\n\n" }
158
+ before :each do
159
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
160
+ Facter.fact(:operatingsystem).stubs(:value).returns("Ubuntu")
161
+ end
162
+
163
+ it "Returns only the major and minor version (not patch version)" do
164
+ Facter::Util::FileRead.stubs(:read).with("/etc/issue").returns(issue)
165
+ Facter.fact(:operatingsystemrelease).value.should == "10.04"
166
+ end
167
+ end
59
168
  end
@@ -23,7 +23,7 @@ describe "Processor facts" do
23
23
  # processor facts belong to a file with a different name,
24
24
  # so load the file explicitly (after stubbing kernel),
25
25
  # but we have to stub execquery first
26
- Facter.collection.loader.load(:processor)
26
+ Facter.collection.internal_loader.load(:processor)
27
27
  end
28
28
 
29
29
  describe "2003" do
@@ -69,7 +69,7 @@ describe "Processor facts" do
69
69
 
70
70
  describe "on Solaris" do
71
71
  before :each do
72
- Facter.collection.loader.load(:processor)
72
+ Facter.collection.internal_loader.load(:processor)
73
73
  Facter.fact(:kernel).stubs(:value).returns(:sunos)
74
74
  Facter.stubs(:value).with(:kernelrelease).returns("5.10")
75
75
  end
@@ -89,7 +89,7 @@ describe "Processor facts" do
89
89
 
90
90
  describe "on Unixes" do
91
91
  before :each do
92
- Facter.collection.loader.load(:processor)
92
+ Facter.collection.internal_loader.load(:processor)
93
93
  end
94
94
 
95
95
  it "should be 1 in SPARC fixture" do
@@ -188,6 +188,21 @@ describe "Processor facts" do
188
188
  Facter.fact(:processorcount).value.should == "2"
189
189
  end
190
190
 
191
+ it "should be 2 on dual-processor FreeBSD box" do
192
+ Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
193
+ Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
194
+
195
+ Facter.fact(:processorcount).value.should == "2"
196
+ end
197
+
198
+ it "should print the correct CPU Model on FreeBSD" do
199
+ Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
200
+ Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.model").returns('SomeVendor CPU 3GHz')
201
+
202
+ Facter.fact(:processor).value.should == "SomeVendor CPU 3GHz"
203
+ end
204
+
205
+
191
206
  it "should be 2 on dual-processor DragonFly box" do
192
207
  Facter.fact(:kernel).stubs(:value).returns("DragonFly")
193
208
  Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
@@ -297,7 +312,7 @@ describe "processorX facts" do
297
312
  Facter.fact(:kernel).stubs(:value).returns("AIX")
298
313
  Facter::Util::Processor.stubs(:lsdev).returns(lsdev_example)
299
314
  Facter::Util::Processor.stubs(:lsattr).returns(lsattr)
300
- Facter.collection.loader.load(:processor)
315
+ Facter.collection.internal_loader.load(:processor)
301
316
  end
302
317
 
303
318
  lsdev_example.split("\n").each_with_index do |line, idx|
@@ -335,7 +350,7 @@ describe "processorX facts" do
335
350
  Facter.fact(:kernel).stubs(:value).returns("HP-UX")
336
351
  Facter::Util::Processor.stubs(:ioscan).returns(ioscan)
337
352
  Facter::Util::Processor.stubs(:machinfo).returns(machinfo_example)
338
- Facter.collection.loader.load(:processor)
353
+ Facter.collection.internal_loader.load(:processor)
339
354
  end
340
355
 
341
356
  %w{ 0 1 }.each do |j|
@@ -387,12 +402,12 @@ describe "processorX facts" do
387
402
  if sm == "sched.models_present" then
388
403
  before :each do
389
404
  Facter::Util::Processor.stubs(:read_sched_models).returns(sched_models)
390
- Facter.collection.loader.load(:processor)
405
+ Facter.collection.internal_loader.load(:processor)
391
406
  end
392
407
  else
393
408
  before :each do
394
409
  Facter::Util::Processor.stubs(:read_sched_models).returns(nil)
395
- Facter.collection.loader.load(:processor)
410
+ Facter.collection.internal_loader.load(:processor)
396
411
  end
397
412
  end
398
413
 
@@ -0,0 +1,42 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'spec_helper'
4
+
5
+ describe "ps facts" do
6
+
7
+ it "should return busybox style ps www on OpenWrt" do
8
+ Facter.fact(:operatingsystem).stubs(:value).returns 'OpenWrt'
9
+ Facter.fact(:ps).value.should == 'ps www'
10
+ end
11
+
12
+ [
13
+ 'FreeBSD',
14
+ 'NetBSD',
15
+ 'OpenBSD',
16
+ 'Darwin',
17
+ 'DragonFly'
18
+ ].each do |os|
19
+ it "should return unix style ps on operatingsystem #{os}" do
20
+ Facter.fact(:operatingsystem).stubs(:value).returns os
21
+ Facter.fact(:ps).value.should == 'ps auxwww'
22
+ end
23
+ end
24
+
25
+ # Other Linux Distros should return a ps -ef
26
+ [
27
+ 'RedHat',
28
+ 'Debian',
29
+ ].each do |os|
30
+ it "should return gnu/linux style ps -ef on operatingsystem #{os}" do
31
+ Facter.fact(:operatingsystem).stubs(:value).returns os
32
+ Facter.fact(:ps).value.should == 'ps -ef'
33
+ end
34
+ end
35
+
36
+ it "should return tasklist.exe on Windows" do
37
+ Facter.fact(:operatingsystem).stubs(:value).returns 'windows'
38
+ Facter.fact(:ps).value.should == 'tasklist.exe'
39
+ end
40
+
41
+ end
42
+
@@ -0,0 +1,76 @@
1
+ #! /usr/bin/env ruby -S rspec
2
+
3
+ require 'spec_helper'
4
+ require 'facter/ssh'
5
+ require 'pathname'
6
+
7
+ describe "SSH fact" do
8
+
9
+ dirs = [ '/etc/ssh',
10
+ '/usr/local/etc/ssh',
11
+ '/etc',
12
+ '/usr/local/etc',
13
+ '/etc/opt/ssh',
14
+ ]
15
+
16
+ before :each do
17
+ # We need these facts loaded, but they belong to a file with a
18
+ # different name, so load the file explicitly.
19
+ Facter.collection.internal_loader.load(:ssh)
20
+ end
21
+
22
+ # fingerprints extracted from ssh-keygen -r '' -f /etc/ssh/ssh_host_dsa_key.pub
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
+ '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"]
26
+ }.each_pair do |fact, data|
27
+ describe "#{fact}" do
28
+ let(:filename) { data[0] }
29
+ let(:contents) { data[1] }
30
+ let(:fingerprint) { data[2] }
31
+ let(:fingerprint_fact) { "SSHFP_#{fact[3..-4]}" }
32
+ let(:private_key) { /AAAA\S+/.match(contents).to_s }
33
+
34
+ # Before we start testing, we'll say that the file
35
+ # doesn't exist in any of our search locations.
36
+ # Then, when we test a specific directory, we'll
37
+ # toggle just that one on.
38
+ # This doesn't test the search order, but it does
39
+ # make testing each of the individual cases *way*
40
+ # easier. --jeffweiss 24 May 2012
41
+ before(:each) do
42
+ dirs.each do |dir|
43
+ full_path = File.join(dir, filename)
44
+ FileTest.stubs(:file?).with(full_path).returns false
45
+ end
46
+ end
47
+
48
+ # Now, let's go through each and individually flip then
49
+ # on for that test.
50
+ dirs.each do |dir|
51
+ describe "when data is in #{dir}" do
52
+ let(:full_path) { File.join(dir, filename) }
53
+ before(:each) do
54
+ full_path = File.join(dir, filename)
55
+ FileTest.stubs(:file?).with(full_path).returns true
56
+ end
57
+
58
+ it "should find in #{dir}" do
59
+ FileTest.expects(:file?).with(full_path)
60
+ Facter.fact(fact).value
61
+ end
62
+
63
+ it "should match the contents" do
64
+ File.expects(:read).with(full_path).at_least_once.returns contents
65
+ Facter.fact(fact).value.should == private_key
66
+ end
67
+
68
+ it "should have matching fingerprint" do
69
+ File.expects(:read).with(full_path).at_least_once.returns contents
70
+ Facter.fact(fingerprint_fact).value.should == fingerprint
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -2,58 +2,40 @@
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'facter/util/collection'
5
+ require 'facter/util/nothing_loader'
5
6
 
6
7
  describe Facter::Util::Collection do
7
- it "should have a method for adding facts" do
8
- Facter::Util::Collection.new.should respond_to(:add)
9
- end
10
-
11
- it "should have a method for returning a loader" do
12
- Facter::Util::Collection.new.should respond_to(:loader)
13
- end
14
-
15
- it "should use an instance of the Loader class as its loader" do
16
- Facter::Util::Collection.new.loader.should be_instance_of(Facter::Util::Loader)
17
- end
18
-
19
- it "should cache its loader" do
20
- coll = Facter::Util::Collection.new
21
- coll.loader.should equal(coll.loader)
22
- end
23
-
24
- it "should have a method for loading all facts" do
25
- Facter::Util::Collection.new.should respond_to(:load_all)
8
+ let(:external_loader) { Facter::Util::NothingLoader.new }
9
+ let(:internal_loader) do
10
+ load = Facter::Util::Loader.new
11
+ load.stubs(:load).returns nil
12
+ load.stubs(:load_all).returns nil
13
+ load
26
14
  end
15
+ let(:collection) { Facter::Util::Collection.new(internal_loader, external_loader) }
27
16
 
28
17
  it "should delegate its load_all method to its loader" do
29
- coll = Facter::Util::Collection.new
30
- coll.loader.expects(:load_all)
31
- coll.load_all
18
+ internal_loader.expects(:load_all)
19
+
20
+ collection.load_all
32
21
  end
33
22
 
34
23
  describe "when adding facts" do
35
- before do
36
- @coll = Facter::Util::Collection.new
37
- end
38
-
39
24
  it "should create a new fact if no fact with the same name already exists" do
40
- fact = mock 'fact'
41
- Facter::Util::Fact.expects(:new).with { |name, *args| name == :myname }.returns fact
42
-
43
- @coll.add(:myname)
25
+ collection.add(:myname)
26
+ collection.fact(:myname).name.should == :myname
44
27
  end
45
28
 
46
29
  it "should accept options" do
47
- @coll.add(:myname, :ldapname => "whatever") { }
30
+ collection.add(:myname, :ldapname => "whatever") { }
48
31
  end
49
32
 
50
33
  it "should set any appropriate options on the fact instances" do
51
34
  # Use a real fact instance, because we're using respond_to?
52
35
  fact = Facter::Util::Fact.new(:myname)
53
- fact.expects(:ldapname=).with("testing")
54
- Facter::Util::Fact.expects(:new).with(:myname).returns fact
55
36
 
56
- @coll.add(:myname, :ldapname => "testing")
37
+ collection.add(:myname, :ldapname => "testing")
38
+ collection.fact(:myname).ldapname.should == "testing"
57
39
  end
58
40
 
59
41
  it "should set appropriate options on the resolution instance" do
@@ -63,7 +45,7 @@ describe Facter::Util::Collection do
63
45
  resolve = Facter::Util::Resolution.new(:myname) {}
64
46
  fact.expects(:add).returns resolve
65
47
 
66
- @coll.add(:myname, :timeout => "myval") {}
48
+ collection.add(:myname, :timeout => "myval") {}
67
49
  end
68
50
 
69
51
  it "should not pass fact-specific options to resolutions" do
@@ -76,11 +58,11 @@ describe Facter::Util::Collection do
76
58
  fact.expects(:ldapname=).with("foo")
77
59
  resolve.expects(:timeout=).with("myval")
78
60
 
79
- @coll.add(:myname, :timeout => "myval", :ldapname => "foo") {}
61
+ collection.add(:myname, :timeout => "myval", :ldapname => "foo") {}
80
62
  end
81
63
 
82
64
  it "should fail if invalid options are provided" do
83
- lambda { @coll.add(:myname, :foo => :bar) }.should raise_error(ArgumentError)
65
+ lambda { collection.add(:myname, :foo => :bar) }.should raise_error(ArgumentError)
84
66
  end
85
67
 
86
68
  describe "and a block is provided" do
@@ -90,175 +72,169 @@ describe Facter::Util::Collection do
90
72
 
91
73
  fact.expects(:add)
92
74
 
93
- @coll.add(:myname) {}
75
+ collection.add(:myname) {}
94
76
  end
95
77
 
96
78
  it "should discard resolutions that throw an exception when added" do
97
79
  lambda {
98
- @coll.add('yay') do
80
+ collection.add('yay') do
99
81
  raise
100
82
  setcode { 'yay' }
101
83
  end
102
84
  }.should_not raise_error
103
- @coll.value('yay').should be_nil
85
+ collection.value('yay').should be_nil
104
86
  end
105
87
  end
106
88
  end
107
89
 
108
- it "should have a method for retrieving facts by name" do
109
- Facter::Util::Collection.new.should respond_to(:fact)
110
- end
111
-
112
90
  describe "when retrieving facts" do
113
91
  before do
114
- @coll = Facter::Util::Collection.new
115
-
116
- @fact = @coll.add("YayNess")
92
+ @fact = collection.add("YayNess")
117
93
  end
118
94
 
119
95
  it "should return the fact instance specified by the name" do
120
- @coll.fact("YayNess").should equal(@fact)
96
+ collection.fact("YayNess").should equal(@fact)
121
97
  end
122
98
 
123
99
  it "should be case-insensitive" do
124
- @coll.fact("yayness").should equal(@fact)
100
+ collection.fact("yayness").should equal(@fact)
125
101
  end
126
102
 
127
103
  it "should treat strings and symbols equivalently" do
128
- @coll.fact(:yayness).should equal(@fact)
104
+ collection.fact(:yayness).should equal(@fact)
129
105
  end
130
106
 
131
107
  it "should use its loader to try to load the fact if no fact can be found" do
132
- @coll.loader.expects(:load).with(:testing)
133
- @coll.fact("testing")
108
+ collection.internal_loader.expects(:load).with(:testing)
109
+ collection.fact("testing")
134
110
  end
135
111
 
136
112
  it "should return nil if it cannot find or load the fact" do
137
- @coll.loader.expects(:load).with(:testing)
138
- @coll.fact("testing").should be_nil
113
+ collection.internal_loader.expects(:load).with(:testing)
114
+ collection.fact("testing").should be_nil
139
115
  end
140
116
  end
141
117
 
142
- it "should have a method for returning a fact's value" do
143
- Facter::Util::Collection.new.should respond_to(:value)
144
- end
145
-
146
118
  describe "when returning a fact's value" do
147
119
  before do
148
- @coll = Facter::Util::Collection.new
149
- @fact = @coll.add("YayNess")
150
-
151
- @fact.stubs(:value).returns "result"
152
- end
153
-
154
- it "should use the 'fact' method to retrieve the fact" do
155
- @coll.expects(:fact).with(:yayness).returns @fact
156
- @coll.value(:yayness)
120
+ @fact = collection.add("YayNess", :value => "result")
157
121
  end
158
122
 
159
123
  it "should return the result of calling :value on the fact" do
160
- @fact.expects(:value).returns "result"
161
-
162
- @coll.value("YayNess").should == "result"
124
+ collection.value("YayNess").should == "result"
163
125
  end
164
126
 
165
127
  it "should be case-insensitive" do
166
- @coll.value("yayness").should_not be_nil
128
+ collection.value("yayness").should == "result"
167
129
  end
168
130
 
169
131
  it "should treat strings and symbols equivalently" do
170
- @coll.value(:yayness).should_not be_nil
132
+ collection.value(:yayness).should == "result"
171
133
  end
172
134
  end
173
135
 
174
136
  it "should return the fact's value when the array index method is used" do
175
- @coll = Facter::Util::Collection.new
176
- @coll.expects(:value).with("myfact").returns "foo"
177
- @coll["myfact"].should == "foo"
137
+ collection.add("myfact", :value => "foo")
138
+
139
+ collection["myfact"].should == "foo"
178
140
  end
179
141
 
180
142
  it "should have a method for flushing all facts" do
181
- @coll = Facter::Util::Collection.new
182
- @fact = @coll.add("YayNess")
143
+ fact = collection.add("YayNess")
183
144
 
184
- @fact.expects(:flush)
145
+ fact.expects(:flush)
185
146
 
186
- @coll.flush
147
+ collection.flush
187
148
  end
188
149
 
189
150
  it "should have a method that returns all fact names" do
190
- @coll = Facter::Util::Collection.new
191
- @coll.add(:one)
192
- @coll.add(:two)
151
+ collection.add(:one)
152
+ collection.add(:two)
193
153
 
194
- @coll.list.sort { |a,b| a.to_s <=> b.to_s }.should == [:one, :two]
195
- end
196
-
197
- it "should have a method for returning a hash of fact values" do
198
- Facter::Util::Collection.new.should respond_to(:to_hash)
154
+ collection.list.sort { |a,b| a.to_s <=> b.to_s }.should == [:one, :two]
199
155
  end
200
156
 
201
157
  describe "when returning a hash of values" do
202
- before do
203
- @coll = Facter::Util::Collection.new
204
- @fact = @coll.add(:one)
205
- @fact.stubs(:value).returns "me"
206
- end
207
-
208
158
  it "should return a hash of fact names and values with the fact names as strings" do
209
- @coll.to_hash.should == {"one" => "me"}
210
- end
159
+ collection.add(:one, :value => "me")
211
160
 
212
- it "should not include facts that did not return a value" do
213
- f = @coll.add(:two)
214
- f.stubs(:value).returns nil
215
- @coll.to_hash.should_not be_include(:two)
161
+ collection.to_hash.should == {"one" => "me"}
216
162
  end
217
- end
218
163
 
219
- it "should have a method for iterating over all facts" do
220
- Facter::Util::Collection.new.should respond_to(:each)
221
- end
164
+ it "should not include facts that did not return a value" do
165
+ collection.add(:two, :value => nil)
222
166
 
223
- it "should include Enumerable" do
224
- Facter::Util::Collection.ancestors.should be_include(Enumerable)
167
+ collection.to_hash.should_not be_include(:two)
168
+ end
225
169
  end
226
170
 
227
171
  describe "when iterating over facts" do
228
172
  before do
229
- @coll = Facter::Util::Collection.new
230
- @one = @coll.add(:one)
231
- @two = @coll.add(:two)
173
+ collection.add(:one, :value => "ONE")
174
+ collection.add(:two, :value => "TWO")
232
175
  end
233
176
 
234
177
  it "should yield each fact name and the fact value" do
235
- @one.stubs(:value).returns "ONE"
236
- @two.stubs(:value).returns "TWO"
237
178
  facts = {}
238
- @coll.each do |fact, value|
179
+ collection.each do |fact, value|
239
180
  facts[fact] = value
240
181
  end
241
182
  facts.should == {"one" => "ONE", "two" => "TWO"}
242
183
  end
243
184
 
244
185
  it "should convert the fact name to a string" do
245
- @one.stubs(:value).returns "ONE"
246
- @two.stubs(:value).returns "TWO"
247
186
  facts = {}
248
- @coll.each do |fact, value|
187
+ collection.each do |fact, value|
249
188
  fact.should be_instance_of(String)
250
189
  end
251
190
  end
252
191
 
253
192
  it "should only yield facts that have values" do
254
- @one.stubs(:value).returns "ONE"
255
- @two.stubs(:value).returns nil
193
+ collection.add(:nil_fact, :value => nil)
256
194
  facts = {}
257
- @coll.each do |fact, value|
195
+ collection.each do |fact, value|
258
196
  facts[fact] = value
259
197
  end
260
198
 
261
- facts.should_not be_include("two")
199
+ facts.should_not be_include("nil_fact")
200
+ end
201
+ end
202
+
203
+ describe "when no facts are loaded" do
204
+ it "should warn when no facts were loaded" do
205
+ Facter.expects(:warnonce).with("No facts loaded from #{internal_loader.search_path.join(File::PATH_SEPARATOR)}").once
206
+
207
+ collection.fact("one")
208
+ end
209
+ end
210
+
211
+ describe "external facts" do
212
+ let(:collection) { Facter::Util::Collection.new(internal_loader, SingleFactLoader.new(:test_fact, "fact value")) }
213
+
214
+ it "loads when a specific fact is requested" do
215
+ collection.fact(:test_fact).value.should == "fact value"
216
+ end
217
+
218
+ it "loads when facts are listed" do
219
+ collection.list.should == [:test_fact]
220
+ end
221
+
222
+ it "loads when all facts are iterated over" do
223
+ facts = []
224
+ collection.each { |fact_name, fact_value| facts << [fact_name, fact_value] }
225
+
226
+ facts.should == [["test_fact", "fact value"]]
227
+ end
228
+ end
229
+
230
+ class SingleFactLoader
231
+ def initialize(name, value)
232
+ @name = name
233
+ @value = value
234
+ end
235
+
236
+ def load(collection)
237
+ collection.add(@name, :value => @value)
262
238
  end
263
239
  end
264
240
  end