Issue #8425 has been reported by Ken Barber.
----------------------------------------
Bug #8425: exported resources with hashes for param values (and probably
arrays) require multiple runs
https://projects.puppetlabs.com/issues/8425
Author: Ken Barber
Status: Unreviewed
Priority: Normal
Assignee:
Category: stored configuration
Target version:
Affected Puppet version: 2.7.1
Keywords: serialization hashes stored configs exported resources
Branch:
So I've been working through a bug in puppet whereby when I export a resource
that contains a hash in a property, it requires 2 runs before it works
correctly. The first run returns errors in my types - because the hashes get
munged (much like when one does {"a"=>"b"}.to_s).
The problem is tracked back to the param_value being set gets converted naively
to a string during creation before serialization - which messes up the entry in
the database. So things like:
{"a"=>"b"}
Get stored as:
ab
Instead of the yaml format:
---
a: b
This traces back to a single call to 'v.to_s' in the method munge_parser_values
in puppet/rails/param_value.rb. Upon the second run, the update call directly
to value=() does the correct thing and corrects it ... but its rather silly to
have to require 2 runs.
So the fix is something like:
diff -ru puppet.bak//rails/param_value.rb puppet/rails/param_value.rb
--- puppet.bak//rails/param_value.rb 2011-07-14 19:16:55.000000000
+0200
+++ puppet/rails/param_value.rb 2011-07-14 20:54:28.000000000 +0200
@@ -9,7 +9,7 @@
# Store a new parameter in a Rails db.
def self.from_parser_param(param, values)
- values = munge_parser_values(values)
+ values = values.is_a?(Array) ? values : [values]
param_name = Puppet::Rails::ParamName.find_or_create_by_name(param.to_s)
return values.collect do |v|
@@ -17,21 +17,6 @@
end
end
- # Make sure an array (or possibly not an array) of values is correctly
- # set up for Rails. The main thing is that Resource::Reference objects
- # should stay objects, so they just get serialized.
- def self.munge_parser_values(value)
- values = value.is_a?(Array) ? value : [value]
- values.map do |v|
- if v.is_a?(Puppet::Resource)
- v
- else
- v.to_s
- end
- end
- end
-
-
def value
unserialize_value(self[:value])
end
I've removed the need for the extra method here because it seems silly to have
1 conversion mechanism for creation and have it not applied during update. This
works each time - and serializes hashes, strings, resources etc. each time the
first time.
I'm pretty sure this is a duplicate but I can't find any others ... I think its
been around since Brice introduced hashes in 2009 or something.
Not sure if anyone can confirm what I'm saying is sane or not ...
--
You have received this notification because you have either subscribed to it,
or are involved in it.
To change your notification preferences, please click here:
http://projects.puppetlabs.com/my/account
--
You received this message because you are subscribed to the Google Groups
"Puppet Bugs" 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-bugs?hl=en.