]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
added no-deploy check and simple `leap test run`.
authorelijah <elijah@riseup.net>
Fri, 6 Dec 2013 00:26:36 +0000 (16:26 -0800)
committerelijah <elijah@riseup.net>
Fri, 6 Dec 2013 00:26:36 +0000 (16:26 -0800)
lib/leap_cli/commands/deploy.rb
lib/leap_cli/commands/test.rb
lib/leap_cli/logger.rb
lib/leap_cli/remote/leap_plugin.rb

index 23af0f75d765754ebaa1616d032a4656809d778c..61323c9aeb613556520dc8b8fdd7bae64e2d5e81 100644 (file)
@@ -39,6 +39,7 @@ module LeapCli
 
         ssh_connect(nodes, connect_options(options)) do |ssh|
           ssh.leap.log :checking, 'node' do
+            ssh.leap.check_for_no_deploy
             ssh.leap.assert_initialized
           end
           ssh.leap.log :synching, "configuration files" do
@@ -94,13 +95,13 @@ module LeapCli
 
     def sync_puppet_files(ssh)
       ssh.rsync.update do |server|
-        ssh.leap.log(Path.platform + '/[bin,puppet] -> ' + server.host + ':' + LeapCli::PUPPET_DESTINATION)
+        ssh.leap.log(Path.platform + '/[bin,tests,puppet] -> ' + server.host + ':' + LeapCli::PUPPET_DESTINATION)
         {
           :dest => LeapCli::PUPPET_DESTINATION,
           :source => '.',
           :chdir => Path.platform,
           :excludes => '*',
-          :includes => ['/bin', '/bin/**', '/puppet', '/puppet/**'],
+          :includes => ['/bin', '/bin/**', '/puppet', '/puppet/**', '/tests', '/tests/**'],
           :flags => "-rlt --relative --delete --copy-links"
         }
       end
index c240a707031aa86cb07b47025b6d06b83b1f7d65..7066241bd005fadb14786c71779cc76297455249 100644 (file)
@@ -12,7 +12,11 @@ module LeapCli; module Commands
     test.desc 'Run tests.'
     test.command :run do |run|
       run.action do |global_options,options,args|
-        log 'not yet implemented'
+        manager.filter!(args).each_node do |node|
+          ssh_connect(node) do |ssh|
+            ssh.run(test_cmd)
+          end
+        end
       end
     end
 
@@ -21,6 +25,10 @@ module LeapCli; module Commands
 
   private
 
+  def test_cmd
+    "#{PUPPET_DESTINATION}/bin/run_tests"
+  end
+
   #
   # generates a whole bunch of openvpn configs that can be used to connect to different openvpn gateways
   #
index a4962601bc05ce37b09ec81e87945a7172d8029b..91fa22dfa99f6dca180c6023935e179957c991f5 100644 (file)
@@ -133,7 +133,13 @@ module LeapCli
       { :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 => /^Puppet apply complete.*fail/,  :level => 0, :color => :red, :priority => -1, :exit => 1}
+      { :match => /^Puppet apply complete.*fail/,  :level => 0, :color => :red, :priority => -1, :exit => 1},
+
+      # TESTS
+      { :match => /^PASS: /,                :color => :green,   :priority => -20},
+      { :match => /^(FAIL|ERROR): /,        :color => :red,     :priority => -20},
+      { :match => /^SKIP: /,                :color => :yellow,  :priority => -20}
+
     ]
 
     def self.sorted_formatters
index 04b1e2cc905cfc2a9d404e2423b2700a9bd2ff90..a284712b135df69d72e67d4b0637f79e1fa545ad 100644 (file)
@@ -21,6 +21,9 @@ module LeapCli; module Remote; module LeapPlugin
     run dirs.collect{|dir| "mkdir -m 700 -p #{dir}; "}.join
   end
 
+  #
+  # echos "ok" if the node has been initialized and the required packages are installed, bails out otherwise.
+  #
   def assert_initialized
     begin
       test_initialized_file = "test -f #{INITIALIZED_FILE}"
@@ -35,6 +38,24 @@ module LeapCli; module Remote; module LeapPlugin
     end
   end
 
+  #
+  # bails out the deploy if the file /etc/leap/no-deploy exists.
+  # This kind of sucks, because it would be better to skip over nodes that have no-deploy set instead
+  # halting the entire deploy. As far as I know, with capistrano, there is no way to close one of the
+  # ssh connections in the pool and make sure it gets no further commands.
+  #
+  def check_for_no_deploy
+    begin
+      run "test ! -f /etc/leap/no-deploy"
+    rescue Capistrano::CommandError => exc
+      LeapCli::Util.bail! do
+        exc.hosts.each do |host|
+          LeapCli::Util.log "Can't continue because file /etc/leap/no-deploy exists", :host => host
+        end
+      end
+    end
+  end
+
   def mark_initialized
     run "touch #{INITIALIZED_FILE}"
   end