[PUP-9477] Unable to use call() on custom functions Created: 2019/02/06  Updated: 2019/02/20  Resolved: 2019/02/14

Status: Closed
Project: Puppet
Component/s: Functions
Affects Version/s: PUP 5.5.0, PUP 6.2.0
Fix Version/s: PUP 5.5.12, PUP 6.0.7, PUP 6.3.0

Type: Bug Priority: Normal
Reporter: Jan Vansteenkiste Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: resolved-issue-added
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template: PUP Bug Template
Sub-team: Language
Team: Froyo
Sprint: Platform Core KANBAN
Method Found: Needs Assessment
Release Notes: Bug Fix
Release Notes Summary: The `call()` function was only able to call functions in puppet core. This is now fixed so that any function in the environment is visible and can be called.
QA Risk Assessment: Needs Assessment

 Description   

Using custom functions, I'm unable to call them using the call() function.

Test case:
modules/call_me/functions/pfunction.pp

function call_me::pfunction(
 Optional[String] $args = undef
) {
 "returned from pfunction"
}

test.pp;

  $message = call_me::pfunction()
  notify {'direct function call': message => $message, }
 
 
  $deferred = Deferred('call_me::pfunction')
  $message3 = $deferred.call()
  notify {'deferred, function name hardcoded': message => $message3, }  
 
 
  $function_name = 'call_me::pfunction'
  $deferred2 = Deferred($function_name)
  $message4 = $deferred2.call()
  notify {'deferred, function name in variable': message => $message4, }

output:

 Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for cyberflox.irken.org
Info: Applying configuration version '1549449374'
Notice: returned from pfunction
Notice: /Stage[main]/Main/Node[default]/Notify[direct function call]/message: defined 'message' as 'returned from pfunction'
Notice: returned from pfunction
Notice: /Stage[main]/Main/Node[default]/Notify[deferred, function name hardcoded]/message: defined 'message' as 'returned from pfunction'
Notice: returned from pfunction
Notice: /Stage[main]/Main/Node[default]/Notify[deferred, function name in variable]/message: defined 'message' as 'returned from pfunction'
Notice: Applied catalog in 0.02 seconds

code that fails:

# THIS BLOCK FAILS
$message2 = call('call_me::pfunction')
notify{'call(call_me::pfunction)': message => $message2, }

output:

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, Function call(): Unknown function: 'call_me::pfunction' (file: /etc/puppetlabs/code/environments/production/manifests/site.pp, line: 9, column: 15) on node cyberflox.irken.org
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run



 Comments   
Comment by Henrik Lindberg [ 2019/02/06 ]

This simple snippet replicates the problem.

function pfunction() {
  "from pfunction"
}
 
$message = pfunction()
  notify {$message: }
$message2 = call('pfunction')
notify{$message2: }

The `call` version fails with an error that it cannot find the function.

Comment by Henrik Lindberg [ 2019/02/06 ]

Note that `Deferred` cannot be used agent side with functions written in the puppet language since they are not plugin synced.

Comment by Henrik Lindberg [ 2019/02/11 ]

Merged to 5.5.x at 6316287

Comment by Casey Williams [ 2019/02/14 ]

This has passed nightly CI for puppet-agent#master, so I'm marking it as fixed

Generated at Thu Aug 06 15:18:37 PDT 2020 using Jira 8.5.2#805002-sha1:a66f9354b9e12ac788984e5d84669c903a370049.