Class: Kitchen::Driver::SSHBase Deprecated
- Inherits:
-
Object
- Object
- Kitchen::Driver::SSHBase
- Includes:
- Configurable, Logging, ShellOut
- Defined in:
- lib/kitchen/driver/ssh_base.rb
Overview
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)
Direct Known Subclasses
Class Attribute Summary collapse
-
.serial_actions ⇒ Array<Symbol>
readonly
An array of action method names that cannot be run concurrently and must be run in serial via a shared mutex.
Attributes included from Configurable
Class Method Summary collapse
-
.no_parallel_for(*methods) ⇒ Object
Registers certain driver actions that cannot be safely run concurrently in threads across multiple instances.
Instance Method Summary collapse
- #converge(state) ⇒ Object
-
#create(state) ⇒ Object
Creates an instance.
-
#destroy(state) ⇒ Object
Destroys an instance.
-
#initialize(config = {}) ⇒ SSHBase
constructor
Creates a new Driver object using the provided configuration data which will be merged with any default configuration.
- #legacy_state(state) ⇒ Object
- #login_command(state) ⇒ Object
-
#package(state) ⇒ Object
Package an instance.
-
#remote_command(state, command) ⇒ Object
Executes an arbitrary command on an instance over an SSH connection.
- #setup(state) ⇒ Object
-
#ssh(ssh_args, command) ⇒ Object
deprecated
Deprecated.
This method should no longer be called directly and exists to support very old drivers. This will be removed in the future.
- #verify(state) ⇒ Object
-
#verify_dependencies ⇒ Object
Performs whatever tests that may be required to ensure that this driver will be able to function in the current environment.
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?
Constructor Details
#initialize(config = {}) ⇒ SSHBase
Creates a new Driver object using the provided configuration data which will be merged with any default configuration.
63 64 65 |
# File 'lib/kitchen/driver/ssh_base.rb', line 63 def initialize(config = {}) init_config(config) end |
Class Attribute Details
.serial_actions ⇒ Array<Symbol> (readonly)
Returns an array of action method names that cannot be run concurrently and must be run in serial via a shared mutex.
185 186 187 |
# File 'lib/kitchen/driver/ssh_base.rb', line 185 def serial_actions @serial_actions end |
Class Method Details
.no_parallel_for(*methods) ⇒ Object
Registers certain driver actions that cannot be safely run concurrently in threads across multiple instances. Typically this might be used for create or destroy actions that use an underlying resource that cannot be used at the same time.
A shared mutex for this driver object will be used to synchronize all registered methods.
206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/kitchen/driver/ssh_base.rb', line 206 def self.no_parallel_for(*methods) action_methods = [:create, :converge, :setup, :verify, :destroy] Array(methods).each do |meth| next if action_methods.include?(meth) raise ClientError, "##{meth} is not a valid no_parallel_for method" end @serial_actions ||= [] @serial_actions += methods end |
Instance Method Details
#converge(state) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/kitchen/driver/ssh_base.rb', line 73 def converge(state) # rubocop:disable Metrics/AbcSize provisioner = instance.provisioner provisioner.create_sandbox sandbox_dirs = Dir.glob("#{provisioner.sandbox_path}/*") 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)) end rescue Kitchen::Transport::TransportFailed => ex raise ActionFailed, ex. ensure instance.provisioner.cleanup_sandbox end |
#create(state) ⇒ Object
Creates an instance.
68 69 70 |
# File 'lib/kitchen/driver/ssh_base.rb', line 68 def create(state) # rubocop:disable Lint/UnusedMethodArgument raise ClientError, "#{self.class}#create must be implemented" end |
#destroy(state) ⇒ Object
Destroys an instance.
125 126 127 |
# File 'lib/kitchen/driver/ssh_base.rb', line 125 def destroy(state) # rubocop:disable Lint/UnusedMethodArgument raise ClientError, "#{self.class}#destroy must be implemented" end |
#legacy_state(state) ⇒ Object
129 130 131 |
# File 'lib/kitchen/driver/ssh_base.rb', line 129 def legacy_state(state) backcompat_merged_state(state) end |
#login_command(state) ⇒ Object
140 141 142 143 |
# File 'lib/kitchen/driver/ssh_base.rb', line 140 def login_command(state) instance.transport.connection(backcompat_merged_state(state)). login_command end |
#package(state) ⇒ Object
Package an instance.
(see Base#package)
136 137 |
# File 'lib/kitchen/driver/ssh_base.rb', line 136 def package(state) # rubocop:disable Lint/UnusedMethodArgument end |
#remote_command(state, command) ⇒ Object
Executes an arbitrary command on an instance over an SSH connection.
150 151 152 153 154 |
# File 'lib/kitchen/driver/ssh_base.rb', line 150 def remote_command(state, command) instance.transport.connection(backcompat_merged_state(state)) do |conn| conn.execute(env_cmd(command)) end end |
#setup(state) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/kitchen/driver/ssh_base.rb', line 94 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. end |
#ssh(ssh_args, command) ⇒ Object
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.
162 163 164 165 166 167 168 169 170 |
# File 'lib/kitchen/driver/ssh_base.rb', line 162 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
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/kitchen/driver/ssh_base.rb', line 105 def verify(state) # rubocop:disable Metrics/AbcSize verifier = instance.verifier verifier.create_sandbox sandbox_dirs = Dir.glob(File.join(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. ensure instance.verifier.cleanup_sandbox end |
#verify_dependencies ⇒ Object
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.
179 180 |
# File 'lib/kitchen/driver/ssh_base.rb', line 179 def verify_dependencies end |