summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Dalén <dalen@spotify.com>2014-01-27 15:03:59 +0100
committerErik Dalén <dalen@spotify.com>2014-02-06 14:46:01 +0100
commit39c2fdffa9d6e6ed8ff932cc742c1b71e7b9d051 (patch)
treeb7807857f5e69ccb900ffa35d3d00b22e4a2d327
parentc87f1fe9c639323202a40c8c2a915ebf1c08971f (diff)
downloadpuppet-39c2fdffa9d6e6ed8ff932cc742c1b71e7b9d051.tar.gz
(maint) Change name from from_pson to from_data_hash
This is because these methods are also used for deserialization from other formats than PSON. The method for serializing a object is called to_data_hash, so makes sense to call this from_data_hash.
-rwxr-xr-xext/puppet-test2
-rw-r--r--lib/puppet/file_bucket/file.rb14
-rw-r--r--lib/puppet/file_serving/metadata.rb6
-rw-r--r--lib/puppet/indirector/request.rb18
-rw-r--r--lib/puppet/indirector/resource/rest.rb2
-rw-r--r--lib/puppet/network/formats.rb12
-rw-r--r--lib/puppet/node.rb14
-rw-r--r--lib/puppet/node/facts.rb6
-rw-r--r--lib/puppet/relationship.rb14
-rw-r--r--lib/puppet/resource.rb16
-rw-r--r--lib/puppet/resource/catalog.rb37
-rw-r--r--lib/puppet/resource/status.rb8
-rw-r--r--lib/puppet/resource/type.rb6
-rw-r--r--lib/puppet/run.rb12
-rw-r--r--lib/puppet/ssl/host.rb12
-rw-r--r--lib/puppet/status.rb12
-rw-r--r--lib/puppet/transaction/event.rb6
-rw-r--r--lib/puppet/transaction/report.rb12
-rw-r--r--lib/puppet/util/instrumentation/data.rb4
-rw-r--r--lib/puppet/util/instrumentation/indirection_probe.rb6
-rw-r--r--lib/puppet/util/instrumentation/listener.rb6
-rw-r--r--lib/puppet/util/log.rb6
-rw-r--r--lib/puppet/util/metric.rb6
-rw-r--r--lib/puppet/util/pson.rb2
-rw-r--r--lib/puppet/util/tag_set.rb6
-rwxr-xr-xspec/integration/network/formats_spec.rb2
-rw-r--r--spec/lib/puppet/indirector_testing.rb8
-rwxr-xr-xspec/unit/file_serving/metadata_spec.rb4
-rwxr-xr-xspec/unit/network/formats_spec.rb18
-rwxr-xr-xspec/unit/relationship_spec.rb8
-rwxr-xr-xspec/unit/resource/status_spec.rb2
-rwxr-xr-xspec/unit/resource/type_spec.rb4
-rwxr-xr-xspec/unit/resource_spec.rb42
-rwxr-xr-xspec/unit/run_spec.rb6
-rwxr-xr-xspec/unit/ssl/host_spec.rb2
-rwxr-xr-xspec/unit/transaction/event_spec.rb4
-rwxr-xr-xspec/unit/util/instrumentation/data_spec.rb2
-rwxr-xr-xspec/unit/util/instrumentation/listener_spec.rb4
-rwxr-xr-xspec/unit/util/log_spec.rb2
-rwxr-xr-xspec/unit/util/metric_spec.rb2
-rwxr-xr-xspec/unit/util/pson_spec.rb4
-rw-r--r--spec/unit/util/tag_set_spec.rb2
42 files changed, 221 insertions, 140 deletions
diff --git a/ext/puppet-test b/ext/puppet-test
index c2264da8c..2078806e7 100755
--- a/ext/puppet-test
+++ b/ext/puppet-test
@@ -241,7 +241,7 @@ Suite.new :resource_type, "Managing resource types" do
ARGV.each do |name|
json = Puppet::Resource::Type.find(name).to_pson
data = PSON.parse(json)
- p Puppet::Resource::Type.from_pson(data)
+ p Puppet::Resource::Type.from_data_hash(data)
end
end
diff --git a/lib/puppet/file_bucket/file.rb b/lib/puppet/file_bucket/file.rb
index 50e5d4d92..3445753cb 100644
--- a/lib/puppet/file_bucket/file.rb
+++ b/lib/puppet/file_bucket/file.rb
@@ -69,20 +69,24 @@ class Puppet::FileBucket::File
self.new(contents)
end
+ def to_data_hash
+ { "contents" => contents }
+ end
+
+ def self.from_data_hash(data)
+ self.new(data["contents"])
+ end
+
def to_pson
Puppet.deprecation_warning("Serializing Puppet::FileBucket::File objects to pson is deprecated.")
to_data_hash.to_pson
end
- def to_data_hash
- { "contents" => contents }
- end
-
# This method is deprecated, but cannot be removed for awhile, otherwise
# older agents sending pson couldn't backup to filebuckets on newer masters
def self.from_pson(pson)
Puppet.deprecation_warning("Deserializing Puppet::FileBucket::File objects from pson is deprecated. Upgrade to a newer version.")
- self.new(pson["contents"])
+ self.from_data_hash(pson)
end
end
diff --git a/lib/puppet/file_serving/metadata.rb b/lib/puppet/file_serving/metadata.rb
index 880c95993..1fd6e6506 100644
--- a/lib/puppet/file_serving/metadata.rb
+++ b/lib/puppet/file_serving/metadata.rb
@@ -172,6 +172,10 @@ class Puppet::FileServing::Metadata < Puppet::FileServing::Base
)
end
+ def self.from_data_hash(data)
+ new(data.delete('path'), data)
+ end
+
PSON.register_document_type('FileMetadata',self)
def to_pson_data_hash
{
@@ -188,7 +192,7 @@ class Puppet::FileServing::Metadata < Puppet::FileServing::Base
end
def self.from_pson(data)
- new(data.delete('path'), data)
+ self.from_data_hash(data)
end
end
diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb
index cd451745c..b4c6b7380 100644
--- a/lib/puppet/indirector/request.rb
+++ b/lib/puppet/indirector/request.rb
@@ -20,25 +20,29 @@ class Puppet::Indirector::Request
::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']
- raise ArgumentError, "No key provided in json data" unless key = json['key']
+ def self.from_data_hash(data)
+ raise ArgumentError, "No indirection name provided in data" unless indirection_name = data['type']
+ raise ArgumentError, "No method name provided in data" unless method = data['method']
+ raise ArgumentError, "No key provided in data" unless key = data['key']
- request = new(indirection_name, method, key, nil, json['attributes'])
+ request = new(indirection_name, method, key, nil, data['attributes'])
- if instance = json['instance']
+ if instance = data['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)
+ request.instance = klass.from_data_hash(instance)
end
end
request
end
+ def self.from_pson(json)
+ self.from_data_hash(json)
+ end
+
def to_data_hash
result = {
'type' => indirection_name,
diff --git a/lib/puppet/indirector/resource/rest.rb b/lib/puppet/indirector/resource/rest.rb
index 9992fc057..66384796b 100644
--- a/lib/puppet/indirector/resource/rest.rb
+++ b/lib/puppet/indirector/resource/rest.rb
@@ -12,6 +12,6 @@ class Puppet::Resource::Rest < Puppet::Indirector::REST
# Body is [ral_res.to_resource, transaction.report]
format = Puppet::Network::FormatHandler.format_for(content_type)
ary = format.intern(Array, body)
- [Puppet::Resource.from_pson(ary[0]), Puppet::Transaction::Report.from_pson(ary[1])]
+ [Puppet::Resource.from_data_hash(ary[0]), Puppet::Transaction::Report.from_data_hash(ary[1])]
end
end
diff --git a/lib/puppet/network/formats.rb b/lib/puppet/network/formats.rb
index 62e40d376..5b218e611 100644
--- a/lib/puppet/network/formats.rb
+++ b/lib/puppet/network/formats.rb
@@ -4,12 +4,12 @@ Puppet::Network::FormatHandler.create_serialized_formats(:msgpack, :weight => 20
def intern(klass, text)
data = MessagePack.unpack(text)
return data if data.is_a?(klass)
- klass.from_pson(data)
+ klass.from_data_hash(data)
end
def intern_multiple(klass, text)
MessagePack.unpack(text).collect do |data|
- klass.from_pson(data)
+ klass.from_data_hash(data)
end
end
@@ -22,7 +22,7 @@ Puppet::Network::FormatHandler.create_serialized_formats(:msgpack, :weight => 20
end
def supported?(klass)
- Puppet.features.msgpack? && klass.method_defined?(:to_msgpack)
+ Puppet.features.msgpack? && klass.method_defined?(:to_msgpack) && klass.method_defined?(:from_data_hash)
end
end
@@ -50,7 +50,7 @@ Puppet::Network::FormatHandler.create_serialized_formats(:yaml) do
raise Puppet::Network::FormatHandler::FormatError, "Serialized YAML did not contain a valid instance of #{klass}"
end
- klass.from_pson(data)
+ klass.from_data_hash(data)
end
def render(instance)
@@ -143,7 +143,7 @@ Puppet::Network::FormatHandler.create(:raw, :mime => "application/x-raw", :weigh
end
end
-Puppet::Network::FormatHandler.create_serialized_formats(:pson, :weight => 10, :required_methods => [:render_method, :intern_method]) do
+Puppet::Network::FormatHandler.create_serialized_formats(:pson, :weight => 10, :required_methods => [:render_method, :intern_method], :intern_method => :from_data_hash) do
def intern(klass, text)
data_to_instance(klass, PSON.parse(text))
end
@@ -168,7 +168,7 @@ Puppet::Network::FormatHandler.create_serialized_formats(:pson, :weight => 10, :
data = d
end
return data if data.is_a?(klass)
- klass.from_pson(data)
+ klass.from_data_hash(data)
end
end
diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb
index 4577ea7e3..468f8e764 100644
--- a/lib/puppet/node.rb
+++ b/lib/puppet/node.rb
@@ -18,16 +18,20 @@ class Puppet::Node
::PSON.register_document_type('Node',self)
- def self.from_pson(pson)
- raise ArgumentError, "No name provided in serialized data" unless name = pson['name']
+ def self.from_data_hash(data)
+ raise ArgumentError, "No name provided in serialized data" unless name = data['name']
node = new(name)
- node.classes = pson['classes']
- node.parameters = pson['parameters']
- node.environment = pson['environment']
+ node.classes = data['classes']
+ node.parameters = data['parameters']
+ node.environment = data['environment']
node
end
+ def self.from_pson(pson)
+ self.from_data_hash(pson)
+ end
+
def to_data_hash
result = {
'name' => name,
diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb
index 2be4e68b9..ac1b4ec76 100644
--- a/lib/puppet/node/facts.rb
+++ b/lib/puppet/node/facts.rb
@@ -78,12 +78,16 @@ class Puppet::Node::Facts
strip_internal == other.send(:strip_internal)
end
- def self.from_pson(data)
+ def self.from_data_hash(data)
new_facts = allocate
new_facts.initialize_from_hash(data)
new_facts
end
+ def self.from_pson(data)
+ self.from_data_hash(data)
+ end
+
def to_data_hash
result = {
'name' => name,
diff --git a/lib/puppet/relationship.rb b/lib/puppet/relationship.rb
index ebac97e7e..8655ae882 100644
--- a/lib/puppet/relationship.rb
+++ b/lib/puppet/relationship.rb
@@ -12,21 +12,25 @@ class Puppet::Relationship
attr_reader :event
- def self.from_pson(pson)
- source = pson["source"]
- target = pson["target"]
+ def self.from_data_hash(data)
+ source = data["source"]
+ target = data["target"]
args = {}
- if event = pson["event"]
+ if event = data["event"]
args[:event] = event
end
- if callback = pson["callback"]
+ if callback = data["callback"]
args[:callback] = callback
end
new(source, target, args)
end
+ def self.from_pson(pson)
+ self.from_data_hash(pson)
+ end
+
def event=(event)
raise ArgumentError, "You must pass a callback for non-NONE events" if event != :NONE and ! callback
@event = event
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
index bc8625750..198703beb 100644
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@ -26,22 +26,22 @@ class Puppet::Resource
ATTRIBUTES = [:file, :line, :exported]
- def self.from_pson(pson)
- raise ArgumentError, "No resource type provided in serialized data" unless type = pson['type']
- raise ArgumentError, "No resource title provided in serialized data" unless title = pson['title']
+ def self.from_data_hash(data)
+ raise ArgumentError, "No resource type provided in serialized data" unless type = data['type']
+ raise ArgumentError, "No resource title provided in serialized data" unless title = data['title']
resource = new(type, title)
- if params = pson['parameters']
+ if params = data['parameters']
params.each { |param, value| resource[param] = value }
end
- if tags = pson['tags']
+ if tags = data['tags']
tags.each { |tag| resource.tag(tag) }
end
ATTRIBUTES.each do |a|
- if value = pson[a.to_s]
+ if value = data[a.to_s]
resource.send(a.to_s + "=", value)
end
end
@@ -49,6 +49,10 @@ class Puppet::Resource
resource
end
+ def self.from_pson(pson)
+ self.from_data_hash(pson)
+ end
+
def inspect
"#{@type}[#{@title}]#{to_hash.inspect}"
end
diff --git a/lib/puppet/resource/catalog.rb b/lib/puppet/resource/catalog.rb
index 61b4f0b81..c31b3490c 100644
--- a/lib/puppet/resource/catalog.rb
+++ b/lib/puppet/resource/catalog.rb
@@ -313,7 +313,7 @@ class Puppet::Resource::Catalog < Puppet::Graph::SimpleGraph
end
end
- def self.from_pson(data)
+ def self.from_data_hash(data)
result = new(data['name'])
if tags = data['tags']
@@ -330,14 +330,24 @@ class Puppet::Resource::Catalog < Puppet::Graph::SimpleGraph
if resources = data['resources']
result.add_resource(*resources.collect do |res|
- Puppet::Resource.from_pson(res)
+ Puppet::Resource.from_data_hash(res)
end)
end
if edges = data['edges']
- edges = PSON.parse(edges) if edges.is_a?(String)
- edges.each do |edge|
- edge_from_pson(result, edge)
+ edges.each do |edge_hash|
+ edge = Puppet::Relationship.from_data_hash(edge_hash)
+ unless source = result.resource(edge.source)
+ raise ArgumentError, "Could not intern from data: Could not find relationship source #{edge.source.inspect}"
+ end
+ edge.source = source
+
+ unless target = result.resource(edge.target)
+ raise ArgumentError, "Could not intern from data: Could not find relationship target #{edge.target.inspect}"
+ end
+ edge.target = target
+
+ result.add_edge(edge)
end
end
@@ -348,21 +358,8 @@ class Puppet::Resource::Catalog < Puppet::Graph::SimpleGraph
result
end
- def self.edge_from_pson(result, edge)
- # If no type information was presented, we manually find
- # the class.
- edge = Puppet::Relationship.from_pson(edge) if edge.is_a?(Hash)
- unless source = result.resource(edge.source)
- raise ArgumentError, "Could not convert from pson: Could not find relationship source #{edge.source.inspect}"
- end
- edge.source = source
-
- unless target = result.resource(edge.target)
- raise ArgumentError, "Could not convert from pson: Could not find relationship target #{edge.target.inspect}"
- end
- edge.target = target
-
- result.add_edge(edge)
+ def self.from_pson(data)
+ self.from_data_hash(data)
end
def to_data_hash
diff --git a/lib/puppet/resource/status.rb b/lib/puppet/resource/status.rb
index eae5aeed9..3d0273516 100644
--- a/lib/puppet/resource/status.rb
+++ b/lib/puppet/resource/status.rb
@@ -24,12 +24,16 @@ module Puppet
map(&:to_sym)
- def self.from_pson(data)
+ def self.from_data_hash(data)
obj = self.allocate
obj.initialize_from_hash(data)
obj
end
+ def self.from_pson(data)
+ self.from_data_hash(data)
+ end
+
# Provide a boolean method for each of the states.
STATES.each do |attr|
define_method("#{attr}?") do
@@ -111,7 +115,7 @@ module Puppet
@failed = data['failed']
@events = data['events'].map do |event|
- Puppet::Transaction::Event.from_pson(event)
+ Puppet::Transaction::Event.from_data_hash(event)
end
end
diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb
index cc09ecbba..63727b429 100644
--- a/lib/puppet/resource/type.rb
+++ b/lib/puppet/resource/type.rb
@@ -46,7 +46,7 @@ class Puppet::Resource::Type
extend Puppet::Indirector
indirects :resource_type, :terminus_class => :parser
- def self.from_pson(data)
+ def self.from_data_hash(data)
name = data.delete('name') or raise ArgumentError, "Resource Type names must be specified"
kind = data.delete('kind') || "definition"
@@ -63,6 +63,10 @@ class Puppet::Resource::Type
new(type, name, data)
end
+ def self.from_pson(data)
+ self.from_data_hash(data)
+ end
+
def to_pson(*args)
to_data_hash.to_pson(*args)
end
diff --git a/lib/puppet/run.rb b/lib/puppet/run.rb
index 1d89304be..c5512d37a 100644
--- a/lib/puppet/run.rb
+++ b/lib/puppet/run.rb
@@ -80,20 +80,24 @@ class Puppet::Run
obj
end
- def self.from_pson(hash)
- if hash['options']
- return from_hash(hash)
+ def self.from_data_hash(data)
+ if data['options']
+ return from_hash(data)
end
options = { :pluginsync => Puppet[:pluginsync] }
- hash.each do |key, value|
+ data.each do |key, value|
options[key.to_sym] = value
end
new(options)
end
+ def self.from_pson(hash)
+ self.from_data_hash(hash)
+ end
+
def to_data_hash
{
:options => @options,
diff --git a/lib/puppet/ssl/host.rb b/lib/puppet/ssl/host.rb
index f30b4dee7..d66e0985c 100644
--- a/lib/puppet/ssl/host.rb
+++ b/lib/puppet/ssl/host.rb
@@ -118,14 +118,18 @@ DOC
indirection.destroy(name)
end
- def self.from_pson(pson)
- instance = new(pson["name"])
- if pson["desired_state"]
- instance.desired_state = pson["desired_state"]
+ def self.from_data_hash(data)
+ instance = new(data["name"])
+ if data["desired_state"]
+ instance.desired_state = data["desired_state"]
end
instance
end
+ def self.from_pson(pson)
+ self.from_data_hash(pson)
+ end
+
# Puppet::SSL::Host is actually indirected now so the original implementation
# has been moved into the certificate_status indirector. This method does not
# appear to be in use in `puppet cert -l`.
diff --git a/lib/puppet/status.rb b/lib/puppet/status.rb
index 0b26ae22e..22ad5504f 100644
--- a/lib/puppet/status.rb
+++ b/lib/puppet/status.rb
@@ -18,14 +18,18 @@ class Puppet::Status
@status.to_pson
end
- def self.from_pson(pson)
- if pson.include?('status')
- self.new(pson['status'])
+ def self.from_data_hash(data)
+ if data.include?('status')
+ self.new(data['status'])
else
- self.new(pson)
+ self.new(data)
end
end
+ def self.from_pson(pson)
+ self.from_data_hash(pson)
+ end
+
def name
"status"
end
diff --git a/lib/puppet/transaction/event.rb b/lib/puppet/transaction/event.rb
index ca4255937..1ea53e4e0 100644
--- a/lib/puppet/transaction/event.rb
+++ b/lib/puppet/transaction/event.rb
@@ -19,12 +19,16 @@ class Puppet::Transaction::Event
EVENT_STATUSES = %w{noop success failure audit}
- def self.from_pson(data)
+ def self.from_data_hash(data)
obj = self.allocate
obj.initialize_from_hash(data)
obj
end
+ def self.from_pson(data)
+ self.from_data_hash(data)
+ end
+
def initialize(options = {})
@audited = false
diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb
index 25144ef68..8acc14512 100644
--- a/lib/puppet/transaction/report.rb
+++ b/lib/puppet/transaction/report.rb
@@ -97,12 +97,16 @@ class Puppet::Transaction::Report
#
attr_reader :report_format
- def self.from_pson(data)
+ def self.from_data_hash(data)
obj = self.allocate
obj.initialize_from_hash(data)
obj
end
+ def self.from_pson(data)
+ self.from_data_hash(data)
+ end
+
def as_logging_destination(&block)
Puppet::Util::Log.with_destination(self, &block)
end
@@ -197,11 +201,11 @@ class Puppet::Transaction::Report
@metrics = {}
data['metrics'].each do |name, hash|
- @metrics[name] = Puppet::Util::Metric.from_pson(hash)
+ @metrics[name] = Puppet::Util::Metric.from_data_hash(hash)
end
@logs = data['logs'].map do |record|
- Puppet::Util::Log.from_pson(record)
+ Puppet::Util::Log.from_data_hash(record)
end
@resource_statuses = {}
@@ -209,7 +213,7 @@ class Puppet::Transaction::Report
if record[1] == {}
status = nil
else
- status = Puppet::Resource::Status.from_pson(record[1])
+ status = Puppet::Resource::Status.from_data_hash(record[1])
end
@resource_statuses[record[0]] = status
end
diff --git a/lib/puppet/util/instrumentation/data.rb b/lib/puppet/util/instrumentation/data.rb
index 48e595432..5d06b4be2 100644
--- a/lib/puppet/util/instrumentation/data.rb
+++ b/lib/puppet/util/instrumentation/data.rb
@@ -35,6 +35,10 @@ class Puppet::Util::Instrumentation::Data
to_pson_data_hash.to_pson(*args)
end
+ def self.from_data_hash(data)
+ data
+ end
+
def self.from_pson(data)
data
end
diff --git a/lib/puppet/util/instrumentation/indirection_probe.rb b/lib/puppet/util/instrumentation/indirection_probe.rb
index 237d8dbc8..c4817a1b6 100644
--- a/lib/puppet/util/instrumentation/indirection_probe.rb
+++ b/lib/puppet/util/instrumentation/indirection_probe.rb
@@ -30,7 +30,11 @@ class Puppet::Util::Instrumentation::IndirectionProbe
to_pson_data_hash.to_pson(*args)
end
- def self.from_pson(data)
+ def self.from_data_hash(data)
self.new(data["name"])
end
+
+ def self.from_pson(data)
+ self.from_data_hash(data)
+ end
end
diff --git a/lib/puppet/util/instrumentation/listener.rb b/lib/puppet/util/instrumentation/listener.rb
index b965e976f..9baa15288 100644
--- a/lib/puppet/util/instrumentation/listener.rb
+++ b/lib/puppet/util/instrumentation/listener.rb
@@ -60,8 +60,12 @@ class Puppet::Util::Instrumentation::Listener
to_pson_data_hash.to_pson(*args)
end
- def self.from_pson(data)
+ def self.from_data_hash(data)
result = Puppet::Util::Instrumentation[data["name"]]
self.new(result.listener, result.pattern, data["enabled"])
end
+
+ def self.from_pson(data)
+ self.from_data_hash(data)
+ end
end
diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb
index 808e0631d..79414a8f0 100644
--- a/lib/puppet/util/log.rb
+++ b/lib/puppet/util/log.rb
@@ -233,12 +233,16 @@ class Puppet::Util::Log
@levels.include?(level)
end
- def self.from_pson(data)
+ def self.from_data_hash(data)
obj = allocate
obj.initialize_from_hash(data)
obj
end
+ def self.from_pson(data)
+ self.from_data_hash(data)
+ end
+
attr_accessor :time, :remote, :file, :line, :source
attr_reader :level, :message
diff --git a/lib/puppet/util/metric.rb b/lib/puppet/util/metric.rb
index 7b07a181d..6e64ee098 100644
--- a/lib/puppet/util/metric.rb
+++ b/lib/puppet/util/metric.rb
@@ -11,12 +11,16 @@ class Puppet::Util::Metric
attr_writer :basedir
- def self.from_pson(data)
+ def self.from_data_hash(data)
metric = new(data['name'], data['label'])
metric.values = data['values']
metric
end
+ def self.from_pson(data)
+ self.from_data_hash(data)
+ end
+
def to_data_hash
{
'name' => @name,
diff --git a/lib/puppet/util/pson.rb b/lib/puppet/util/pson.rb
index 1441069c0..b796cb111 100644
--- a/lib/puppet/util/pson.rb
+++ b/lib/puppet/util/pson.rb
@@ -8,6 +8,6 @@
module Puppet::Util::Pson
def pson_create(pson)
raise ArgumentError, "No data provided in pson data" unless pson['data']
- from_pson(pson['data'])
+ from_data_hash(pson['data'])
end
end
diff --git a/lib/puppet/util/tag_set.rb b/lib/puppet/util/tag_set.rb
index d9c9d9695..7c92cd5dc 100644
--- a/lib/puppet/util/tag_set.rb
+++ b/lib/puppet/util/tag_set.rb
@@ -12,10 +12,14 @@ class Puppet::Util::TagSet < Set
@hash.keys.to_yaml
end
- def self.from_pson(data)
+ def self.from_data_hash(data)
self.new(data)
end
+ def self.from_pson(data)
+ self.from_data_hash(data)
+ end
+
def to_data_hash
to_a
end
diff --git a/spec/integration/network/formats_spec.rb b/spec/integration/network/formats_spec.rb
index 2834e33f0..686961338 100755
--- a/spec/integration/network/formats_spec.rb
+++ b/spec/integration/network/formats_spec.rb
@@ -9,7 +9,7 @@ class PsonIntTest
other.class == self.class and string == other.string
end
- def self.from_pson(data)
+ def self.from_data_hash(data)
new(data[0])
end
diff --git a/spec/lib/puppet/indirector_testing.rb b/spec/lib/puppet/indirector_testing.rb
index e6b88ddcd..0fd4ef044 100644
--- a/spec/lib/puppet/indirector_testing.rb
+++ b/spec/lib/puppet/indirector_testing.rb
@@ -19,14 +19,18 @@ class Puppet::IndirectorTesting
end
PSON.register_document_type('IndirectorTesting',self)
- def self.from_pson(data)
+ def self.from_data_hash(data)
new(data['value'])
end
+ def to_data_hash
+ { 'value' => value }
+ end
+
def to_pson
{
'document_type' => 'IndirectorTesting',
- 'data' => { 'value' => value },
+ 'data' => self.to_data_hash,
'metadata' => { 'api_version' => 1 }
}.to_pson
end
diff --git a/spec/unit/file_serving/metadata_spec.rb b/spec/unit/file_serving/metadata_spec.rb
index 51161c4fe..f3b0c4347 100755
--- a/spec/unit/file_serving/metadata_spec.rb
+++ b/spec/unit/file_serving/metadata_spec.rb
@@ -26,8 +26,8 @@ describe Puppet::FileServing::Metadata do
Puppet::FileServing::Metadata.new(foobar).should respond_to(:to_pson_data_hash)
end
- it "should support pson deserialization" do
- Puppet::FileServing::Metadata.should respond_to(:from_pson)
+ it "should support deserialization" do
+ Puppet::FileServing::Metadata.should respond_to(:from_data_hash)
end
describe "when serializing" do
diff --git a/spec/unit/network/formats_spec.rb b/spec/unit/network/formats_spec.rb
index a64f96e1e..99535ff1e 100755
--- a/spec/unit/network/formats_spec.rb
+++ b/spec/unit/network/formats_spec.rb
@@ -9,7 +9,7 @@ class PsonTest
string == other.string
end
- def self.from_pson(data)
+ def self.from_data_hash(data)
new(data)
end
@@ -43,7 +43,7 @@ describe "Puppet Network Format" do
@msgpack.weight.should == 20
end
- it "should fail when one element does not have a from_pson" do
+ it "should fail when one element does not have a from_data_hash" do
expect do
@msgpack.intern_multiple(Hash, MessagePack.pack(["foo"]))
end.to raise_error(NoMethodError)
@@ -316,10 +316,10 @@ describe "Puppet Network Format" do
@pson.render_multiple(instances).should == "foo"
end
- it "should intern by calling 'PSON.parse' on the text and then using from_pson to convert the data into an instance" do
+ it "should intern by calling 'PSON.parse' on the text and then using from_data_hash to convert the data into an instance" do
text = "foo"
PSON.expects(:parse).with("foo").returns("type" => "PsonTest", "data" => "foo")
- PsonTest.expects(:from_pson).with("foo").returns "parsed_pson"
+ PsonTest.expects(:from_data_hash).with("foo").returns "parsed_pson"
@pson.intern(PsonTest, text).should == "parsed_pson"
end
@@ -327,22 +327,22 @@ describe "Puppet Network Format" do
text = "foo"
instance = PsonTest.new("foo")
PSON.expects(:parse).with("foo").returns(instance)
- PsonTest.expects(:from_pson).never
+ PsonTest.expects(:from_data_hash).never
@pson.intern(PsonTest, text).should equal(instance)
end
- it "should intern by calling 'PSON.parse' on the text and then using from_pson to convert the actual into an instance if the pson has no class/data separation" do
+ it "should intern by calling 'PSON.parse' on the text and then using from_data_hash to convert the actual into an instance if the pson has no class/data separation" do
text = "foo"
PSON.expects(:parse).with("foo").returns("foo")
- PsonTest.expects(:from_pson).with("foo").returns "parsed_pson"
+ PsonTest.expects(:from_data_hash).with("foo").returns "parsed_pson"
@pson.intern(PsonTest, text).should == "parsed_pson"
end
it "should intern multiples by parsing the text and using 'class.intern' on each resulting data structure" do
text = "foo"
PSON.expects(:parse).with("foo").returns ["bar", "baz"]
- PsonTest.expects(:from_pson).with("bar").returns "BAR"
- PsonTest.expects(:from_pson).with("baz").returns "BAZ"
+ PsonTest.expects(:from_data_hash).with("bar").returns "BAR"
+ PsonTest.expects(:from_data_hash).with("baz").returns "BAZ"
@pson.intern_multiple(PsonTest, text).should == %w{BAR BAZ}
end
diff --git a/spec/unit/relationship_spec.rb b/spec/unit/relationship_spec.rb
index a6aeffc4f..66cd38183 100755
--- a/spec/unit/relationship_spec.rb
+++ b/spec/unit/relationship_spec.rb
@@ -211,18 +211,18 @@ describe Puppet::Relationship, "when converting from pson" do
# LAK:NOTE For all of these tests, we convert back to the edge so we can
# trap the actual data structure then.
it "should pass the source in as the first argument" do
- Puppet::Relationship.from_pson("source" => "mysource", "target" => "mytarget").source.should == "mysource"
+ Puppet::Relationship.from_data_hash("source" => "mysource", "target" => "mytarget").source.should == "mysource"
end
it "should pass the target in as the second argument" do
- Puppet::Relationship.from_pson("source" => "mysource", "target" => "mytarget").target.should == "mytarget"
+ Puppet::Relationship.from_data_hash("source" => "mysource", "target" => "mytarget").target.should == "mytarget"
end
it "should pass the event as an argument if it's provided" do
- Puppet::Relationship.from_pson("source" => "mysource", "target" => "mytarget", "event" => "myevent", "callback" => "eh").event.should == "myevent"
+ Puppet::Relationship.from_data_hash("source" => "mysource", "target" => "mytarget", "event" => "myevent", "callback" => "eh").event.should == "myevent"
end
it "should pass the callback as an argument if it's provided" do
- Puppet::Relationship.from_pson("source" => "mysource", "target" => "mytarget", "callback" => "mycallback").callback.should == "mycallback"
+ Puppet::Relationship.from_data_hash("source" => "mysource", "target" => "mytarget", "callback" => "mycallback").callback.should == "mycallback"
end
end
diff --git a/spec/unit/resource/status_spec.rb b/spec/unit/resource/status_spec.rb
index d50abdce3..271554325 100755
--- a/spec/unit/resource/status_spec.rb
+++ b/spec/unit/resource/status_spec.rb
@@ -181,7 +181,7 @@ describe Puppet::Resource::Status do
@status.containment_path.should == @containment_path
- tripped = Puppet::Resource::Status.from_pson(PSON.parse(@status.to_pson))
+ tripped = Puppet::Resource::Status.from_data_hash(PSON.parse(@status.to_pson))
tripped.title.should == @status.title
tripped.containment_path.should == @status.containment_path
diff --git a/spec/unit/resource/type_spec.rb b/spec/unit/resource/type_spec.rb
index 1dd0c41db..b3a4aab78 100755
--- a/spec/unit/resource/type_spec.rb
+++ b/spec/unit/resource/type_spec.rb
@@ -39,11 +39,11 @@ describe Puppet::Resource::Type do
end
def from_json(json)
- Puppet::Resource::Type.from_pson(json)
+ Puppet::Resource::Type.from_data_hash(json)
end
def double_convert
- Puppet::Resource::Type.from_pson(PSON.parse(@type.to_pson))
+ Puppet::Resource::Type.from_data_hash(PSON.parse(@type.to_pson))
end
it "should include the name and type" do
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index 1ac2decf1..b7a95aaba 100755
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -671,45 +671,45 @@ describe Puppet::Resource do
# trap the actual data structure then.
it "should set its type to the provided type" do
- Puppet::Resource.from_pson(PSON.parse(Puppet::Resource.new("File", "/foo").to_pson)).type.should == "File"
+ Puppet::Resource.from_data_hash(PSON.parse(Puppet::Resource.new("File", "/foo").to_pson)).type.should == "File"
end
it "should set its title to the provided title" do
- Puppet::Resource.from_pson(PSON.parse(Puppet::Resource.new("File", "/foo").to_pson)).title.should == "/foo"
+ Puppet::Resource.from_data_hash(PSON.parse(Puppet::Resource.new("File", "/foo").to_pson)).title.should == "/foo"
end
it "should include all tags from the resource" do
resource = Puppet::Resource.new("File", "/foo")
resource.tag("yay")
- Puppet::Resource.from_pson(PSON.parse(resource.to_pson)).tags.should == resource.tags
+ Puppet::Resource.from_data_hash(PSON.parse(resource.to_pson)).tags.should == resource.tags
end
it "should include the file if one is set" do
resource = Puppet::Resource.new("File", "/foo")
resource.file = "/my/file"
- Puppet::Resource.from_pson(PSON.parse(resource.to_pson)).file.should == "/my/file"
+ Puppet::Resource.from_data_hash(PSON.parse(resource.to_pson)).file.should == "/my/file"
end
it "should include the line if one is set" do
resource = Puppet::Resource.new("File", "/foo")
resource.line = 50
- Puppet::Resource.from_pson(PSON.parse(resource.to_pson)).line.should == 50
+ Puppet::Resource.from_data_hash(PSON.parse(resource.to_pson)).line.should == 50
end
it "should include the 'exported' value if one is set" do
resource = Puppet::Resource.new("File", "/foo")
resource.exported = true
- Puppet::Resource.from_pson(PSON.parse(resource.to_pson)).exported?.should be_true
+ Puppet::Resource.from_data_hash(PSON.parse(resource.to_pson)).exported?.should be_true
end
it "should set 'exported' to false if no value is set" do
resource = Puppet::Resource.new("File", "/foo")
- Puppet::Resource.from_pson(PSON.parse(resource.to_pson)).exported?.should be_false
+ Puppet::Resource.from_data_hash(PSON.parse(resource.to_pson)).exported?.should be_false
end
it "should set all of its parameters as the 'parameters' entry" do
@@ -717,7 +717,7 @@ describe Puppet::Resource do
resource[:foo] = %w{bar eh}
resource[:fee] = %w{baz}
- result = Puppet::Resource.from_pson(PSON.parse(resource.to_pson))
+ result = Puppet::Resource.from_data_hash(PSON.parse(resource.to_pson))
result["foo"].should == %w{bar eh}
result["fee"].should == %w{baz}
end
@@ -725,14 +725,14 @@ describe Puppet::Resource do
it "should serialize relationships as reference strings" do
resource = Puppet::Resource.new("File", "/foo")
resource[:requires] = Puppet::Resource.new("File", "/bar")
- result = Puppet::Resource.from_pson(PSON.parse(resource.to_pson))
+ result = Puppet::Resource.from_data_hash(PSON.parse(resource.to_pson))
result[:requires].should == "File[/bar]"
end
it "should serialize multiple relationships as arrays of reference strings" do
resource = Puppet::Resource.new("File", "/foo")
resource[:requires] = [Puppet::Resource.new("File", "/bar"), Puppet::Resource.new("File", "/baz")]
- result = Puppet::Resource.from_pson(PSON.parse(resource.to_pson))
+ result = Puppet::Resource.from_data_hash(PSON.parse(resource.to_pson))
result[:requires].should == [ "File[/bar]", "File[/baz]" ]
end
end
@@ -750,59 +750,59 @@ describe Puppet::Resource do
end
it "should set its type to the provided type" do
- Puppet::Resource.from_pson(@data).type.should == "File"
+ Puppet::Resource.from_data_hash(@data).type.should == "File"
end
it "should set its title to the provided title" do
- Puppet::Resource.from_pson(@data).title.should == basepath+"/yay"
+ Puppet::Resource.from_data_hash(@data).title.should == basepath+"/yay"
end
it "should tag the resource with any provided tags" do
@data['tags'] = %w{foo bar}
- resource = Puppet::Resource.from_pson(@data)
+ resource = Puppet::Resource.from_data_hash(@data)
resource.tags.should be_include("foo")
resource.tags.should be_include("bar")
end
it "should set its file to the provided file" do
@data['file'] = "/foo/bar"
- Puppet::Resource.from_pson(@data).file.should == "/foo/bar"
+ Puppet::Resource.from_data_hash(@data).file.should == "/foo/bar"
end
it "should set its line to the provided line" do
@data['line'] = 50
- Puppet::Resource.from_pson(@data).line.should == 50
+ Puppet::Resource.from_data_hash(@data).line.should == 50
end
it "should 'exported' to true if set in the pson data" do
@data['exported'] = true
- Puppet::Resource.from_pson(@data).exported.should be_true
+ Puppet::Resource.from_data_hash(@data).exported.should be_true
end
it "should 'exported' to false if not set in the pson data" do
- Puppet::Resource.from_pson(@data).exported.should be_false
+ Puppet::Resource.from_data_hash(@data).exported.should be_false
end
it "should fail if no title is provided" do
@data.delete('title')
- expect { Puppet::Resource.from_pson(@data) }.to raise_error(ArgumentError)
+ expect { Puppet::Resource.from_data_hash(@data) }.to raise_error(ArgumentError)
end
it "should fail if no type is provided" do
@data.delete('type')
- expect { Puppet::Resource.from_pson(@data) }.to raise_error(ArgumentError)
+ expect { Puppet::Resource.from_data_hash(@data) }.to raise_error(ArgumentError)
end
it "should set each of the provided parameters" do
@data['parameters'] = {'foo' => %w{one two}, 'fee' => %w{three four}}
- resource = Puppet::Resource.from_pson(@data)
+ resource = Puppet::Resource.from_data_hash(@data)
resource['foo'].should == %w{one two}
resource['fee'].should == %w{three four}
end
it "should convert single-value array parameters to normal values" do
@data['parameters'] = {'foo' => %w{one}}
- resource = Puppet::Resource.from_pson(@data)
+ resource = Puppet::Resource.from_data_hash(@data)
resource['foo'].should == %w{one}
end
end
diff --git a/spec/unit/run_spec.rb b/spec/unit/run_spec.rb
index 266f65334..c1b1d8a93 100755
--- a/spec/unit/run_spec.rb
+++ b/spec/unit/run_spec.rb
@@ -121,14 +121,14 @@ describe Puppet::Run do
end
end
- describe ".from_pson" do
+ describe ".from_data_hash" do
it "should read from a hash that represents the 'options' to initialize" do
options = {
"tags" => "whatever",
"background" => true,
"ignoreschedules" => false,
}
- run = Puppet::Run.from_pson(options)
+ run = Puppet::Run.from_data_hash(options)
run.options.should == {
:tags => "whatever",
@@ -145,7 +145,7 @@ describe Puppet::Run do
"tags" => [],
"ignoreschedules" => false},
"status" => "success"}
- run = Puppet::Run.from_pson(hash)
+ run = Puppet::Run.from_data_hash(hash)
run.options.should == {
:pluginsync => true,
diff --git a/spec/unit/ssl/host_spec.rb b/spec/unit/ssl/host_spec.rb
index a9ab9b51e..a80fe9205 100755
--- a/spec/unit/ssl/host_spec.rb
+++ b/spec/unit/ssl/host_spec.rb
@@ -931,7 +931,7 @@ describe Puppet::SSL::Host do
"name" => host.name,
"desired_state" => host.desired_state,
}
- generated_host = Puppet::SSL::Host.from_pson(pson_hash)
+ generated_host = Puppet::SSL::Host.from_data_hash(pson_hash)
generated_host.desired_state.should == host.desired_state
generated_host.name.should == host.name
end
diff --git a/spec/unit/transaction/event_spec.rb b/spec/unit/transaction/event_spec.rb
index 8e62e02f6..4781cbca1 100755
--- a/spec/unit/transaction/event_spec.rb
+++ b/spec/unit/transaction/event_spec.rb
@@ -149,7 +149,7 @@ describe Puppet::Transaction::Event do
:property => :mode,
:status => 'success')
- tripped = Puppet::Transaction::Event.from_pson(PSON.parse(event.to_pson))
+ tripped = Puppet::Transaction::Event.from_data_hash(PSON.parse(event.to_pson))
tripped.audited.should == event.audited
tripped.property.should == event.property
@@ -176,7 +176,7 @@ describe Puppet::Transaction::Event do
:property => :mode,
:status => 'success')
- tripped = Puppet::Transaction::Event.from_pson(PSON.parse(event.to_pson))
+ tripped = Puppet::Transaction::Event.from_data_hash(PSON.parse(event.to_pson))
tripped.desired_value.should be_nil
tripped.historical_value.should be_nil
diff --git a/spec/unit/util/instrumentation/data_spec.rb b/spec/unit/util/instrumentation/data_spec.rb
index d8a6b32d0..418d89724 100755
--- a/spec/unit/util/instrumentation/data_spec.rb
+++ b/spec/unit/util/instrumentation/data_spec.rb
@@ -41,6 +41,6 @@ describe Puppet::Util::Instrumentation::Data do
end
it "should return a hash containing data when unserializing from pson" do
- Puppet::Util::Instrumentation::Data.from_pson({:name => "name"}).should == {:name => "name"}
+ Puppet::Util::Instrumentation::Data.from_data_hash({:name => "name"}).should == {:name => "name"}
end
end
diff --git a/spec/unit/util/instrumentation/listener_spec.rb b/spec/unit/util/instrumentation/listener_spec.rb
index 90c76978f..344934908 100755
--- a/spec/unit/util/instrumentation/listener_spec.rb
+++ b/spec/unit/util/instrumentation/listener_spec.rb
@@ -88,14 +88,14 @@ describe Puppet::Util::Instrumentation::Listener do
describe "when deserializing from pson" do
it "should lookup the archetype listener from the instrumentation layer" do
Puppet::Util::Instrumentation.expects(:[]).with("listener").returns(@listener)
- Puppet::Util::Instrumentation::Listener.from_pson({"name" => "listener"})
+ Puppet::Util::Instrumentation::Listener.from_data_hash({"name" => "listener"})
end
it "should create a new listener shell instance delegating to the archetypal listener" do
Puppet::Util::Instrumentation.expects(:[]).with("listener").returns(@listener)
@listener.stubs(:listener).returns(@delegate)
Puppet::Util::Instrumentation::Listener.expects(:new).with(@delegate, nil, true)
- Puppet::Util::Instrumentation::Listener.from_pson({"name" => "listener", "enabled" => true})
+ Puppet::Util::Instrumentation::Listener.from_data_hash({"name" => "listener", "enabled" => true})
end
end
end
diff --git a/spec/unit/util/log_spec.rb b/spec/unit/util/log_spec.rb
index 99984246a..bc6ecfcf0 100755
--- a/spec/unit/util/log_spec.rb
+++ b/spec/unit/util/log_spec.rb
@@ -365,7 +365,7 @@ describe Puppet::Util::Log do
it "should round trip through pson" do
log = Puppet::Util::Log.new(:level => 'notice', :message => 'hooray', :file => 'thefile', :line => 1729, :source => 'specs', :tags => ['a', 'b', 'c'])
- tripped = Puppet::Util::Log.from_pson(PSON.parse(log.to_pson))
+ tripped = Puppet::Util::Log.from_data_hash(PSON.parse(log.to_pson))
tripped.file.should == log.file
tripped.line.should == log.line
diff --git a/spec/unit/util/metric_spec.rb b/spec/unit/util/metric_spec.rb
index e8ffe00dd..2f0d99b6a 100755
--- a/spec/unit/util/metric_spec.rb
+++ b/spec/unit/util/metric_spec.rb
@@ -89,7 +89,7 @@ describe Puppet::Util::Metric do
metric.newvalue("v1", 10.1, "something")
metric.newvalue("v2", 20, "something else")
- tripped = Puppet::Util::Metric.from_pson(PSON.parse(metric.to_pson))
+ tripped = Puppet::Util::Metric.from_data_hash(PSON.parse(metric.to_pson))
tripped.name.should == metric.name
tripped.label.should == metric.label
diff --git a/spec/unit/util/pson_spec.rb b/spec/unit/util/pson_spec.rb
index e0d79cda6..c2307498f 100755
--- a/spec/unit/util/pson_spec.rb
+++ b/spec/unit/util/pson_spec.rb
@@ -15,9 +15,9 @@ describe Puppet::Util::Pson do
}.to raise_error(ArgumentError, /No data provided in pson data/)
end
- it "should call 'from_pson' with the provided data" do
+ it "should call 'from_data_hash' with the provided data" do
pson = PsonUtil.new
- pson.expects(:from_pson).with("mydata")
+ pson.expects(:from_data_hash).with("mydata")
pson.pson_create("type" => "foo", "data" => "mydata")
end
diff --git a/spec/unit/util/tag_set_spec.rb b/spec/unit/util/tag_set_spec.rb
index c59674fcb..5d6d36dfe 100644
--- a/spec/unit/util/tag_set_spec.rb
+++ b/spec/unit/util/tag_set_spec.rb
@@ -33,7 +33,7 @@ describe Puppet::Util::TagSet do
array = ['a', 'b', 1, 5.4]
set.merge(array)
- tes = Puppet::Util::TagSet.from_pson(PSON.parse(set.to_pson))
+ tes = Puppet::Util::TagSet.from_data_hash(PSON.parse(set.to_pson))
tes.should == set
end