diff options
| author | Luke Kanies <luke@puppetlabs.com> | 2011-07-15 11:05:50 -0700 |
|---|---|---|
| committer | Luke Kanies <luke@puppetlabs.com> | 2011-07-15 11:16:15 -0700 |
| commit | 361220166525762634dd1886f84c9a928b28766b (patch) | |
| tree | 19c3c9a4126df7f29fe771e44252475c6643fd10 | |
| parent | 8c4cc7cae65b43fc4ab2f56ec27ee05a9bfc0494 (diff) | |
| download | puppet-361220166525762634dd1886f84c9a928b28766b.tar.gz puppet-361220166525762634dd1886f84c9a928b28766b.tar.xz puppet-361220166525762634dd1886f84c9a928b28766b.zip | |
(#7080) Registering PSON document types
We were originally using the actual constant for both Indirector
Requests and Nodes, and this registers their document types
as symbolic names.
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Reviewed-by: Nick Lewis <nick@puppetlabs.com>
| -rw-r--r-- | lib/puppet/indirector/request.rb | 6 | ||||
| -rw-r--r-- | lib/puppet/node.rb | 5 | ||||
| -rwxr-xr-x | spec/unit/indirector/request_spec.rb | 10 | ||||
| -rwxr-xr-x | spec/unit/node_spec.rb | 8 |
4 files changed, 26 insertions, 3 deletions
diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb index 1918a3fb5..697d9df47 100644 --- a/lib/puppet/indirector/request.rb +++ b/lib/puppet/indirector/request.rb @@ -1,6 +1,7 @@ require 'cgi' require 'uri' require 'puppet/indirector' +require 'puppet/util/pson' # This class encapsulates all of the information you need to make an # Indirection call, and as a a result also handles REST calls. It's somewhat @@ -14,6 +15,9 @@ class Puppet::Indirector::Request OPTION_ATTRIBUTES = [:ip, :node, :authenticated, :ignore_terminus, :ignore_cache, :instance, :environment] + # Load json before trying to register. + Puppet.features.pson? and ::PSON.register_document_type('IndirectorRequest',self) + 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'] @@ -35,7 +39,7 @@ class Puppet::Indirector::Request def to_pson(*args) result = { - 'document_type' => 'Puppet::Indirector::Request', + 'document_type' => 'IndirectorRequest', 'data' => { 'type' => indirection_name, 'method' => method, diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb index 4bd4d1de6..16a0e5c3d 100644 --- a/lib/puppet/node.rb +++ b/lib/puppet/node.rb @@ -19,6 +19,9 @@ class Puppet::Node attr_accessor :name, :classes, :source, :ipaddress, :parameters attr_reader :time + # + # Load json before trying to register. + Puppet.features.pson? and ::PSON.register_document_type('Node',self) def self.from_pson(pson) raise ArgumentError, "No name provided in pson data" unless name = pson['name'] @@ -32,7 +35,7 @@ class Puppet::Node def to_pson(*args) result = { - 'document_type' => "Puppet::Node", + 'document_type' => "Node", 'data' => {} } result['data']['name'] = name diff --git a/spec/unit/indirector/request_spec.rb b/spec/unit/indirector/request_spec.rb index 450cad2ed..059357869 100755 --- a/spec/unit/indirector/request_spec.rb +++ b/spec/unit/indirector/request_spec.rb @@ -2,8 +2,16 @@ require 'spec_helper' require 'matchers/json' require 'puppet/indirector/request' +require 'puppet/util/pson' describe Puppet::Indirector::Request do + + describe "when registering the document type" do + it "should register its document type with JSON" do + PSON.registered_document_types["IndirectorRequest"].should equal(Puppet::Indirector::Request) + end + end + describe "when initializing" do it "should require an indirection name, a key, and a method" do lambda { Puppet::Indirector::Request.new }.should raise_error(ArgumentError) @@ -308,7 +316,7 @@ describe Puppet::Indirector::Request do end it "should produce a hash with the document_type set to 'request'" do - @request.should set_json_document_type_to("Puppet::Indirector::Request") + @request.should set_json_document_type_to("IndirectorRequest") end it "should set the 'key'" do diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index a6ae67aeb..476b0d6e5 100755 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -3,6 +3,10 @@ require 'spec_helper' require 'matchers/json' describe Puppet::Node do + it "should register its document type as Node" do + PSON.registered_document_types["Node"].should equal(Puppet::Node) + end + describe "when managing its environment" do it "should use any set environment" do Puppet::Node.new("foo", :environment => "bar").environment.name.should == :bar @@ -46,6 +50,10 @@ describe Puppet::Node do @node.should set_json_attribute('name').to("mynode") end + it "should produce a hash with the document_type set to 'Node'" do + @node.should set_json_document_type_to("Node") + end + it "should include the classes if set" do @node.classes = %w{a b c} @node.should set_json_attribute("classes").to(%w{a b c}) |
