This reverts commit 07a7a68a25eb9b21189751c27f90f972224ea533.
The JSON patch series has caused problems with the inventory service,
and further discussion is needed to decide how to serialize objects to
PSON with regards to future compatibility.

Conflicts:

        spec/unit/node/facts_spec.rb

Paired-with:Matt Robinson <[email protected]>
Signed-off-by: Max Martin <[email protected]>
---
Local-branch: ticket/2.7.x/7080-reverts
 lib/puppet/node/facts.rb     |   20 ++++++++------------
 spec/unit/node/facts_spec.rb |   30 ++++++------------------------
 2 files changed, 14 insertions(+), 36 deletions(-)

diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb
index 2ff7156..577b62b 100755
--- a/lib/puppet/node/facts.rb
+++ b/lib/puppet/node/facts.rb
@@ -61,22 +61,18 @@ class Puppet::Node::Facts
 
   def self.from_pson(data)
     result = new(data['name'], data['values'])
-    result.timestamp = Time.parse(data['timestamp']) if data['timestamp']
-    result.expiration = Time.parse(data['expiration']) if data['expiration']
+    result.timestamp = Time.parse(data['timestamp'])
+    result.expiration = Time.parse(data['expiration'])
     result
   end
 
   def to_pson(*args)
-    result = {
-      'document_type' => "Puppet::Node::Facts",
-      'data' => {}
-    }
-
-    result['data']['name'] = name
-    result['data']['expiration'] = expiration if expiration
-    result['data']['timestamp'] = timestamp if timestamp
-    result['data']['values'] = strip_internal
-    result.to_pson(*args)
+    {
+      'expiration' => expiration,
+      'name' => name,
+      'timestamp' => timestamp,
+      'values' => strip_internal,
+    }.to_pson(*args)
   end
 
   # Add internal data to the facts for storage.
diff --git a/spec/unit/node/facts_spec.rb b/spec/unit/node/facts_spec.rb
index 1b6991c..efaa76e 100755
--- a/spec/unit/node/facts_spec.rb
+++ b/spec/unit/node/facts_spec.rb
@@ -110,11 +110,7 @@ describe Puppet::Node::Facts, "when indirecting" do
       end
 
       it "should accept properly formatted pson" do
-        facts = Puppet::Node::Facts.new("foo")
-        facts.values = {"a" => "1", "b" => "2", "c" => "3"}
-        facts.expiration = Time.now
-        #pson = %Q({"document_type": "Puppet::Node::Facts", "data: {"name": 
"foo", "expiration": "#{@expiration}", "timestamp": "#{@timestamp}", "values": 
{"a": "1", "b": "2", "c": "3"}}})
-        pson = %Q({"data": {"name":"foo", "expiration":"#{@expiration}", 
"timestamp": "#{@timestamp}", "values":{"a":"1","b":"2","c":"3"}}, 
"document_type":"Puppet::Node::Facts"})
+        pson = %Q({"name": "foo", "expiration": "#{@expiration}", "timestamp": 
"#{@timestamp}", "values": {"a": "1", "b": "2", "c": "3"}})
         format = Puppet::Network::FormatHandler.format('pson')
         facts = format.intern(Puppet::Node::Facts,pson)
         facts.name.should == 'foo'
@@ -126,25 +122,11 @@ describe Puppet::Node::Facts, "when indirecting" do
         Time.stubs(:now).returns(@timestamp)
         facts = Puppet::Node::Facts.new("foo", {'a' => 1, 'b' => 2, 'c' => 3})
         facts.expiration = @expiration
-        facts.to_pson.should == 
%Q[{"data":{"name":"foo","timestamp":"#{@timestamp}","expiration":"#{@expiration}","values":{"a":1,"b":2,"c":3}},"document_type":"Puppet::Node::Facts"}]
-      end
-
-      it "should not include nil values" do
-        facts = Puppet::Node::Facts.new("foo", {'a' => 1, 'b' => 2, 'c' => 3})
-
-        # XXX:LAK For some reason this is resurrection the full instance, 
instead
-        # of just returning the hash.  This code works, but I can't figure out 
what's
-        # going on.
-        newfacts = PSON.parse(facts.to_pson)
-        newfacts.expiration.should be_nil
-      end
-
-      it "should be able to handle nil values" do
-        pson = %Q({"name": "foo", "values": {"a": "1", "b": "2", "c": "3"}})
-        format = Puppet::Network::FormatHandler.format('pson')
-        facts = format.intern(Puppet::Node::Facts,pson)
-        facts.name.should == 'foo'
-        facts.expiration.should be_nil
+        result = PSON.parse(facts.to_pson)
+        result['name'].should == facts.name
+        result['values'].should == facts.values.reject { |key, value| key.to_s 
=~ /_/ }
+        result['timestamp'].should == facts.timestamp.to_s
+        result['expiration'].should == facts.expiration.to_s
       end
     end
   end
-- 
1.7.4

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

Reply via email to