lib/kitchen/transport/ssh.rb in test-kitchen-1.9.1 vs lib/kitchen/transport/ssh.rb in test-kitchen-1.9.2
- old
+ new
@@ -44,10 +44,12 @@
default_config :port, 22
default_config :username, "root"
default_config :keepalive, true
default_config :keepalive_interval, 60
+ # needs to be one less than the configured sshd_config MaxSessions
+ default_config :max_ssh_sessions, 9
default_config :connection_timeout, 15
default_config :connection_retries, 5
default_config :connection_retry_sleep, 1
default_config :max_wait_until_ready, 600
@@ -147,16 +149,18 @@
# (see Base::Connection#upload)
def upload(locals, remote)
logger.debug("TIMING: scp async upload (Kitchen::Transport::Ssh)")
elapsed = Benchmark.measure do
- waits = Array(locals).map do |local|
+ waits = []
+ Array(locals).map do |local|
opts = File.directory?(local) ? { :recursive => true } : {}
- session.scp.upload(local, remote, opts) do |_ch, name, sent, total|
+ waits.push session.scp.upload(local, remote, opts) do |_ch, name, sent, total|
logger.debug("Async Uploaded #{name} (#{total} bytes)") if sent == total
end
+ waits.shift.wait while waits.length >= max_ssh_sessions
end
waits.each(&:wait)
end
delta = Util.duration(elapsed.real)
logger.debug("TIMING: scp async upload (Kitchen::Transport::Ssh) took #{delta}")
@@ -185,10 +189,14 @@
Errno::ECONNRESET, Errno::ENETUNREACH, Errno::EHOSTUNREACH,
Net::SSH::Disconnect, Net::SSH::AuthenticationFailed, Net::SSH::ConnectionTimeout,
Timeout::Error
].freeze
+ # @return [Integer] cap on number of parallel ssh sessions we can use
+ # @api private
+ attr_reader :max_ssh_sessions
+
# @return [Integer] how many times to retry when failing to execute
# a command or transfer files
# @api private
attr_reader :connection_retries
@@ -284,10 +292,11 @@
@username = @options.delete(:username)
@hostname = @options.delete(:hostname)
@port = @options[:port] # don't delete from options
@connection_retries = @options.delete(:connection_retries)
@connection_retry_sleep = @options.delete(:connection_retry_sleep)
+ @max_ssh_sessions = @options.delete(:max_ssh_sessions)
@max_wait_until_ready = @options.delete(:max_wait_until_ready)
end
# Returns a connection session, or establishes one when invoked the
# first time.
@@ -333,9 +342,10 @@
:keepalive => data[:keepalive],
:keepalive_interval => data[:keepalive_interval],
:timeout => data[:connection_timeout],
:connection_retries => data[:connection_retries],
:connection_retry_sleep => data[:connection_retry_sleep],
+ :max_ssh_sessions => data[:max_ssh_sessions],
:max_wait_until_ready => data[:max_wait_until_ready]
}
opts[:keys_only] = true if data[:ssh_key]
opts[:keys] = Array(data[:ssh_key]) if data[:ssh_key]