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

5.5.7 breaks custom function

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Normal
    • Resolution: Fixed
    • PUP 5.5.7
    • PUP 5.5.8
    • None
    • Needs Assessment
    • Deprecation
    • Hide
      A regression was found that was triggered by illegal construct in functions using the legacy (3.x) function API. We decided to revert the change that caused this regression but will raise errors for the illegal constructs in Puppet 6 as they can seriously screw up the system.

      If you have 3.x functions that defines methods inside the function body, or outside of the call to `newfunction` those functions *must* be updated to work with Puppet 6 - preferably to use the modern (4x) function API where it is supported to have additional methods.
      Show
      A regression was found that was triggered by illegal construct in functions using the legacy (3.x) function API. We decided to revert the change that caused this regression but will raise errors for the illegal constructs in Puppet 6 as they can seriously screw up the system. If you have 3.x functions that defines methods inside the function body, or outside of the call to `newfunction` those functions *must* be updated to work with Puppet 6 - preferably to use the modern (4x) function API where it is supported to have additional methods.
    • Needs Assessment

    Description

      Puppet Version: 5.5.7
      Puppet Server Version: 5.3.6
      OS Name/Version: Debian 9

      After upgrading Puppet from 5.5.6 to 5.5.7, certain custom functions do not work anymore. Specifically, camptocamp/accounts has a function strformat which doesn't work anymore.

      The client shows:

      Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, undefined method `strformat' for Scope(Accounts::Authorized_key[stefan-eris-on-root]):Puppet::Parser::Scope (file: /etc/puppetlabs/code/environments/production/modules/accounts/manifests/authorized_key.pp, line: 32, column: 36) (file: /etc/puppetlabs/code/environments/production/modules/accounts/manifests/account.pp, line: 98)
      

      The server log shows:

      ERROR [qtp2035689341-63] [puppetserver] Puppet Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evalu
      ating a Function Call, undefined method `strformat' for Scope(Accounts::Authorized_key[stefan-eris-on-root]):Puppet::Parser::Scope (file: /etc/puppetlabs/code/environmen
      ts/production/modules/accounts/manifests/authorized_key.pp, line: 32, column: 36) (file: /etc/puppetlabs/code/environments/production/modules/accounts/manifests/account.
      pp, line: 98) on node node.example.com
      org/jruby/RubyBasicObject.java:1555:in `method_missing'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/scope.rb:1036:in `method_missing'
      /etc/puppetlabs/code/environments/production/modules/accounts/lib/puppet/parser/functions/strformat.rb:22:in `real_function_strformat'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/functions.rb:174:in `function_strformat'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler.rb:51:in `profile'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/functions.rb:167:in `function_strformat'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/functions.rb:752:in `call'
      org/jruby/RubyKernel.java:1242:in `catch'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/functions.rb:749:in `call'
      /etc/puppetlabs/code/environments/production/modules/accounts/manifests/authorized_key.pp:32:in `call_function'
      org/jruby/RubyKernel.java:1079:in `eval'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/runtime3_support.rb:305:in `call_function'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler.rb:51:in `profile'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/runtime3_support.rb:303:in `call_function'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/evaluator_impl.rb:964:in `call_function_with_block'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/evaluator_impl.rb:933:in `eval_CallNamedFunctionExpression'
      
      

      The code in question reads (abbreviated):

      Puppet::Parser::Functions.newfunction(:strformat, :type => :rvalue) do |args|
        def strformat(format, arg)
          new = format.gsub(/%\{([^%\[\}]+)([^%\}]*)\}/) { eval("arg[$1]#{$2}") }
          (new =~ /%/) ? strformat(new, arg) : new
        end
       
        strformat(args[0], self.to_hash)
      end
      
      

      Attachments

        Issue Links

          Activity

            People

              henrik.lindberg Henrik Lindberg
              seidler Stefan Seidel
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support