glance_image provider fails with puppet >= 3.0

Bug #1199513 reported by François Charlier
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
puppet-glance
Fix Released
High
Ivan Chavero (imcsk8)
Havana
Fix Committed
Undecided
Unassigned

Bug Description

The glance_image provider fails to detect existing images with puppet 3.x (tested with 3.1.1 & 3.2.2) and adds images at each puppet run …

This is the output of "puppet resource …" using puppet 2.7.22

    root@keystone:/etc/puppet/modules/glance# puppet --version
    2.7.22
    root@keystone:/etc/puppet/modules/glance# puppet resource glance_image
    glance_image { 'cirros':
      ensure => 'present',
      container_format => 'bare',
      disk_format => 'qcow2',
      id => '85169467-ba13-47e8-996e-eabef2910739',
      is_public => 'Yes',
    }
    root@keystone:/etc/puppet/modules/glance# puppet resource glance_image cirros
    glance_image { 'cirros':
      ensure => 'present',
      container_format => 'bare',
      disk_format => 'qcow2',
      id => '85169467-ba13-47e8-996e-eabef2910739',
      is_public => 'Yes',
    }

This is the output of "puppet resource …" using puppet 3.2.2

    root@keystone:/etc/puppet/modules/glance# puppet --version
    3.2.2
    root@keystone:/etc/puppet/modules/glance# puppet resource glance_image
    glance_image { '["cirros"]':
      ensure => 'present',
      container_format => '["bare"]',
      disk_format => '["qcow2"]',
      id => '["85169467-ba13-47e8-996e-eabef2910739"]',
      is_public => '["Yes"]',
    }
    root@keystone:/etc/puppet/modules/glance# puppet resource glance_image cirros
    glance_image { 'cirros':
      ensure => 'absent',
    }

Mathieu Gagné (mgagne)
affects: puppet-openstack → puppet-glance
Mathieu Gagné (mgagne)
Changed in puppet-glance:
importance: Undecided → High
status: New → Triaged
Changed in puppet-glance:
assignee: nobody → Ivan Chavero (imcsk8) (ichavero-ichavero)
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

Revision history for this message
Openstack Gerrit (openstack-gerrit) wrote : Fix proposed to puppet-glance (master)

Fix proposed to branch: master
Review: https://review.openstack.org/92015

Changed in puppet-glance:
status: Triaged → In Progress
Revision history for this message
Openstack Gerrit (openstack-gerrit) wrote : Fix merged to puppet-glance (master)

Reviewed: https://review.openstack.org/92015
Committed: https://git.openstack.org/cgit/stackforge/puppet-glance/commit/?id=0adbbcf9f44367cb840c8786b05c35c63d7d2f41
Submitter: Jenkins
Branch: master

commit 0adbbcf9f44367cb840c8786b05c35c63d7d2f41
Author: Ivan Chavero <email address hidden>
Date: Sun May 4 10:14:17 2014 -0600

    Fixes wrong values in get_glance_image_attrs

    The output of the glance show command in get_glance_image_attrs
    does not get properly converted while being added to the
    attrs array.

    Change-Id: Ibe503b24ae3bfa10944537d5deaa068a01eaa5f3
    Closes-Bug: #1199513

Changed in puppet-glance:
status: In Progress → Fix Committed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to puppet-glance (stable/havana)

Fix proposed to branch: stable/havana
Review: https://review.openstack.org/93977

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to puppet-glance (stable/havana)

Reviewed: https://review.openstack.org/93977
Committed: https://git.openstack.org/cgit/stackforge/puppet-glance/commit/?id=15780880b0476e5a80eff0b85268ccd139ac5d46
Submitter: Jenkins
Branch: stable/havana

commit 15780880b0476e5a80eff0b85268ccd139ac5d46
Author: Ivan Chavero <email address hidden>
Date: Sun May 4 10:14:17 2014 -0600

    Fixes wrong values in get_glance_image_attrs

    The output of the glance show command in get_glance_image_attrs
    does not get properly converted while being added to the
    attrs array.

    Change-Id: Ibe503b24ae3bfa10944537d5deaa068a01eaa5f3
    Closes-Bug: #1199513
    (cherry picked from commit 0adbbcf9f44367cb840c8786b05c35c63d7d2f41)

tags: added: in-stable-havana
Mathieu Gagné (mgagne)
Changed in puppet-glance:
milestone: none → 4.0.0
Mathieu Gagné (mgagne)
Changed in puppet-glance:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.