The reason for this change is that puppet would not read options from the
puppet.conf file if they were in a section other than main, but would if you
passed them in on the command line.

On Wed, Jun 30, 2010 at 3:54 PM, Luke Kanies <[email protected]> wrote:

> One question below.
>
>
> On Jun 30, 2010, at 3:42 PM, Matt Robinson wrote:
>
>  Along the way this fixes an issue with 2.6 alpha that sections of the
>> puppet config file were getting ignored.
>>
>> Signed-off-by: Matt Robinson <[email protected]>
>> ---
>> lib/puppet.rb                       |    2 +-
>> lib/puppet/application.rb           |    8 +++++-
>> lib/puppet/defaults.rb              |    2 -
>> lib/puppet/reports/store.rb         |    2 -
>> lib/puppet/util/settings.rb         |    4 +-
>> spec/unit/application/agent_spec.rb |   25 ++++++++++++++++++++++++
>> spec/unit/application_spec.rb       |   14 ++++++++++++-
>> spec/unit/util/settings_spec.rb     |   36
>> +++++++++++++++++++++++++++-------
>> 8 files changed, 75 insertions(+), 18 deletions(-)
>>
>> diff --git a/lib/puppet.rb b/lib/puppet.rb
>> index 4e496e7..af1bd8d 100644
>> --- a/lib/puppet.rb
>> +++ b/lib/puppet.rb
>> @@ -93,7 +93,7 @@ module Puppet
>>
>>    def self.run_mode
>>        require 'puppet/util/run_mode'
>> -        $puppet_application_mode ||= Puppet::Util::RunMode.new( :user )
>> +        $puppet_application_mode || Puppet::Util::RunMode.new( :user )
>>    end
>>
>>    def self.application_name
>> diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb
>> index f74b375..c49f42f 100644
>> --- a/lib/puppet/application.rb
>> +++ b/lib/puppet/application.rb
>> @@ -221,10 +221,14 @@ class Application
>>            find(name).new
>>        end
>>
>> +        # Sets or gets the run_mode name. Sets the run_mode name if a
>> mode_name is
>> +        # passed. Otherwise, gets the run_mode or a default run_mode
>> +        #
>>        def run_mode( mode_name = nil)
>> -            @run_mode ||= mode_name || @run_mode || :user
>> +            return @run_mode if @run_mode and not mode_name
>> +
>>            require 'puppet/util/run_mode'
>> -            Puppet::Util::RunMode.new( @run_mode )
>> +            @run_mode = Puppet::Util::RunMode.new( mode_name || :user )
>>        end
>>    end
>>
>> diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
>> index bfc18d8..ac82975 100644
>> --- a/lib/puppet/defaults.rb
>> +++ b/lib/puppet/defaults.rb
>> @@ -6,8 +6,6 @@ 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``."],
>> -        :run_mode => [Puppet.run_mode.name.to_s, "The name of the
>> application, if we are running as one.  The
>>            default is essentially $0 without the path or ``.rb``."]
>>    )
>>
>> diff --git a/lib/puppet/reports/store.rb b/lib/puppet/reports/store.rb
>> index a745275..a71cd33 100644
>> --- a/lib/puppet/reports/store.rb
>> +++ b/lib/puppet/reports/store.rb
>> @@ -1,8 +1,6 @@
>> require 'puppet'
>>
>> Puppet::Reports.register_report(:store) do
>> -    Puppet.settings.use(:reporting)
>> -
>>
>
> What's the reason for this change?  Have you confirmed that report storage
> still works?
>
>
>     desc "Store the yaml report on disk.  Each host sends its report as a
>> YAML dump
>>        and this just stores the file on disk, in the ``reportdir``
>> directory.
>>
>> diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
>> index 8b4be66..9ea7909 100644
>> --- a/lib/puppet/util/settings.rb
>> +++ b/lib/puppet/util/settings.rb
>> @@ -284,9 +284,9 @@ class Puppet::Util::Settings
>>        end
>>    end
>>
>> -    # Figure out the section name for the mode.
>> +    # Figure out the section name for the run_mode.
>>    def run_mode
>> -        convert(@config[:run_mode].default).intern if @config[:run_mode]
>> +        Puppet.run_mode.name
>>    end
>>
>>    # Return all of the parameters associated with a given section.
>> diff --git a/spec/unit/application/agent_spec.rb
>> b/spec/unit/application/agent_spec.rb
>> index 76a378e..21f5143 100755
>> --- a/spec/unit/application/agent_spec.rb
>> +++ b/spec/unit/application/agent_spec.rb
>> @@ -8,6 +8,31 @@ require 'puppet/network/server'
>> require 'puppet/daemon'
>>
>> describe Puppet::Application::Agent do
>> +    it "should ask Puppet::Application to parse Puppet configuration
>> file" do
>> +        agent = Puppet::Application::Agent.new
>> +        agent.preinit
>> +
>> +        Puppet[:vardir].should == '/dev/null'
>> +        Puppet[:report].should be_false
>> +
>> +        text = <<-CONF
>> +            [main]
>> +                vardir='/foo/bar'
>> +            [puppetd]
>> +                report=true
>> +        CONF
>> +
>> +        FileTest.expects(:exist?).with('file').returns true
>> +        Puppet.settings.expects(:read_file).returns(text)
>> +
>> +        Puppet.settings.unsafe_parse('file')
>> +
>> +        Puppet[:vardir].should == '/foo/bar'
>> +        Puppet[:report].should be_true
>> +    end
>> +end
>> +
>> +describe Puppet::Application::Agent do
>>    before :each do
>>        @puppetd = Puppet::Application[:agent]
>>        @puppetd.stubs(:puts)
>> diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb
>> index 9dc655d..87424fb 100755
>> --- a/spec/unit/application_spec.rb
>> +++ b/spec/unit/application_spec.rb
>> @@ -10,11 +10,23 @@ describe Puppet::Application do
>>
>>    before do
>>        @app = Class.new(Puppet::Application).new
>> +        @appclass = @app.class
>>
>>        # avoid actually trying to parse any settings
>>        Puppet.settings.stubs(:parse)
>>    end
>>
>> +    describe ".run_mode" do
>> +        it "should default to user" do
>> +            @appclass.run_mode.name.should == :user
>> +        end
>> +
>> +        it "should set and get a value" do
>> +            @appclass.run_mode :agent
>> +            @appclass.run_mode.name.should == :agent
>> +        end
>> +    end
>> +
>>    it "should have a run entry-point" do
>>        @app.should respond_to(:run)
>>    end
>> @@ -150,7 +162,7 @@ describe Puppet::Application do
>>
>>        describe 'on POSIX systems' do
>>            confine "HUP works only on POSIX systems" =>
>> Puppet.features.posix?
>> -
>> +
>>            it 'should signal process with HUP after block if restart
>> requested during block execution' do
>>                Puppet::Application.run_status = nil
>>                target = mock 'target'
>> diff --git a/spec/unit/util/settings_spec.rb
>> b/spec/unit/util/settings_spec.rb
>> index 1e694a4..9aeed60 100755
>> --- a/spec/unit/util/settings_spec.rb
>> +++ b/spec/unit/util/settings_spec.rb
>> @@ -274,11 +274,18 @@ describe Puppet::Util::Settings do
>>            @settings.value(:one, "env2").should == "twoval"
>>        end
>>
>> -        it "should have a run_mode determined by the 'run_mode' parameter
>> that cannot be edited" do
>> +        it "should have a run_mode that defaults to user" do
>> +            @settings.run_mode.should == :user
>> +        end
>> +
>> +        it "should not give a shit if you set a default run_mode
>> yourself" do
>>            @settings.setdefaults(:whatever, :run_mode => ["something",
>> "yayness"])
>> -            @settings.run_mode.should == :something
>> +            lambda{ @settings[:run_mode] = :other }.should
>> raise_error(ArgumentError, /read-only/)
>> +        end
>>
>> -            lambda{ @settings[:run_mode] = :other }.should raise_error
>> +        it "CURRENTLY should not allow the user to set a run_mode
>> default" do
>> +            @settings.setdefaults(:whatever, :run_mode => ["something",
>> "yayness"])
>> +            @settings.run_mode.should == :user
>>        end
>>    end
>>
>> @@ -286,10 +293,10 @@ describe Puppet::Util::Settings do
>>        before do
>>            @settings = Puppet::Util::Settings.new
>>            @settings.setdefaults :section,
>> -                :config   => ["/my/file", "a"],
>> -                :one      => ["ONE", "a"     ],
>> -                :run_mode => ["mymode", "w"  ]
>> +                :config => ["/my/file", "a"],
>> +                :one => ["ONE", "a"]
>>            FileTest.stubs(:exist?).returns true
>> +            Puppet.stubs(:run_mode).returns stub('run_mode', :name =>
>> :mymode)
>>        end
>>
>>        it "should return default values if no values have been set" do
>> @@ -358,6 +365,19 @@ describe Puppet::Util::Settings do
>>            FileTest.stubs(:exist?).returns true
>>        end
>>
>> +        it "should not ignore the report setting" do
>> +            @settings.setdefaults :section, :report => ["false", "a"]
>> +            myfile = stub "myfile"
>> +            @settings[:config] = myfile
>> +            text = <<-CONF
>> +                [puppetd]
>> +                    report=true
>> +            CONF
>> +            @settings.expects(:read_file).returns(text)
>> +            @settings.parse
>> +            @settings[:report].should be_true
>> +        end
>> +
>>        it "should use its current ':config' value for the file to parse"
>> do
>>            myfile = Puppet.features.posix? ? "/my/file" : "C:/myfile" # do
>> not stub expand_path here, as this leads to a stack overflow, when mocha
>> tries to use it
>>            @settings[:config] = myfile
>> @@ -464,9 +484,9 @@ describe Puppet::Util::Settings do
>>            values = []
>>            @settings.setdefaults :section, :mysetting => {:default =>
>> "defval", :desc => "a", :hook => proc { |v| values << v }}
>>
>> -            text = "[main]
>> +            text = "[user]
>>            mysetting = setval
>> -            [puppet]
>> +            [main]
>>            mysetting = other
>>            "
>>            @settings.expects(:read_file).returns(text)
>> --
>> 1.7.1
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Puppet Developers" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<puppet-dev%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/puppet-dev?hl=en.
>>
>>
>
> --
> Man is the only animal that can remain on friendly terms with the
> victims he intends to eat until he eats them.
>    -- Samuel Butler (1835-1902)
> ---------------------------------------------------------------------
> Luke Kanies  -|-   http://puppetlabs.com   -|-   +1(615)594-8199
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Developers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<puppet-dev%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/puppet-dev?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to