diff options
author | Jesse Wolfe <jes5199@gmail.com> | 2010-05-12 18:35:01 -0700 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | b7d387e3e71f6af1b2967098b67440f8daa53e7d (patch) | |
tree | 147958b739b57a470b98e261dccdbbe644fa3dc1 | |
parent | 342298c4f9fcb2874d4017219a472ddf37dbfc6b (diff) | |
download | puppet-b7d387e3e71f6af1b2967098b67440f8daa53e7d.tar.gz puppet-b7d387e3e71f6af1b2967098b67440f8daa53e7d.tar.xz puppet-b7d387e3e71f6af1b2967098b67440f8daa53e7d.zip |
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@gmail.com>
-rw-r--r-- | lib/puppet/util/settings.rb | 24 | ||||
-rwxr-xr-x | spec/unit/util/settings.rb | 28 | ||||
-rwxr-xr-x | test/network/authorization.rb | 4 | ||||
-rwxr-xr-x | test/network/handler/ca.rb | 2 | ||||
-rwxr-xr-x | test/network/server/webrick.rb | 2 | ||||
-rwxr-xr-x | test/other/puppet.rb | 6 | ||||
-rwxr-xr-x | test/util/settings.rb | 4 |
7 files changed, 51 insertions, 19 deletions
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index ea18d22bf..c8f85a072 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 afdcf626a..24bd04b27 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 3ee10a4a8..9200c5824 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 16782bb18..503d0188d 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 5a930848d..5cde2b756 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 2d55c2fba..0dea54da4 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 a080ca03b..e94778e2a 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 { |