Skip to content

Commit

Permalink
fix quality tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smurawski committed Jun 16, 2016
1 parent 919839f commit e4878ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
9 changes: 7 additions & 2 deletions lib/kitchen/command.rb
Expand Up @@ -176,14 +176,19 @@ def run_action(action, instances, *args)
end
end
threads.map(&:join)
report_errors
end

# private

def report_errors
unless @action_errors.empty?
msg = ["#{@action_errors.length} actions failed.",
@action_errors.map { |e| ">>>>>> #{e.message}"}].join("\n")
@action_errors.map { |e| ">>>>>> #{e.message}" }].join("\n")
raise ActionFailed.new(msg, @action_errors)
end
end

# private
def concurrency_setting(instances)
concurrency = 1
if options[:concurrency]
Expand Down
19 changes: 13 additions & 6 deletions lib/kitchen/transport/base.rb
Expand Up @@ -61,7 +61,8 @@ def initialize(config = {})
# @param state [Hash] mutable instance state
# @return [Connection] a connection for this transport
# @raise [TransportFailed] if a connection could not be returned
def connection(state) # rubocop:disable Lint/UnusedMethodArgument
# rubocop:disable Lint/UnusedMethodArgument
def connection(state)
raise ClientError, "#{self.class}#connection must be implemented"
end

Expand Down Expand Up @@ -104,16 +105,18 @@ def close
# @param command [String] command string to execute
# @raise [TransportFailed] if the command does not exit successfully,
# which may vary by implementation
def execute(command) # rubocop:disable Lint/UnusedMethodArgument
def execute(command)
raise ClientError, "#{self.class}#execute must be implemented"
end

# Execute a command on the remote host and retry
#
# @param command [String] command string to execute
# @param retryable_exit_codes [Array] Array of exit codes to retry against
# @param max_retries [Fixnum] maximum number of retry attempts
# @param wait_time [Fixnum] number of seconds to wait before retrying command
# @raise [TransportFailed] if the command does not exit successfully,
# which may vary by implementation
# rubocop:disable Lint/UnusedMethodArgument
def execute_with_retry(command, retryable_exit_codes = [], max_retries, wait_time)
max_retries = 1 if max_retries.nil?
wait_time = 30 if wait_time.nil?
Expand All @@ -123,9 +126,7 @@ def execute_with_retry(command, retryable_exit_codes = [], max_retries, wait_tim
debug("Attempting to execute command - try #{tries} of #{max_retries}.")
execute(command)
rescue Kitchen::Transport::TransportFailed => e
if (tries <= max_retries) &&
!retryable_exit_codes.nil? &&
(retryable_exit_codes.include? e.exit_code)
if retry? tries, max_retries, retryable_exit_codes, e.exit_code
close
sleep wait_time
retry
Expand All @@ -135,6 +136,12 @@ def execute_with_retry(command, retryable_exit_codes = [], max_retries, wait_tim
end
end

def retry?(current_try, max_retries, retryable_exit_codes, exit_code)
current_try <= max_retries &&
!retryable_exit_codes.nil? &&
retryable_exit_codes.include?(exit_code)
end

# Builds a LoginCommand which can be used to open an interactive
# session on the remote host.
#
Expand Down

0 comments on commit e4878ed

Please sign in to comment.