Bug #2110
versioncmp broken
| Status: | Closed | Start: | 03/25/2009 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 100% |
||
| Category: | functions | |||
| Target version: | 0.25.0 | |||
| Affected version: | 0.24.8 | Branch: | ||
| Keywords: | ||||
| Votes: | 0 |
Description
hello,
the versioncmp function in 0.24.8 is broken:
Puppet::Parser::Functions::newfunction(:versioncmp, :doc => "Compares two versions.") do |args|return Puppet::Util::Package.versioncmp(args[0], args[1]) end
clearly the function is supposed to return a value, however the newfunction() call does not set it to return anything resulting in:
Function ‘versioncmp’ does not return a value at /home/rip/test.pp:1 on node nephilim.ml.org
when used.
Simply adding ‘:type => :rvalue’ to the newfunction() call fixes it.
Associated revisions
Revision 3f61df8716d1ed66fb24bf7bcf64fcc2ebc711b9
Fixed #2110 – versioncmp broken
History
Updated by James Turnbull over 1 year ago
- Category set to functions
- Status changed from Unreviewed to Accepted
- Assignee set to Brice Figureau
- Target version set to 0.25.0
Updated by James Turnbull over 1 year ago
- Status changed from Accepted to Closed
- % Done changed from 0 to 100
Applied in changeset commit:“3f61df8716d1ed66fb24bf7bcf64fcc2ebc711b9”.
Updated by micah - over 1 year ago
- Status changed from Closed to Re-opened
I was getting this issue, so I applied this fix to my 0.24.8 and tried it out but I’m still getting the error:
err: Could not retrieve catalog: Failed to parse template backupninja/rdiff.conf.erb: private method `versioncmp' called for Puppet::Parser::TemplateWrapper::VersionComparer:Class at /etc/puppet/modules/backupninja/manifests/rdiff.pp:52
The code I’m using is:
<%- include Puppet::Util::Package
class VersionComparer; extend Puppet::Util::Package; end
if VersionComparer.versioncmp(Puppet.version,'0.24.6') >= 0
%w{type host directory user sshoptions}.each do |v|
if has_variable?(v) and instance_variable_get("@#{v}").to_s != "false"
-%>
<%= v + ' = ' + instance_variable_get("@#{v}").to_s %>
Updated by R.I. Pienaar aka Volcane over 1 year ago
I doubt what you’re experiencing can fall under this bug.
I’d suggest what you do is instead of trying to use the versioncmp function in your template, use it in the manifest.
something like:
$ver = versioncmp($puppetversion)
and then simply use the $ver variable in an if statement inside your template, this should be much cleaner and more readable as well.
Updated by Luke Kanies over 1 year ago
- Status changed from Re-opened to Closed
As volcane says, versioncmp is meant to be used in the manifest.
If you use it in a template, you need to use ‘function_versioncmp’, or just do what the function does: ‘Puppet::Util::Package.versioncmp(args[0], args[1])’.