Class: Kitchen::Driver::SSHBase

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/driver/ssh_base.rb

Overview

Base class for a driver that uses SSH to communication with an instance. 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 inherited from Base

#initialize, #name, no_parallel_for, #verify_dependencies

Methods included from Logging

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

Methods included from Configurable

#[], #calculate_path, #config_keys, #diagnose, #finalize_config!, included

Methods included from ShellOut

#run_command

Constructor Details

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

Instance Method Details

#converge(state) ⇒ Object

Converges a running instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/kitchen/driver/ssh_base.rb', line 40

def converge(state)
  provisioner = instance.provisioner
  provisioner.create_sandbox
  sandbox_dirs = Dir.glob("#{provisioner.sandbox_path}/*")

  Kitchen::SSH.new(*build_ssh_args(state)) do |conn|
    run_remote(provisioner.install_command, conn)
    run_remote(provisioner.init_command, conn)
    transfer_path(sandbox_dirs, provisioner[:root_path], conn)
    run_remote(provisioner.prepare_command, conn)
    run_remote(provisioner.run_command, conn)
  end
ensure
  provisioner && provisioner.cleanup_sandbox
end

#create(state) ⇒ Object

Creates an instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



35
36
37
# File 'lib/kitchen/driver/ssh_base.rb', line 35

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:



72
73
74
# File 'lib/kitchen/driver/ssh_base.rb', line 72

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

#login_command(state) ⇒ LoginCommand

Returns the shell command that will log into an instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Returns:

  • (LoginCommand)

    an object containing the array of command line tokens and exec options to be used in a fork/exec

Raises:



77
78
79
# File 'lib/kitchen/driver/ssh_base.rb', line 77

def (state)
  SSH.new(*build_ssh_args(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



86
87
88
89
90
# File 'lib/kitchen/driver/ssh_base.rb', line 86

def remote_command(state, command)
  Kitchen::SSH.new(*build_ssh_args(state)) do |conn|
    run_remote(command, conn)
  end
end

#setup(state) ⇒ Object

Sets up an instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



57
58
59
60
61
# File 'lib/kitchen/driver/ssh_base.rb', line 57

def setup(state)
  Kitchen::SSH.new(*build_ssh_args(state)) do |conn|
    run_remote(busser.setup_cmd, conn)
  end
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



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

def ssh(ssh_args, command)
  Kitchen::SSH.new(*ssh_args) do |conn|
    run_remote(command, conn)
  end
end

#verify(state) ⇒ Object

Verifies a converged instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



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

def verify(state)
  Kitchen::SSH.new(*build_ssh_args(state)) do |conn|
    run_remote(busser.sync_cmd, conn)
    run_remote(busser.run_cmd, conn)
  end
end