diff options
author | Luke Kanies <luke@madstop.com> | 2009-02-12 22:58:57 -0600 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2009-02-12 22:58:57 -0600 |
commit | 39a8b28690377339d4c430ebf62cec5ef0ed34b8 (patch) | |
tree | 6a55de1b849f508033b812a74c9d3330bcb68e5e | |
parent | 7cf085c9ebdb1d1c92e317a406844bfc0eceafe6 (diff) | |
download | puppet-39a8b28690377339d4c430ebf62cec5ef0ed34b8.tar.gz puppet-39a8b28690377339d4c430ebf62cec5ef0ed34b8.tar.xz puppet-39a8b28690377339d4c430ebf62cec5ef0ed34b8.zip |
Fixing #1964 - Facts get loaded from plugins
Applying slightly modified patch.
Also added tests.
Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r-- | lib/puppet/indirector/facts/facter.rb | 8 | ||||
-rwxr-xr-x | spec/unit/indirector/facts/facter.rb | 22 |
2 files changed, 26 insertions, 4 deletions
diff --git a/lib/puppet/indirector/facts/facter.rb b/lib/puppet/indirector/facts/facter.rb index 6ed89dac1..a026dfe60 100644 --- a/lib/puppet/indirector/facts/facter.rb +++ b/lib/puppet/indirector/facts/facter.rb @@ -24,8 +24,12 @@ class Puppet::Node::Facts::Facter < Puppet::Indirector::Code end def self.loadfacts - # LAK:NOTE See http://snurl.com/21zf8 [groups_google_com] - x = Puppet[:factpath].split(":").each do |dir| + # Add any per-module fact directories to the factpath + module_fact_dirs = Puppet[:modulepath].split(":").collect do |d| + Dir.glob("%s/*/plugins/facter" % d) + end.flatten + dirs = module_fact_dirs + Puppet[:factpath].split(":") + x = dirs.each do |dir| loaddir(dir, "fact") end end diff --git a/spec/unit/indirector/facts/facter.rb b/spec/unit/indirector/facts/facter.rb index 5dcc4442b..530e5a752 100755 --- a/spec/unit/indirector/facts/facter.rb +++ b/spec/unit/indirector/facts/facter.rb @@ -70,8 +70,9 @@ describe Puppet::Node::Facts::Facter do end end - describe Puppet::Node::Facts::Facter, "when loading facts from the factpath" do - it "should load each directory in the Fact path when loading fact" do + describe Puppet::Node::Facts::Facter, "when loading facts from disk" do + it "should load each directory in the Fact path" do + Puppet.settings.stubs(:value).returns "foo" Puppet.settings.expects(:value).with(:factpath).returns("one%stwo" % File::PATH_SEPARATOR) Puppet::Node::Facts::Facter.expects(:loaddir).with("one", "fact") @@ -79,5 +80,22 @@ describe Puppet::Node::Facts::Facter do Puppet::Node::Facts::Facter.loadfacts end + + it "should load all facts from the modules" do + Puppet.settings.stubs(:value).returns "foo" + Puppet::Node::Facts::Facter.stubs(:loaddir) + + Puppet.settings.expects(:value).with(:modulepath).returns("one%stwo" % File::PATH_SEPARATOR) + + Dir.expects(:glob).with("one/*/plugins/facter").returns %w{oneA oneB} + Dir.expects(:glob).with("two/*/plugins/facter").returns %w{twoA twoB} + + Puppet::Node::Facts::Facter.expects(:loaddir).with("oneA", "fact") + Puppet::Node::Facts::Facter.expects(:loaddir).with("oneB", "fact") + Puppet::Node::Facts::Facter.expects(:loaddir).with("twoA", "fact") + Puppet::Node::Facts::Facter.expects(:loaddir).with("twoB", "fact") + + Puppet::Node::Facts::Facter.loadfacts + end end end |