Issue #2930 has been updated by Markus Roberts.

Status changed from Investigating to Rejected

When I try I get the expected:

    err: in :template_search exception in 2930.pp: undefined method 
`function_template' for
    #<Puppet::Parser::Scope:0x22b747c> at 
/Users/markus/projects/puppet/2930.pp:2 on node phage.home

Feel free to reopen the ticket (or a new one) if you find a circumstance in 
which it still happens.
----------------------------------------
Bug #2930: endless loop when calling function from within custom function
http://projects.reductivelabs.com/issues/2930

Author: konrad rzentarzewski
Status: Rejected
Priority: Normal
Assigned to: Markus Roberts
Category: functions
Target version: 
Affected version: 0.25.1
Keywords: puppetmaster hangs in endless loop
Branch: 


based on [http://reductivelabs.com/trac/puppet/wiki/WritingYourOwnFunctions] it 
should be possible to call custom functions (including template and include 
functions) from within own function. however in 0.25.1 this leads to endless 
loops, consuming all system memory on puppetmaster.

below are the 2 functions. 1st one causes loop and exhausts all resources, 
while 2nd one runs without problems.

<pre>
Puppet::Parser::Functions::newfunction(:template_search, :type => :rvalue, :doc 
=>
    "Find first existing file and run puppet template function on it. If you 
want
    to concatenate multiple templates try var = template_search(file1,file2) +
    template_search(file3,file4) and then use var in your resources.") do |vals|
            ret = nil
            errors = Array.new
            vals.each do |file|
                debug "in :template_search find %s" % file
                ret = nil
                begin
                    ret = function_template(file)
                rescue Exception=>e
                    if /could.not.find.template/i =~ e
                        debug "in :template_search not found %s" % file
                    else
                        raise Puppet::ParseError, "in :template_search 
exception in %s: %s" % [file,e]
                        errors.push(e)
                    end
                end
                if ret
                    debug "in :template_search found %s" % file
                    break
                end
            end
            if ret
                ret
            else
                if errors.length > 0
                    raise Puppet::ParseError, "Errors from :template function: 
%s" %
                        errors.join(", ")
                else
                    raise Puppet::ParseError, "Could not find any files from 
%s" %
                        vals.join(", ")
                end
            end
end
</pre>

<pre>
Puppet::Parser::Functions::newfunction(:template_search, :type => :rvalue, :doc 
=>
    "Find first existing file and run puppet template function on it. If you 
want
    to concatenate multiple templates try var = template_search(file1,file2) +
    template_search(file3,file4) and then use var in your resources.") do |vals|
            require 'erb'
 
            ret = nil
            errors = Array.new
            vals.each do |file|
                debug "in :template_search find %s" % file
                ret = nil
                begin
                    wrapper = Puppet::Parser::TemplateWrapper.new(self)
                    wrapper.file = file
                    ret = wrapper.result
                rescue Exception=>e
                    if /could.not.find.template/i =~ e
                        debug "in :template_search not found %s" % file
                    else
                        raise Puppet::ParseError, "in :template_search 
exception in %s: %s" % [file,e]
                        errors.push(e)
                    end
                end
                if ret
                    debug "in :template_search found %s" % file
                    break
                end
            end
            if ret
                ret
            else
                if errors.length > 0
                    raise Puppet::ParseError, "Errors from :template function: 
%s" %
                        errors.join(", ")
                else
                    raise Puppet::ParseError, "Could not find any files from 
%s" %
                        vals.join(", ")
                end
            end
end
</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://reductivelabs.com/redmine/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