Merge pull request #6587 from mitchellh/sethvargo/chef_presence
Use the new presence helpers in the Chef provisioner
This commit is contained in:
commit
977e3f92e4
|
@ -14,7 +14,11 @@ module Vagrant
|
|||
case obj
|
||||
when String
|
||||
!obj.strip.empty?
|
||||
when Array, Hash
|
||||
when Symbol
|
||||
!obj.to_s.strip.empty?
|
||||
when Array
|
||||
!obj.compact.empty?
|
||||
when Hash
|
||||
!obj.empty?
|
||||
when TrueClass, FalseClass
|
||||
obj
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
require "vagrant/util/presence"
|
||||
|
||||
module VagrantPlugins
|
||||
module Chef
|
||||
module Config
|
||||
class Base < Vagrant.plugin("2", :config)
|
||||
include Vagrant::Util::Presence
|
||||
|
||||
# The path to Chef's bin/ directory.
|
||||
# @return [String]
|
||||
attr_accessor :binary_path
|
||||
|
@ -114,18 +118,12 @@ EOH
|
|||
def validate_base(machine)
|
||||
errors = _detected_errors
|
||||
|
||||
if missing?(log_level)
|
||||
if !present?(log_level)
|
||||
errors << I18n.t("vagrant.provisioners.chef.log_level_empty")
|
||||
end
|
||||
|
||||
errors
|
||||
end
|
||||
|
||||
# Determine if the given string is "missing" (blank)
|
||||
# @return [true, false]
|
||||
def missing?(obj)
|
||||
obj.to_s.strip.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
require "vagrant/util/presence"
|
||||
|
||||
require_relative "base"
|
||||
|
||||
module VagrantPlugins
|
||||
module Chef
|
||||
module Config
|
||||
class ChefApply < Base
|
||||
include Vagrant::Util::Presence
|
||||
|
||||
# The raw recipe text (as a string) to execute via chef-apply.
|
||||
# @return [String]
|
||||
attr_accessor :recipe
|
||||
|
@ -30,11 +34,11 @@ module VagrantPlugins
|
|||
def validate(machine)
|
||||
errors = validate_base(machine)
|
||||
|
||||
if missing?(recipe)
|
||||
if !present?(recipe)
|
||||
errors << I18n.t("vagrant.provisioners.chef.recipe_empty")
|
||||
end
|
||||
|
||||
if missing?(upload_path)
|
||||
if !present?(upload_path)
|
||||
errors << I18n.t("vagrant.provisioners.chef.upload_path_empty")
|
||||
end
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
require "vagrant/util/presence"
|
||||
require "vagrant/util/which"
|
||||
|
||||
require_relative "base_runner"
|
||||
|
@ -6,6 +7,8 @@ module VagrantPlugins
|
|||
module Chef
|
||||
module Config
|
||||
class ChefClient < BaseRunner
|
||||
include Vagrant::Util::Presence
|
||||
|
||||
# The URL endpoint to the Chef Server.
|
||||
# @return [String]
|
||||
attr_accessor :chef_server_url
|
||||
|
@ -55,11 +58,11 @@ module VagrantPlugins
|
|||
def validate(machine)
|
||||
errors = validate_base(machine)
|
||||
|
||||
if chef_server_url.to_s.strip.empty?
|
||||
if !present?(chef_server_url)
|
||||
errors << I18n.t("vagrant.config.chef.server_url_empty")
|
||||
end
|
||||
|
||||
if validation_key_path.to_s.strip.empty?
|
||||
if !present?(validation_key_path)
|
||||
errors << I18n.t("vagrant.config.chef.validation_key_path")
|
||||
end
|
||||
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
require "vagrant/util/presence"
|
||||
|
||||
require_relative "base_runner"
|
||||
|
||||
module VagrantPlugins
|
||||
module Chef
|
||||
module Config
|
||||
class ChefSolo < BaseRunner
|
||||
include Vagrant::Util::Presence
|
||||
|
||||
# The path on disk where Chef cookbooks are stored.
|
||||
# Default is "cookbooks".
|
||||
# @return [String]
|
||||
|
@ -82,11 +86,11 @@ module VagrantPlugins
|
|||
def validate(machine)
|
||||
errors = validate_base(machine)
|
||||
|
||||
if [cookbooks_path].flatten.compact.empty?
|
||||
if !present?(Array(cookbooks_path))
|
||||
errors << I18n.t("vagrant.config.chef.cookbooks_path_empty")
|
||||
end
|
||||
|
||||
if environment && environments_path.empty?
|
||||
if environment && !present?(environments_path)
|
||||
errors << I18n.t("vagrant.config.chef.environment_path_required")
|
||||
end
|
||||
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
require "vagrant/util/presence"
|
||||
|
||||
require_relative "chef_solo"
|
||||
|
||||
module VagrantPlugins
|
||||
module Chef
|
||||
module Config
|
||||
class ChefZero < BaseRunner
|
||||
include Vagrant::Util::Presence
|
||||
|
||||
# The path on disk where Chef cookbooks are stored.
|
||||
# Default is "cookbooks".
|
||||
# @return [String]
|
||||
|
@ -69,11 +73,11 @@ module VagrantPlugins
|
|||
def validate(machine)
|
||||
errors = validate_base(machine)
|
||||
|
||||
if [cookbooks_path].flatten.compact.empty?
|
||||
if !present?(Array(cookbooks_path))
|
||||
errors << I18n.t("vagrant.config.chef.cookbooks_path_empty")
|
||||
end
|
||||
|
||||
if [nodes_path].flatten.compact.empty?
|
||||
if !present?(Array(nodes_path))
|
||||
errors << I18n.t("vagrant.config.chef.nodes_path_empty")
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require 'tempfile'
|
||||
|
||||
require "vagrant/util/presence"
|
||||
require "vagrant/util/template_renderer"
|
||||
|
||||
require_relative "../installer"
|
||||
|
@ -11,6 +12,8 @@ module VagrantPlugins
|
|||
# chef-solo and chef-client provisioning are stored. This is **not an actual
|
||||
# provisioner**. Instead, {ChefSolo} or {ChefServer} should be used.
|
||||
class Base < Vagrant.plugin("2", :provisioner)
|
||||
include Vagrant::Util::Presence
|
||||
|
||||
class ChefError < Vagrant::Errors::VagrantError
|
||||
error_namespace("vagrant.provisioners.chef")
|
||||
end
|
||||
|
@ -20,7 +23,7 @@ module VagrantPlugins
|
|||
|
||||
@logger = Log4r::Logger.new("vagrant::provisioners::chef")
|
||||
|
||||
if @config.node_name.to_s.empty?
|
||||
if !present?(@config.node_name)
|
||||
cache = @machine.data_dir.join("chef_node_name")
|
||||
|
||||
if !cache.exist?
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'pathname'
|
||||
|
||||
require 'vagrant'
|
||||
require 'vagrant/util/presence'
|
||||
require 'vagrant/util/subprocess'
|
||||
|
||||
require_relative "base"
|
||||
|
@ -11,6 +12,8 @@ module VagrantPlugins
|
|||
# This class implements provisioning via chef-client, allowing provisioning
|
||||
# with a chef server.
|
||||
class ChefClient < Base
|
||||
include Vagrant::Util::Presence
|
||||
|
||||
def configure(root_config)
|
||||
raise ChefError, :server_validation_key_required if @config.validation_key_path.nil?
|
||||
raise ChefError, :server_validation_key_doesnt_exist if !File.file?(validation_key_path)
|
||||
|
@ -132,7 +135,7 @@ module VagrantPlugins
|
|||
def delete_from_chef_server(deletable)
|
||||
node_name = @config.node_name || @machine.config.vm.hostname
|
||||
|
||||
if node_name.to_s.empty?
|
||||
if !present?(node_name)
|
||||
@machine.ui.warn(I18n.t("vagrant.provisioners.chef.missing_node_name",
|
||||
deletable: deletable,
|
||||
))
|
||||
|
|
|
@ -26,6 +26,10 @@ describe Vagrant::Util::Presence do
|
|||
expect(subject.presence([])).to be(false)
|
||||
end
|
||||
|
||||
it "returns false for an array with nil values" do
|
||||
expect(subject.presence([nil, nil])).to be(false)
|
||||
end
|
||||
|
||||
it "returns false for an empty hash" do
|
||||
expect(subject.presence({})).to be(false)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue