The noop option has been suppressing exit statuses. This is
counterintuitive, as per discussion at 
http://projects.puppetlabs.com/issues/6322

This patch causes noop runs to return the same exit codes as real runs.

Reviewed-By: Daniel Pittman <dan...@puppetlabs.com>
Signed-off-by: Jesse Wolfe <jes5...@gmail.com>
---
 lib/puppet/application/agent.rb     |    2 +-
 lib/puppet/application/apply.rb     |    2 +-
 spec/unit/application/agent_spec.rb |    4 ++--
 spec/unit/application/apply_spec.rb |   16 ++++++++++++++++
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/lib/puppet/application/agent.rb b/lib/puppet/application/agent.rb
index 895156f..3749241 100644
--- a/lib/puppet/application/agent.rb
+++ b/lib/puppet/application/agent.rb
@@ -119,7 +119,7 @@ class Puppet::Application::Agent < Puppet::Application
 
     if not report
       exit(1)
-    elsif not Puppet[:noop] and options[:detailed_exitcodes] then
+    elsif options[:detailed_exitcodes] then
       exit(report.exit_status)
     else
       exit(0)
diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb
index 8f5aa86..cc733e1 100644
--- a/lib/puppet/application/apply.rb
+++ b/lib/puppet/application/apply.rb
@@ -125,7 +125,7 @@ class Puppet::Application::Apply < Puppet::Application
       configurer = Puppet::Configurer.new
       report = configurer.run(:skip_plugin_download => true, :catalog => 
catalog)
 
-      exit( Puppet[:noop] ? 0 : options[:detailed_exitcodes] ? 
report.exit_status : 0 )
+      exit( options[:detailed_exitcodes] ? report.exit_status : 0 )
     rescue => detail
       puts detail.backtrace if Puppet[:trace]
       $stderr.puts detail.message
diff --git a/spec/unit/application/agent_spec.rb 
b/spec/unit/application/agent_spec.rb
index 9fc7879..8f498d4 100755
--- a/spec/unit/application/agent_spec.rb
+++ b/spec/unit/application/agent_spec.rb
@@ -526,11 +526,11 @@ describe Puppet::Application::Agent do
           @puppetd.onetime
         end
 
-        it "should always exit with 0 if --noop" do
+        it "should exit with the report's computer exit status, even if --noop 
is set." do
           Puppet.stubs(:[]).with(:noop).returns(true)
           report = stub 'report', :exit_status => 666
           @agent.stubs(:run).returns(report)
-          @puppetd.expects(:exit).with(0)
+          @puppetd.expects(:exit).with(666)
 
           @puppetd.onetime
         end
diff --git a/spec/unit/application/apply_spec.rb 
b/spec/unit/application/apply_spec.rb
index ceba4a3..d4f39ab 100755
--- a/spec/unit/application/apply_spec.rb
+++ b/spec/unit/application/apply_spec.rb
@@ -166,6 +166,13 @@ describe Puppet::Application::Apply do
         @apply.expects(:exit).with(1)
         @apply.parseonly
       end
+
+      it "should exit with exit code 1 if error, even if --noop is set" do
+        Puppet[:noop] = true
+        @collection.stubs(:perform_initial_import).raises(Puppet::ParseError)
+        @apply.expects(:exit).with(1)
+        @apply.parseonly
+      end
     end
 
     describe "the main command" do
@@ -327,6 +334,15 @@ describe Puppet::Application::Apply do
           @apply.main
         end
 
+        it "should exit with report's computed exit status, even if --noop is 
set" do
+          Puppet.stubs(:[]).with(:noop).returns(true)
+          @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true)
+          
Puppet::Transaction::Report.any_instance.stubs(:exit_status).returns(666)
+          @apply.expects(:exit).with(666)
+
+          @apply.main
+        end
+
         it "should always exit with 0 if option is disabled" do
           Puppet.stubs(:[]).with(:noop).returns(false)
           @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(false)
-- 
1.7.3.5

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

Reply via email to