When querying Puppet 2.6.7 and storedconfigs are enabled along with the inventory service, the timestamp information comes back as a "special" fact in the values section rather than as metadata in the top level.
Now we handle pulling out this "special" fact, along with being able to cope with no timestamp coming back in the metadata section, or as this "special" fact. Paired-with: Jesse Wolfe <[email protected]> Signed-off-by: Jacob Helwig <[email protected]> --- app/models/node.rb | 9 ++++++++- app/views/nodes/_facts.html.haml | 2 +- spec/models/node_spec.rb | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/models/node.rb b/app/models/node.rb index d8660ff..285ab2d 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -185,7 +185,14 @@ class Node < ActiveRecord::Base return @facts if @facts pson_data = PuppetHttps.get("https://#{SETTINGS.inventory_server}:#{SETTINGS.inventory_port}/production/facts/#{CGI.escape(self.name)}", 'pson') data = JSON.parse(pson_data) - @facts = { :timestamp => Time.parse(data['timestamp']), + if data['timestamp'] + timestamp = Time.parse data['timestamp'] + elsif data['values']['--- !ruby/sym _timestamp'] + timestamp = Time.parse(data['values'].delete('--- !ruby/sym _timestamp')) + else + timestamp = nil + end + @facts = { :timestamp => timestamp, :values => data['values'] } end diff --git a/app/views/nodes/_facts.html.haml b/app/views/nodes/_facts.html.haml index 0854824..855aa67 100644 --- a/app/views/nodes/_facts.html.haml +++ b/app/views/nodes/_facts.html.haml @@ -1 +1 @@ -= inspector_table facts[:values].sort, :first, :last, :link => false, :key_title => :fact, :value_title => :value, :caption => "Current inventory for #{node.name} as of #{facts[:timestamp]}" += inspector_table facts[:values].sort, :first, :last, :link => false, :key_title => :fact, :value_title => :value, :caption => "Current inventory for #{node.name} #{facts[:timestamp] ? "as of #{facts[:timestamp]}" : ""}" diff --git a/spec/models/node_spec.rb b/spec/models/node_spec.rb index d67e4cd..b492820 100644 --- a/spec/models/node_spec.rb +++ b/spec/models/node_spec.rb @@ -478,6 +478,8 @@ describe Node do before :each do @node = Node.generate!(:name => 'gonaddynode') @sample_pson = '{"name":"foo","timestamp":"Fri Oct 29 10:33:53 -0700 2010","expiration":"Fri Oct 29 11:03:53 -0700 2010","values":{"a":"1","b":"2"}}' + @sample_pson_without_timestamp = '{"name":"foo","expiration":"Fri Oct 29 11:03:53 -0700 2010","values":{"a":"1","b":"2"}}' + @sample_pson_with_malformed_timestamp = '{"name":"foo","expiration":"Fri Oct 29 11:03:53 -0700 2010","values":{"a":"1","b":"2","--- !ruby/sym _timestamp":"Sat Oct 30 10:33:53 -0700 2010"}}' SETTINGS.stubs(:inventory_server).returns('fred') SETTINGS.stubs(:inventory_port).returns(12345) end @@ -495,5 +497,20 @@ describe Node do @sample_pson) @node.facts end + + it "should return facts from an external REST call when timestamp is missing" do + PuppetHttps.stubs(:get).with("https://fred:12345/production/facts/gonaddynode", 'pson').returns( + @sample_pson_without_timestamp) + @node.facts.should == {:timestamp => nil, :values => {"a" => "1", "b" => "2"}} + end + + # The malformed timestamp can come back with Puppet 2.6.7 when both + # storedconfigs and the inventory service are enabled. See #6835 + it "should return facts from an external REST call when timestamp is malformed" do + PuppetHttps.stubs(:get).with("https://fred:12345/production/facts/gonaddynode", 'pson').returns( + @sample_pson_with_malformed_timestamp) + timestamp = Time.parse("Sat Oct 30 10:33:53 -0700 2010") + @node.facts.should == {:timestamp => timestamp, :values => {"a" => "1", "b" => "2"}} + end end end -- 1.7.4.1 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
