Class: Kitchen::Transport::Ssh::Connection

Inherits:
Base::Connection
  • Object
show all
Defined in:
lib/kitchen/provisioner/finder/ssh.rb

Overview

Monkey patch of test-kitchen ssh transport that returns stdout

Instance Method Summary collapse

Instance Method Details

#node_execute(command, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# 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 != 0
    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) ⇒ Object

rubocop:disable Metrics/AbcSize



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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