[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35
test branch
puppet-dev at googlegroups.com
Wed Jul 14 10:33:56 UTC 2010
The following commit has been merged in the upstream branch:
commit b7d387e3e71f6af1b2967098b67440f8daa53e7d
Author: Jesse Wolfe <jes5199 at gmail.com>
Date: Wed May 12 18:35:01 2010 -0700
Feature #2935 Puppet[:mode] and Puppet[:name] are read-only
Historically, the Puppet[:name] setting has been settable, but the
results of chaning it are poorly defined.
The switch to modes instead of executable names seems like a good time
to disable this complexity.
Signed-off-by: Jesse Wolfe <jes5199 at gmail.com>
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index ea18d22..c8f85a0 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -17,6 +17,8 @@ class Puppet::Util::Settings
attr_accessor :file
attr_reader :timer
+ ReadOnly = [:mode, :name]
+
# Retrieve a config value
def [](param)
value(param)
@@ -480,9 +482,21 @@ class Puppet::Util::Settings
if setting.respond_to?(:handle)
setting.handle(value)
end
- # Reset the name, so it's looked up again.
- if param == :name
- @name = nil
+ if ReadOnly.include? param
+ raise ArgumentError,
+ "You're attempting to set configuration parameter $#{param}, which is read-only."
+ end
+ require 'puppet/util/command_line'
+ command_line = Puppet::Util::CommandLine.new
+ legacy_to_mode = Puppet::Util::CommandLine::LegacyName.inject({}) do |hash, pair|
+ app, legacy = pair
+ command_line.require_application app
+ hash[legacy.to_sym] = Puppet::Application.find(app).mode.name
+ hash
+ end
+ if new_type = legacy_to_mode[type]
+ Puppet.warning "You have configuration parameter $#{param} specified in [#{type}], which is a deprecated section. I'm assuming you meant [#{new_type}]"
+ type = new_type
end
@sync.synchronize do # yay, thread-safe
@values[type][param] = value
@@ -501,8 +515,6 @@ class Puppet::Util::Settings
return value
end
- private :set_value
-
# Set a bunch of defaults in a given section. The sections are actually pretty
# pointless, but they help break things up a bit, anyway.
def setdefaults(section, defs)
@@ -587,7 +599,7 @@ Generated on #{Time.now}.
end
eachsection do |section|
persection(section) do |obj|
- str += obj.to_config + "\n"
+ str += obj.to_config + "\n" unless ReadOnly.include? obj.name
end
end
diff --git a/spec/unit/util/settings.rb b/spec/unit/util/settings.rb
index afdcf62..24bd04b 100755
--- a/spec/unit/util/settings.rb
+++ b/spec/unit/util/settings.rb
@@ -194,6 +194,30 @@ describe Puppet::Util::Settings do
Puppet::Node::Environment.expects(:clear).at_least(1)
@settings[:myval] = "memarg"
end
+
+ it "should raise an error if we try to set 'name'" do
+ lambda{ @settings[:name] = "foo" }.should raise_error(ArgumentError)
+ end
+
+ it "should raise an error if we try to set 'mode'" do
+ lambda{ @settings[:mode] = "foo" }.should raise_error(ArgumentError)
+ end
+
+ it "should warn and use [master] if we ask for [puppetmasterd]" do
+ Puppet.expects(:warning)
+ @settings.set_value(:myval, "foo", :puppetmasterd)
+
+ @settings.stubs(:mode).returns(:master)
+ @settings.value(:myval).should == "foo"
+ end
+
+ it "should warn and use [agent] if we ask for [puppetd]" do
+ Puppet.expects(:warning)
+ @settings.set_value(:myval, "foo", :puppetd)
+
+ @settings.stubs(:mode).returns(:agent)
+ @settings.value(:myval).should == "foo"
+ end
end
describe "when returning values" do
@@ -250,9 +274,11 @@ describe Puppet::Util::Settings do
@settings.value(:one, "env2").should == "twoval"
end
- it "should have a mode determined by the 'mode' parameter" do
+ it "should have a mode determined by the 'mode' parameter that cannot be edited" do
@settings.setdefaults(:whatever, :mode => ["something", "yayness"])
@settings.mode.should == :something
+
+ lambda{ @settings[:mode] = :other }.should raise_error
end
end
diff --git a/test/network/authorization.rb b/test/network/authorization.rb
index 3ee10a4..9200c58 100755
--- a/test/network/authorization.rb
+++ b/test/network/authorization.rb
@@ -82,8 +82,8 @@ class TestAuthConfig < Test::Unit::TestCase
assert(! @obj.authorized?(@request), "Allowed call with no config file")
assert_logged(:notice, /Denying/, "did not log call")
- # Now set our name to the master, so calls are allowed
- Puppet[:name] = "puppetmasterd"
+ # Now set our mode to master, so calls are allowed
+ Puppet.mode.stubs(:master?).returns true
assert(@obj.authorized?(@request),
"Denied call with no config file and master")
assert_logged(:debug, /Allowing/, "did not log call")
diff --git a/test/network/handler/ca.rb b/test/network/handler/ca.rb
index 16782bb..503d018 100755
--- a/test/network/handler/ca.rb
+++ b/test/network/handler/ca.rb
@@ -189,7 +189,7 @@ class TestCA < Test::Unit::TestCase
# the puppetmasterd CA does not autostart.
def test_caautosign
server = nil
- Puppet[:name] = "puppetmasterd"
+ Puppet.stubs(:master?).returns true
assert_nothing_raised {
server = Puppet::Network::HTTPServer::WEBrick.new(
:Port => @@port,
diff --git a/test/network/server/webrick.rb b/test/network/server/webrick.rb
index 5a93084..5cde2b7 100755
--- a/test/network/server/webrick.rb
+++ b/test/network/server/webrick.rb
@@ -93,7 +93,7 @@ class TestWebrickServer < Test::Unit::TestCase
}
pid = fork {
- Puppet[:name] = "puppetmasterd"
+ Puppet.mode.stubs(:master?).returns(true)
assert_nothing_raised() {
trap(:INT) { server.shutdown }
server.start
diff --git a/test/other/puppet.rb b/test/other/puppet.rb
index 2d55c2f..0dea54d 100755
--- a/test/other/puppet.rb
+++ b/test/other/puppet.rb
@@ -84,11 +84,5 @@ class TestPuppetModule < Test::Unit::TestCase
assert($:.include?(two), "libdir was not added")
assert(! $:.include?(one), "old libdir was not removed")
end
-
- def test_name
- Puppet[:name] = "puppetca"
-
- assert_equal("puppetca", Puppet[:name], "name reset did not take")
- end
end
diff --git a/test/util/settings.rb b/test/util/settings.rb
index a080ca0..e94778e 100755
--- a/test/util/settings.rb
+++ b/test/util/settings.rb
@@ -449,8 +449,8 @@ yay = /a/path
def test_configs_replace_in_url
config = mkconfig
- config.setdefaults(:mysection, :name => ["yayness", "yay"])
- config.setdefaults(:mysection, :url => ["http://$name/rahness", "yay"])
+ config.setdefaults(:mysection, :host => ["yayness", "yay"])
+ config.setdefaults(:mysection, :url => ["http://$host/rahness", "yay"])
val = nil
assert_nothing_raised {
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list