Class: Kitchen::Provisioner::Base
- Inherits:
-
Object
- Object
- Kitchen::Provisioner::Base
- Includes:
- Logging
- Defined in:
- lib/kitchen/provisioner/base.rb
Overview
Base class for a provisioner.
Instance Attribute Summary collapse
-
#instance ⇒ Object
Returns the value of attribute instance.
Instance Method Summary collapse
-
#[](attr) ⇒ Object
Provides hash-like access to configuration keys.
- #calculate_path(path, type = :directory) ⇒ Object
- #cleanup_sandbox ⇒ Object
-
#config_keys ⇒ Array
Returns an array of configuration keys.
- #create_sandbox ⇒ Object
-
#diagnose ⇒ Hash
Returns a Hash of configuration and other useful diagnostic information.
- #init_command ⇒ Object
-
#initialize(config = {}) ⇒ Base
constructor
A new instance of Base.
- #install_command ⇒ Object
-
#name ⇒ String
Returns the name of this driver, suitable for display in a CLI.
- #prepare_command ⇒ Object
- #run_command ⇒ Object
- #sandbox_path ⇒ Object
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
#instance ⇒ Object
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.
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_sandbox ⇒ Object
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_keys ⇒ Array
Returns an array of configuration keys.
65 66 67 |
# File 'lib/kitchen/provisioner/base.rb', line 65 def config_keys config.keys end |
#create_sandbox ⇒ Object
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 |
#diagnose ⇒ Hash
Returns a Hash of configuration and other useful diagnostic information.
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_command ⇒ Object
69 |
# File 'lib/kitchen/provisioner/base.rb', line 69 def init_command ; end |
#install_command ⇒ Object
71 |
# File 'lib/kitchen/provisioner/base.rb', line 71 def install_command ; end |
#name ⇒ String
Returns the name of this driver, suitable for display in a CLI.
50 51 52 |
# File 'lib/kitchen/provisioner/base.rb', line 50 def name self.class.name.split('::').last end |
#prepare_command ⇒ Object
73 |
# File 'lib/kitchen/provisioner/base.rb', line 73 def prepare_command ; end |
#run_command ⇒ Object
75 |
# File 'lib/kitchen/provisioner/base.rb', line 75 def run_command ; end |
#sandbox_path ⇒ Object
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 |