Class: Kitchen::Driver::Base

Inherits:
Object
  • Object
show all
Includes:
Configurable, Logging, ShellOut
Defined in:
lib/kitchen/driver/base.rb

Overview

Base class for a driver.

Author:

Direct Known Subclasses

Dummy, SSHBase

Class Attribute Summary collapse

Attributes included from Configurable

#instance

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

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

Methods included from Configurable

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

Constructor Details

#initialize(config = {}) ⇒ Base

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



40
41
42
# File 'lib/kitchen/driver/base.rb', line 40

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

Class Attribute Details

.serial_actionsArray<Symbol> (readonly)

Returns an array of action method names that cannot be run concurrently and must be run in serial via a shared mutex.

Returns:

  • (Array<Symbol>)

    an array of action method names that cannot be run concurrently and must be run in serial via a shared mutex



109
110
111
# File 'lib/kitchen/driver/base.rb', line 109

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.

Examples:

a single action method that cannot be run concurrently


no_parallel_for :create

multiple action methods that cannot be run concurrently


no_parallel_for :create, :destroy

Parameters:

  • methods (Array<Symbol>)

    one or more actions as symbols

Raises:

  • (ClientError)

    if any method is not a valid action method name



130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/kitchen/driver/base.rb', line 130

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

Converges a running instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



62
63
# File 'lib/kitchen/driver/base.rb', line 62

def converge(state) # rubocop:disable Lint/UnusedMethodArgument
end

#create(state) ⇒ Object

Creates an instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



55
56
# File 'lib/kitchen/driver/base.rb', line 55

def create(state) # rubocop:disable Lint/UnusedMethodArgument
end

#destroy(state) ⇒ Object

Destroys an instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



83
84
# File 'lib/kitchen/driver/base.rb', line 83

def destroy(state) # rubocop:disable Lint/UnusedMethodArgument
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:



92
93
94
# File 'lib/kitchen/driver/base.rb', line 92

def (state) # rubocop:disable Lint/UnusedMethodArgument
  raise ActionFailed, "Remote login is not supported in this driver."
end

#nameString

Returns the name of this driver, suitable for display in a CLI.

Returns:

  • (String)

    name of this driver



47
48
49
# File 'lib/kitchen/driver/base.rb', line 47

def name
  self.class.name.split("::").last
end

#setup(state) ⇒ Object

Sets up an instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



69
70
# File 'lib/kitchen/driver/base.rb', line 69

def setup(state) # rubocop:disable Lint/UnusedMethodArgument
end

#verify(state) ⇒ Object

Verifies a converged instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



76
77
# File 'lib/kitchen/driver/base.rb', line 76

def verify(state) # rubocop:disable Lint/UnusedMethodArgument
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



103
104
# File 'lib/kitchen/driver/base.rb', line 103

def verify_dependencies
end