On Apr 15, 2009, at 2:28 AM, Brice Figureau wrote:

>
> One comment below,
>
> On Tue, 2009-04-14 at 23:30 -0500, Luke Kanies wrote:
>> Also working around a YAML bug in Ruby.
>>
>> Signed-off-by: Luke Kanies <[email protected]>
>> ---
>> lib/puppet/node/catalog.rb              |   20 +++++++++++---------
>> lib/puppet/parser/resource.rb           |    2 ++
>> lib/puppet/parser/resource/param.rb     |    8 +++++---
>> lib/puppet/parser/resource/reference.rb |    6 ++++++
>> lib/puppet/parser/yaml_trimmer.rb       |   11 +++++++++++
>> 5 files changed, 35 insertions(+), 12 deletions(-)
>> create mode 100644 lib/puppet/parser/yaml_trimmer.rb
>>
>> diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb
>> index 3473deb..ab80a97 100644
>> --- a/lib/puppet/node/catalog.rb
>> +++ b/lib/puppet/node/catalog.rb
>> @@ -432,16 +432,18 @@ class Puppet::Node::Catalog < Puppet::PGraph
>>         }
>>     end
>>
>> -    # LAK:NOTE We cannot yaml-dump the class in the  
>> edgelist_class, because classes cannot be
>> -    # dumped by default, nor does yaml-dumping # the edge-labels  
>> work at this point (I don't
>> -    # know why).
>> -    #  Neither of these matters right now, but I suppose it could  
>> at some point.
>> -    # We also have to have the vertex_dict dumped after the  
>> resource table, because yaml can't
>> -    # seem to handle the output of yaml-dumping the vertex_dict.
>>     def to_yaml_properties
>> -        props = instance_variables.reject { |v| %...@edgelist_class  
>> @edge_labels @vertex_dict}.include?(v) }
>> -        props << "@vertex_dict"
>> -        props
>> +        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
>> diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/ 
>> resource.rb
>> index 893d5ba..9f496c7 100644
>> --- a/lib/puppet/parser/resource.rb
>> +++ b/lib/puppet/parser/resource.rb
>> @@ -5,6 +5,7 @@ class Puppet::Parser::Resource
>>     require 'puppet/parser/resource/reference'
>>     require 'puppet/util/tagging'
>>     require 'puppet/file_collection/lookup'
>> +    require 'puppet/parser/yaml_trimmer'
>>
>>     include Puppet::FileCollection::Lookup
>>
>> @@ -13,6 +14,7 @@ class Puppet::Parser::Resource
>>     include Puppet::Util::Errors
>>     include Puppet::Util::Logging
>>     include Puppet::Util::Tagging
>> +    include Puppet::Parser::YamlTrimmer
>>
>>     attr_accessor :source, :scope, :rails_id
>>     attr_accessor :virtual, :override, :translated
>> diff --git a/lib/puppet/parser/resource/param.rb b/lib/puppet/ 
>> parser/resource/param.rb
>> index 6e22d3e..3fbc596 100644
>> --- a/lib/puppet/parser/resource/param.rb
>> +++ b/lib/puppet/parser/resource/param.rb
>> @@ -1,4 +1,5 @@
>> require 'puppet/file_collection/lookup'
>> +require 'puppet/parser/yaml_trimmer'
>>
>>  # The parameters we stick in Resources.
>> class Puppet::Parser::Resource::Param
>> @@ -8,6 +9,7 @@ class Puppet::Parser::Resource::Param
>>     include Puppet::Util::MethodHelper
>>
>>     include Puppet::FileCollection::Lookup
>> +    include Puppet::Parser::YamlTrimmer
>>
>>     def initialize(hash)
>>         set_options(hash)
>> @@ -15,9 +17,9 @@ class Puppet::Parser::Resource::Param
>>         @name = symbolize(@name)
>>     end
>>
>> -    def inspect
>> -        "#<#{self.class} @name => #{name}, @value => #{value},  
>> @source => #{source.name}, @line => #{line}>"
>> -    end
>> +    #def inspect
>> +    #    "#<#{self.class} @name => #{name}, @value => #{value},  
>> @source => #{source.name if source}, @line => #{line}>"
>> +    #end
>
> If this causes an issue, you should either comment on why it was
> commented, or if it isn't needed, remove it altogether.

You're right; thanks.  The problem was only occurring in a test script  
I have that takes existing catalogs, instantiates them, and stores  
them to the db, but without a source.

It was only a transient problem, though, so I'll add the method back.

>
>>     def line_to_i
>>         return line ? Integer(line) : nil
>> diff --git a/lib/puppet/parser/resource/reference.rb b/lib/puppet/ 
>> parser/resource/reference.rb
>> index bffc037..4a003f6 100644
>> --- a/lib/puppet/parser/resource/reference.rb
>> +++ b/lib/puppet/parser/resource/reference.rb
>> @@ -1,8 +1,10 @@
>> require 'puppet/resource_reference'
>> require 'puppet/file_collection/lookup'
>> +require 'puppet/parser/yaml_trimmer'
>>
>> # A reference to a resource.  Mostly just the type and title.
>> class Puppet::Parser::Resource::Reference < Puppet::ResourceReference
>> +    include Puppet::Parser::YamlTrimmer
>>     include Puppet::FileCollection::Lookup
>>     include Puppet::Util::MethodHelper
>>     include Puppet::Util::Errors
>> @@ -68,6 +70,10 @@ class Puppet::Parser::Resource::Reference <  
>> Puppet::ResourceReference
>>         requiredopts(:type, :title)
>>     end
>>
>> +    def skip_for_yaml
>> +        %...@typeclass @definedtype}
>> +    end
>> +
>>     def to_ref
>>         # We have to return different cases to provide backward  
>> compatibility
>>         # from 0.24.x to 0.23.x.
>> diff --git a/lib/puppet/parser/yaml_trimmer.rb b/lib/puppet/parser/ 
>> yaml_trimmer.rb
>> new file mode 100644
>> index 0000000..14064c8
>> --- /dev/null
>> +++ b/lib/puppet/parser/yaml_trimmer.rb
>> @@ -0,0 +1,11 @@
>> +module Puppet::Parser::YamlTrimmer
>> +    REMOVE = %...@scope @source}
>> +
>> +    def to_yaml_properties
>> +        r = instance_variables - REMOVE
>> +        if respond_to?(:skip_for_yaml)
>> +            r -= skip_for_yaml()
>> +        end
>> +        r
>> +    end
>> +end
> -- 
> Brice Figureau
> My Blog: http://www.masterzen.fr/
>
>
> >


-- 
Yesterday upon the stair
I met a man who wasn't there.
He wasn't there again today --
I think he's from the CIA.
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" 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-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to