Bug #1824

passing arrays to custom functions stopped working in 0.24.7

Added by Marlon de Boer about 3 years ago. Updated almost 2 years ago.

Status:Duplicate Start date:12/16/2008
Priority:High Due date:
Assignee:Brice Figureau % Done:

0%

Category:functions
Target version:0.24.8
Affected Puppet version:0.24.7 Branch:
Keywords:
Votes: 0

Description

the custom function:

module Puppet::Parser::Functions

    newfunction(:somefunction, :type => :rvalue) do |args|

    File.open("/tmp/puppet", 'a') { |fd| fd.puts args[0].is_a?(Array) }

    end

end

puppet code:

$array = [“a”, “b”, “c”] $useless_var = somefunction($array)

After catting the /tmp/puppet file on the puppetmaster on version 0.24.6 it returned True, on 0.24.7 it returned False.


Related issues

duplicates Puppet - Bug #1922: Functions squash all arguments into a single hash Closed 01/30/2009

History

Updated by Ben - about 3 years ago

i also have experienced this problem. here is a real work example.

Function:

module Puppet::Parser::Functions
  newfunction(:file_append, :type => :rvalue) do |args|
    if argscommit:0].is_a?(Array)
      output = args[0.map { |val| val + "/" + args[1] }
    else
      output = args[0] + "/" + args[1]
    end
    output
  end
end

Manifest:

define talk (){ info($title) }

$s = [ "/test/path", "/test/path/2/" ]
$f = "filename.txt"

$a = file_append($s,$f)

talk { $a: }

correct result with 0.24.6

info: Scope(Talk[/test/path/2//filename.txt]): /test/path/2//filename.txt
info: Scope(Talk[/test/path/filename.txt]): /test/path/filename.txt

incorrect result with 0.24.7

info: Scope(Talk[/test/path//test/path/2/]): /test/path//test/path/2/

Updated by James Turnbull about 3 years ago

  • Status changed from Unreviewed to Accepted
  • Assignee set to Luke Kanies

Updated by micah - about 3 years ago

It wasn’t obvious to me at first, but when we tried to upgrade to 0.24.7, we got bit by this bug. This actually resulted in us scratching our heads for some time and then downgrading back to 0.24.5.

We have some modules (such as DavidS' munin module) which depend on this function working properly. When it doesn’t, nodes fail to compile manifests and we get confusingly opaque errors about duplicate definitons, for example:

err: Could not retrieve catalog: Puppet::Parser::AST::Resource failed with error ArgumentError: Duplicate definition: Munin::Plugin[] is already defined in file /etc/puppet/modules/munin/manifests/plugin.pp at line 94; cannot redefine at /etc/puppet/modules/munin/manifests/plugin.pp:94 on node

Updated by James Turnbull about 3 years ago

  • Target version changed from 4 to 0.25.0

Updated by micah - about 3 years ago

  • Target version changed from 0.25.0 to 0.24.8
  • Affected Puppet version changed from 0.24.6 to 0.24.7

Updated by Luke Kanies about 3 years ago

Looks like this is caused by commit:c7ccc4ba7c42d56595564491ae578a1604c628d1; now I just need to find out why that commit happened.

Updated by Luke Kanies about 3 years ago

  • Assignee changed from Luke Kanies to Brice Figureau

Brice is actually doing all the work on this ticket.

Updated by Brice Figureau about 3 years ago

  • Status changed from Accepted to Duplicate

dup of #1922, which will get merged in for 0.24.8 if I’m not mistaken.

Also available in: Atom PDF