From 3304068fe96df86c3616f3f441595811d71162b0 Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Thu, 1 Jul 2010 15:15:14 -0700 Subject: maint: :mutable_defaults to improve spec consistency Added a Puppet::Util::Settings layer called :mutable_defaults to emulate the interaction between Puppet::Application and defaults.rb that was getting thwarted by rspec. --- lib/puppet/application.rb | 13 +++++++++++++ lib/puppet/defaults.rb | 3 ++- lib/puppet/util/settings.rb | 6 +++--- 3 files changed, 18 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb index ac2cc1002..35d6024be 100644 --- a/lib/puppet/application.rb +++ b/lib/puppet/application.rb @@ -280,6 +280,19 @@ class Application $puppet_application_mode = @run_mode $puppet_application_name = name + + if Puppet.respond_to? :settings + # This is to reduce the amount of confusion in rspec + # because it might have loaded defaults.rb before the globals were set + # and thus have the wrong defaults for the current application + Puppet.settings.set_value(:confdir, Puppet.run_mode.conf_dir, :mutable_defaults) + Puppet.settings.set_value(:vardir, Puppet.run_mode.var_dir, :mutable_defaults) + Puppet.settings.set_value(:name, Puppet.application_name.to_s, :mutable_defaults) + Puppet.settings.set_value(:logdir, Puppet.run_mode.logopts, :mutable_defaults) + Puppet.settings.set_value(:rundir, Puppet.run_mode.run_dir, :mutable_defaults) + Puppet.settings.set_value(:mode, Puppet.run_mode.name.to_s, :mutable_defaults) + end + require 'puppet' end diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index ac82975eb..ed0623127 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -6,7 +6,8 @@ module Puppet it defaults to being in ``~``."], :vardir => [Puppet.run_mode.var_dir, "Where Puppet stores dynamic and growing data. The default for this parameter is calculated specially, like `confdir`_."], :name => [Puppet.application_name.to_s, "The name of the application, if we are running as one. The - default is essentially $0 without the path or ``.rb``."] + default is essentially $0 without the path or ``.rb``."], + :mode => [Puppet.run_mode.name.to_s, "The effective 'run mode' of the application: master, agent, or user."] ) setdefaults(:main, :logdir => Puppet.run_mode.logopts) diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index 3e2020c55..d1e1448cb 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -443,9 +443,9 @@ class Puppet::Util::Settings # The order in which to search for values. def searchpath(environment = nil) if environment - [:cli, :memory, environment, :run_mode, :main] + [:cli, :memory, environment, :run_mode, :main, :mutable_defaults] else - [:cli, :memory, :run_mode, :main] + [:cli, :memory, :run_mode, :main, :mutable_defaults] end end @@ -490,7 +490,7 @@ class Puppet::Util::Settings if setting.respond_to?(:handle) and not options[:dont_trigger_handles] setting.handle(value) end - if ReadOnly.include? param + if ReadOnly.include? param and type != :mutable_defaults raise ArgumentError, "You're attempting to set configuration parameter $#{param}, which is read-only." end -- cgit