Comment 1 for bug 1199513

Revision history for this message
Ivan Chavero (imcsk8) (ichavero-ichavero) wrote :

After a quite painful debugging i found that the self.get_glance_image_attrs function converts directly to string the result of a split operation, this split is done on the output of a glance show call [1]:

(auth_glance('show', id).split("\n") || []).collect do |line|
        attrs[line.split(': ').first.downcase] = line.split(': ')[1..-1].to_s
 end

this function is called from the instances function that is used by prefetch which populates the @property_hash variable with the wrong values:

#<Puppet::Type::Glance_image::ProviderGl
ance:0x0000000475d0d8 @property_hash={:ensure=>:present, :name=>"[\"cirros\"]", :is_public=>"[\"Yes\"]", :container_format
=>"[\"bare\"]", :id=>"[\"1ffa10a0-a587-4c21-8af3-e667f6e123fd\"]", :disk_format=>"[\"qcow2\"]"}>

in ruby 2.0.0 and 1.9 if you do a var.to_s operation over an array you'll get a string representation of the array not the contents of the array eg:

$ irb
irb(main):001:0> name = ["cirros"]
=> ["cirros"]
irb(main):002:0> txtvar = name.to_s
=> "[\"cirros\"]"
irb(main):003:0> print txtvar
["cirros"]=> nil

which differs from the ruby 1.8 behaviour in which the to_s operation on an array returns the contents of the array as a string:

$ irb18
irb(main):001:0> name = ["cirros"]
=> ["cirros"]
irb(main):002:0> txtvar = name.to_s
=> "cirros"
irb(main):003:0> print txtvar
cirros=> nil

instead of calling to_s we can the pop function to get the correct value (this also works in ruby 1.8):

irb(main):004:0> txtvar = name.pop
=> "cirros"
irb(main):005:0> print txtvar
cirros=> nil

[1] https://github.com/stackforge/puppet-glance/blob/master/lib/puppet/provider/glance.rb#L129