lib/kitchen/transport/ssh.rb in test-kitchen-1.21.2 vs lib/kitchen/transport/ssh.rb in test-kitchen-1.22.0

- old
+ new

@@ -52,10 +52,11 @@ default_config :connection_retries, 5 default_config :connection_retry_sleep, 1 default_config :max_wait_until_ready, 600 default_config :ssh_gateway, nil + default_config :ssh_gateway_port, 22 default_config :ssh_gateway_username, nil default_config :ssh_http_proxy, nil default_config :ssh_http_proxy_port, nil default_config :ssh_http_proxy_user, nil @@ -155,12 +156,11 @@ if options.key?(:forward_agent) args += %W{ -o ForwardAgent=#{options[:forward_agent] ? 'yes' : 'no'} } end if ssh_gateway gateway_command = "ssh -q #{ssh_gateway_username}@#{ssh_gateway} nc #{hostname} #{port}" - # Should support other ports than 22 for ssh gateways - args += %W{ -o ProxyCommand=#{gateway_command} -p 22 } + args += %W{ -o ProxyCommand=#{gateway_command} -p #{ssh_gateway_port} } end Array(options[:keys]).each { |ssh_key| args += %W{ -i #{ssh_key} } } args += %W{ -p #{port} } args += %W{ #{username}@#{hostname} } @@ -275,10 +275,14 @@ # @return [String] The username to use when using an ssh gateway # @api private attr_reader :ssh_gateway_username + # @return [Integer] The port to use when using an ssh gateway + # @api private + attr_reader :ssh_gateway_port + # @return [String] The kitchen ssh proxy to use when connecting to the # remote SSH host via http proxy # @api private attr_reader :ssh_http_proxy @@ -308,12 +312,13 @@ # debug (overriding the default) when a rescuable exception is raised # @return [Net::SSH::Connection::Session] the SSH connection session # @api private def establish_connection_via_gateway(opts) retry_connection(opts) do + gateway_options = options.merge(:port => ssh_gateway_port) Net::SSH::Gateway.new(ssh_gateway, - ssh_gateway_username, options).ssh(hostname, username, options) + ssh_gateway_username, gateway_options).ssh(hostname, username, options) end end # Establish an SSH session on the remote host. # @@ -343,11 +348,11 @@ # debug (overriding the default) when a rescuable exception is raised # @return [Net::SSH::Connection::Session] the SSH connection session # @api private def retry_connection(opts) log_msg = "[SSH] opening connection to #{self}" - log_msg += " via #{ssh_gateway_username}@#{ssh_gateway}" if ssh_gateway + log_msg += " via #{ssh_gateway_username}@#{ssh_gateway}:#{ssh_gateway_port}" if ssh_gateway logger.debug(log_msg) yield rescue *RESCUE_EXCEPTIONS_ON_ESTABLISH => e if (opts[:retries] -= 1) > 0 message = if opts[:message] @@ -404,10 +409,11 @@ @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) @ssh_gateway = @options.delete(:ssh_gateway) @ssh_gateway_username = @options.delete(:ssh_gateway_username) + @ssh_gateway_port = @options.delete(:ssh_gateway_port) @ssh_http_proxy = @options.delete(:ssh_http_proxy) @ssh_http_proxy_user = @options.delete(:ssh_http_proxy_user) @ssh_http_proxy_password = @options.delete(:ssh_http_proxy_password) @ssh_http_proxy_port = @options.delete(:ssh_http_proxy_port) end @@ -466,9 +472,10 @@ connection_retry_sleep: data[:connection_retry_sleep], max_ssh_sessions: data[:max_ssh_sessions], max_wait_until_ready: data[:max_wait_until_ready], ssh_gateway: data[:ssh_gateway], ssh_gateway_username: data[:ssh_gateway_username], + ssh_gateway_port: data[:ssh_gateway_port], } if data[:ssh_key] && !data[:password] opts[:keys_only] = true opts[:keys] = Array(data[:ssh_key])