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

meaning of Integer[0] different in a ruby function

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: PUP 4.2.0
    • Fix Version/s: PUP 3.8.2, PUP 4.2.1
    • Component/s: Language
    • Labels:
      None
    • Template:
    • Story Points:
      1
    • Sprint:
      Language 2015-07-22
    • Release Notes:
      Bug Fix

      Description

      Update


      Th 4.x function API created types that were more restrictive for Integer and Float than the corresponding expressions in the puppet language.
      When using Integer[1], the expectation was that this produces the type Integer[1, default], but it produced Integer[1,1]. The handling of
      Float had the same problem.

      After the fix, the types in the 4.x function API behaves as documented for the Puppet Language.

      Original


      Hi,

      According to the documentation,

      Integer[0]
      

      matches any integer greater than or equal to 0. But the behavior is different in a ruby function. Here is the content of the ruby function f.rb in a test puppet module :

      # The function is in <module-root>/test/lib/puppet/functions/test/f.rb
      Puppet::Functions.create_function(:'test::f') do
       
        dispatch :f do
          required_param 'Integer[0]', :n
        end
       
        def f(n)
          true
        end
       
      end
      

      Then, if I try to call the function in a puppet class like this:

      class test {
       
        test::f(10)
       
      }
      

      I have this error:

      root@puppet4:~# puppet agent --test
      Info: Retrieving pluginfacts
      Info: Retrieving plugin
      Info: Loading facts
      Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Function Call, function 'test::f' called with mis-matched arguments
      expected:
        test::f(Integer[0, 0] n) - arg count {1}
      actual:
        test::f(Integer) - arg count {1} at /etc/puppetlabs/code/environments/production/modules/test/manifests/init.pp:12:3 on node puppet4.athome.priv
      Warning: Not using cache on failed catalog
      Error: Could not retrieve catalog; skipping run
      

      In ruby function, it seems that:

      Integer[0] <=> Integer[0, 0]
      

      It isn't a big problem because there is a workaround with:

      Puppet::Functions.create_function(:'test::f') do
       
        dispatch :f do
          #required_param 'Integer[0]', :n
          required_param 'Integer[0, default]', :n
        end
       
        def f(n)
          true
        end
       
      end
      

      However it seems to me that there is a little inconsistency.
      Regards.

        Attachments

          Activity

            jsd-sla-details-panel

              People

              • Assignee:
                john.duarte John Duarte
                Reporter:
                flaf Francois Lafont
                QA Contact:
                John Duarte
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: