Skip to content

Commit

Permalink
Making WinRM retries configurable
Browse files Browse the repository at this point in the history
Extends #1480 to add
test coverage and make retries configurable using existing keys.

Signed-off-by: tyler-ball <tball@chef.io>
  • Loading branch information
tyler-ball committed Nov 13, 2018
1 parent 7cc9da0 commit 1265f53
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/kitchen/transport/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def establish_connection(opts)
end
end

# Connecto to a host executing passed block and properly handling retreis.
# Connect to a host executing passed block and properly handling retries.
#
# @param opts [Hash] retry options
# @option opts [Integer] :retries the number of times to retry before
Expand Down
4 changes: 2 additions & 2 deletions lib/kitchen/transport/winrm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ def wait_until_ready
)
execute(PING_COMMAND.dup)
rescue *RESCUE_EXCEPTIONS_ON_ESTABLISH => e
retries ||= 6
retries ||= connection_retries.to_i
raise e if (retries -= 1) < 0
logger.debug("[WinRM] PING_COMMAND failed. Retrying...")
logger.debug("#{e.class}::#{e.message}")
sleep 5
sleep(connection_retry_sleep.to_i)
retry
end

Expand Down
15 changes: 15 additions & 0 deletions spec/kitchen/transport/winrm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,21 @@ def upload # execute every time, not lazily once
logged_output.string.must_match warn_line("Ah crap.\n")
end
end

describe "when connection is over HTTPS" do
before do
executor.expects(:run).times(2)
.with("Write-Host '[WinRM] Established\n'").raises(OpenSSL::SSL::SSLError)
options[:connection_retries] = 1
options[:connection_retry_sleep] = 1
end

it "fails with SSL error" do
proc do
connection.wait_until_ready
end.must_raise OpenSSL::SSL::SSLError
end
end
end

def debug_output(output)
Expand Down

0 comments on commit 1265f53

Please sign in to comment.