Issue #4370 has been updated by Daniel Pittman.

Assignee deleted (Matt Robinson)


----------------------------------------
Bug #4370: extlookup gives wrong answers in 2.6
https://projects.puppetlabs.com/issues/4370#change-59160

Author: R.I. Pienaar
Status: Closed
Priority: High
Assignee: 
Category: 
Target version: 2.6.1
Affected Puppet version: 2.6.1rc1
Keywords: extlookup
Branch: 
http://github.com/mmrobins/puppet/tree/bug/2.6.x/4370-extlookup_inconsistent_answers


We've been debugging an issue where extlookup would return data that was 
previously gathered for a different node.

Given the site.pp:

<pre>
$extlookup_precedence = ["%{fqdn}", "location_%{location}", "domain_%{domain}", 
"country_%{country}", "common"]
</pre>


I've debugged this and distilled it in a small bit of broken code and fixed 
code.  I cannot see why my fixes work, but they do, so here's the sample broken 
code verbatim from extlookup.rb:

<pre>
module Puppet::Parser::Functions
  newfunction(:extlookupbug, :type => :rvalue) do |args|
    key = args[0]

    extlookup_precedence = Array.new

    lookupvar('extlookup_precedence').each do |prec|
      Puppet.notice("[#{key}] Found a precedence variable: #{prec}")

      while prec =~ /%\{(.+?)\}/
        prec.gsub!(/%\{#{$1}\}/, lookupvar($1))
      end

      Puppet.notice("[#{key}] adding #{prec} to precedence")

      extlookup_precedence << prec
    end

    "foo"
  end
end
</pre>

Here are two runs:

<pre>
2010-07-26T18:12:33.650535-04:00 li190-90 puppet-master[4320]: [test] Found a 
precedence variable: %{fqdn}
2010-07-26T18:12:33.650748-04:00 li190-90 puppet-master[4320]: [test] adding 
nephilim.ml.org to precedence
2010-07-26T18:12:33.650897-04:00 li190-90 puppet-master[4320]: [test] Found a 
precedence variable: location_%{location}
2010-07-26T18:12:33.651092-04:00 li190-90 puppet-master[4320]: [test] adding 
location_hetzner to precedence
2010-07-26T18:12:33.651231-04:00 li190-90 puppet-master[4320]: [test] Found a 
precedence variable: domain_%{domain}
2010-07-26T18:12:33.651412-04:00 li190-90 puppet-master[4320]: [test] adding 
domain_ml.org to precedence
2010-07-26T18:12:33.651584-04:00 li190-90 puppet-master[4320]: [test] Found a 
precedence variable: country_%{country}
2010-07-26T18:12:33.651799-04:00 li190-90 puppet-master[4320]: [test] adding 
country_de to precedence
2010-07-26T18:12:33.651932-04:00 li190-90 puppet-master[4320]: [test] Found a 
precedence variable: common
2010-07-26T18:12:33.652084-04:00 li190-90 puppet-master[4320]: [test] adding 
common to precedence
2010-07-26T18:12:33.656282-04:00 li190-90 puppet-master[4320]: Compiled catalog 
for nephilim.ml.org in environment production in 0.05 seconds
</pre>

And another box now - on a different domain etc:

<pre>
2010-07-26T18:12:42.466384-04:00 li190-90 puppet-master[4320]: [test] Found a 
precedence variable: nephilim.ml.org
2010-07-26T18:12:42.466562-04:00 li190-90 puppet-master[4320]: [test] adding 
nephilim.ml.org to precedence
2010-07-26T18:12:42.466775-04:00 li190-90 puppet-master[4320]: [test] Found a 
precedence variable: location_hetzner
2010-07-26T18:12:42.466983-04:00 li190-90 puppet-master[4320]: [test] adding 
location_hetzner to precedence
2010-07-26T18:12:42.467197-04:00 li190-90 puppet-master[4320]: [test] Found a 
precedence variable: domain_ml.org
2010-07-26T18:12:42.467412-04:00 li190-90 puppet-master[4320]: [test] adding 
domain_ml.org to precedence
2010-07-26T18:12:42.467616-04:00 li190-90 puppet-master[4320]: [test] Found a 
precedence variable: country_de
2010-07-26T18:12:42.467838-04:00 li190-90 puppet-master[4320]: [test] adding 
country_de to precedence
2010-07-26T18:12:42.468038-04:00 li190-90 puppet-master[4320]: [test] Found a 
precedence variable: common
2010-07-26T18:12:42.468264-04:00 li190-90 puppet-master[4320]: [test] adding 
common to precedence
2010-07-26T18:12:42.471109-04:00 li190-90 puppet-master[4320]: Compiled catalog 
for dev1.another.net in environment production in 0.02 seconds
</pre>

Note how here lookupvar("domain") is apparently giving back "ml.org" when it 
should be giving "another.net"

Now if I change my function to be:

<pre>
module Puppet::Parser::Functions
  newfunction(:extlookupbug, :type => :rvalue) do |args|
    key = args[0]

    extlookup_precedence = Array.new

    lookupvar('extlookup_precedence').each do |prec|
      Puppet.notice("[#{key}] Found a precedence variable: #{prec}")

      wtf = prec.clone

      while wtf =~ /%\{(.+?)\}/
        wtf.gsub!(/%\{#{$1}\}/, lookupvar($1))
      end

      Puppet.notice("[#{key}] adding #{wtf} to precedence")

      extlookup_precedence << wtf
    end

    "foo"
  end
end
</pre>

Just look for 'wtf' to see the difference.  Now it works as expected:

<pre>
2010-07-26T18:18:14.728655-04:00 li190-90 puppet-master[4385]: [test] Found a 
precedence variable: %{fqdn}
2010-07-26T18:18:14.729082-04:00 li190-90 puppet-master[4385]: [test] adding 
nephilim.ml.org to precedence
2010-07-26T18:18:14.729369-04:00 li190-90 puppet-master[4385]: [test] Found a 
precedence variable: location_%{location}
2010-07-26T18:18:14.729766-04:00 li190-90 puppet-master[4385]: [test] adding 
location_hetzner to precedence
2010-07-26T18:18:14.730042-04:00 li190-90 puppet-master[4385]: [test] Found a 
precedence variable: domain_%{domain}
2010-07-26T18:18:14.730411-04:00 li190-90 puppet-master[4385]: [test] adding 
domain_ml.org to precedence
2010-07-26T18:18:14.730726-04:00 li190-90 puppet-master[4385]: [test] Found a 
precedence variable: country_%{country}
2010-07-26T18:18:14.731070-04:00 li190-90 puppet-master[4385]: [test] adding 
country_de to precedence
2010-07-26T18:18:14.731348-04:00 li190-90 puppet-master[4385]: [test] Found a 
precedence variable: common
2010-07-26T18:18:14.731672-04:00 li190-90 puppet-master[4385]: [test] adding 
common to precedence
2010-07-26T18:18:14.735186-04:00 li190-90 puppet-master[4385]: Compiled catalog 
for nephilim.ml.org in environment production in 0.02 seconds
</pre>

and with the another.net machine:

<pre>
2010-07-26T18:18:41.547939-04:00 li190-90 puppet-master[4385]: [test] Found a 
precedence variable: %{fqdn}
2010-07-26T18:18:41.548154-04:00 li190-90 puppet-master[4385]: [test] adding 
dev1.another.net to precedence
2010-07-26T18:18:41.548318-04:00 li190-90 puppet-master[4385]: [test] Found a 
precedence variable: location_%{location}
2010-07-26T18:18:41.548506-04:00 li190-90 puppet-master[4385]: [test] adding 
location_hetzner to precedence
2010-07-26T18:18:41.548652-04:00 li190-90 puppet-master[4385]: [test] Found a 
precedence variable: domain_%{domain}
2010-07-26T18:18:41.548863-04:00 li190-90 puppet-master[4385]: [test] adding 
domain_another.net to precedence
2010-07-26T18:18:41.549027-04:00 li190-90 puppet-master[4385]: [test] Found a 
precedence variable: country_%{country}
2010-07-26T18:18:41.549208-04:00 li190-90 puppet-master[4385]: [test] adding 
country_de to precedence
2010-07-26T18:18:41.549353-04:00 li190-90 puppet-master[4385]: [test] Found a 
precedence variable: common
2010-07-26T18:18:41.549508-04:00 li190-90 puppet-master[4385]: [test] adding 
common to precedence
2010-07-26T18:18:41.551891-04:00 li190-90 puppet-master[4385]: Compiled catalog 
for dev1.another.net in environment production in 0.02 seconds
</pre>

All is well.

So doing this to the actual extlookup.rb doesnt resolve the whole problem - 
once I understand why the above code behaves the way it does I could probably 
fix the rest of extlookup too since no doubt its related.  

Some magic is happening somewhere that I think I need someone more familiar 
with the puppet code base to resolve.


-- 
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