Class: Kitchen::Driver::SSHBase Deprecated

Inherits:
Plugin::Base show all
Includes:
Configurable, Logging, ShellOut
Defined in:
lib/kitchen/driver/ssh_base.rb

Overview

Deprecated.

While all possible effort has been made to preserve the original behavior of this class, future improvements to the Driver, Transport, and Verifier subsystems may not be picked up in these Drivers. When legacy Driver::SSHBase support is removed, this class will no longer be available.

Legacy base class for a driver that uses SSH to communication with an instance. This class has been updated to use the Instance’s Transport to issue commands and transfer files and no longer uses the ‘Kitchen:SSH` class directly.

NOTE: Authors of new Drivers are encouraged to inherit from ‘Kitchen::Driver::Base` instead and existing Driver authors are encouraged to update their Driver class to inherit from `Kitchen::Driver::SSHBase`.

A subclass must implement the following methods:

  • #create(state)

  • #destroy(state)

Author:

Direct Known Subclasses

Proxy

Instance Attribute Summary

Attributes included from Configurable

#instance

Instance Method Summary collapse

Methods included from Logging

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

Methods included from Configurable

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

Methods inherited from Plugin::Base

no_parallel_for

Constructor Details

#initialize(config = {}) ⇒ SSHBase

Creates a new Driver object using the provided configuration data which will be merged with any default configuration.

Parameters:

  • config (Hash) (defaults to: {})

    provided driver configuration



60
61
62
# File 'lib/kitchen/driver/ssh_base.rb', line 60

def initialize(config = {})
  init_config(config)
end

Instance Method Details

#cache_directoryObject

Cache directory that a driver could implement to inform the provisioner that it can leverage it internally



187
# File 'lib/kitchen/driver/ssh_base.rb', line 187

def cache_directory; end

#converge(state) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/kitchen/driver/ssh_base.rb', line 70

def converge(state) # rubocop:disable Metrics/AbcSize
  provisioner = instance.provisioner
  provisioner.create_sandbox
  sandbox_dirs = provisioner.sandbox_dirs

  instance.transport.connection(backcompat_merged_state(state)) do |conn|
    conn.execute(env_cmd(provisioner.install_command))
    conn.execute(env_cmd(provisioner.init_command))
    info("Transferring files to #{instance.to_str}")
    conn.upload(sandbox_dirs, provisioner[:root_path])
    debug("Transfer complete")
    conn.execute(env_cmd(provisioner.prepare_command))
    conn.execute(env_cmd(provisioner.run_command))
    info("Downloading files from #{instance.to_str}")
    provisioner[:downloads].to_h.each do |remotes, local|
      debug("Downloading #{Array(remotes).join(", ")} to #{local}")
      conn.download(remotes, local)
    end
    debug("Download complete")
  end
rescue Kitchen::Transport::TransportFailed => ex
  raise ActionFailed, ex.message
ensure
  instance.provisioner.cleanup_sandbox
end

#create(state) ⇒ Object

Creates an instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



65
66
67
# File 'lib/kitchen/driver/ssh_base.rb', line 65

def create(state) # rubocop:disable Lint/UnusedMethodArgument
  raise ClientError, "#{self.class}#create must be implemented"
end

#destroy(state) ⇒ Object

Destroys an instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



128
129
130
# File 'lib/kitchen/driver/ssh_base.rb', line 128

def destroy(state) # rubocop:disable Lint/UnusedMethodArgument
  raise ClientError, "#{self.class}#destroy must be implemented"
end

#legacy_state(state) ⇒ Object



132
133
134
# File 'lib/kitchen/driver/ssh_base.rb', line 132

def legacy_state(state)
  backcompat_merged_state(state)
end

#login_command(state) ⇒ Object



142
143
144
145
# File 'lib/kitchen/driver/ssh_base.rb', line 142

def (state)
  instance.transport.connection(backcompat_merged_state(state))
    .
end

#package(state) ⇒ Object

Package an instance.

(see Base#package)



139
# File 'lib/kitchen/driver/ssh_base.rb', line 139

def package(state); end

#remote_command(state, command) ⇒ Object

Executes an arbitrary command on an instance over an SSH connection.

Parameters:

  • state (Hash)

    mutable instance and driver state

  • command (String)

    the command to be executed

Raises:

  • (ActionFailed)

    if the command could not be successfully completed



152
153
154
155
156
# File 'lib/kitchen/driver/ssh_base.rb', line 152

def remote_command(state, command)
  instance.transport.connection(backcompat_merged_state(state)) do |conn|
    conn.execute(env_cmd(command))
  end
end

#setup(state) ⇒ Object



97
98
99
100
101
102
103
104
105
# File 'lib/kitchen/driver/ssh_base.rb', line 97

def setup(state)
  verifier = instance.verifier

  instance.transport.connection(backcompat_merged_state(state)) do |conn|
    conn.execute(env_cmd(verifier.install_command))
  end
rescue Kitchen::Transport::TransportFailed => ex
  raise ActionFailed, ex.message
end

#ssh(ssh_args, command) ⇒ Object

Deprecated.

This method should no longer be called directly and exists to support very old drivers. This will be removed in the future.

**(Deprecated)** Executes a remote command over SSH.

Parameters:

  • ssh_args (Array)

    ssh arguments

  • command (String)

    remote command to invoke



164
165
166
167
168
169
170
171
172
# File 'lib/kitchen/driver/ssh_base.rb', line 164

def ssh(ssh_args, command)
  pseudo_state = { hostname: ssh_args[0], username: ssh_args[1] }
  pseudo_state.merge!(ssh_args[2])
  connection_state = backcompat_merged_state(pseudo_state)

  instance.transport.connection(connection_state) do |conn|
    conn.execute(env_cmd(command))
  end
end

#verify(state) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/kitchen/driver/ssh_base.rb', line 108

def verify(state) # rubocop:disable Metrics/AbcSize
  verifier = instance.verifier
  verifier.create_sandbox
  sandbox_dirs = Util.list_directory(verifier.sandbox_path)

  instance.transport.connection(backcompat_merged_state(state)) do |conn|
    conn.execute(env_cmd(verifier.init_command))
    info("Transferring files to #{instance.to_str}")
    conn.upload(sandbox_dirs, verifier[:root_path])
    debug("Transfer complete")
    conn.execute(env_cmd(verifier.prepare_command))
    conn.execute(env_cmd(verifier.run_command))
  end
rescue Kitchen::Transport::TransportFailed => ex
  raise ActionFailed, ex.message
ensure
  instance.verifier.cleanup_sandbox
end

#verify_dependenciesObject

Performs whatever tests that may be required to ensure that this driver will be able to function in the current environment. This may involve checking for the presence of certain directories, software installed, etc.

Raises:

  • (UserError)

    if the driver will not be able to perform or if a documented dependency is missing from the system



181
# File 'lib/kitchen/driver/ssh_base.rb', line 181

def verify_dependencies; end