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

ClassInformationService.classes_per_environment errantly evaluates parameter default expression

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: PUP 4.2.0
    • Fix Version/s: PUP 4.4.0
    • Component/s: None
    • Labels:
      None
    • Template:
    • Story Points:
      1
    • Sprint:
      Language 2016-01-27, Language 2016-02-10
    • Release Notes:
      Not Needed
    • Release Notes Summary:
      This is part of an enabling service used by puppet server/NC.

      Description

      In doing some testing against the Puppet::InfoService::ClassInformationService.classes_per_environment() method, I found that the value for :default_source apparently tries to evaluate the expression that it needs to return for a class parameter's default value rather than just retaining the original expression verbatim from the Puppet manifest .pp file, passing that back as a String.

      For example, I used a Puppet class with the following content...

      class myclass (String $string_with_expression_default = "for os in family $::osfamily")
      {
      }
      

      ... and used the following code to try to parse it ...

      require 'puppet'
      require 'puppet/info_service'
       
      files_to_parse = { "production" => [ "./parse.pp" ] }
       
      puts Puppet::InfoService::ClassInformationService.new.classes_per_environment(files_to_parse)
      

      I was expecting to get something back like this in stdout:

      {"production"=>{"./parse.pp"=>[{:name=>"myclass", :params=>[{:name=>"string_with_expression_default", :type=>"String", :default_literal=>"\"for os in family $::osfamily\""}]}]}}
      

      Instead, though, I got this:

      {"production"=>{"./parse.pp"=>{:error=>"undefined method `<' for nil:NilClass"}}}
      

      If I omit the $ from the default value, just "for os in family ::osfamily" instead, then I get more reasonable looking output:

      {"production"=>{"./parse.pp"=>[{:name=>"myclass", :params=>[{:name=>"string_with_expression_default", :type=>"String", :default_literal=>"for os in family ::osfamily"}]}]}}
      

      At least at doesn't error out. But in this case, the string doesn't have the surrounding double-quotes escaped in the value - so there would be no difference between wrapping the value in single-quotes vs. double-quotes, for example.

        Attachments

          Issue Links

            Activity

              jsd-sla-details-panel

                People

                • Assignee:
                  Unassigned
                  Reporter:
                  jeremy.barlow Jeremy Barlow
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  6 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:

                    Zendesk Support