Class: Kitchen::Driver::Base

Inherits:
Object
  • Object
show all
Includes:
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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Base

Returns a new instance of Base.



41
42
43
44
45
46
# File 'lib/kitchen/driver/base.rb', line 41

def initialize(config = {})
  @config = LazyHash.new(config, self)
  self.class.defaults.each do |attr, value|
    @config[attr] = value unless @config.has_key?(attr)
  end
end

Class Attribute Details

.serial_actionsObject (readonly)

Returns the value of attribute serial_actions.



38
39
40
# File 'lib/kitchen/driver/base.rb', line 38

def serial_actions
  @serial_actions
end

Instance Attribute Details

#instanceObject

Returns the value of attribute instance.



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

def instance
  @instance
end

Class Method Details

.default_config(attr, value = nil, &block) ⇒ Object



194
195
196
# File 'lib/kitchen/driver/base.rb', line 194

def self.default_config(attr, value = nil, &block)
  defaults[attr] = block_given? ? block : value
end

.defaultsObject



180
181
182
# File 'lib/kitchen/driver/base.rb', line 180

def self.defaults
  @defaults ||= Hash.new.merge(super_defaults)
end

.no_parallel_for(*methods) ⇒ Object



216
217
218
219
220
221
222
223
224
225
# File 'lib/kitchen/driver/base.rb', line 216

def self.no_parallel_for(*methods)
  Array(methods).each do |meth|
    if ! ACTION_METHODS.include?(meth)
      raise ClientError, "##{meth} is not a valid no_parallel_for method"
    end
  end

  @serial_actions ||= []
  @serial_actions += methods
end

.required_config(attr, &block) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/kitchen/driver/base.rb', line 202

def self.required_config(attr, &block)
  @validations = [] if @validations.nil?
  if ! block_given?
    klass = self
    block = lambda do |attr, value, driver|
      if value.nil? || value.to_s.empty?
        attribute = "#{klass}#{driver.instance.to_str}#config[:#{attr}]"
        raise UserError, "#{attribute} cannot be blank"
      end
    end
  end
  @validations << [attr, block]
end

.super_defaultsObject



184
185
186
187
188
189
190
191
192
# File 'lib/kitchen/driver/base.rb', line 184

def self.super_defaults
  klass = self.superclass

  if klass.respond_to?(:defaults)
    klass.defaults
  else
    Hash.new
  end
end

.validationsObject



198
199
200
# File 'lib/kitchen/driver/base.rb', line 198

def self.validations
  @validations
end

Instance Method Details

#[](attr) ⇒ Object

Provides hash-like access to configuration keys.

Parameters:

  • attr (Object)

    configuration key

Returns:

  • (Object)

    value at configuration key



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

def [](attr)
  config[attr]
end

#config_keysArray

Returns an array of configuration keys.

Returns:

  • (Array)

    array of configuration keys



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

def config_keys
  config.keys
end

#converge(state) ⇒ Object

Converges a running instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



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

def converge(state) ; end

#create(state) ⇒ Object

Creates an instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



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

def create(state) ; end

#destroy(state) ⇒ Object

Destroys an instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



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

def destroy(state) ; end

#diagnoseHash

Returns a Hash of configuration and other useful diagnostic information.

Returns:

  • (Hash)

    a diagnostic hash



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

def diagnose
  result = Hash.new
  config_keys.sort.each { |k| result[k] = config[k] }
  result
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:



112
113
114
# File 'lib/kitchen/driver/base.rb', line 112

def (state)
  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



57
58
59
# File 'lib/kitchen/driver/base.rb', line 57

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

#setup(state) ⇒ Object

Sets up an instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



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

def setup(state) ; end

#validate_config!Object



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

def validate_config!
  Array(self.class.validations).each do |tuple|
    tuple.last.call(tuple.first, config[tuple.first], self)
  end
end

#verify(state) ⇒ Object

Verifies a converged instance.

Parameters:

  • state (Hash)

    mutable instance and driver state

Raises:



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

def verify(state) ; 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



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

def verify_dependencies ; end