Class: Kitchen::Provisioner::Base

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/kitchen/provisioner/base.rb

Overview

Base class for a provisioner.

Author:

Direct Known Subclasses

ChefBase, Dummy, Shell

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Base

Returns a new instance of Base.



34
35
36
37
38
39
# File 'lib/kitchen/provisioner/base.rb', line 34

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

Instance Attribute Details

#instanceObject

Returns the value of attribute instance.



32
33
34
# File 'lib/kitchen/provisioner/base.rb', line 32

def instance
  @instance
end

Instance Method Details

#[](attr) ⇒ Object

Provides hash-like access to configuration keys.

Parameters:

  • attr (Object)

    configuration key

Returns:

  • (Object)

    value at configuration key



58
59
60
# File 'lib/kitchen/provisioner/base.rb', line 58

def [](attr)
  config[attr]
end

#calculate_path(path, type = :directory) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/kitchen/provisioner/base.rb', line 106

def calculate_path(path, type = :directory)
  base = config[:test_base_path]
  candidates = []
  candidates << File.join(base, instance.suite.name, path)
  candidates << File.join(base, path)
  candidates << File.join(Dir.pwd, path)

  candidates.find do |c|
    type == :directory ? File.directory?(c) : File.file?(c)
  end
end

#cleanup_sandboxObject



90
91
92
93
94
95
# File 'lib/kitchen/provisioner/base.rb', line 90

def cleanup_sandbox
  return if sandbox_path.nil?

  debug("Cleaning up local sandbox in #{sandbox_path}")
  FileUtils.rmtree(sandbox_path)
end

#config_keysArray

Returns an array of configuration keys.

Returns:

  • (Array)

    array of configuration keys



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

def config_keys
  config.keys
end

#create_sandboxObject



77
78
79
80
81
82
# File 'lib/kitchen/provisioner/base.rb', line 77

def create_sandbox
  @sandbox_path = Dir.mktmpdir("#{instance.name}-sandbox-")
  File.chmod(0755, sandbox_path)
  info("Preparing files for transfer")
  debug("Creating local sandbox in #{sandbox_path}")
end

#diagnoseHash

Returns a Hash of configuration and other useful diagnostic information.

Returns:

  • (Hash)

    a diagnostic hash



100
101
102
103
104
# File 'lib/kitchen/provisioner/base.rb', line 100

def diagnose
  result = Hash.new
  config_keys.sort.each { |k| result[k] = config[k] }
  result
end

#init_commandObject



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

def init_command ; end

#install_commandObject



71
# File 'lib/kitchen/provisioner/base.rb', line 71

def install_command ; end

#nameString

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

Returns:

  • (String)

    name of this driver



50
51
52
# File 'lib/kitchen/provisioner/base.rb', line 50

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

#prepare_commandObject



73
# File 'lib/kitchen/provisioner/base.rb', line 73

def prepare_command ; end

#run_commandObject



75
# File 'lib/kitchen/provisioner/base.rb', line 75

def run_command ; end

#sandbox_pathObject



84
85
86
87
88
# File 'lib/kitchen/provisioner/base.rb', line 84

def sandbox_path
  @sandbox_path || (raise ClientError, "Sandbox directory has not yet " +
    "been created. Please run #{self.class}#create_sandox before " +
    "trying to access the path.")
end