summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG4
-rw-r--r--lib/puppet/config.rb39
-rwxr-xr-xtest/other/config.rb48
3 files changed, 77 insertions, 14 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 8f8c59e4a..9d19ece26 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,7 @@
+0.18.3
+ Mostly a bug-fix release; fixed small bugs in the functionality added in
+ 0.18.2.
+
0.18.2
Added templating support.
diff --git a/lib/puppet/config.rb b/lib/puppet/config.rb
index e4dfe9086..701ee5942 100644
--- a/lib/puppet/config.rb
+++ b/lib/puppet/config.rb
@@ -19,7 +19,7 @@ class Config
return val
end
else
- raise ArgumentError, "Invalid argument %s" % param
+ raise ArgumentError, "Undefined configuration parameter '%s'" % param
end
end
@@ -104,15 +104,6 @@ class Config
@used = []
end
- def symbolize(param)
- case param
- when String: return param.intern
- when Symbol: return param
- else
- raise ArgumentError, "Invalid param type %s" % param.class
- end
- end
-
def each
@order.each { |name|
if @config.include?(name)
@@ -170,6 +161,11 @@ class Config
end
end
+ def include?(name)
+ name = name.intern if name.is_a? String
+ @config.include?(name)
+ end
+
# Create a new config object
def initialize
@order = []
@@ -306,8 +302,8 @@ class Config
else
raise Puppet::Error, "Invalid value '%s' for %s" % [value.inspect, hash[:name]]
end
+ hash[:parent] = self
element = klass.new(hash)
- element.parent = self
@order << element.name
@@ -421,6 +417,15 @@ class Config
}
end
+ def symbolize(param)
+ case param
+ when String: return param.intern
+ when Symbol: return param
+ else
+ raise ArgumentError, "Invalid param type %s" % param.class
+ end
+ end
+
# Convert our list of objects into a component that can be applied.
def to_component
transport = self.to_transportable
@@ -656,6 +661,10 @@ Generated on #{Time.now}.
# Create the new element. Pretty much just sets the name.
def initialize(args = {})
+ if args.include?(:parent)
+ self.parent = args[:parent]
+ args.delete(:parent)
+ end
args.each do |param, value|
method = param.to_s + "="
unless self.respond_to? method
@@ -834,9 +843,11 @@ Generated on #{Time.now}.
def validate(value)
return true unless value.is_a? String
value.scan(/\$(\w+)/) { |name|
- name = name[0]
- unless @parent[name]
- raise Puppet::Error, "'%s' is unset" % name
+ name = $1
+ unless @parent.include?(name)
+ raise ArgumentError,
+ "Configuration parameter '%s' is undefined" %
+ name
end
}
end
diff --git a/test/other/config.rb b/test/other/config.rb
index 457010ac0..9f941af4e 100755
--- a/test/other/config.rb
+++ b/test/other/config.rb
@@ -646,6 +646,54 @@ inttest = 27
assert_equal("yayness", Puppet[:tags],
"Tags got changed during config")
end
+
+ def test_configs_replace_in_url
+ config = mkconfig
+
+ config.setdefaults(:mysection, :name => ["yayness", "yay"])
+ config.setdefaults(:mysection, :url => ["http://$name/rahness", "yay"])
+
+ val = nil
+ assert_nothing_raised {
+ val = config[:url]
+ }
+
+ assert_equal("http://yayness/rahness", val,
+ "Config got messed up")
+ end
+
+ def test_correct_type_assumptions
+ config = mkconfig
+
+ file = Puppet::Config::CFile
+ element = Puppet::Config::CElement
+ bool = Puppet::Config::CBoolean
+
+ # We have to keep these ordered, unfortunately.
+ [
+ ["/this/is/a/file", file],
+ ["true", bool],
+ [true, bool],
+ ["false", bool],
+ ["server", element],
+ ["http://$server/yay", element],
+ ["$server/yayness", file],
+ ["$server/yayness.conf", file]
+ ].each do |ary|
+ value, type = ary
+ elem = nil
+ assert_nothing_raised {
+ elem = config.newelement(
+ :name => value,
+ :default => value,
+ :section => :yayness
+ )
+ }
+
+ assert_instance_of(type, elem,
+ "%s got created as wrong type" % value.inspect)
+ end
+ end
end
# $Id$