facter 1.5 → 1.5.2
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.
- data/CHANGELOG +51 -1
- data/Rakefile +10 -1
- data/conf/osx/PackageInfo.plist +36 -0
- data/conf/osx/createpackage.sh +167 -0
- data/conf/osx/preflight +11 -0
- data/conf/redhat/facter.spec +120 -0
- data/conf/solaris/pkginfo +7 -0
- data/documentation/custom.page +22 -0
- data/documentation/index.page +19 -0
- data/install.rb +227 -92
- data/lib/facter.rb +1 -1
- data/lib/facter/domain.rb +14 -0
- data/lib/facter/hardwaremodel.rb +8 -0
- data/lib/facter/ipaddress.rb +21 -2
- data/lib/facter/ipmess.rb +8 -37
- data/lib/facter/kernel.rb +7 -1
- data/lib/facter/kernelrelease.rb +16 -1
- data/lib/facter/kernelversion.rb +5 -0
- data/lib/facter/lsb.rb +1 -0
- data/lib/facter/macaddress.rb +15 -1
- data/lib/facter/operatingsystem.rb +6 -1
- data/lib/facter/operatingsystemrelease.rb +34 -7
- data/lib/facter/puppetversion.rb +1 -1
- data/lib/facter/util/ip.rb +37 -47
- data/lib/facter/util/manufacturer.rb +2 -2
- data/lib/facter/util/resolution.rb +13 -3
- data/lib/facter/virtual.rb +62 -0
- data/spec/Rakefile +18 -0
- data/spec/integration/facter.rb +27 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/unit/data/linux_ifconfig_all_with_single_interface +18 -0
- data/spec/unit/data/solaris_ifconfig_single_interface +3 -0
- data/spec/unit/facter.rb +134 -0
- data/spec/unit/util/collection.rb +255 -0
- data/spec/unit/util/confine.rb +75 -0
- data/spec/unit/util/fact.rb +129 -0
- data/spec/unit/util/ip.rb +40 -0
- data/spec/unit/util/loader.rb +219 -0
- data/spec/unit/util/resolution.rb +209 -0
- metadata +31 -2
@@ -0,0 +1,209 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
4
|
+
|
5
|
+
require 'facter/util/resolution'
|
6
|
+
|
7
|
+
describe Facter::Util::Resolution do
|
8
|
+
it "should require a name" do
|
9
|
+
lambda { Facter::Util::Resolution.new }.should raise_error(ArgumentError)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have a name" do
|
13
|
+
Facter::Util::Resolution.new("yay").name.should == "yay"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have a method for setting the code" do
|
17
|
+
Facter::Util::Resolution.new("yay").should respond_to(:setcode)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should support a timeout value" do
|
21
|
+
Facter::Util::Resolution.new("yay").should respond_to(:timeout=)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should default to a timeout of 0 seconds" do
|
25
|
+
Facter::Util::Resolution.new("yay").limit.should == 0
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should provide a 'limit' method that returns the timeout" do
|
29
|
+
res = Facter::Util::Resolution.new("yay")
|
30
|
+
res.timeout = "testing"
|
31
|
+
res.limit.should == "testing"
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "when setting the code" do
|
35
|
+
before do
|
36
|
+
@resolve = Facter::Util::Resolution.new("yay")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should default to /bin/sh as the interpreter if a string is provided" do
|
40
|
+
@resolve.setcode "foo"
|
41
|
+
@resolve.interpreter.should == "/bin/sh"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should set the code to any provided string" do
|
45
|
+
@resolve.setcode "foo"
|
46
|
+
@resolve.code.should == "foo"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should set the code to any provided block" do
|
50
|
+
block = lambda { }
|
51
|
+
@resolve.setcode(&block)
|
52
|
+
@resolve.code.should equal(block)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should prefer the string over a block" do
|
56
|
+
@resolve.setcode("foo") { }
|
57
|
+
@resolve.code.should == "foo"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should fail if neither a string nor block has been provided" do
|
61
|
+
lambda { @resolve.setcode }.should raise_error(ArgumentError)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should be able to return a value" do
|
66
|
+
Facter::Util::Resolution.new("yay").should respond_to(:value)
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "when returning the value" do
|
70
|
+
before do
|
71
|
+
@resolve = Facter::Util::Resolution.new("yay")
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "and the code is a string" do
|
75
|
+
it "should return the result of executing the code with the interpreter" do
|
76
|
+
@resolve.setcode "/bin/foo"
|
77
|
+
Facter::Util::Resolution.expects(:exec).with("/bin/foo", "/bin/sh").returns "yup"
|
78
|
+
|
79
|
+
@resolve.value.should == "yup"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should return nil if the value is an empty string" do
|
83
|
+
@resolve.setcode "/bin/foo"
|
84
|
+
Facter::Util::Resolution.stubs(:exec).returns ""
|
85
|
+
@resolve.value.should be_nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "and the code is a block" do
|
90
|
+
it "should return the value returned by the block" do
|
91
|
+
@resolve.setcode { "yayness" }
|
92
|
+
@resolve.value.should == "yayness"
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should return nil if the value is an empty string" do
|
96
|
+
@resolve.setcode { "" }
|
97
|
+
@resolve.value.should be_nil
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should use its limit method to determine the timeout, to avoid conflict when a 'timeout' method exists for some other reason" do
|
101
|
+
@resolve.expects(:timeout).never
|
102
|
+
@resolve.expects(:limit).returns "foo"
|
103
|
+
Timeout.expects(:timeout).with("foo")
|
104
|
+
|
105
|
+
@resolve.value
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should timeout after the provided timeout" do
|
109
|
+
@resolve.expects(:warn)
|
110
|
+
@resolve.timeout = 0.1
|
111
|
+
@resolve.setcode { sleep 2; raise "This is a test" }
|
112
|
+
|
113
|
+
@resolve.value.should be_nil
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should waitall to avoid zombies if the timeout is exceeded" do
|
117
|
+
@resolve.stubs(:warn)
|
118
|
+
@resolve.timeout = 0.1
|
119
|
+
@resolve.setcode { sleep 2; raise "This is a test" }
|
120
|
+
|
121
|
+
Thread.expects(:new).yields
|
122
|
+
Process.expects(:waitall)
|
123
|
+
|
124
|
+
@resolve.value
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should return its value when converted to a string" do
|
130
|
+
@resolve = Facter::Util::Resolution.new("yay")
|
131
|
+
@resolve.expects(:value).returns "myval"
|
132
|
+
@resolve.to_s.should == "myval"
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should allow the adding of confines" do
|
136
|
+
Facter::Util::Resolution.new("yay").should respond_to(:confine)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should provide a method for returning the number of confines" do
|
140
|
+
@resolve = Facter::Util::Resolution.new("yay")
|
141
|
+
@resolve.confine "one" => "foo", "two" => "fee"
|
142
|
+
@resolve.length.should == 2
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should return 0 confines when no confines have been added" do
|
146
|
+
Facter::Util::Resolution.new("yay").length.should == 0
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should have a method for determining if it is suitable" do
|
150
|
+
Facter::Util::Resolution.new("yay").should respond_to(:suitable?)
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "when adding confines" do
|
154
|
+
before do
|
155
|
+
@resolve = Facter::Util::Resolution.new("yay")
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should accept a hash of fact names and values" do
|
159
|
+
lambda { @resolve.confine :one => "two" }.should_not raise_error
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should create a Util::Confine instance for every argument in the provided hash" do
|
163
|
+
Facter::Util::Confine.expects(:new).with("one", "foo")
|
164
|
+
Facter::Util::Confine.expects(:new).with("two", "fee")
|
165
|
+
|
166
|
+
@resolve.confine "one" => "foo", "two" => "fee"
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
describe "when determining suitability" do
|
172
|
+
before do
|
173
|
+
@resolve = Facter::Util::Resolution.new("yay")
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should always be suitable if no confines have been added" do
|
177
|
+
@resolve.should be_suitable
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should be unsuitable if any provided confines return false" do
|
181
|
+
confine1 = mock 'confine1', :true? => true
|
182
|
+
confine2 = mock 'confine2', :true? => false
|
183
|
+
Facter::Util::Confine.expects(:new).times(2).returns(confine1).then.returns(confine2)
|
184
|
+
@resolve.confine :one => :two, :three => :four
|
185
|
+
|
186
|
+
@resolve.should_not be_suitable
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should be suitable if all provided confines return true" do
|
190
|
+
confine1 = mock 'confine1', :true? => true
|
191
|
+
confine2 = mock 'confine2', :true? => true
|
192
|
+
Facter::Util::Confine.expects(:new).times(2).returns(confine1).then.returns(confine2)
|
193
|
+
@resolve.confine :one => :two, :three => :four
|
194
|
+
|
195
|
+
@resolve.should be_suitable
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should have a class method for executing code" do
|
200
|
+
Facter::Util::Resolution.should respond_to(:exec)
|
201
|
+
end
|
202
|
+
|
203
|
+
# It's not possible, AFAICT, to mock %x{}, so I can't really test this bit.
|
204
|
+
describe "when executing code" do
|
205
|
+
it "should fail if any interpreter other than /bin/sh is requested" do
|
206
|
+
lambda { Facter::Util::Resolution.exec("/something", "/bin/perl") }.should raise_error(ArgumentError)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: facter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Kanies
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-09-09 00:00:00 +02:00
|
13
13
|
default_executable: facter
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- lib/facter/Cfkey.rb
|
52
52
|
- lib/facter/lsbmajdistrelease.rb
|
53
53
|
- lib/facter/hardwaremodel.rb
|
54
|
+
- lib/facter/kernelversion.rb
|
54
55
|
- lib/facter/macaddress.rb
|
55
56
|
- lib/facter/util/resolution.rb
|
56
57
|
- lib/facter/util/collection.rb
|
@@ -71,10 +72,38 @@ files:
|
|
71
72
|
- lib/facter/puppetversion.rb
|
72
73
|
- lib/facter/macosx.rb
|
73
74
|
- lib/facter/kernelrelease.rb
|
75
|
+
- lib/facter/virtual.rb
|
74
76
|
- lib/facter/manufacturer.rb
|
75
77
|
- lib/facter/kernel.rb
|
76
78
|
- lib/facter/ipmess.rb
|
77
79
|
- lib/facter/netmask.rb
|
80
|
+
- spec/spec.opts
|
81
|
+
- spec/unit
|
82
|
+
- spec/unit/facter.rb
|
83
|
+
- spec/unit/data
|
84
|
+
- spec/unit/data/solaris_ifconfig_single_interface
|
85
|
+
- spec/unit/data/linux_ifconfig_all_with_single_interface
|
86
|
+
- spec/unit/util
|
87
|
+
- spec/unit/util/resolution.rb
|
88
|
+
- spec/unit/util/collection.rb
|
89
|
+
- spec/unit/util/confine.rb
|
90
|
+
- spec/unit/util/loader.rb
|
91
|
+
- spec/unit/util/fact.rb
|
92
|
+
- spec/unit/util/ip.rb
|
93
|
+
- spec/integration
|
94
|
+
- spec/integration/facter.rb
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
- spec/Rakefile
|
97
|
+
- conf/osx
|
98
|
+
- conf/osx/createpackage.sh
|
99
|
+
- conf/osx/PackageInfo.plist
|
100
|
+
- conf/osx/preflight
|
101
|
+
- conf/redhat
|
102
|
+
- conf/redhat/facter.spec
|
103
|
+
- conf/solaris
|
104
|
+
- conf/solaris/pkginfo
|
105
|
+
- documentation/index.page
|
106
|
+
- documentation/custom.page
|
78
107
|
- etc/facter.conf
|
79
108
|
has_rdoc: false
|
80
109
|
homepage: http://reductivelabs.com/projects/facter
|