Calling custom functions from functions, parameter weirdness

93 views
Skip to first unread message

ad

unread,
Jun 22, 2012, 11:20:52 AM6/22/12
to puppet...@googlegroups.com
This is on Windows running 2.7.16. I haven't tested on Linux or other versions. I'm still relatively new to Puppet and haven't used custom functions before, so wanted to run this by the list before filing a bug.

When calling custom functions from functions, arguments are being converted to decimal arrays. That is, passing the argument 'bar' from a custom function to another function results in 

arg[0]: 98
arg[1]: 97
arg[2]: 114

Here's a full example in case I'm doing something wrong here.

Function 1:

module Puppet::Parser::Functions
  newfunction(:foo) do |args|
    puts 'args[0]:' + args[0].to_s
    puts 'args.size:' + args.size.to_s
  end
end

Function 2:

module Puppet::Parser::Functions
  newfunction(:foo2) do |args|
    Puppet::Parser::Functions.autoloader.loadall
    function_foo('from_function')
  end
end

A manifest:

foo('from_manifest')
foo2()

Puppet Agent run Result:

args[0]:from_manifest
args.size:1
args[0]:102
args.size:13

13 is the string length of 'from_function', and 102 is the decimal representation of 'f'.

- Adam

ad

unread,
Jun 22, 2012, 12:13:38 PM6/22/12
to puppet...@googlegroups.com
I just tested this on CentOS/Puppet 2.7.12 with the same result.

- Adam 

Josh Cooper

unread,
Jun 22, 2012, 1:01:24 PM6/22/12
to puppet...@googlegroups.com
On Fri, Jun 22, 2012 at 9:13 AM, ad <adam.d...@gmail.com> wrote:
I just tested this on CentOS/Puppet 2.7.12 with the same result.

- Adam 


On Friday, June 22, 2012 10:20:52 AM UTC-5, ad wrote:
This is on Windows running 2.7.16. I haven't tested on Linux or other versions. I'm still relatively new to Puppet and haven't used custom functions before, so wanted to run this by the list before filing a bug.

When calling custom functions from functions, arguments are being converted to decimal arrays. That is, passing the argument 'bar' from a custom function to another function results in 

arg[0]: 98
arg[1]: 97
arg[2]: 114

Here's a full example in case I'm doing something wrong here.

Function 1:

module Puppet::Parser::Functions
  newfunction(:foo) do |args|
    puts 'args[0]:' + args[0].to_s
    puts 'args.size:' + args.size.to_s
  end
end

Function 2:

module Puppet::Parser::Functions
  newfunction(:foo2) do |args|
    Puppet::Parser::Functions.autoloader.loadall
    function_foo('from_function')

Since you are calling foo with a single argument, I believe the args in function foo is a string, not an array. If you instead say `function_foo(['from_function'])`, it should do what function foo expects.

  end
end

A manifest:

foo('from_manifest')
foo2()

Puppet Agent run Result:

args[0]:from_manifest
args.size:1
args[0]:102
args.size:13

13 is the string length of 'from_function', and 102 is the decimal representation of 'f'.

- Adam

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/-eqfuh4NRI0J.

To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

--
Josh Cooper
Developer, Puppet Labs

ad

unread,
Jun 22, 2012, 1:53:55 PM6/22/12
to puppet...@googlegroups.com
Josh,

I appreciate the help. Using function_foo(['bar']) rather than function_foo('bar') works as expected. I'm sure this will also solve the same issue I was having calling a custom function from a Ruby DSL defined type.

Cheers,

Adam
To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Krzysztof Wilczynski

unread,
Jun 25, 2012, 6:06:03 AM6/25/12
to puppet...@googlegroups.com
Hi,

Ruby DSL and templates (via e.g. inline_template) would have the same problem, unless this was handled properly on the function's side.

KW
Reply all
Reply to author
Forward
0 new messages