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.
- checksums.yaml +7 -0
- data/COMMITTERS.md +194 -0
- data/CONTRIBUTING.md +63 -235
- data/Gemfile +12 -8
- data/README.md +1 -2
- data/Rakefile +1 -1
- data/bin/facter +0 -4
- data/ext/build_defaults.yaml +2 -2
- data/ext/project_data.yaml +18 -0
- data/install.rb +1 -16
- data/lib/facter.rb +171 -171
- data/lib/facter/application.rb +65 -54
- data/lib/facter/core/aggregate.rb +220 -0
- data/lib/facter/core/directed_graph.rb +46 -0
- data/lib/facter/core/execution.rb +100 -0
- data/lib/facter/core/execution/base.rb +73 -0
- data/lib/facter/core/execution/posix.rb +50 -0
- data/lib/facter/core/execution/windows.rb +57 -0
- data/lib/facter/core/logging.rb +169 -0
- data/lib/facter/core/resolvable.rb +94 -0
- data/lib/facter/core/suitable.rb +117 -0
- data/lib/facter/domain.rb +15 -9
- data/lib/facter/filesystems.rb +1 -1
- data/lib/facter/hardwaremodel.rb +1 -1
- data/lib/facter/hostname.rb +3 -3
- data/lib/facter/interfaces.rb +6 -1
- data/lib/facter/ipaddress.rb +2 -2
- data/lib/facter/kernel.rb +1 -1
- data/lib/facter/kernelrelease.rb +1 -1
- data/lib/facter/ldom.rb +1 -1
- data/lib/facter/lsbdistcodename.rb +1 -1
- data/lib/facter/lsbdistdescription.rb +1 -1
- data/lib/facter/lsbdistid.rb +1 -1
- data/lib/facter/lsbdistrelease.rb +1 -1
- data/lib/facter/lsbrelease.rb +1 -1
- data/lib/facter/macaddress.rb +1 -14
- data/lib/facter/macosx.rb +2 -2
- data/lib/facter/memory.rb +8 -19
- data/lib/facter/operatingsystem.rb +1 -1
- data/lib/facter/operatingsystemrelease.rb +34 -1
- data/lib/facter/physicalprocessorcount.rb +6 -6
- data/lib/facter/processor.rb +11 -10
- data/lib/facter/selinux.rb +4 -15
- data/lib/facter/ssh.rb +5 -2
- data/lib/facter/util/architecture.rb +2 -2
- data/lib/facter/util/collection.rb +42 -38
- data/lib/facter/util/config.rb +19 -9
- data/lib/facter/util/confine.rb +34 -4
- data/lib/facter/util/ec2.rb +1 -1
- data/lib/facter/util/fact.rb +108 -36
- data/lib/facter/util/file_read.rb +7 -6
- data/lib/facter/util/formatter.rb +38 -0
- data/lib/facter/util/ip.rb +3 -3
- data/lib/facter/util/loader.rb +62 -42
- data/lib/facter/util/macosx.rb +7 -8
- data/lib/facter/util/manufacturer.rb +3 -3
- data/lib/facter/util/memory.rb +13 -13
- data/lib/facter/util/monkey_patches.rb +0 -31
- data/lib/facter/util/netmask.rb +3 -3
- data/lib/facter/util/normalization.rb +94 -0
- data/lib/facter/util/nothing_loader.rb +3 -6
- data/lib/facter/util/parser.rb +3 -5
- data/lib/facter/util/plist/generator.rb +1 -1
- data/lib/facter/util/processor.rb +15 -15
- data/lib/facter/util/resolution.rb +112 -289
- data/lib/facter/util/solaris_zones.rb +4 -4
- data/lib/facter/util/uptime.rb +8 -3
- data/lib/facter/util/values.rb +67 -1
- data/lib/facter/util/virtual.rb +10 -10
- data/lib/facter/util/xendomains.rb +1 -1
- data/lib/facter/version.rb +42 -39
- data/lib/facter/virtual.rb +6 -7
- data/lib/facter/zfs_version.rb +3 -3
- data/lib/facter/zpool_version.rb +3 -3
- data/spec/fixtures/unit/netmask/darwin_10_8_5.txt +30 -0
- data/spec/unit/application_spec.rb +46 -1
- data/spec/unit/core/aggregate_spec.rb +125 -0
- data/spec/unit/core/directed_graph_spec.rb +79 -0
- data/spec/unit/core/execution/base_spec.rb +119 -0
- data/spec/unit/core/execution/posix_spec.rb +86 -0
- data/spec/unit/core/execution/windows_spec.rb +106 -0
- data/spec/unit/core/execution_spec.rb +37 -0
- data/spec/unit/core/logging_spec.rb +104 -0
- data/spec/unit/core/resolvable_spec.rb +81 -0
- data/spec/unit/core/suitable_spec.rb +96 -0
- data/spec/unit/domain_spec.rb +5 -5
- data/spec/unit/facter_spec.rb +61 -222
- data/spec/unit/filesystems_spec.rb +2 -2
- data/spec/unit/hardwareisa_spec.rb +5 -5
- data/spec/unit/hardwaremodel_spec.rb +1 -1
- data/spec/unit/hostname_spec.rb +4 -4
- data/spec/unit/id_spec.rb +3 -3
- data/spec/unit/interfaces_spec.rb +10 -0
- data/spec/unit/ipaddress6_spec.rb +4 -4
- data/spec/unit/ipaddress_spec.rb +1 -1
- data/spec/unit/kernel_spec.rb +2 -2
- data/spec/unit/kernelmajversion_spec.rb +1 -1
- data/spec/unit/kernelrelease_spec.rb +4 -4
- data/spec/unit/kernelversion_spec.rb +2 -2
- data/spec/unit/ldom_spec.rb +2 -2
- data/spec/unit/lsbdistcodename_spec.rb +2 -2
- data/spec/unit/lsbdistdescription_spec.rb +2 -2
- data/spec/unit/lsbdistid_spec.rb +2 -2
- data/spec/unit/lsbdistrelease_spec.rb +2 -2
- data/spec/unit/lsbrelease_spec.rb +2 -2
- data/spec/unit/manufacturer_spec.rb +1 -1
- data/spec/unit/memory_spec.rb +24 -31
- data/spec/unit/netmask_spec.rb +9 -0
- data/spec/unit/operatingsystem_spec.rb +1 -1
- data/spec/unit/operatingsystemrelease_spec.rb +62 -4
- data/spec/unit/physicalprocessorcount_spec.rb +10 -10
- data/spec/unit/processor_spec.rb +11 -11
- data/spec/unit/selinux_spec.rb +2 -8
- data/spec/unit/ssh_spec.rb +3 -2
- data/spec/unit/uniqueid_spec.rb +3 -3
- data/spec/unit/util/collection_spec.rb +37 -35
- data/spec/unit/util/config_spec.rb +20 -0
- data/spec/unit/util/confine_spec.rb +21 -0
- data/spec/unit/util/directory_loader_spec.rb +1 -0
- data/spec/unit/util/ec2_spec.rb +6 -6
- data/spec/unit/util/fact_spec.rb +92 -90
- data/spec/unit/util/ip_spec.rb +2 -2
- data/spec/unit/util/loader_spec.rb +127 -186
- data/spec/unit/util/macaddress_spec.rb +2 -2
- data/spec/unit/util/macosx_spec.rb +8 -8
- data/spec/unit/util/manufacturer_spec.rb +3 -3
- data/spec/unit/util/normalization_spec.rb +113 -0
- data/spec/unit/util/parser_spec.rb +25 -3
- data/spec/unit/util/processor_spec.rb +2 -2
- data/spec/unit/util/resolution_spec.rb +60 -631
- data/spec/unit/util/solaris_zones_spec.rb +5 -5
- data/spec/unit/util/uptime_spec.rb +1 -1
- data/spec/unit/util/values_spec.rb +131 -0
- data/spec/unit/util/virtual_spec.rb +16 -16
- data/spec/unit/util/xendomains_spec.rb +2 -2
- data/spec/unit/virtual_spec.rb +39 -39
- data/spec/unit/zfs_version_spec.rb +11 -11
- data/spec/unit/zonename_spec.rb +2 -2
- data/spec/unit/zones_spec.rb +1 -1
- data/spec/unit/zpool_version_spec.rb +11 -11
- metadata +466 -447
- data/lib/facter/util/cfpropertylist.rb +0 -6
- data/lib/facter/util/cfpropertylist/LICENSE +0 -19
- data/lib/facter/util/cfpropertylist/README +0 -44
- data/lib/facter/util/cfpropertylist/Rakefile +0 -44
- data/lib/facter/util/cfpropertylist/THANKS +0 -7
- data/lib/facter/util/cfpropertylist/lib/cfpropertylist.rb +0 -6
- data/lib/facter/util/cfpropertylist/lib/rbBinaryCFPropertyList.rb +0 -562
- data/lib/facter/util/cfpropertylist/lib/rbCFPlistError.rb +0 -26
- data/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb +0 -407
- data/lib/facter/util/cfpropertylist/lib/rbCFTypes.rb +0 -244
- data/lib/facter/util/cfpropertylist/lib/rbLibXMLParser.rb +0 -135
- data/lib/facter/util/cfpropertylist/lib/rbNokogiriParser.rb +0 -140
- data/lib/facter/util/cfpropertylist/lib/rbREXMLParser.rb +0 -136
- data/spec/unit/util/monkey_patches_spec.rb +0 -42
@@ -123,5 +123,26 @@ describe Facter::Util::Confine do
|
|
123
123
|
it "should return false if none of the provided ranges matches the fact's value" do
|
124
124
|
confined(8, (5..7)).should be_false
|
125
125
|
end
|
126
|
+
|
127
|
+
it "should accept and evaluate a block argument against the fact" do
|
128
|
+
@fact.expects(:value).returns 'foo'
|
129
|
+
confine = Facter::Util::Confine.new :yay do |f| f === 'foo' end
|
130
|
+
confine.true?.should be_true
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should return false if the block raises a StandardError when checking a fact" do
|
134
|
+
@fact.stubs(:value).returns 'foo'
|
135
|
+
confine = Facter::Util::Confine.new :yay do |f| raise StandardError end
|
136
|
+
confine.true?.should be_false
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should accept and evaluate only a block argument" do
|
140
|
+
Facter::Util::Confine.new { true }.true?.should be_true
|
141
|
+
Facter::Util::Confine.new { false }.true?.should be_false
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should return false if the block raises a StandardError" do
|
145
|
+
Facter::Util::Confine.new { raise StandardError }.true?.should be_false
|
146
|
+
end
|
126
147
|
end
|
127
148
|
end
|
@@ -55,6 +55,7 @@ describe Facter::Util::DirectoryLoader do
|
|
55
55
|
|
56
56
|
%w{bak orig}.each do |ext|
|
57
57
|
it "should ignore files with an extension of '#{ext}'" do
|
58
|
+
Facter.expects(:warn).with(regexp_matches(/#{ext}/))
|
58
59
|
write_to_file("data" + ".#{ext}", "foo=bar")
|
59
60
|
|
60
61
|
subject.load(collection)
|
data/spec/unit/util/ec2_spec.rb
CHANGED
@@ -17,21 +17,21 @@ describe Facter::Util::EC2 do
|
|
17
17
|
|
18
18
|
it "should succeed if arp table contains fe:ff:ff:ff:ff:ff" do
|
19
19
|
ec2arp = my_fixture_read("linux-arp-ec2.out")
|
20
|
-
Facter::
|
20
|
+
Facter::Core::Execution.expects(:exec).with("arp -an").\
|
21
21
|
at_least_once.returns(ec2arp)
|
22
22
|
Facter::Util::EC2.has_ec2_arp?.should == true
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should succeed if arp table contains FE:FF:FF:FF:FF:FF" do
|
26
26
|
ec2arp = my_fixture_read("centos-arp-ec2.out")
|
27
|
-
Facter::
|
27
|
+
Facter::Core::Execution.expects(:exec).with("arp -an").\
|
28
28
|
at_least_once.returns(ec2arp)
|
29
29
|
Facter::Util::EC2.has_ec2_arp?.should == true
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should fail if arp table does not contain fe:ff:ff:ff:ff:ff" do
|
33
33
|
ec2arp = my_fixture_read("linux-arp-not-ec2.out")
|
34
|
-
Facter::
|
34
|
+
Facter::Core::Execution.expects(:exec).with("arp -an").
|
35
35
|
at_least_once.returns(ec2arp)
|
36
36
|
Facter::Util::EC2.has_ec2_arp?.should == false
|
37
37
|
end
|
@@ -45,14 +45,14 @@ describe Facter::Util::EC2 do
|
|
45
45
|
|
46
46
|
it "should succeed if arp table contains fe-ff-ff-ff-ff-ff" do
|
47
47
|
ec2arp = my_fixture_read("windows-2008-arp-a.out")
|
48
|
-
Facter::
|
48
|
+
Facter::Core::Execution.expects(:exec).with("arp -a").\
|
49
49
|
at_least_once.returns(ec2arp)
|
50
50
|
Facter::Util::EC2.has_ec2_arp?.should == true
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should fail if arp table does not contain fe-ff-ff-ff-ff-ff" do
|
54
54
|
ec2arp = my_fixture_read("windows-2008-arp-a-not-ec2.out")
|
55
|
-
Facter::
|
55
|
+
Facter::Core::Execution.expects(:exec).with("arp -a").
|
56
56
|
at_least_once.returns(ec2arp)
|
57
57
|
Facter::Util::EC2.has_ec2_arp?.should == false
|
58
58
|
end
|
@@ -66,7 +66,7 @@ describe Facter::Util::EC2 do
|
|
66
66
|
it "should fail if arp table does not contain fe:ff:ff:ff:ff:ff" do
|
67
67
|
ec2arp = my_fixture_read("solaris8_arp_a_not_ec2.out")
|
68
68
|
|
69
|
-
Facter::
|
69
|
+
Facter::Core::Execution.expects(:exec).with("arp -a").
|
70
70
|
at_least_once.returns(ec2arp)
|
71
71
|
|
72
72
|
Facter::Util::EC2.has_ec2_arp?.should == false
|
data/spec/unit/util/fact_spec.rb
CHANGED
@@ -4,108 +4,123 @@ require 'spec_helper'
|
|
4
4
|
require 'facter/util/fact'
|
5
5
|
|
6
6
|
describe Facter::Util::Fact do
|
7
|
-
it "should require a name" do
|
8
|
-
lambda { Facter::Util::Fact.new }.should raise_error(ArgumentError)
|
9
|
-
end
|
10
7
|
|
11
|
-
|
12
|
-
Facter::Util::Fact.new("YayNess").name.should == :yayness
|
13
|
-
end
|
8
|
+
subject(:fact) { Facter::Util::Fact.new("yay") }
|
14
9
|
|
15
|
-
|
16
|
-
|
10
|
+
let(:resolution) { Facter::Util::Resolution.new("yay", fact) }
|
11
|
+
|
12
|
+
it "requires a name" do
|
13
|
+
expect { Facter::Util::Fact.new }.to raise_error(ArgumentError)
|
17
14
|
end
|
18
15
|
|
19
|
-
it "
|
20
|
-
Facter::Util::Fact.new("YayNess"
|
16
|
+
it "downcases and converts the name to a symbol" do
|
17
|
+
expect(Facter::Util::Fact.new("YayNess").name).to eq :yayness
|
21
18
|
end
|
22
19
|
|
23
|
-
it "
|
24
|
-
|
20
|
+
it "issues a deprecation warning for use of ldapname" do
|
21
|
+
Facter.expects(:warnonce).with("ldapname is deprecated and will be removed in a future version")
|
22
|
+
Facter::Util::Fact.new("YayNess", :ldapname => "fooness")
|
25
23
|
end
|
26
24
|
|
27
|
-
|
28
|
-
|
25
|
+
describe "when adding resolution mechanisms using #add" do
|
26
|
+
it "delegates to #define_resolution with an anonymous resolution" do
|
27
|
+
subject.expects(:define_resolution).with(nil, {})
|
28
|
+
subject.add
|
29
|
+
end
|
29
30
|
end
|
30
31
|
|
31
|
-
describe "
|
32
|
-
|
33
|
-
@fact = Facter::Util::Fact.new("yay")
|
32
|
+
describe "looking up resolutions by name" do
|
33
|
+
subject(:fact) { described_class.new('yay') }
|
34
34
|
|
35
|
-
|
35
|
+
it "returns nil if no such resolution exists" do
|
36
|
+
expect(fact.resolution('nope')).to be_nil
|
36
37
|
end
|
37
38
|
|
38
|
-
it "
|
39
|
-
|
39
|
+
it "never returns anonymous resolutions" do
|
40
|
+
fact.add() { setcode { 'anonymous' } }
|
40
41
|
|
41
|
-
|
42
|
-
end
|
43
|
-
it "should instance_eval the passed block on the new resolution" do
|
44
|
-
@fact.add {
|
45
|
-
setcode { "foo" }
|
46
|
-
}
|
47
|
-
@fact.value.should == "foo"
|
42
|
+
expect(fact.resolution(nil)).to be_nil
|
48
43
|
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "adding resolution mechanisms by name" do
|
49
47
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
48
|
+
let(:res) do
|
49
|
+
stub 'resolution',
|
50
|
+
:name => 'named',
|
51
|
+
:set_options => nil,
|
52
|
+
:resolution_type => :simple
|
55
53
|
end
|
56
|
-
end
|
57
54
|
|
58
|
-
|
59
|
-
|
60
|
-
end
|
55
|
+
it "creates a new resolution if no such resolution exists" do
|
56
|
+
Facter::Util::Resolution.expects(:new).once.with('named', fact).returns(res)
|
61
57
|
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
fact.define_resolution('named')
|
59
|
+
|
60
|
+
expect(fact.resolution('named')).to eq res
|
65
61
|
end
|
66
62
|
|
67
|
-
it "
|
68
|
-
|
63
|
+
it "creates a simple resolution when the type is nil" do
|
64
|
+
fact.define_resolution('named')
|
65
|
+
expect(fact.resolution('named')).to be_a_kind_of Facter::Util::Resolution
|
66
|
+
end
|
67
|
+
|
68
|
+
it "creates a simple resolution when the type is :simple" do
|
69
|
+
fact.define_resolution('named', :type => :simple)
|
70
|
+
expect(fact.resolution('named')).to be_a_kind_of Facter::Util::Resolution
|
69
71
|
end
|
70
72
|
|
71
|
-
it "
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
Facter::Util::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3)
|
76
|
-
@fact.add { }
|
77
|
-
@fact.add { }
|
78
|
-
@fact.add { }
|
73
|
+
it "creates an aggregate resolution when the type is :aggregate" do
|
74
|
+
fact.define_resolution('named', :type => :aggregate)
|
75
|
+
expect(fact.resolution('named')).to be_a_kind_of Facter::Core::Aggregate
|
76
|
+
end
|
79
77
|
|
80
|
-
|
78
|
+
it "raises an error if there is an existing resolution with a different type" do
|
79
|
+
pending "We need to stop rescuing all errors when instantiating resolutions"
|
80
|
+
fact.define_resolution('named')
|
81
|
+
expect {
|
82
|
+
fact.define_resolution('named', :type => :aggregate)
|
83
|
+
}.to raise_error(ArgumentError, /Cannot return resolution.*already defined as simple/)
|
81
84
|
end
|
82
85
|
|
83
|
-
it "
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
@fact.add { }
|
86
|
+
it "returns existing resolutions by name" do
|
87
|
+
Facter::Util::Resolution.expects(:new).once.with('named', fact).returns(res)
|
88
|
+
|
89
|
+
fact.define_resolution('named')
|
90
|
+
fact.define_resolution('named')
|
89
91
|
|
90
|
-
|
92
|
+
expect(fact.resolution('named')).to eq res
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "when returning a value" do
|
97
|
+
it "returns nil if there are no resolutions" do
|
98
|
+
Facter::Util::Fact.new("yay").value.should be_nil
|
91
99
|
end
|
92
100
|
|
93
|
-
it "
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
101
|
+
it "prefers the highest weight resolution" do
|
102
|
+
fact.add { has_weight 1; setcode { "1" } }
|
103
|
+
fact.add { has_weight 2; setcode { "2" } }
|
104
|
+
fact.add { has_weight 0; setcode { "0" } }
|
105
|
+
expect(fact.value).to eq "2"
|
106
|
+
end
|
99
107
|
|
100
|
-
|
108
|
+
it "returns the first value returned by a resolution" do
|
109
|
+
fact.add { has_weight 1; setcode { "1" } }
|
110
|
+
fact.add { has_weight 2; setcode { nil } }
|
111
|
+
fact.add { has_weight 0; setcode { "0" } }
|
112
|
+
expect(fact.value).to eq "1"
|
101
113
|
end
|
102
114
|
|
103
|
-
it "
|
104
|
-
|
105
|
-
|
106
|
-
|
115
|
+
it "skips unsuitable resolutions" do
|
116
|
+
fact.add { has_weight 1; setcode { "1" } }
|
117
|
+
fact.add do
|
118
|
+
def suitable?; false; end
|
119
|
+
has_weight 2
|
120
|
+
setcode { 2 }
|
121
|
+
end
|
107
122
|
|
108
|
-
|
123
|
+
expect(fact.value).to eq "1"
|
109
124
|
end
|
110
125
|
end
|
111
126
|
|
@@ -113,28 +128,15 @@ describe Facter::Util::Fact do
|
|
113
128
|
subject do
|
114
129
|
Facter::Util::Fact.new(:foo)
|
115
130
|
end
|
116
|
-
context 'basic facts using setcode' do
|
117
|
-
it "flushes the cached value when invoked" do
|
118
|
-
system = mock('some_system_call')
|
119
|
-
system.expects(:data).twice.returns(100,200)
|
120
131
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
model = { :data => "Hello World" }
|
130
|
-
subject.add do
|
131
|
-
on_flush { model[:data] = "FLUSHED!" }
|
132
|
-
setcode { model[:data] }
|
133
|
-
end
|
134
|
-
subject.value.should == "Hello World"
|
135
|
-
subject.flush
|
136
|
-
subject.value.should == "FLUSHED!"
|
137
|
-
end
|
132
|
+
it "invokes #flush on all resolutions" do
|
133
|
+
simple = subject.add(:type => :simple)
|
134
|
+
simple.expects(:flush)
|
135
|
+
|
136
|
+
aggregate = subject.add(:type => :aggregate)
|
137
|
+
aggregate.expects(:flush)
|
138
|
+
|
139
|
+
subject.flush
|
138
140
|
end
|
139
141
|
end
|
140
142
|
end
|
data/spec/unit/util/ip_spec.rb
CHANGED
@@ -408,14 +408,14 @@ describe Facter::Util::IP do
|
|
408
408
|
it "support additional arguments" do
|
409
409
|
Facter::Util::IP.stubs(:get_ifconfig).returns("/sbin/ifconfig")
|
410
410
|
|
411
|
-
Facter::
|
411
|
+
Facter::Core::Execution.stubs(:exec).with("/sbin/ifconfig -a")
|
412
412
|
|
413
413
|
Facter::Util::IP.exec_ifconfig(["-a"])
|
414
414
|
end
|
415
415
|
it "joins multiple arguments correctly" do
|
416
416
|
Facter::Util::IP.stubs(:get_ifconfig).returns("/sbin/ifconfig")
|
417
417
|
|
418
|
-
Facter::
|
418
|
+
Facter::Core::Execution.stubs(:exec).with("/sbin/ifconfig -a -e -i -j")
|
419
419
|
|
420
420
|
Facter::Util::IP.exec_ifconfig(["-a","-e","-i","-j"])
|
421
421
|
end
|
@@ -3,24 +3,19 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
require 'facter/util/loader'
|
5
5
|
|
6
|
-
# loader subclass for making assertions about file/directory ordering
|
7
|
-
class TestLoader < Facter::Util::Loader
|
8
|
-
def loaded_files
|
9
|
-
@loaded_files ||= []
|
10
|
-
end
|
11
|
-
|
12
|
-
def load_file(file)
|
13
|
-
loaded_files << file
|
14
|
-
super
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
6
|
describe Facter::Util::Loader do
|
20
7
|
before :each do
|
21
8
|
Facter::Util::Loader.any_instance.unstub(:load_all)
|
22
9
|
end
|
23
10
|
|
11
|
+
def loader_from(places)
|
12
|
+
env = places[:env] || {}
|
13
|
+
search_path = places[:search_path] || []
|
14
|
+
loader = Facter::Util::Loader.new(env)
|
15
|
+
loader.stubs(:search_path).returns search_path
|
16
|
+
loader
|
17
|
+
end
|
18
|
+
|
24
19
|
it "should have a method for loading individual facts by name" do
|
25
20
|
Facter::Util::Loader.new.should respond_to(:load)
|
26
21
|
end
|
@@ -34,20 +29,7 @@ describe Facter::Util::Loader do
|
|
34
29
|
end
|
35
30
|
|
36
31
|
describe "#valid_seach_path?" do
|
37
|
-
|
38
|
-
@loader = Facter::Util::Loader.new
|
39
|
-
@settings = mock 'settings'
|
40
|
-
@settings.stubs(:value).returns "/eh"
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should cache the result of a previous check" do
|
44
|
-
Pathname.any_instance.expects(:absolute?).returns(true).once
|
45
|
-
|
46
|
-
# we explicitly want two calls here to check that we get
|
47
|
-
# the second from the cache
|
48
|
-
@loader.should be_valid_search_path "/foo"
|
49
|
-
@loader.should be_valid_search_path "/foo"
|
50
|
-
end
|
32
|
+
let(:loader) { Facter::Util::Loader.new }
|
51
33
|
|
52
34
|
# Used to have test for " " as a directory since that should
|
53
35
|
# be a relative directory, but on Windows in both 1.8.7 and
|
@@ -68,7 +50,7 @@ describe Facter::Util::Loader do
|
|
68
50
|
' \/',
|
69
51
|
].each do |dir|
|
70
52
|
it "should be false for relative path #{dir}" do
|
71
|
-
|
53
|
+
loader.should_not be_valid_search_path dir
|
72
54
|
end
|
73
55
|
end
|
74
56
|
[
|
@@ -84,41 +66,30 @@ describe Facter::Util::Loader do
|
|
84
66
|
'/ /..',
|
85
67
|
].each do |dir|
|
86
68
|
it "should be true for absolute path #{dir}" do
|
87
|
-
|
69
|
+
loader.should be_valid_search_path dir
|
88
70
|
end
|
89
71
|
end
|
90
72
|
end
|
91
73
|
|
92
74
|
describe "when determining the search path" do
|
93
|
-
|
94
|
-
@loader = Facter::Util::Loader.new
|
95
|
-
@settings = mock 'settings'
|
96
|
-
@settings.stubs(:value).returns "/eh"
|
97
|
-
end
|
75
|
+
let(:loader) { Facter::Util::Loader.new }
|
98
76
|
|
99
77
|
it "should include the facter subdirectory of all paths in ruby LOAD_PATH" do
|
100
|
-
dirs = $LOAD_PATH.collect { |d| File.
|
101
|
-
|
102
|
-
|
78
|
+
dirs = $LOAD_PATH.collect { |d| File.expand_path('facter', d) }
|
79
|
+
loader.stubs(:valid_search_path?).returns(true)
|
80
|
+
File.stubs(:directory?).returns true
|
103
81
|
|
104
|
-
|
105
|
-
paths.should be_include(dir)
|
106
|
-
end
|
107
|
-
end
|
82
|
+
paths = loader.search_path
|
108
83
|
|
109
|
-
it "should warn the user when an invalid search path has been excluded" do
|
110
|
-
dirs = $LOAD_PATH.collect { |d| File.join(d, "facter") }
|
111
|
-
@loader.stubs(:valid_search_path?).returns(false)
|
112
84
|
dirs.each do |dir|
|
113
|
-
|
85
|
+
paths.should be_include(dir)
|
114
86
|
end
|
115
|
-
paths = @loader.search_path
|
116
87
|
end
|
117
88
|
|
118
89
|
it "should exclude invalid search paths" do
|
119
90
|
dirs = $LOAD_PATH.collect { |d| File.join(d, "facter") }
|
120
|
-
|
121
|
-
paths =
|
91
|
+
loader.stubs(:valid_search_path?).returns(false)
|
92
|
+
paths = loader.search_path
|
122
93
|
dirs.each do |dir|
|
123
94
|
paths.should_not be_include(dir)
|
124
95
|
end
|
@@ -126,56 +97,93 @@ describe Facter::Util::Loader do
|
|
126
97
|
|
127
98
|
it "should include all search paths registered with Facter" do
|
128
99
|
Facter.expects(:search_path).returns %w{/one /two}
|
129
|
-
|
100
|
+
loader.stubs(:valid_search_path?).returns true
|
101
|
+
|
102
|
+
File.stubs(:directory?).returns false
|
103
|
+
File.stubs(:directory?).with('/one').returns true
|
104
|
+
File.stubs(:directory?).with('/two').returns true
|
105
|
+
|
106
|
+
paths = loader.search_path
|
130
107
|
paths.should be_include("/one")
|
131
108
|
paths.should be_include("/two")
|
132
109
|
end
|
133
110
|
|
111
|
+
it "should warn on invalid search paths registered with Facter" do
|
112
|
+
Facter.expects(:search_path).returns %w{/one two/three}
|
113
|
+
loader.stubs(:valid_search_path?).returns false
|
114
|
+
loader.stubs(:valid_search_path?).with('/one').returns true
|
115
|
+
loader.stubs(:valid_search_path?).with('two/three').returns false
|
116
|
+
Facter.expects(:warn).with('Excluding two/three from search path. Fact file paths must be an absolute directory').once
|
117
|
+
|
118
|
+
File.stubs(:directory?).returns false
|
119
|
+
File.stubs(:directory?).with('/one').returns true
|
120
|
+
|
121
|
+
paths = loader.search_path
|
122
|
+
paths.should be_include("/one")
|
123
|
+
paths.should_not be_include("two/three")
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should strip paths that are valid paths but not are not present" do
|
127
|
+
Facter.expects(:search_path).returns %w{/one /two}
|
128
|
+
loader.stubs(:valid_search_path?).returns false
|
129
|
+
loader.stubs(:valid_search_path?).with('/one').returns true
|
130
|
+
loader.stubs(:valid_search_path?).with('/two').returns true
|
131
|
+
|
132
|
+
File.stubs(:directory?).returns false
|
133
|
+
File.stubs(:directory?).with('/one').returns true
|
134
|
+
File.stubs(:directory?).with('/two').returns false
|
135
|
+
|
136
|
+
paths = loader.search_path
|
137
|
+
paths.should be_include("/one")
|
138
|
+
paths.should_not be_include('/two')
|
139
|
+
end
|
140
|
+
|
134
141
|
describe "and the FACTERLIB environment variable is set" do
|
135
142
|
it "should include all paths in FACTERLIB" do
|
136
|
-
Facter::Util::
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
143
|
+
loader = Facter::Util::Loader.new("FACTERLIB" => "/one/path#{File::PATH_SEPARATOR}/two/path")
|
144
|
+
|
145
|
+
File.stubs(:directory?).returns false
|
146
|
+
File.stubs(:directory?).with('/one/path').returns true
|
147
|
+
File.stubs(:directory?).with('/two/path').returns true
|
148
|
+
|
149
|
+
loader.stubs(:valid_search_path?).returns true
|
150
|
+
paths = loader.search_path
|
151
|
+
%w{/one/path /two/path}.each do |dir|
|
152
|
+
paths.should be_include(dir)
|
141
153
|
end
|
142
154
|
end
|
143
155
|
end
|
144
156
|
end
|
145
157
|
|
146
158
|
describe "when loading facts" do
|
147
|
-
before do
|
148
|
-
@loader = Facter::Util::Loader.new
|
149
|
-
@loader.stubs(:search_path).returns []
|
150
|
-
end
|
151
|
-
|
152
159
|
it "should load values from the matching environment variable if one is present" do
|
160
|
+
loader = loader_from(:env => { "facter_testing" => "yayness" })
|
161
|
+
|
153
162
|
Facter.expects(:add).with("testing")
|
154
163
|
|
155
|
-
|
156
|
-
@loader.load(:testing)
|
157
|
-
end
|
164
|
+
loader.load(:testing)
|
158
165
|
end
|
159
166
|
|
160
167
|
it "should load any files in the search path with names matching the fact name" do
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
168
|
+
loader = loader_from(:search_path => %w{/one/dir /two/dir})
|
169
|
+
|
170
|
+
loader.expects(:search_path).returns %w{/one/dir /two/dir}
|
171
|
+
File.stubs(:file?).returns false
|
172
|
+
File.expects(:file?).with("/one/dir/testing.rb").returns true
|
165
173
|
|
166
174
|
Kernel.expects(:load).with("/one/dir/testing.rb")
|
167
|
-
Kernel.expects(:load).with("/two/dir/testing.rb")
|
168
175
|
|
169
|
-
|
176
|
+
loader.load(:testing)
|
170
177
|
end
|
171
178
|
|
172
|
-
it 'should load any ruby files
|
173
|
-
|
179
|
+
it 'should not load any ruby files from subdirectories matching the fact name in the search path' do
|
180
|
+
loader = Facter::Util::Loader.new
|
181
|
+
File.stubs(:file?).returns false
|
182
|
+
File.expects(:file?).with("/one/dir/testing.rb").returns true
|
183
|
+
Kernel.expects(:load).with("/one/dir/testing.rb")
|
174
184
|
|
175
|
-
|
176
|
-
|
177
|
-
FileTest.stubs(:directory?).with("/one/dir/testing").returns true
|
178
|
-
@loader.stubs(:search_path).returns %w{/one/dir}
|
185
|
+
File.stubs(:directory?).with("/one/dir/testing").returns true
|
186
|
+
loader.stubs(:search_path).returns %w{/one/dir}
|
179
187
|
|
180
188
|
Dir.stubs(:entries).with("/one/dir/testing").returns %w{foo.rb bar.rb}
|
181
189
|
%w{/one/dir/testing/foo.rb /one/dir/testing/bar.rb}.each do |f|
|
@@ -183,163 +191,96 @@ describe Facter::Util::Loader do
|
|
183
191
|
Kernel.stubs(:load).with(f)
|
184
192
|
end
|
185
193
|
|
186
|
-
|
187
|
-
@loader.loaded_files.should == %w{/one/dir/testing/bar.rb /one/dir/testing/foo.rb}
|
188
|
-
end
|
189
|
-
|
190
|
-
it "should load any ruby files in directories matching the fact name in the search path" do
|
191
|
-
@loader.expects(:search_path).returns %w{/one/dir}
|
192
|
-
FileTest.stubs(:exist?).returns false
|
193
|
-
FileTest.expects(:directory?).with("/one/dir/testing").returns true
|
194
|
-
|
195
|
-
Dir.expects(:entries).with("/one/dir/testing").returns %w{two.rb}
|
196
|
-
|
197
|
-
Kernel.expects(:load).with("/one/dir/testing/two.rb")
|
198
|
-
|
199
|
-
@loader.load(:testing)
|
194
|
+
loader.load(:testing)
|
200
195
|
end
|
201
196
|
|
202
197
|
it "should not load files that don't end in '.rb'" do
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
198
|
+
loader = Facter::Util::Loader.new
|
199
|
+
loader.expects(:search_path).returns %w{/one/dir}
|
200
|
+
File.stubs(:file?).returns false
|
201
|
+
File.expects(:file?).with("/one/dir/testing.rb").returns false
|
202
|
+
File.expects(:exist?).with("/one/dir/testing").never
|
209
203
|
Kernel.expects(:load).never
|
210
204
|
|
211
|
-
|
205
|
+
loader.load(:testing)
|
212
206
|
end
|
213
207
|
end
|
214
208
|
|
215
209
|
describe "when loading all facts" do
|
216
|
-
|
217
|
-
@loader = Facter::Util::Loader.new
|
218
|
-
@loader.stubs(:search_path).returns []
|
210
|
+
let(:loader) { Facter::Util::Loader.new }
|
219
211
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
it "should skip directories that do not exist" do
|
224
|
-
@loader.expects(:search_path).returns %w{/one/dir}
|
225
|
-
|
226
|
-
FileTest.expects(:directory?).with("/one/dir").returns false
|
227
|
-
|
228
|
-
Dir.expects(:entries).with("/one/dir").never
|
212
|
+
before :each do
|
213
|
+
loader.stubs(:search_path).returns []
|
229
214
|
|
230
|
-
|
215
|
+
File.stubs(:directory?).returns true
|
231
216
|
end
|
232
217
|
|
233
218
|
it "should load all files in all search paths" do
|
234
|
-
|
235
|
-
|
236
|
-
Dir.expects(:entries).with("/one/dir").returns %w{a.rb b.rb}
|
237
|
-
Dir.expects(:entries).with("/two/dir").returns %w{c.rb d.rb}
|
238
|
-
|
239
|
-
%w{/one/dir/a.rb /one/dir/b.rb /two/dir/c.rb /two/dir/d.rb}.each { |f| Kernel.expects(:load).with(f) }
|
240
|
-
|
241
|
-
@loader.load_all
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should load all files in all subdirectories in all search paths" do
|
245
|
-
@loader.expects(:search_path).returns %w{/one/dir /two/dir}
|
246
|
-
|
247
|
-
Dir.expects(:entries).with("/one/dir").returns %w{a}
|
248
|
-
Dir.expects(:entries).with("/two/dir").returns %w{b}
|
249
|
-
|
250
|
-
%w{/one/dir/a /two/dir/b}.each { |f| File.expects(:directory?).with(f).returns true }
|
251
|
-
|
252
|
-
Dir.expects(:entries).with("/one/dir/a").returns %w{c.rb}
|
253
|
-
Dir.expects(:entries).with("/two/dir/b").returns %w{d.rb}
|
254
|
-
|
255
|
-
%w{/one/dir/a/c.rb /two/dir/b/d.rb}.each { |f| Kernel.expects(:load).with(f) }
|
256
|
-
|
257
|
-
@loader.load_all
|
258
|
-
end
|
219
|
+
loader = loader_from(:search_path => %w{/one/dir /two/dir})
|
259
220
|
|
260
|
-
|
261
|
-
|
221
|
+
Dir.expects(:glob).with('/one/dir/*.rb').returns %w{/one/dir/a.rb /one/dir/b.rb}
|
222
|
+
Dir.expects(:glob).with('/two/dir/*.rb').returns %w{/two/dir/c.rb /two/dir/d.rb}
|
262
223
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
%w{/one/dir}.each { |f| File.stubs(:directory?).with(f).returns true }
|
267
|
-
|
268
|
-
%w{/one/dir/foo.rb /one/dir/bar.rb}.each do |f|
|
269
|
-
File.stubs(:directory?).with(f).returns false
|
224
|
+
%w{/one/dir/a.rb /one/dir/b.rb /two/dir/c.rb /two/dir/d.rb}.each do |f|
|
225
|
+
File.expects(:file?).with(f).returns true
|
270
226
|
Kernel.expects(:load).with(f)
|
271
227
|
end
|
272
228
|
|
273
|
-
|
274
|
-
|
275
|
-
@loader.loaded_files.should == %w{/one/dir/bar.rb /one/dir/foo.rb}
|
229
|
+
loader.load_all
|
276
230
|
end
|
277
231
|
|
278
|
-
it "should not load
|
279
|
-
|
280
|
-
|
281
|
-
Dir.expects(:entries).with("/one/dir").returns %w{util}
|
282
|
-
|
283
|
-
File.expects(:directory?).with("/one/dir/util").returns true
|
284
|
-
|
285
|
-
Dir.expects(:entries).with("/one/dir/util").never
|
286
|
-
|
287
|
-
@loader.load_all
|
288
|
-
end
|
289
|
-
|
290
|
-
it "should not load files in a lib subdirectory" do
|
291
|
-
@loader.expects(:search_path).returns %w{/one/dir}
|
292
|
-
|
293
|
-
Dir.expects(:entries).with("/one/dir").returns %w{lib}
|
232
|
+
it "should not try to load subdirectories of search paths" do
|
233
|
+
loader.expects(:search_path).returns %w{/one/dir /two/dir}
|
294
234
|
|
295
|
-
|
235
|
+
# a.rb is a directory
|
236
|
+
Dir.expects(:glob).with('/one/dir/*.rb').returns %w{/one/dir/a.rb /one/dir/b.rb}
|
237
|
+
File.expects(:file?).with('/one/dir/a.rb').returns false
|
238
|
+
File.expects(:file?).with('/one/dir/b.rb').returns true
|
239
|
+
Kernel.expects(:load).with('/one/dir/b.rb')
|
296
240
|
|
297
|
-
|
241
|
+
# c.rb is a directory
|
242
|
+
Dir.expects(:glob).with('/two/dir/*.rb').returns %w{/two/dir/c.rb /two/dir/d.rb}
|
243
|
+
File.expects(:file?).with('/two/dir/c.rb').returns false
|
244
|
+
File.expects(:file?).with('/two/dir/d.rb').returns true
|
245
|
+
Kernel.expects(:load).with('/two/dir/d.rb')
|
298
246
|
|
299
|
-
|
300
|
-
end
|
301
|
-
|
302
|
-
it "should not load files in '.' or '..'" do
|
303
|
-
@loader.expects(:search_path).returns %w{/one/dir}
|
304
|
-
|
305
|
-
Dir.expects(:entries).with("/one/dir").returns %w{. ..}
|
306
|
-
|
307
|
-
File.expects(:entries).with("/one/dir/.").never
|
308
|
-
File.expects(:entries).with("/one/dir/..").never
|
309
|
-
|
310
|
-
@loader.load_all
|
247
|
+
loader.load_all
|
311
248
|
end
|
312
249
|
|
313
250
|
it "should not raise an exception when a file is unloadable" do
|
314
|
-
|
315
|
-
|
251
|
+
loader.expects(:search_path).returns %w{/one/dir}
|
252
|
+
|
253
|
+
Dir.expects(:glob).with('/one/dir/*.rb').returns %w{/one/dir/a.rb}
|
254
|
+
File.expects(:file?).with('/one/dir/a.rb').returns true
|
316
255
|
|
317
256
|
Kernel.expects(:load).with("/one/dir/a.rb").raises(LoadError)
|
318
257
|
Facter.expects(:warn)
|
319
258
|
|
320
|
-
|
259
|
+
expect { loader.load_all }.to_not raise_error
|
321
260
|
end
|
322
261
|
|
323
262
|
it "should load all facts from the environment" do
|
324
263
|
Facter::Util::Resolution.with_env "facter_one" => "yayness", "facter_two" => "boo" do
|
325
|
-
|
264
|
+
loader.load_all
|
326
265
|
end
|
327
266
|
Facter.value(:one).should == 'yayness'
|
328
267
|
Facter.value(:two).should == 'boo'
|
329
268
|
end
|
330
269
|
|
331
270
|
it "should only load all facts one time" do
|
332
|
-
|
333
|
-
|
334
|
-
|
271
|
+
loader = loader_from(:env => {})
|
272
|
+
loader.expects(:load_env).once
|
273
|
+
|
274
|
+
loader.load_all
|
275
|
+
loader.load_all
|
335
276
|
end
|
336
277
|
end
|
337
278
|
|
338
279
|
it "should load facts on the facter search path only once" do
|
339
280
|
facterlibdir = File.expand_path(File.dirname(__FILE__) + '../../../fixtures/unit/util/loader')
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
281
|
+
|
282
|
+
Facter::Util::Loader.new('FACTERLIB' => facterlibdir).load_all
|
283
|
+
|
284
|
+
Facter.value(:nosuchfact).should be_nil
|
344
285
|
end
|
345
286
|
end
|