From 90af9201aefdbd7647827ba772e4564ee05aa6ad Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Mon, 1 Nov 2010 11:38:38 -0700 Subject: Maint: spec/unit/indirector/catalog/compiler_spec.rb wouldn't run by itself Require puppet/rails so we can run this test alone. --- spec/unit/indirector/catalog/compiler_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/unit/indirector/catalog/compiler_spec.rb b/spec/unit/indirector/catalog/compiler_spec.rb index 2ae5f6ff3..5cbb62985 100755 --- a/spec/unit/indirector/catalog/compiler_spec.rb +++ b/spec/unit/indirector/catalog/compiler_spec.rb @@ -9,6 +9,7 @@ require 'puppet/indirector/catalog/compiler' describe Puppet::Resource::Catalog::Compiler do before do + require 'puppet/rails' Puppet::Rails.stubs(:init) Facter.stubs(:to_hash).returns({}) Facter.stubs(:value).returns(Facter::Util::Fact.new("something")) -- cgit From 5f0cf4ef50a3676229a1c824b9a730b6951e1c7a Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Mon, 1 Nov 2010 11:40:48 -0700 Subject: Maint: Don't use a stub for a Facts object in the compiler specs The catalog compiler spec was overstubbing the Node::Facts object, making it hard to test the interaction between those two systems. --- spec/unit/indirector/catalog/compiler_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/unit/indirector/catalog/compiler_spec.rb b/spec/unit/indirector/catalog/compiler_spec.rb index 5cbb62985..a9c2e3e28 100755 --- a/spec/unit/indirector/catalog/compiler_spec.rb +++ b/spec/unit/indirector/catalog/compiler_spec.rb @@ -156,7 +156,8 @@ describe Puppet::Resource::Catalog::Compiler do @compiler = Puppet::Resource::Catalog::Compiler.new @request = stub 'request', :options => {} - @facts = stub 'facts', :save => nil + @facts = Puppet::Node::Facts.new('hostname', "fact" => "value", "architecture" => "i386") + @facts.stubs(:save).returns(nil) end it "should do nothing if no facts are provided" do -- cgit From fb5f859cf4a89042a1768b6cbc2dbfc43da49c99 Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Mon, 1 Nov 2010 11:45:27 -0700 Subject: Fix #5164 Change Facts timestamp when they are received by the master This patch causes the puppet master to re-timestamp facts when they are received by the catalog compiler terminus. This makes the timestamps more trustworthy, as it means that they are all based upon the same clock's time. Paired-With: Paul Berry --- lib/puppet/indirector/catalog/compiler.rb | 1 + lib/puppet/node/facts.rb | 18 +++++++++++++----- spec/unit/indirector/catalog/compiler_spec.rb | 7 ++++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/puppet/indirector/catalog/compiler.rb b/lib/puppet/indirector/catalog/compiler.rb index c50022fff..1e1ae12b1 100644 --- a/lib/puppet/indirector/catalog/compiler.rb +++ b/lib/puppet/indirector/catalog/compiler.rb @@ -22,6 +22,7 @@ class Puppet::Resource::Catalog::Compiler < Puppet::Indirector::Code else facts = Puppet::Node::Facts.convert_from(format, text_facts) end + facts.add_timestamp facts.save end diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb index ad4b91e98..d84d54113 100755 --- a/lib/puppet/node/facts.rb +++ b/lib/puppet/node/facts.rb @@ -35,7 +35,7 @@ class Puppet::Node::Facts @name = name @values = values - add_internal + add_timestamp end def downcase_if_necessary @@ -75,13 +75,21 @@ class Puppet::Node::Facts }.to_pson(*args) end - private - # Add internal data to the facts for storage. - def add_internal - self.values[:_timestamp] = Time.now + def add_timestamp + self.timestamp = Time.now + end + + def timestamp=(time) + self.values[:_timestamp] = time end + def timestamp + self.values[:_timestamp] + end + + private + # Strip out that internal data. def strip_internal newvals = values.dup diff --git a/spec/unit/indirector/catalog/compiler_spec.rb b/spec/unit/indirector/catalog/compiler_spec.rb index a9c2e3e28..f9980807a 100755 --- a/spec/unit/indirector/catalog/compiler_spec.rb +++ b/spec/unit/indirector/catalog/compiler_spec.rb @@ -167,12 +167,17 @@ describe Puppet::Resource::Catalog::Compiler do @compiler.extract_facts_from_request(@request) end - it "should use the Facts class to deserialize the provided facts" do + it "should use the Facts class to deserialize the provided facts and update the timestamp" do @request.options[:facts_format] = "foo" @request.options[:facts] = "bar" Puppet::Node::Facts.expects(:convert_from).returns @facts + @facts.timestamp = Time.parse('2010-11-01') + @now = Time.parse('2010-11-02') + Time.expects(:now).returns(@now) + @compiler.extract_facts_from_request(@request) + @facts.timestamp.should == @now end it "should use the provided fact format" do -- cgit