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, Exec

Class Attribute Summary collapse

Attributes included from Configurable

#instance

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ShellOut

#run_command

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?, #verify_dependencies, #windows_os?

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



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

def serial_actions
  @serial_actions
end

Class Method Details

.kitchen_driver_api_version(version) ⇒ Object

Sets the API version for this driver. If the driver does not set this value, then ‘nil` will be used and reported.

Sets the API version for this driver

Examples:

setting an API version


module Kitchen
  module Driver
    class NewDriver < Kitchen::Driver::Base

      kitchen_driver_api_version 2

    end
  end
end

Parameters:

  • version (Integer, String)

    a version number



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

def self.kitchen_driver_api_version(version)
  @api_version = version
end

.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



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

def self.no_parallel_for(*methods)
  action_methods = %i{create setup converge 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

#cache_directoryObject

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



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

def cache_directory; end

#create(state) ⇒ Object

Creates an instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



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

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

#destroy(state) ⇒ Object

Destroys an instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



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

def destroy(state); end

#doctor(state) ⇒ Object

Check system and configuration for common errors.

Parameters:

  • state (Hash)

    mutable instance and driver state



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

def doctor(state)
  false
end

#package(state) ⇒ Object

Package an instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



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

def package(state); end