Changes to allowed function calls in Puppet 3.0

133 views
Skip to first unread message

Andy Parker

unread,
Sep 14, 2012, 2:22:55 PM9/14/12
to puppet...@googlegroups.com, puppe...@googlegroups.com
This is a heads up to anyone who has written code that calls custom
functions. We are making a change in Puppet 3.0 that will make the
calls reject incorrect calls (see bug #15756). Calling functions from
ruby code (either other functions or erb templates) was always
supposed to be done by placing all of the arguments in an array and
passing the array to the method call. This was using done by
surrounding the arguments with square brackets.

function_template( [ 'my_template.erb' ] )

Some, but not all, functions had been written in a way that would by
chance work when this was not done. The template function is one such
example. It would work if you were running on a 1.8 ruby if it was
called as:

function_template( 'my_template.erb' )

However, if you tried running on a 1.9 ruby that function call would
fail with an error about not having a method named 'collect' on a
String, which is caused by a change in the String class in ruby. To
prevent these kinds of errors in the future, Puppet 3.0 is going to
check that the arguments are passed in an array and fail if they are
not.

I did a quick check across the code available in the Forge and it
doesn't look like it was too common that this was done wrong, but you
might want to check through your code for calls of functions where the
arguments are not being passed in an array, and change them to use an
array.

NOTE: If you have only ever called custom functions from inside the
Puppet Language, then you don't need to worry about anything, this
does not apply to that.

Thanks,
Andrew Parker
Puppet Team Lead

Alessandro Franceschi

unread,
Sep 14, 2012, 4:55:46 PM9/14/12
to puppe...@googlegroups.com, puppet...@googlegroups.com
Hi Andrew,
thank you for the notice (and thanks to Ken B. for informing me about it).
In my modules I have tons of calls to custom functions in the *arguments* of my classes.
Things like:

class apache (
  $my_class            = params_lookup( 'my_class' ),
  $source              = params_lookup( 'source' ),
  $source_dir          = params_lookup( 'source_dir' ),
[...]

that, I guess, should be something like 

class apache (
  $my_class            = params_lookup( [ 'my_class' ] ),
  $source              = params_lookup( [ 'source' ] ),
  $source_dir          = params_lookup( [ 'source_dir' ]),
[...]

Now, my question is:
you wrote that this "conversion" from string to array is needed when calling custom functions in templates or other functions, but not in Puppet DSL.
Is the conversion required  also for the class/define arguments list (which might be considered somehow a border case)?

Any info is welcomed.

Best regards
Alessandro Franceschi
Example42.com

Nick Lewis

unread,
Sep 14, 2012, 5:02:25 PM9/14/12
to puppe...@googlegroups.com, puppet...@googlegroups.com
On Friday, September 14, 2012 at 1:55 PM, Alessandro Franceschi wrote:
Hi Andrew,
thank you for the notice (and thanks to Ken B. for informing me about it).
In my modules I have tons of calls to custom functions in the *arguments* of my classes.
Things like:

class apache (
  $my_class            = params_lookup( 'my_class' ),
  $source              = params_lookup( 'source' ),
  $source_dir          = params_lookup( 'source_dir' ),
[...]

that, I guess, should be something like 

class apache (
  $my_class            = params_lookup( [ 'my_class' ] ),
  $source              = params_lookup( [ 'source' ] ),
  $source_dir          = params_lookup( [ 'source_dir' ]),
[...]

Now, my question is:
you wrote that this "conversion" from string to array is needed when calling custom functions in templates or other functions, but not in Puppet DSL.
Is the conversion required  also for the class/define arguments list (which might be considered somehow a border case)?

This code doesn't need to change. The reason for this issue in the first place is that Puppet's calling convention for functions is to wrap all the arguments in an array and pass that as a single argument to the corresponding Ruby method. So when calling the Ruby method directly, you need to also wrap your arguments in an array. This is still Puppet code, so it's fine.
 
--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-dev/-/Fbji-OwL4I4J.
To post to this group, send email to puppe...@googlegroups.com.
To unsubscribe from this group, send email to puppet-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

Reply all
Reply to author
Forward
0 new messages