From ea5847875b5fd7e2d13470d9e74bb0f671ee4d95 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 3 Sep 2009 17:41:42 -0700 Subject: Fixing #2590 - modulepath is not cached inappropriately It was getting cached by Environment instances too early, thus causing some executables to use the default even when it was overridden. We're taking the slightly extreme step of clearing the environment list if any parameter is set, but this is relatively inexpensive and is the only way to always be correct. The reason that the environments cache this value at all is that to build up their module path they have to search through every known module for a lib or plugins directory, which is then done every time a class is sought in the language. Caching it saves a *ton* of file accesses. Signed-off-by: Luke Kanies --- lib/puppet/util/settings.rb | 8 ++++++++ spec/unit/util/settings.rb | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index 625bab42a..3e3bc7f76 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -494,7 +494,15 @@ class Puppet::Util::Settings @sync.synchronize do # yay, thread-safe @values[type][param] = value @cache.clear + clearused + + # Clear the list of environments, because they cache, at least, the module path. + # We *could* preferentially just clear them if the modulepath is changed, + # but we don't really know if, say, the vardir is changed and the modulepath + # is defined relative to it. We need the defined? stuff because of loading + # order issues. + Puppet::Node::Environment.clear if defined?(Puppet::Node) and defined?(Puppet::Node::Environment) end return value diff --git a/spec/unit/util/settings.rb b/spec/unit/util/settings.rb index c00ca5881..ae8aaac8a 100755 --- a/spec/unit/util/settings.rb +++ b/spec/unit/util/settings.rb @@ -171,6 +171,11 @@ describe Puppet::Util::Settings do @settings[:myval] = "memarg" @settings[:myval].should == "cliarg" end + + it "should clear the list of environments" do + Puppet::Node::Environment.expects(:clear).at_least(1) + @settings[:myval] = "memarg" + end end describe "when returning values" do -- cgit