summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-08-25 15:47:49 -0500
committerLuke Kanies <luke@madstop.com>2007-08-25 15:47:49 -0500
commit3030d3eb3f6ed5640c14f3dae2c5167c51ce43eb (patch)
tree214aa536f4e9ecf167ec465056670b23a2bae934 /lib/puppet
parentab5418390e3e49ce3a12b60902f405db157ed45b (diff)
downloadpuppet-3030d3eb3f6ed5640c14f3dae2c5167c51ce43eb.tar.gz
puppet-3030d3eb3f6ed5640c14f3dae2c5167c51ce43eb.tar.xz
puppet-3030d3eb3f6ed5640c14f3dae2c5167c51ce43eb.zip
Modules are now tested with spec, and they now can handle environment-specific module paths.
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/module.rb56
-rw-r--r--lib/puppet/parser/configuration.rb10
-rw-r--r--lib/puppet/parser/templatewrapper.rb4
-rw-r--r--lib/puppet/util/config.rb18
4 files changed, 43 insertions, 45 deletions
diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb
index 87f849d17..34b13edb7 100644
--- a/lib/puppet/module.rb
+++ b/lib/puppet/module.rb
@@ -8,10 +8,11 @@ class Puppet::Module
# Return an array of paths by splitting the +modulepath+ config
# parameter. Only consider paths that are absolute and existing
# directories
- def self.modulepath
- dirs = Puppet[:modulepath].split(":")
+ def self.modulepath(environment = nil)
+ dirs = Puppet.config.value(:modulepath, environment).split(":")
if ENV["PUPPETLIB"]
dirs = ENV["PUPPETLIB"].split(":") + dirs
+ else
end
dirs.select do |p|
p =~ /^#{File::SEPARATOR}/ && File::directory?(p)
@@ -21,15 +22,12 @@ class Puppet::Module
# Find and return the +module+ that +path+ belongs to. If +path+ is
# absolute, or if there is no module whose name is the first component
# of +path+, return +nil+
- def self.find(path)
- if path =~ %r/^#{File::SEPARATOR}/
+ def self.find(modname, environment = nil)
+ if modname =~ %r/^#{File::SEPARATOR}/
return nil
end
- modname, rest = path.split(File::SEPARATOR, 2)
- return nil if modname.nil? || modname.empty?
-
- modpath = modulepath.collect { |p|
+ modpath = modulepath(environment).collect { |p|
File::join(p, modname)
}.find { |f| File::directory?(f) }
return nil unless modpath
@@ -45,16 +43,17 @@ class Puppet::Module
# param.
# In all cases, an absolute path is returned, which does not
# necessarily refer to an existing file
- def self.find_template(file)
+ def self.find_template(file, environment = nil)
if file =~ /^#{File::SEPARATOR}/
return file
end
- mod = find(file)
+ path, file = split_path(file)
+ mod = find(path, environment)
if mod
return mod.template(file)
else
- return File.join(Puppet[:templatedir], file)
+ return File.join(Puppet.config.value(:templatedir, environment), path, file)
end
end
@@ -63,13 +62,14 @@ class Puppet::Module
# +pat+ does not contain any wildcards and is an existing module, return
# a list of manifests in that module matching the rest of +pat+
# Otherwise, try to find manifests matching +pat+ relative to +cwd+
- def self.find_manifests(pat, cwd = nil)
- cwd ||= Dir.getwd
- mod = find(pat)
+ def self.find_manifests(start, options = {})
+ cwd = options[:cwd] || Dir.getwd
+ path, pat = split_path(start)
+ mod = find(path, options[:environment])
if mod
return mod.manifests(pat)
else
- abspat = File::expand_path(pat, cwd)
+ abspat = File::expand_path(start, cwd)
files = Dir.glob(abspat).reject { |f| FileTest.directory?(f) }
if files.size == 0
files = Dir.glob(abspat + ".pp").reject { |f| FileTest.directory?(f) }
@@ -78,28 +78,34 @@ class Puppet::Module
end
end
+ # Split the path into the module and the rest of the path.
+ def self.split_path(path)
+ if path =~ %r/^#{File::SEPARATOR}/
+ return nil
+ end
+
+ modname, rest = path.split(File::SEPARATOR, 2)
+ return nil if modname.nil? || modname.empty?
+ return modname, rest
+ end
+
attr_reader :name, :path
def initialize(name, path)
@name = name
@path = path
end
- def strip(file)
- n, rest = file.split(File::SEPARATOR, 2)
- rest = nil if rest && rest.empty?
- return rest
- end
-
def template(file)
- return File::join(path, TEMPLATES, strip(file))
+ return File::join(path, TEMPLATES, file)
end
def files
return File::join(path, FILES)
end
- def manifests(pat)
- rest = strip(pat)
+ # Return the list of manifests matching the given glob pattern,
+ # defaulting to 'init.pp' for empty modules.
+ def manifests(rest)
rest ||= "init.pp"
p = File::join(path, MANIFESTS, rest)
files = Dir.glob(p)
@@ -111,5 +117,3 @@ class Puppet::Module
private :initialize
end
-
-# $Id$
diff --git a/lib/puppet/parser/configuration.rb b/lib/puppet/parser/configuration.rb
index 148f4dcd1..a56bfa080 100644
--- a/lib/puppet/parser/configuration.rb
+++ b/lib/puppet/parser/configuration.rb
@@ -97,6 +97,16 @@ class Puppet::Parser::Configuration
@resource_graph.remove_vertex!(resource) if @resource_graph.vertex?(resource)
end
+ # Return the node's environment.
+ def environment
+ unless defined? @environment
+ if node.environment and node.environment != ""
+ @environment = node.environment
+ end
+ end
+ @environment
+ end
+
# Evaluate each class in turn. If there are any classes we can't find,
# just tag the configuration and move on.
def evaluate_classes(classes = nil)
diff --git a/lib/puppet/parser/templatewrapper.rb b/lib/puppet/parser/templatewrapper.rb
index 9c3c6c0d0..ecef60e43 100644
--- a/lib/puppet/parser/templatewrapper.rb
+++ b/lib/puppet/parser/templatewrapper.rb
@@ -7,14 +7,14 @@ class Puppet::Parser::TemplateWrapper
def initialize(scope, file)
@scope = scope
- @file = Puppet::Module::find_template(file)
+ @file = Puppet::Module::find_template(file, @scope.configuration.environment)
unless FileTest.exists?(@file)
raise Puppet::ParseError,
"Could not find template %s" % file
end
- # We'll only ever not have an interpreter in testing, but, eh.
+ # We'll only ever not have a parser in testing, but, eh.
if @scope.parser
@scope.parser.watch_file(@file)
end
diff --git a/lib/puppet/util/config.rb b/lib/puppet/util/config.rb
index 796529f32..b6831ba9b 100644
--- a/lib/puppet/util/config.rb
+++ b/lib/puppet/util/config.rb
@@ -369,7 +369,7 @@ class Puppet::Util::Config
# after cli arguments are handled.
unless @config.include?(var) and @config[var].setbycli
Puppet.debug "%s: Setting %s to '%s'" % [section, var, value]
- self[var] = value
+ @values[:main][var] = value
end
@config[var].section = symbolize(section)
@@ -949,22 +949,6 @@ Generated on #{Time.now}.
end
end
- # Take all members of a hash and assign their values appropriately.
- def set_parameter_hash(params)
- params.each do |param, value|
- next if param == :_meta
- unless @config.include?(param)
- Puppet.warning "Discarded unknown configuration parameter %s" % param
- next
- end
- if @config[param].setbycli
- Puppet.debug "Ignoring %s set by config file; overridden by cli" % param
- else
- self[param] = value
- end
- end
- end
-
# Set file metadata.
def set_metadata(meta)
meta.each do |var, values|