class Kitchen::Transport::Ssh::Connection

Monkey patch of test-kitchen ssh transport that returns stdout

Public Instance Methods

node_execute(command, &block) click to toggle source
# File lib/kitchen/provisioner/finder/ssh.rb, line 7
def node_execute(command, &block)
  return if command.nil?
  out, exit_code = node_execute_with_exit_code(command, &block)

  if exit_code.nonzero?
    raise Transport::SshFailed,
          "SSH exited (#{exit_code}) for command: [#{command}]"
  end
  out
rescue Net::SSH::Exception => ex
  raise SshFailed, "SSH command failed (#{ex.message})"
end
node_execute_with_exit_code(command) { |data| ... } click to toggle source

rubocop:disable Metrics/AbcSize

# File lib/kitchen/provisioner/finder/ssh.rb, line 21
def node_execute_with_exit_code(command)
  exit_code = nil
  out = []
  session.open_channel do |channel|
    channel.request_pty
    channel.exec(command) do |_ch, _success|
      channel.on_data do |_ch, data|
        out << data
        yield data if block_given?
      end

      channel.on_extended_data do |_ch, _type, data|
        out << data
        yield data if block_given?
      end

      channel.on_request('exit-status') do |_ch, data|
        exit_code = data.read_long
      end
    end
  end
  session.loop
  [out.join("\n"), exit_code]
end