summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2009-05-01 16:59:51 +0200
committerJames Turnbull <james@lovedthanlost.net>2009-05-02 09:08:00 +1000
commita1c0ae0fe3c4bef6f21240c4d0a8da985cc7c8af (patch)
tree089ead1cdd48bb6dd21e7abe07acc7ab041b50dc /lib
parentbf054e1b2c0117135de5f54421c112523e83a88c (diff)
downloadpuppet-a1c0ae0fe3c4bef6f21240c4d0a8da985cc7c8af.tar.gz
puppet-a1c0ae0fe3c4bef6f21240c4d0a8da985cc7c8af.tar.xz
puppet-a1c0ae0fe3c4bef6f21240c4d0a8da985cc7c8af.zip
Fix #2218 - Ruby YAML bug prevents reloading catalog in puppetd
Because of ruby bug: http://rubyforge.org/tracker/?group_id=426&atid=1698&func=detail&aid=8886 and http://redmine.ruby-lang.org/issues/show/1331 YAML dump of hashes using ruby objects as keys is incorrect leading to an error when deserializing the YAML in puppetd. The error is easy to correct by a post-process fix-up of the generated YAML, which transforms: &id004 !ruby/object:Puppet::Relationship ? to the correct: ? &id004 !ruby/object:Puppet::Relationship Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/network/formats.rb17
-rw-r--r--lib/puppet/resource/catalog.rb14
-rw-r--r--lib/puppet/simple_graph.rb14
3 files changed, 15 insertions, 30 deletions
diff --git a/lib/puppet/network/formats.rb b/lib/puppet/network/formats.rb
index 85e8ce6f8..51354b03d 100644
--- a/lib/puppet/network/formats.rb
+++ b/lib/puppet/network/formats.rb
@@ -12,18 +12,31 @@ Puppet::Network::FormatHandler.create(:yaml, :mime => "text/yaml") do
end
def render(instance)
- instance.to_yaml
+ yaml = instance.to_yaml
+
+ yaml = fixup(yaml) unless yaml.nil?
+ yaml
end
# Yaml monkey-patches Array, so this works.
def render_multiple(instances)
- instances.to_yaml
+ yaml = instances.to_yaml
+
+ yaml = fixup(yaml) unless yaml.nil?
+ yaml
end
# Everything's supported
def supported?(klass)
true
end
+
+ # fixup invalid yaml as per:
+ # http://redmine.ruby-lang.org/issues/show/1331
+ def fixup(yaml)
+ yaml.gsub!(/((?:&id\d+\s+)?!ruby\/object:.*?)\s*\?/) { "? #{$1}" }
+ yaml
+ end
end
diff --git a/lib/puppet/resource/catalog.rb b/lib/puppet/resource/catalog.rb
index 32fbc38d6..4f60f6e56 100644
--- a/lib/puppet/resource/catalog.rb
+++ b/lib/puppet/resource/catalog.rb
@@ -417,20 +417,6 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
super
end
- def to_yaml_properties
- result = instance_variables
-
- # There's a ruby bug that hits us without this:
- # http://rubyforge.org/tracker/?group_id=426&atid=1698&func=detail&aid=8886
- # We need our resources to show up in as values in a hash
- # before they show up as keys, because otherwise
- # the loading fails.
- result.delete "@resource_table"
- result.unshift "@resource_table"
-
- result
- end
-
private
def cleanup
diff --git a/lib/puppet/simple_graph.rb b/lib/puppet/simple_graph.rb
index c5b0f4928..5d6f72943 100644
--- a/lib/puppet/simple_graph.rb
+++ b/lib/puppet/simple_graph.rb
@@ -360,20 +360,6 @@ class Puppet::SimpleGraph
end
end
- def to_yaml_properties
- result = instance_variables
-
- # There's a ruby bug that hits us without this:
- # http://rubyforge.org/tracker/?group_id=426&atid=1698&func=detail&aid=8886
- # We need our resources to show up in as values in a hash
- # before they show up as keys, because otherwise
- # the loading fails.
- result.delete "@edges"
- result.unshift "@edges"
-
- result
- end
-
# Just walk the tree and pass each edge.
def walk(source, direction)
# Use an iterative, breadth-first traversal of the graph. One could do