[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5

Max Martin max at puppetlabs.com
Tue May 10 08:17:49 UTC 2011


The following commit has been merged in the experimental branch:
commit aaf7e2300b12a0ef03b620efc5eea7af0dc6f71b
Author: Max Martin <max at puppetlabs.com>
Date:   Thu Apr 21 16:53:26 2011 -0700

    Revert "(7080) Adding json support to Indirector Request"
    
    This reverts commit e0615cbc1eea67ef8caf4edbc8b7b3d3ce618f4d.
    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/indirector/request_spec.rb
    
    Paired-with:Matt Robinson <matt at puppetlabs.com>

diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb
index 1918a3f..fd8d654 100644
--- a/lib/puppet/indirector/request.rb
+++ b/lib/puppet/indirector/request.rb
@@ -14,51 +14,6 @@ class Puppet::Indirector::Request
 
   OPTION_ATTRIBUTES = [:ip, :node, :authenticated, :ignore_terminus, :ignore_cache, :instance, :environment]
 
-  def self.from_pson(json)
-    raise ArgumentError, "No indirection name provided in json data" unless indirection_name = json['type']
-    raise ArgumentError, "No method name provided in json data" unless method = json['method']
-    raise ArgumentError, "No key provided in json data" unless key = json['key']
-
-    request = new(indirection_name, method, key, json['attributes'])
-
-    if instance = json['instance']
-      klass = Puppet::Indirector::Indirection.instance(request.indirection_name).model
-      if instance.is_a?(klass)
-        request.instance = instance
-      else
-        request.instance = klass.from_pson(instance)
-      end
-    end
-
-    request
-  end
-
-  def to_pson(*args)
-    result = {
-      'document_type' => 'Puppet::Indirector::Request',
-      'data' => {
-        'type' => indirection_name,
-        'method' => method,
-        'key' => key
-      }
-    }
-    data = result['data']
-    attributes = {}
-    OPTION_ATTRIBUTES.each do |key|
-      next unless value = send(key)
-      attributes[key] = value
-    end
-
-    options.each do |opt, value|
-      attributes[opt] = value
-    end
-
-    data['attributes'] = attributes unless attributes.empty?
-    data['instance'] = instance if instance
-
-    result.to_pson(*args)
-  end
-
   # Is this an authenticated request?
   def authenticated?
     # Double negative, so we just get true or false
@@ -106,11 +61,9 @@ class Puppet::Indirector::Request
     self.indirection_name = indirection_name
     self.method = method
 
-    options = options.inject({}) { |hash, ary| hash[ary[0].to_sym] = ary[1]; hash }
-
     set_attributes(options)
 
-    @options = options
+    @options = options.inject({}) { |hash, ary| hash[ary[0].to_sym] = ary[1]; hash }
 
     if key_or_instance.is_a?(String) || key_or_instance.is_a?(Symbol)
       key = key_or_instance
@@ -200,7 +153,7 @@ class Puppet::Indirector::Request
 
   def set_attributes(options)
     OPTION_ATTRIBUTES.each do |attribute|
-      if options.include?(attribute.to_sym)
+      if options.include?(attribute)
         send(attribute.to_s + "=", options[attribute])
         options.delete(attribute)
       end
diff --git a/spec/unit/indirector/request_spec.rb b/spec/unit/indirector/request_spec.rb
index ba7dc81..87b9af4 100755
--- a/spec/unit/indirector/request_spec.rb
+++ b/spec/unit/indirector/request_spec.rb
@@ -301,99 +301,4 @@ describe Puppet::Indirector::Request do
       lambda { @request.query_string }.should raise_error(ArgumentError)
     end
   end
-
-  describe "when converting to json" do
-    before do
-      @request = Puppet::Indirector::Request.new(:facts, :find, "foo")
-    end
-
-    it "should produce a hash with the document_type set to 'request'" do
-      @request.should set_json_document_type_to("Puppet::Indirector::Request")
-    end
-    
-    it "should set the 'key'" do
-      @request.should set_json_attribute("key").to("foo")
-    end
-
-    it "should include an attribute for its indirection name" do
-      @request.should set_json_attribute("type").to("facts")
-    end
-
-    it "should include a 'method' attribute set to its method" do
-      @request.should set_json_attribute("method").to("find")
-    end
-
-    it "should add all attributes under the 'attributes' attribute" do
-      @request.ip = "127.0.0.1"
-      @request.should set_json_attribute("attributes", "ip").to("127.0.0.1")
-    end
-
-    it "should add all options under the 'attributes' attribute" do
-      @request.options["opt"] = "value"
-      PSON.parse(@request.to_pson)["data"]['attributes']['opt'].should == "value"
-    end
-
-    it "should include the instance if provided" do
-      facts = Puppet::Node::Facts.new("foo")
-      @request.instance = facts
-      PSON.parse(@request.to_pson)["data"]['instance'].should be_instance_of(Puppet::Node::Facts)
-    end
-  end
-
-  describe "when converting from json" do
-    before do
-      @request = Puppet::Indirector::Request.new(:facts, :find, "foo")
-      @klass = Puppet::Indirector::Request
-      @format = Puppet::Network::FormatHandler.format('pson')
-    end
-
-    def from_json(json)
-      @format.intern(Puppet::Indirector::Request, json)
-    end
-
-    it "should set the 'key'" do
-      from_json(@request.to_pson).key.should == "foo"
-    end
-
-    it "should fail if no key is provided" do
-      json = PSON.parse(@request.to_pson)
-      json['data'].delete("key")
-      lambda { from_json(json.to_pson) }.should raise_error(ArgumentError)
-    end
-
-    it "should set its indirector name" do
-      from_json(@request.to_pson).indirection_name.should == :facts
-    end
-
-    it "should fail if no type is provided" do
-      json = PSON.parse(@request.to_pson)
-      json['data'].delete("type")
-      lambda { from_json(json.to_pson) }.should raise_error(ArgumentError)
-    end
-
-    it "should set its method" do
-      from_json(@request.to_pson).method.should == "find"
-    end
-
-    it "should fail if no method is provided" do
-      json = PSON.parse(@request.to_pson)
-      json['data'].delete("method")
-      lambda { from_json(json.to_pson) }.should raise_error(ArgumentError)
-    end
-
-    it "should initialize with all attributes and options" do
-      @request.ip = "127.0.0.1"
-      @request.options["opt"] = "value"
-      result = from_json(@request.to_pson)
-      result.options[:opt].should == "value"
-      result.ip.should == "127.0.0.1"
-    end
-
-    it "should set its instance as an instance if one is provided" do
-      facts = Puppet::Node::Facts.new("foo")
-      @request.instance = facts
-      result = from_json(@request.to_pson)
-      result.instance.should be_instance_of(Puppet::Node::Facts)
-    end
-  end
 end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list