Class: Kitchen::Provisioner::ChefBase

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/provisioner/chef_base.rb

Overview

Common implementation details for Chef-related provisioners.

Author:

Direct Known Subclasses

ChefSolo, ChefZero

Instance Attribute Summary

Attributes inherited from Base

#instance

Instance Method Summary collapse

Methods inherited from Base

#[], #config_keys, #create_sandbox, #diagnose, #initialize, #name, #prepare_command, #run_command

Constructor Details

This class inherits a constructor from Kitchen::Provisioner::Base

Instance Method Details

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



117
118
119
120
121
122
123
124
125
126
127
# File 'lib/kitchen/provisioner/chef_base.rb', line 117

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



110
111
112
113
114
115
# File 'lib/kitchen/provisioner/chef_base.rb', line 110

def cleanup_sandbox
  return if tmpdir.nil?

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

#init_commandObject



104
105
106
107
108
# File 'lib/kitchen/provisioner/chef_base.rb', line 104

def init_command
  dirs = %w{cookbooks data data_bags environments roles}.
    map { |dir| File.join(config[:root_path], dir) }.join(" ")
  "#{sudo('rm')} -rf #{dirs} ; mkdir -p #{config[:root_path]}"
end

#install_commandObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/kitchen/provisioner/chef_base.rb', line 73

def install_command
  return unless config[:require_chef_omnibus]

  url = config[:chef_omnibus_url]
  flag = config[:require_chef_omnibus]
  version = if flag.is_a?(String) && flag != "latest"
    "-v #{flag.downcase}"
  else
    ""
  end

  # use Bourne (/bin/sh) as Bash does not exist on all Unix flavors
  <<-INSTALL.gsub(/^ {10}/, '')
    sh -c '
    #{Util.shell_helpers}

    should_update_chef() {
      case "#{flag}" in
        true|`chef-solo -v | cut -d " " -f 2`) return 1 ;;
        latest|*) return 0 ;;
      esac
    }

    if [ ! -d "/opt/chef" ] || should_update_chef ; then
      echo "-----> Installing Chef Omnibus (#{flag})"
      do_download #{url} /tmp/install.sh
      #{sudo('sh')} /tmp/install.sh #{version}
    fi'
  INSTALL
end

#instance=(instance) ⇒ Object



68
69
70
71
# File 'lib/kitchen/provisioner/chef_base.rb', line 68

def instance=(instance)
  @instance = instance
  expand_paths!
end