Class: Kitchen::Transport::Ssh

Inherits:
Base show all
Defined in:
lib/kitchen/transport/ssh.rb

Overview

A Transport which uses the SSH protocol to execute commands and transfer files.

Author:

Defined Under Namespace

Classes: Connection

Instance Attribute Summary

Attributes included from Configurable

#instance

Instance Method Summary collapse

Methods inherited from Base

#doctor, #initialize, kitchen_transport_api_version

Methods included from Logging

#banner, #debug, #error, #fatal, #info, #warn

Methods included from Configurable

#[], #bourne_shell?, #calculate_path, #config_keys, #diagnose, #diagnose_plugin, included, #name, #powershell_shell?, #remote_path_join, #unix_os?, #verify_dependencies, #windows_os?

Methods inherited from Plugin::Base

no_parallel_for

Constructor Details

This class inherits a constructor from Kitchen::Transport::Base

Instance Method Details

#cleanup!void

This method returns an undefined value.

Closes the connection, if it is still active.



104
105
106
107
108
109
110
111
112
# File 'lib/kitchen/transport/ssh.rb', line 104

def cleanup!
  if @connection
    string_to_mask = "[SSH] shutting previous connection #{@connection}"
    masked_string = Util.mask_values(string_to_mask, %w{password ssh_http_proxy_password})
    logger.debug(masked_string)
    @connection.close
    @connection = @connection_options = nil
  end
end

#connection(state, &block) ⇒ Connection

Creates a new Connection, configured by a merging of configuration and state data. Depending on the implementation, the Connection could be saved or cached to speed up multiple calls, given the same state hash as input.

rubocop:disable Lint/UnusedMethodArgument

Parameters:

  • state (Hash)

    mutable instance state

Returns:

  • (Connection)

    a connection for this transport

Raises:



93
94
95
96
97
98
99
100
101
# File 'lib/kitchen/transport/ssh.rb', line 93

def connection(state, &block)
  options = connection_options(config.to_hash.merge(state))

  if @connection && @connection_options == options
    reuse_connection(&block)
  else
    create_new_connection(options, &block)
  end
end

#finalize_config!(instance) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/kitchen/transport/ssh.rb', line 77

def finalize_config!(instance)
  super

  # zlib was never a valid value and breaks in net-ssh >= 2.10
  # TODO: remove these backwards compatiable casts in 2.0
  case config[:compression]
  when "zlib"
    config[:compression] = "[email protected]"
  when "none"
    config[:compression] = false
  end

  self
end