Issue #10934 has been updated by Nigel Kersten.

Status changed from Needs Decision to Rejected

The function supports two arguments, and there is a difference between a single 
argument that is an array, and two individual arguments.

We've had problems in the past where we've tried to support both individual 
arguments and an array that contains those arguments, and we're not going to 
head down that path again. 

The fact that it works in 1.8.7 isn't intentional (as evident by the warning)

You need to dereference the array elements as `$versions[0]` and `$versions[1]`.


----------------------------------------
Bug #10934: versioncmp input parameters inconsistent
https://projects.puppetlabs.com/issues/10934

Author: James Turnbull
Status: Rejected
Priority: High
Assignee: Nigel Kersten
Category: functions
Target version: 
Affected Puppet version: 
Keywords: versioncmp
Branch: 


<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