summaryrefslogtreecommitdiffstats
path: root/lib/puppet
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
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')
-rw-r--r--lib/puppet/network/handler/configuration.rb8
-rw-r--r--lib/puppet/parser/interpreter.rb3
-rw-r--r--lib/puppet/parser/parser_support.rb6
-rw-r--r--lib/puppet/util/config.rb45
4 files changed, 45 insertions, 17 deletions
diff --git a/lib/puppet/network/handler/configuration.rb b/lib/puppet/network/handler/configuration.rb
index fd1ee86ed..b2b16d022 100644
--- a/lib/puppet/network/handler/configuration.rb
+++ b/lib/puppet/network/handler/configuration.rb
@@ -92,6 +92,10 @@ class Puppet::Network::Handler
end
# Ask the interpreter to compile the configuration.
+ str = "Compiled configuration for %s" % node.name
+ if node.environment
+ str += " in environment %s" % node.environment
+ end
config = nil
benchmark(level, "Compiled configuration for %s" % node.name) do
begin
@@ -117,8 +121,8 @@ class Puppet::Network::Handler
# Allow specification of a code snippet or of a file
if code = options[:Code]
args[:Code] = code
- else
- args[:Manifest] = options[:Manifest] || Puppet[:manifest]
+ elsif options[:Manifest]
+ args[:Manifest] = options[:Manifest]
end
args[:Local] = local?
diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb
index b6c61d202..93a4bc170 100644
--- a/lib/puppet/parser/interpreter.rb
+++ b/lib/puppet/parser/interpreter.rb
@@ -67,6 +67,9 @@ class Puppet::Parser::Interpreter
parser.string = self.code
elsif self.file
parser.file = self.file
+ else
+ file = Puppet.config.value(:manifest, environment)
+ parser.file = file
end
parser.parse
return parser
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb
index 401b5b1c0..660fa8169 100644
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@ -15,7 +15,7 @@ class Puppet::Parser::Parser
AST = Puppet::Parser::AST
- attr_reader :file, :version
+ attr_reader :version, :environment
attr_accessor :files
@@ -85,6 +85,10 @@ class Puppet::Parser::Parser
raise except
end
+ def file
+ @lexer.file
+ end
+
def file=(file)
unless FileTest.exists?(file)
unless file =~ /\.pp$/
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