Issue #10934 has been updated by Nigel Kersten.

Subject changed from versioncmp input parameters inconsistent to versioncmp 
called as a function in a template should accept multiple arguments, not an 
array.
Description updated
Status changed from Rejected to Accepted
Assignee deleted (Nigel Kersten)
Priority changed from High to Normal
Target version set to Telly


----------------------------------------
Bug #10934: versioncmp called as a function in a template should accept 
multiple arguments, not an array.
https://projects.puppetlabs.com/issues/10934

Author: James Turnbull
Status: Accepted
Priority: Normal
Assignee: 
Category: functions
Target version: Telly
Affected Puppet version: 
Keywords: versioncmp
Branch: 


Nigel: It's possible this is a wider problem with all functions in templates, 
but it's been observed here at least.

The primary point is that in a template we should have the function work 
exactly the same way as it does in the DSL, with multiple arguments, and not an 
array.

This should work without warnings in Ruby 1.8.x and 1.9.x

<hr>

<pre>
$version1="1.2.3" 
$version2="2.0" 
if versioncmp($version1,$version2) > 0 { 
notify{"${version1} > ${version2}": } 
} else { 
notify{"${version1} <= ${version2}": } 
}
</pre>

Works nicely.. Unfortunately it doesn't want to work with arrays:

<pre>
$version1="1.2.3" 
$version2="2.0" 
$versions=[ $version1, $version2 ] 
if versioncmp($versions) > 0 { 
notify{"${version1} > ${version2}": } 
} else { 
notify{"${version1} <= ${version2}": } 
}
</pre>

as it errors out with "versioncmp should have 2 arguments".

Now we try to do the same in templates..

<pre>
$version1="1.2.3" 
$version2="2.0" 
$versions=[ $version1, $version2 ] 
$out=inline_template('<%= (scope.function_versioncmp(version1,version2)>0) ? 
"#{version1} > #{version2}" : "#{version1} <= #{version2}" %>') 
notify { $out: }
</pre>

works nicely with REE 1.8.7 although produces the following warning: 
"/usr/local/ree/lib/ruby/site_ruby/1.8/puppet/parser/functions/versioncmp.rb:30:
 warning: multiple values for a block parameter (2 for 1) from 
/usr/local/ree/lib/ruby/site_ruby/1.8/puppet/parser/scope.rb:428". 
Unfortunately with Ruby 1.9 this warning becomes an error:

<pre>
Error 400 on SERVER: Failed to parse inline template: wrong number of arguments 
(2 for 1). 
Using the following recipe gets rid of warning and makes REE 1.8.7 and Ruby 1.9 
happy:
</pre>

<pre>
$version1="1.2.3" 
$version2="2.0" 
$versions=[ $version1, $version2 ] 
$out=inline_template('<%= (scope.function_versioncmp(versions)>0) ? 
"#{version1} > #{version2}" : "#{version1} <= #{version2}" %>') 
notify { $out: }
</pre>


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to