summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-08-26 21:54:17 -0500
committerLuke Kanies <luke@madstop.com>2007-08-26 21:54:17 -0500
commit11081ce8864dca2bc92d8c9f825c3fe7f96333f4 (patch)
tree89bc049324cd3d20bcb05b55e6c267e50b82aec9 /lib/puppet/util
parent9ea8e6cc8772053548d3438393dd1ead986ed719 (diff)
downloadpuppet-11081ce8864dca2bc92d8c9f825c3fe7f96333f4.tar.gz
puppet-11081ce8864dca2bc92d8c9f825c3fe7f96333f4.tar.xz
puppet-11081ce8864dca2bc92d8c9f825c3fe7f96333f4.zip
Multiple environment support now works, and I have even tested it in real life. This commit is mostly a bug-fix commit, resulting from the difference between real-life testing and unit testing.
Diffstat (limited to 'lib/puppet/util')
-rw-r--r--lib/puppet/util/config.rb45
1 files changed, 31 insertions, 14 deletions
diff --git a/lib/puppet/util/config.rb b/lib/puppet/util/config.rb
index b6831ba9b..fb1c01d56 100644
--- a/lib/puppet/util/config.rb
+++ b/lib/puppet/util/config.rb
@@ -38,7 +38,7 @@ class Puppet::Util::Config
@name = nil
end
@values[:memory][param] = value
- @values[:cache].clear
+ @cache.clear
end
return value
@@ -113,12 +113,14 @@ class Puppet::Util::Config
@used = []
end
+ @cache.clear
+
@name = nil
end
# This is mostly just used for testing.
def clearused
- @values[:cache].clear
+ @cache.clear
@used = []
end
@@ -173,6 +175,7 @@ class Puppet::Util::Config
# Handle a command-line argument.
def handlearg(opt, value = nil)
+ clear(true)
value = munge_value(value) if value
str = opt.sub(/^--/,'')
bool = true
@@ -215,6 +218,9 @@ class Puppet::Util::Config
# Keep track of set values.
@values = Hash.new { |hash, key| hash[key] = {} }
+ # And keep a per-environment cache
+ @cache = Hash.new { |hash, key| hash[key] = {} }
+
# A central concept of a name.
@name = nil
end
@@ -448,9 +454,9 @@ class Puppet::Util::Config
# The order in which to search for values.
def searchpath(environment = nil)
if environment
- [:cache, :cli, :memory, environment, :name, :main]
+ [:cli, :memory, environment, :name, :main]
else
- [:cache, :cli, :memory, :name, :main]
+ [:cli, :memory, :name, :main]
end
end
@@ -730,7 +736,15 @@ Generated on #{Time.now}.
# Yay, recursion.
self.reparse() unless param == :filetimeout
+ # Check the cache first. It needs to be a per-environment
+ # cache so that we don't spread values from one env
+ # to another.
+ if @cache[environment||"none"].include?(param)
+ return @cache[environment||"none"][param]
+ end
+
# See if we can find it within our searchable list of values
+ val = nil
searchpath(environment).each do |source|
# Modify the source as necessary.
source = case source
@@ -740,21 +754,24 @@ Generated on #{Time.now}.
source
end
- # Look for the value.
+ # Look for the value. We have to test the hash for whether
+ # it exists, because the value might be false.
if @values[source].include?(param)
val = @values[source][param]
- # Cache the value, because we do so many parameter lookups.
- unless source == :cache
- val = convert(val)
- @values[:cache][param] = val
- end
- return val
+ break
end
end
- # No normal source, so get the default and cache it
- val = convert(@config[param].default)
- @values[:cache][param] = val
+ # If we didn't get a value, use the default
+ if val.nil?
+ val = @config[param].default
+ end
+
+ # Convert it if necessary
+ val = convert(val)
+
+ # And cache it
+ @cache[environment||"none"][param] = val
return val
end