Issue #10934 has been reported by James Turnbull.

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

Author: James Turnbull
Status: Needs Decision
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