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 + @settings.setdefaults :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 + @settings.setdefaults :main, :noop => [true, ""] + end + + it "should set noop to false for the duration of the block" do + @settings.without_noop { @settings.value(:noop, :cli).should be_false } + end + + it "should ensure that noop is returned to its previous value" do + @settings.without_noop { raise } rescue nil + @settings.value(:noop, :cli).should be_true + end + end end -- 1.6.4.2 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
