summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/indirector/facts/facter.rb11
-rwxr-xr-xspec/unit/indirector/facts/facter.rb17
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/puppet/indirector/facts/facter.rb b/lib/puppet/indirector/facts/facter.rb
index 6ed89dac1..bc4a0e840 100644
--- a/lib/puppet/indirector/facts/facter.rb
+++ b/lib/puppet/indirector/facts/facter.rb
@@ -58,10 +58,19 @@ class Puppet::Node::Facts::Facter < Puppet::Indirector::Code
# Look a host's facts up in Facter.
def find(request)
- Puppet::Node::Facts.new(request.key, Facter.to_hash)
+ result = Puppet::Node::Facts.new(request.key, Facter.to_hash)
+ add_local_facts(result)
+ result
end
def save(facts)
raise Puppet::DevError, "You cannot save facts to the code store; it is only used for getting facts from Facter"
end
+
+ private
+
+ def add_local_facts(facts)
+ facts.values["clientversion"] = Puppet.version.to_s
+ facts.values["environment"] ||= Puppet.settings[:environment]
+ end
end
diff --git a/spec/unit/indirector/facts/facter.rb b/spec/unit/indirector/facts/facter.rb
index 225eb153b..10b7af398 100755
--- a/spec/unit/indirector/facts/facter.rb
+++ b/spec/unit/indirector/facts/facter.rb
@@ -54,6 +54,23 @@ describe Puppet::Node::Facts::Facter do
facts = @facter.find(@request)
facts.values["one"].should == "two"
end
+
+ it "should add the Puppet version as a 'clientversion' fact" do
+ Facter.expects(:to_hash).returns("one" => "two")
+ @facter.find(@request).values["clientversion"].should == Puppet.version.to_s
+ end
+
+ it "should add the current environment as a fact if one is not set" do
+ Facter.expects(:to_hash).returns("one" => "two")
+
+ @facter.find(@request).values["environment"].should == Puppet[:environment]
+ end
+
+ it "should not replace any existing environment fact" do
+ Facter.expects(:to_hash).returns("one" => "two", "environment" => "foo")
+
+ @facter.find(@request).values["environment"].should == "foo"
+ end
end
describe Puppet::Node::Facts::Facter, " when saving facts" do