Oh, wait, there are a couple sleeps stuck in there for debugging that
need to go unless we want the tests to run a second slower for no
reason. Once more, with feeling...

On Fri, Oct 16, 2009 at 10:30 AM, Luke Kanies <[email protected]> wrote:
>
> +1
>
> On Oct 16, 2009, at 10:23 AM, Rein Henrichs wrote:
>
>>
>> Wrap Puppet::Settings.use in a block that disables noop mode during
>> the
>> execution of the block and ensures that noop returns to its original
>> value afterwards. This allows internal puppet catalog operations like
>> ssl directory creation to occur even when puppet is run in --noop
>> mode.
>> This should actually solve a broader class of related bugs.
>>
>> Signed-off-by: Rein Henrichs <[email protected]>
>> ---
>> lib/puppet/util/settings.rb           |   10 +++++++++-
>> spec/integration/bin/puppetmasterd.rb |   26 ++++++++++++++++++++++++
>> ++
>> spec/unit/util/settings.rb            |   17 +++++++++++++++++
>> 3 files changed, 52 insertions(+), 1 deletions(-)
>>
>> diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
>> index 3e3bc7f..c0e6e02 100644
>> --- a/lib/puppet/util/settings.rb
>> +++ b/lib/puppet/util/settings.rb
>> @@ -157,6 +157,14 @@ class Puppet::Util::Settings
>>         set_value(str, value, :cli)
>>     end
>>
>> +    def without_noop
>> +        old_noop = value(:noop,:cli)
>> +        set_value(:noop, false, :cli)
>> +        yield
>> +    ensure
>> +        set_value(:noop, old_noop, :cli)
>> +    end
>> +
>>     def include?(name)
>>         name = name.intern if name.is_a? String
>>         @config.include?(name)
>> @@ -632,7 +640,7 @@ Generated on #{Time.now}.
>>                 return
>>             end
>>
>> -            begin
>> +            without_noop do
>>                 catalog.host_config = false
>>                 catalog.apply do |transaction|
>>                     if transaction.any_failed?
>> diff --git a/spec/integration/bin/puppetmasterd.rb b/spec/
>> integration/bin/puppetmasterd.rb
>> index b5a3f96..5b3a29f 100755
>> --- a/spec/integration/bin/puppetmasterd.rb
>> +++ b/spec/integration/bin/puppetmasterd.rb
>> @@ -107,4 +107,30 @@ describe "puppetmasterd" do
>>     end
>>
>>     it "should exit with return code 1 after parsing if --parseonly
>> is set and there are errors"
>> +
>> +    describe "when run for the first time" do
>> +        before do
>> +           �...@ssldir = File.join(@dir, 'ssl')
>> +            FileUtils.rm_r(@ssldir) if File.exists?(@ssldir)
>> +        end
>> +
>> +        describe "with noop" do
>> +            it "should create its ssl directory" do
>> +                File.directory?(@ssldir).should be_false
>> +                start(' --noop')
>> +
>> +                sleep 0.5
>> +                File.directory?(@ssldir).should be_true
>> +            end
>> +        end
>> +
>> +        describe "without noop" do
>> +            it "should create its ssl directory" do
>> +                File.directory?(@ssldir).should be_false
>> +                start
>> +                sleep 0.5
>> +                File.directory?(@ssldir).should be_true
>> +            end
>> +        end
>> +    end
>> end
>> diff --git a/spec/unit/util/settings.rb b/spec/unit/util/settings.rb
>> index ae8aaac..5b54fa4 100755
>> --- a/spec/unit/util/settings.rb
>> +++ b/spec/unit/util/settings.rb
>> @@ -712,6 +712,7 @@ describe Puppet::Util::Settings do
>>         before do
>>             @settings = Puppet::Util::Settings.new
>>             @settings.stubs(:service_user_available?).returns true
>> +           �[email protected] :main, :noop => [false, ""]
>>             @settings.setdefaults :main, :maindir => ["/maindir",
>> "a"], :seconddir => ["/seconddir", "a"]
>>             @settings.setdefaults :main, :user => ["suser",
>> "doc"], :group => ["sgroup", "doc"]
>>             @settings.setdefaults :other, :otherdir => {:default =>
>> "/otherdir", :desc => "a", :owner => "service", :group =>
>> "service", :mode => 0755}
>> @@ -993,4 +994,20 @@ describe Puppet::Util::Settings do
>>
>>         it "should cache the result"
>>     end
>> +
>> +    describe "#without_noop" do
>> +        before do
>> +           �...@settings = Puppet::Util::Settings.new
>> +           �[email protected] :main, :noop => [true, ""]
>> +        end
>> +
>> +        it "should set noop to false for the duration of the block"
>> do
>> +           �[email protected]_noop
>> { @settings.value(:noop, :cli).should be_false }
>> +        end
>> +
>> +        it "should ensure that noop is returned to its previous
>> value" do
>> +           �[email protected]_noop { raise } rescue nil
>> +           �[email protected](:noop, :cli).should be_true
>> +        end
>> +    end
>> end
>> --
>> 1.6.4.2
>>
>>
>> >
>
>
> --
> Experience is that marvelous thing that enables you recognize a
> mistake when you make it again. -- F. P. Jones
> ---------------------------------------------------------------------
> Luke Kanies | http://reductivelabs.com | http://madstop.com
>
>
> >
>



-- 
Rein Henrichs
http://reductivelabs.com

--~--~---------~--~----~------------~-------~--~----~
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