From 5780f5dcc024d4f140fe8f6e8dc3f7c4e905a8ec Mon Sep 17 00:00:00 2001 From: elijah Date: Wed, 29 Jun 2016 16:55:06 -0700 Subject: leap cli: move everything we can from leap_cli to leap_platform --- lib/leap_cli/ssh/backend.rb | 5 ++++- lib/leap_cli/ssh/remote_command.rb | 3 +++ lib/leap_cli/ssh/scripts.rb | 8 +++++--- 3 files changed, 12 insertions(+), 4 deletions(-) (limited to 'lib/leap_cli/ssh') diff --git a/lib/leap_cli/ssh/backend.rb b/lib/leap_cli/ssh/backend.rb index f42379cc..67c6ec9a 100644 --- a/lib/leap_cli/ssh/backend.rb +++ b/lib/leap_cli/ssh/backend.rb @@ -94,7 +94,7 @@ module LeapCli # some prewritten servers-side scripts def scripts - @scripts ||= LeapCli::SSH::Scripts.new(self, @host) + @scripts ||= LeapCli::SSH::Scripts.new(self, @host.hostname) end private @@ -139,6 +139,9 @@ module LeapCli @logger.log(:failed, args.join(' '), host: @host.hostname) do @logger.log("Connection timed out") end + if @options[:raise_error] + raise LeapCli::SSH::TimeoutError, exc.to_s + end else raise end diff --git a/lib/leap_cli/ssh/remote_command.rb b/lib/leap_cli/ssh/remote_command.rb index fe9a344a..3ba86740 100644 --- a/lib/leap_cli/ssh/remote_command.rb +++ b/lib/leap_cli/ssh/remote_command.rb @@ -21,6 +21,9 @@ module LeapCli class ExecuteError < StandardError end + class TimeoutError < ExecuteError + end + # override default runner mode class CustomCoordinator < SSHKit::Coordinator private diff --git a/lib/leap_cli/ssh/scripts.rb b/lib/leap_cli/ssh/scripts.rb index 3d8b6570..feefdd46 100644 --- a/lib/leap_cli/ssh/scripts.rb +++ b/lib/leap_cli/ssh/scripts.rb @@ -15,7 +15,7 @@ module LeapCli REQUIRED_PACKAGES = "puppet rsync lsb-release locales" attr_reader :ssh, :host - def initialize(backend, host) + def initialize(backend, hostname) @ssh = backend @host = host end @@ -48,6 +48,8 @@ module LeapCli def check_for_no_deploy begin ssh.stream "test ! -f /etc/leap/no-deploy", :raise_error => true, :log_output => false + rescue SSH::TimeoutError + raise rescue SSH::ExecuteError ssh.log :warning, "can't continue because file /etc/leap/no-deploy exists", :host => host raise # will skip further action on this node @@ -59,7 +61,7 @@ module LeapCli # def debug output = ssh.capture "#{Leap::Platform.leap_dir}/bin/debug.sh" - ssh.log(output, :wrap => true, :host => host.hostname, :color => :cyan) + ssh.log(output, :wrap => true, :host => host, :color => :cyan) end # @@ -69,7 +71,7 @@ module LeapCli cmd = "(test -s /var/log/leap/deploy-summary.log && tail -n #{lines} /var/log/leap/deploy-summary.log) || (test -s /var/log/leap/deploy-summary.log.1 && tail -n #{lines} /var/log/leap/deploy-summary.log.1) || (echo 'no history')" history = ssh.capture(cmd, :log_output => false) if history - ssh.log host.hostname, :color => :cyan, :style => :bold do + ssh.log host, :color => :cyan, :style => :bold do ssh.log history, :wrap => true end end -- cgit v1.2.3