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

Puppet is inconsistent about :libdir setting when multiple paths provided

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: PUP 3.3.3, PUP 3.6.2, PUP 3.7.1
    • Fix Version/s: PUP 4.0.0
    • Component/s: None
    • Labels:
    • Environment:

      Puppet gem
      Rspec-puppet

    • Template:
    • Story Points:
      1
    • Sprint:
      Client 2015-02-04

      Description

      When attempting to rspec-puppet test one of my profiles modules, that has multiple module dependencies, an issue was identified whereby it wasn't auto-loading module fixture lib dirs.

      Example error that was seeing was:

      Error: Could not autoload puppet/provider/domain/asadmin: cannot load such file -- puppet/provider/asadmin
      Error: Could not autoload puppet/type/domain: Could not autoload puppet/provider/domain/asadmin: cannot load such file -- puppet/provider/asadmin
      Error: Could not autoload puppet/type/domain: Could not autoload puppet/provider/domain/asadmin: cannot load such file -- puppet/provider/asadmin on node scratch.dt0388.test
      

      Thanks to _rc on IRC, was able to track the issue down to the Ruby LOAD_PATH not being set correctly:

      /home/vagrant/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/x86_64-linux
      /home/vagrant/.rvm/gems/ruby-1.9.3-p547@depend-test/gems/puppet-3.7.1/lib/puppet/vendor/safe_yaml/lib
      /home/vagrant/.rvm/gems/ruby-1.9.3-p547@depend-test/gems/puppet-3.7.1/lib/puppet/vendor/rgen/lib
      /home/vagrant/.rvm/gems/ruby-1.9.3-p547@depend-test/gems/puppet-3.7.1/lib/puppet/vendor/semantic/lib
      /home/vagrant/.rvm/gems/ruby-1.9.3-p547@depend-test/gems/puppet-3.7.1/lib/puppet/vendor/pathspec/lib
      /home/vagrant/puppet-modules/rspec-deptest/spec/fixtures/modules/glassfish/lib:/home/vagrant/puppet-modules/rspec-deptest/spec/fixtures/modules/stdlib/lib
      

      The last line above is being set by rspec-puppet in: https://github.com/rodjek/rspec-puppet/blob/master/lib/rspec-puppet/support.rb#L140, using `File::PATH_SEPARATOR` to convert the array into a string to set as :libdir.

      This then lead to: https://github.com/puppetlabs/puppet/blob/master/lib/puppet/defaults.rb#L223-L237, which is setting the LOAD_PATH to the value passed in as :libdir, without checking if the value should be split back into an array based on `File::PATH_SEPARATOR`.

      However elsewhere in the Puppet code, the libdir value is correctly being split: https://github.com/puppetlabs/puppet/blob/master/lib/puppet/util/autoload.rb#L145-L153

      A rather hacky work-around was to modify my spec_helper.rb, and add:

      diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
      index 8b91323..be8e080 100644
      --- a/spec/spec_helper.rb
      +++ b/spec/spec_helper.rb
      @@ -3,6 +3,8 @@ require 'puppetlabs_spec_helper/module_spec_helper'
       require 'hiera'
       require 'rspec-puppet'
       
      +$: << "spec/fixtures/modules/glassfish/lib"
      +
       RSpec.configure do |c|
         c.hiera_config = 'spec/fixtures/hiera/hiera.yaml'
         c.manifest_dir = 'spec/fixtures/manifests'
      

      That results in the LOAD_PATH including the glassfish/lib folder, and Ruby being able to load `puppet/provider/asadmin`.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              fatmcgav Gavin Williams
              QA Contact:
              Eric Thompson Eric Thompson
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Zendesk Support