Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-5302

composite namevars not taken into account in prefetch

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Accepted
    • Priority: Normal
    • Resolution: Unresolved
    • Affects Version/s: PUP 3.8.2
    • Fix Version/s: None
    • Component/s: Types and Providers
    • Environment:

      Ubuntu 14.04

    • Template:
    • Team:
      Coremunity

      Description

      Given I create a type Keystone_tenant with composite namevar. Specifically, name and domain are isnamevar parameters.

      In the provider I use self.prefetch to find existing resources relative to the catalogue.

      In the manifest I have this :

       keystone_tenant { 'meaningless_title_one': 
          name => 'project_less',
          domain => 'domain_one', 
          ensure => present
      }
       keystone_tenant { 'meaningless_title_two': 
          name => 'project_less',
          domain => 'domain_two',
          ensure => present 
      }
      

      Then in self.prefetch, puppet is passing me this vision of the relevant part of the catalogue:

        {"project_less"=>Keystone_tenant[meaningless_title_two]}
      

      As you can see, one of the two resources has disappeared from the catalogue. When I run the manifest twice I got a error as puppet try to recreate meaningless_title_one, because I hadn't have a chance to associate it with an existing provider.

      The problem is in def resources_by_provider(type_name, provider_name) in lib/puppet/transaction.rb. The code wrongly assumes that the name is the unique key of the resource, which is not the case when using composite namevar.

      For reference, I came up with this solution in my prefetch:

          catalog = resources.values.first.catalog
       
          keystone_tenants = catalog.resources.find_all do |e|
            e.class.to_s == 'Puppet::Type::Keystone_tenant'
          end
       
          # hash catalog resource by uniq key
          keystone_tenants_keys = Hash[keystone_tenants.map(&:uniqueness_key).
                                       zip(keystone_tenants)]
      

      The last line creates a unique key suitable for composite namevar. keystone_tenants_keys is the structure I traverse to associate catalogue resource with provider. The whole code is there

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            sofer Sofer Athlan-Guyot
            QA Contact:
            Eric Thompson
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:

                Zendesk Support