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

4x function API's call_function cannot call a 3x function

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: PUP 3.7.5
    • Component/s: DSL, Server
    • Labels:
      None
    • Template:
    • Story Points:
      2
    • Sprint:
      Language 2015-01-21, Language 2015-02-04

      Description

      The 4x API exposes a method called "call_function" that a 4x function can use to call other functions.

      This is however currently restricted to only work for 4x functions as the function is loaded using the loaders subsystem, and this subsystem is not used to load 3x functions.

      We can either change the use of the loaders for 3x functions, or add handling in the call_function to perform lookup of a 3x function the "old way" if it is not found in the new loaders subsystem.

        Attachments

          Issue Links

            Activity

            Hide
            henrik.lindberg Henrik Lindberg added a comment -

            Moved to 3.7.5 / 4.0.0 since this will not make it in time for 3.7.4

            Show
            henrik.lindberg Henrik Lindberg added a comment - Moved to 3.7.5 / 4.0.0 since this will not make it in time for 3.7.4
            Hide
            thomas.hallgren Thomas Hallgren added a comment -

            PR-3501 (based on stable) replaces PR-3495

            Show
            thomas.hallgren Thomas Hallgren added a comment - PR-3501 (based on stable) replaces PR-3495
            Hide
            henrik.lindberg Henrik Lindberg added a comment -

            Merged to stable at: 8c1a589

            Show
            henrik.lindberg Henrik Lindberg added a comment - Merged to stable at: 8c1a589
            Hide
            henrik.lindberg Henrik Lindberg added a comment -

            And the merge from stable to master did not apply cleanly and too much to figure out for 3.7.4 - The above merged was reverted at https://github.com/puppetlabs/puppet/commit/5818ce69f5205f4022f5a7641c35c75cdd9173df

            Show
            henrik.lindberg Henrik Lindberg added a comment - And the merge from stable to master did not apply cleanly and too much to figure out for 3.7.4 - The above merged was reverted at https://github.com/puppetlabs/puppet/commit/5818ce69f5205f4022f5a7641c35c75cdd9173df
            Hide
            thomas.hallgren Thomas Hallgren added a comment -

            PR-3504 replaces PR-3501. This new PR is based on stable but has been tested locally as merged to both stable and master.

            Show
            thomas.hallgren Thomas Hallgren added a comment - PR-3504 replaces PR-3501. This new PR is based on stable but has been tested locally as merged to both stable and master.
            Hide
            henrik.lindberg Henrik Lindberg added a comment - - edited

            Marked as blocked because this has to wait on release of 3.7.4 - it should then be ready to merge (it has been reviewed and tested to work against stable and master).

            Show
            henrik.lindberg Henrik Lindberg added a comment - - edited Marked as blocked because this has to wait on release of 3.7.4 - it should then be ready to merge (it has been reviewed and tested to work against stable and master).
            Hide
            henrik.lindberg Henrik Lindberg added a comment -

            unblocked, 3.7.4 is tagged

            Show
            henrik.lindberg Henrik Lindberg added a comment - unblocked, 3.7.4 is tagged
            Hide
            thomas.hallgren Thomas Hallgren added a comment -

            merged tp stable at d75d563 and to master at af02828.

            Show
            thomas.hallgren Thomas Hallgren added a comment - merged tp stable at d75d563 and to master at af02828.
            Hide
            erict Eric Thompson added a comment -

            Henrik Lindberg testing with puppet4 function:

            [root@frzs6yw1xy1ayzs functions]# puppet apply -e 'notice(test_call_function(4))'
            Error: Evaluation Error: Error while evaluating a Function Call, undefined method `max' for #<#<Class:0x00000004c9f230>:0x00000004c9eb78> at line 1:8 on node frzs6yw1xy1ayzs.delivery.puppetlabs.net
            Error: Evaluation Error: Error while evaluating a Function Call, undefined method `max' for #<#<Class:0x00000004c9f230>:0x00000004c9eb78> at line 1:8 on node frzs6yw1xy1ayzs.delivery.puppetlabs.net
            [root@frzs6yw1xy1ayzs functions]# ls
            assert_type.rb  each.rb  epp.rb  filter.rb  import.rb  inline_epp.rb  map.rb  match.rb  max.rb  reduce.rb  scanf.rb  slice.rb  test_call_function.rb  with.rb
            [root@frzs6yw1xy1ayzs functions]# puppet apply -e 'notice(max(4,5))'
            Notice: Scope(Class[main]): 5
            Notice: Compiled catalog for frzs6yw1xy1ayzs.delivery.puppetlabs.net in environment production in 0.34 seconds
            Notice: Applied catalog in 0.01 seconds
            [root@frzs6yw1xy1ayzs functions]# cat test_call_function.rb
            Puppet::Functions.create_function(:test_call_function) do
              def test_call_function(a)
                call_function(max(a,10))
              end
            end
            

            should call_function be able to call a puppet4 function?
            putting all my puppet4 functions here: /usr/local/share/ruby/site_ruby/puppet/functions
            but i also put a copy of max.rb in /lib/puppet/functions/ which i had to create...

            Show
            erict Eric Thompson added a comment - Henrik Lindberg testing with puppet4 function: [root@frzs6yw1xy1ayzs functions]# puppet apply -e 'notice(test_call_function(4))' Error: Evaluation Error: Error while evaluating a Function Call, undefined method `max' for #<#<Class:0x00000004c9f230>:0x00000004c9eb78> at line 1:8 on node frzs6yw1xy1ayzs.delivery.puppetlabs.net Error: Evaluation Error: Error while evaluating a Function Call, undefined method `max' for #<#<Class:0x00000004c9f230>:0x00000004c9eb78> at line 1:8 on node frzs6yw1xy1ayzs.delivery.puppetlabs.net [root@frzs6yw1xy1ayzs functions]# ls assert_type.rb each.rb epp.rb filter.rb import.rb inline_epp.rb map.rb match.rb max.rb reduce.rb scanf.rb slice.rb test_call_function.rb with.rb [root@frzs6yw1xy1ayzs functions]# puppet apply -e 'notice(max(4,5))' Notice: Scope(Class[main]): 5 Notice: Compiled catalog for frzs6yw1xy1ayzs.delivery.puppetlabs.net in environment production in 0.34 seconds Notice: Applied catalog in 0.01 seconds [root@frzs6yw1xy1ayzs functions]# cat test_call_function.rb Puppet::Functions.create_function(:test_call_function) do def test_call_function(a) call_function(max(a,10)) end end should call_function be able to call a puppet4 function? putting all my puppet4 functions here: /usr/local/share/ruby/site_ruby/puppet/functions but i also put a copy of max.rb in /lib/puppet/functions/ which i had to create...
            Hide
            henrik.lindberg Henrik Lindberg added a comment -

            4x functions are under lib/puppet/functions/ in an environment or a module - you cannot stick them in any other directory (although you can have them in puppet itself for those that we ship). If functions are namespaced they go in a sub directory - e.g. mymodule::max() function goes into <mymodule>/lib/puppet/functions/mymodule/max.rb,

            Then, when you use call_function you give it the name of the function (a string), and additional arguments - i.e.:

            Puppet::Functions.create_function(:test_call_function) do
              def test_call_function(a)
                call_function('max', a, 10)
              end
            end
            

            Does that help?

            Show
            henrik.lindberg Henrik Lindberg added a comment - 4x functions are under lib/puppet/functions/ in an environment or a module - you cannot stick them in any other directory (although you can have them in puppet itself for those that we ship). If functions are namespaced they go in a sub directory - e.g. mymodule::max() function goes into <mymodule>/lib/puppet/functions/mymodule/max.rb , Then, when you use call_function you give it the name of the function (a string), and additional arguments - i.e.: Puppet::Functions.create_function(:test_call_function) do def test_call_function(a) call_function('max', a, 10) end end Does that help?
            Hide
            henrik.lindberg Henrik Lindberg added a comment -

            And the problem was, that if max() was defined using 3x, it could not be called with call_function. After the fix it should be possible.

            Show
            henrik.lindberg Henrik Lindberg added a comment - And the problem was, that if max() was defined using 3x, it could not be called with call_function. After the fix it should be possible.
            Hide
            erict Eric Thompson added a comment - - edited

            that makes complete sense, and i'm glad it still mirrors the installed puppet's function dirs. I should have been able to figure that out!
            will take another look in the am

            FYI, your blog says "Also different is that functions are now stored under /lib/puppet/functions instead of under the terribly confusing /lib/puppet/parser/functions in 3x".
            http://puppet-on-the-edge.blogspot.com/2015/01/the-puppet-4x-function-api.html

            Show
            erict Eric Thompson added a comment - - edited that makes complete sense, and i'm glad it still mirrors the installed puppet's function dirs. I should have been able to figure that out! will take another look in the am FYI, your blog says "Also different is that functions are now stored under /lib/puppet/functions instead of under the terribly confusing /lib/puppet/parser/functions in 3x". http://puppet-on-the-edge.blogspot.com/2015/01/the-puppet-4x-function-api.html
            Hide
            henrik.lindberg Henrik Lindberg added a comment -

            What is confusing about the paths mentioned in the blog post? That they are absolute paths? How can this be explained better?

            Show
            henrik.lindberg Henrik Lindberg added a comment - What is confusing about the paths mentioned in the blog post? That they are absolute paths? How can this be explained better?
            Hide
            erict Eric Thompson added a comment - - edited

            yeah, the absolute paths were confusing to me.
            with Henrik's help i verified on rhel7 at SHA: 0f551b3 with:

            [root@eq8ntygsty42ut3 mymodule]# pwd
            /etc/puppet/environments/production/modules/mymodule
            [root@eq8ntygsty42ut3 mymodule]# tree
            .
            └── lib
                └── puppet
                    ├── functions
                    │   ├── puts_useless4.rb
                    │   ├── test_call_function3.rb
                    │   └── test_call_function4.rb
                    └── parser
                        └── functions
                            └── puts_useless3.rb
             
            5 directories, 4 files
            [root@eq8ntygsty42ut3 mymodule]# cat lib/puppet/functions/puts_useless4.rb
            Puppet::Functions.create_function(:puts_useless4) do
              def puts_useless4(y)
                puts "in puppet4 function: #{y}"
              end
            end
            [root@eq8ntygsty42ut3 mymodule]# cat lib/puppet/functions/test_call_function4.rb
            Puppet::Functions.create_function(:test_call_function4) do
              def test_call_function4(a)
                # puppet 4x function
                call_function('puts_useless4', a)
              end
            end
            [root@eq8ntygsty42ut3 mymodule]# cat lib/puppet/functions/test_call_function3.rb
            Puppet::Functions.create_function(:test_call_function3) do
              def test_call_function3(a)
                # puppet 3x function
                call_function('puts_useless3', a)
              end
            end
            [root@eq8ntygsty42ut3 mymodule]# cat lib/puppet/parser/functions/puts_useless3.rb
            module Puppet::Parser::Functions
              newfunction(:puts_useless3) do |args|
                puts "in a puppet3 function: #{args[0]}"
              end
            end
            [root@eq8ntygsty42ut3 mymodule]# puppet apply -e 'notice(test_call_function4("yargh"))'
            in puppet4 function: yargh
            Notice: Scope(Class[main]):
            Notice: Compiled catalog for eq8ntygsty42ut3.delivery.puppetlabs.net in environment production in 0.39 seconds
            Notice: Applied catalog in 0.01 seconds
            [root@eq8ntygsty42ut3 mymodule]# puppet apply -e 'notice(test_call_function3("yargh"))'
            in a puppet3 function: yargh
            Notice: Scope(Class[main]):
            Notice: Compiled catalog for eq8ntygsty42ut3.delivery.puppetlabs.net in environment production in 0.39 seconds
            Notice: Applied catalog in 0.01 seconds
            

            Show
            erict Eric Thompson added a comment - - edited yeah, the absolute paths were confusing to me. with Henrik's help i verified on rhel7 at SHA: 0f551b3 with: [root@eq8ntygsty42ut3 mymodule]# pwd /etc/puppet/environments/production/modules/mymodule [root@eq8ntygsty42ut3 mymodule]# tree . └── lib └── puppet ├── functions │   ├── puts_useless4.rb │   ├── test_call_function3.rb │   └── test_call_function4.rb └── parser └── functions └── puts_useless3.rb   5 directories, 4 files [root@eq8ntygsty42ut3 mymodule]# cat lib/puppet/functions/puts_useless4.rb Puppet::Functions.create_function(:puts_useless4) do def puts_useless4(y) puts "in puppet4 function: #{y}" end end [root@eq8ntygsty42ut3 mymodule]# cat lib/puppet/functions/test_call_function4.rb Puppet::Functions.create_function(:test_call_function4) do def test_call_function4(a) # puppet 4x function call_function('puts_useless4', a) end end [root@eq8ntygsty42ut3 mymodule]# cat lib/puppet/functions/test_call_function3.rb Puppet::Functions.create_function(:test_call_function3) do def test_call_function3(a) # puppet 3x function call_function('puts_useless3', a) end end [root@eq8ntygsty42ut3 mymodule]# cat lib/puppet/parser/functions/puts_useless3.rb module Puppet::Parser::Functions newfunction(:puts_useless3) do |args| puts "in a puppet3 function: #{args[0]}" end end [root@eq8ntygsty42ut3 mymodule]# puppet apply -e 'notice(test_call_function4("yargh"))' in puppet4 function: yargh Notice: Scope(Class[main]): Notice: Compiled catalog for eq8ntygsty42ut3.delivery.puppetlabs.net in environment production in 0.39 seconds Notice: Applied catalog in 0.01 seconds [root@eq8ntygsty42ut3 mymodule]# puppet apply -e 'notice(test_call_function3("yargh"))' in a puppet3 function: yargh Notice: Scope(Class[main]): Notice: Compiled catalog for eq8ntygsty42ut3.delivery.puppetlabs.net in environment production in 0.39 seconds Notice: Applied catalog in 0.01 seconds
            Hide
            erict Eric Thompson added a comment -

            verified on ubuntu14.04 at SHA: 0f551b3 with:

            root@gchhjqakb4s5ewj:/etc/puppet/environments/production/modules/mymodule/lib/puppet#  puppet apply -e 'notice(test_call_function4("yargh"))'
            in puppet4 function: yargh
            Notice: Scope(Class[main]):
            Notice: Compiled catalog for gchhjqakb4s5ewj.delivery.puppetlabs.net in environment production in 0.41 seconds
            Notice: Applied catalog in 0.02 seconds
             
            root@gchhjqakb4s5ewj:/etc/puppet/environments/production/modules/mymodule/lib/puppet# puppet apply -e 'notice(test_call_function3("yargh"))'
            in a puppet3 function: yargh
            Notice: Scope(Class[main]):
            Notice: Compiled catalog for gchhjqakb4s5ewj.delivery.puppetlabs.net in environment production in 0.40 seconds
            Notice: Applied catalog in 0.02 seconds
            

            Show
            erict Eric Thompson added a comment - verified on ubuntu14.04 at SHA: 0f551b3 with: root@gchhjqakb4s5ewj:/etc/puppet/environments/production/modules/mymodule/lib/puppet# puppet apply -e 'notice(test_call_function4("yargh"))' in puppet4 function: yargh Notice: Scope(Class[main]): Notice: Compiled catalog for gchhjqakb4s5ewj.delivery.puppetlabs.net in environment production in 0.41 seconds Notice: Applied catalog in 0.02 seconds   root@gchhjqakb4s5ewj:/etc/puppet/environments/production/modules/mymodule/lib/puppet# puppet apply -e 'notice(test_call_function3("yargh"))' in a puppet3 function: yargh Notice: Scope(Class[main]): Notice: Compiled catalog for gchhjqakb4s5ewj.delivery.puppetlabs.net in environment production in 0.40 seconds Notice: Applied catalog in 0.02 seconds
            Hide
            erict Eric Thompson added a comment -

            verified on win2012r2-r64 at SHA: 0f551b3 with:

            Administrator@t3knzdzax62xizd /cygdrive/c/ProgramData/PuppetLabs/puppet/etc/environments/production/modules/mymodule/lib/puppet
            $ cmd /c puppet apply -e 'notice(test_call_function4("yargh"))'
            in puppet4 function: yargh
            Notice: Scope(Class[main]):
            Notice: Compiled catalog for t3knzdzax62xizd.delivery.puppetlabs.net in environment production in 0.48 seconds
            Notice: Applied catalog in 0.02 seconds
             
            Administrator@t3knzdzax62xizd /cygdrive/c/ProgramData/PuppetLabs/puppet/etc/environments/production/modules/mymodule/lib/puppet
            $ cmd /c puppet apply -e 'notice(test_call_function3("yargh"))'
            in a puppet3 function: yargh
            Notice: Scope(Class[main]):
            Notice: Compiled catalog for t3knzdzax62xizd.delivery.puppetlabs.net in environment production in 0.50 seconds
            Notice: Applied catalog in 0.02 seconds
            

            Show
            erict Eric Thompson added a comment - verified on win2012r2-r64 at SHA: 0f551b3 with: Administrator@t3knzdzax62xizd /cygdrive/c/ProgramData/PuppetLabs/puppet/etc/environments/production/modules/mymodule/lib/puppet $ cmd /c puppet apply -e 'notice(test_call_function4("yargh"))' in puppet4 function: yargh Notice: Scope(Class[main]): Notice: Compiled catalog for t3knzdzax62xizd.delivery.puppetlabs.net in environment production in 0.48 seconds Notice: Applied catalog in 0.02 seconds   Administrator@t3knzdzax62xizd /cygdrive/c/ProgramData/PuppetLabs/puppet/etc/environments/production/modules/mymodule/lib/puppet $ cmd /c puppet apply -e 'notice(test_call_function3("yargh"))' in a puppet3 function: yargh Notice: Scope(Class[main]): Notice: Compiled catalog for t3knzdzax62xizd.delivery.puppetlabs.net in environment production in 0.50 seconds Notice: Applied catalog in 0.02 seconds
            Hide
            dalen Erik Dalén added a comment -
            Show
            dalen Erik Dalén added a comment - It seems like this new syntax is still undocumented: https://docs.puppet.com/puppet/latest/reference/lang_template_erb.html#calling-puppet-functions-from-templates
            Hide
            henrik.lindberg Henrik Lindberg added a comment -

            Erik Dalén There is a doc ticket in flight right now to deal with the 4.x function API not being covered in documentation.
            Ping Jorie Tappa.

            Show
            henrik.lindberg Henrik Lindberg added a comment - Erik Dalén There is a doc ticket in flight right now to deal with the 4.x function API not being covered in documentation. Ping Jorie Tappa .

              People

              • Assignee:
                Unassigned
                Reporter:
                henrik.lindberg Henrik Lindberg
                QA Contact:
                Eric Thompson
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Zendesk Support