Fixing #1964 - Facts get loaded from plugins

Applying slightly modified patch.

Also added tests.

Signed-off-by: Luke Kanies <luke@madstop.com>
This commit is contained in:
Luke Kanies 2009-02-12 22:58:57 -06:00
Родитель 7cf085c9eb
Коммит 39a8b28690
2 изменённых файлов: 26 добавлений и 4 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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