]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
added exit codes for puppet apply
authorelijah <elijah@riseup.net>
Thu, 14 Mar 2013 09:05:58 +0000 (02:05 -0700)
committerelijah <elijah@riseup.net>
Thu, 14 Mar 2013 09:05:58 +0000 (02:05 -0700)
README.md
bin/leap
lib/leap_cli/commands/deploy.rb
lib/leap_cli/logger.rb
lib/leap_cli/util.rb
vendor/supply_drop/lib/supply_drop/plugin.rb

index 75dddfd317634ac501d13005689c7747a4eaf500..8f6db5aabddcefa31df6096bf1d74b824781acb8 100644 (file)
--- a/README.md
+++ b/README.md
@@ -98,3 +98,14 @@ working directory is under leap_cli. Because the point is to be able to run ``le
 other places, it is easier to create the symlink. If you run ``leap`` directly, and not via
 the command launcher that rubygems installs, leap will run in a mode that simulates
 ``bundle exec leap`` (i.e. only gems included in Gemfile are allowed to be loaded).
+
+Future development
+----------------------------------------------------
+
+(1) remove supply_drop - our use of supply drop no longer makes sense, as our needs diverge and we have more and more patches against upstream. the supply drop code we use should be cherry picked and brought into leap_cli.
+
+  (a) create a separate rsync library independent of capistrano or supply_drop.
+  (b) do our own rsync for the puppet manifests (make sure to include --copy-links)
+  (c) do our own puppet apply, with capture of exit status.
+
+(2) remove capistrano. we don't need it, and it makes it awkward to do what we want (exit codes, different options for different hosts). either use another shell lib, or roll our own. maybe something like 'remotedly(hosts) do |host|....'
index 683959a47779cca86bd7e14b1a1a096ef4599519..5dbf0464a5607d54f17fa68c7e54999003d5b1e2 100755 (executable)
--- a/bin/leap
+++ b/bin/leap
@@ -76,5 +76,6 @@ module LeapCli::Commands
   # load commands and run
   commands_from('leap_cli/commands')
   ORIGINAL_ARGV = ARGV.dup
-  exit run(ARGV)
+  exit_status = run(ARGV)
+  exit(LeapCli::Util.exit_status || exit_status)
 end
index d7f5df8c0b5ea509e29c1e710354cc0cdf0d69c8..76df4fb7d139f310779028562e103e32d33a3999 100644 (file)
@@ -60,7 +60,7 @@ module LeapCli
             else ''
           end
 
-          ssh.set :puppet_command, "/usr/bin/puppet apply --color=false --tags=#{tags.join(',')} #{verbosity}"
+          ssh.set :puppet_command, "/usr/bin/puppet apply --color=false --tags=#{tags.join(',')} --detailed-exitcodes #{verbosity}"
           ssh.set :puppet_lib, "puppet/modules"
           ssh.set :puppet_parameters, '--libdir puppet/lib --confdir puppet puppet/manifests/site.pp'
           ssh.set :puppet_stream_output, true
index 58aa3c0f97da188769347ab98f22aca9ce6ca812..e700ee6220d4b74714d9e9fa45e9daf83e3f0a54 100644 (file)
@@ -121,6 +121,8 @@ module LeapCli
       { :match => /^warning:/,                     :level => 0, :color => :yellow, :priority => -20},
       { :match => /^Duplicate declaration:/,       :level => 0, :color => :red,    :priority => -20},
       { :match => /Finished catalog run/,          :level => 0, :color => :green,  :priority => -10},
+      { :match => /^Puppet apply complete \(changes made\)/, :level => 0, :color => :green,  :priority => -10},
+      { :match => /^Puppet apply complete \(no changes\)/, :level => 0, :color => :green,  :priority => -10},
 
       # PUPPET FATAL ERRORS
       { :match => /^err:/,                         :level => 0, :color => :red, :priority => -1, :exit => 1},
@@ -128,7 +130,8 @@ module LeapCli
       { :match => /^Parameter matches failed:/,    :level => 0, :color => :red, :priority => -1, :exit => 1},
       { :match => /^Syntax error/,                 :level => 0, :color => :red, :priority => -1, :exit => 1},
       { :match => /^Cannot reassign variable/,     :level => 0, :color => :red, :priority => -1, :exit => 1},
-      { :match => /^Could not find template/,      :level => 0, :color => :red, :priority => -1, :exit => 1}
+      { :match => /^Could not find template/,      :level => 0, :color => :red, :priority => -1, :exit => 1},
+      { :match => /^Puppet apply complete.*fail/,  :level => 0, :color => :red, :priority => -1, :exit => 1}
     ]
 
     def self.sorted_formatters
index 155796f03fe6a5def4c5987fd09cd99cb28aa70e..0453b6d43f8f220352e268384dd155132986b309 100644 (file)
@@ -12,8 +12,9 @@ module LeapCli
     ## QUITTING
     ##
 
-    def exit_status(code)
-      @exit_status = code
+    def exit_status(code=nil)
+      @exit_status = code if code
+      @exit_status
     end
 
     #
index 9649c5ba3886db12235048ad90a52abfb0a45af2..48198b42f0857858ea43595d571d134166799c99 100644 (file)
@@ -71,15 +71,30 @@ fi
       writer = SupplyDrop::Writer::File.new(writer, puppet_write_to_file) unless puppet_write_to_file.nil?
 
       begin
-        run "#{puppet_cmd} #{flag}" do |channel, stream, data|
-          writer.collect_output(channel[:host], data)
+        exitcode = nil
+        run "#{puppet_cmd} #{flag}; echo exitcode:$?" do |channel, stream, data|
+          if data =~ /exitcode:(\d+)/
+            exitcode = $1
+            writer.collect_output(channel[:host], "Puppet #{command} complete (#{exitcode_description(exitcode)}).\n")
+          else
+            writer.collect_output(channel[:host], data)
+          end
         end
-        logger.debug "Puppet #{command} complete."
       ensure
         writer.all_output_collected
       end
     end
 
+    def exitcode_description(code)
+      case code
+        when "0" then "no changes"
+        when "2" then "changes made"
+        when "4" then "failed"
+        when "6" then "changes and failures"
+        else code
+      end
+    end
+
     def red_text(text)
       "\033[0;31m#{text}\033[0m"
     end