Properly set and validate before/after keys for base provisioner class

This commit is contained in:
Brian Cain 2019-08-19 11:23:06 -07:00
parent 28c0f6085c
commit 66aac23470
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
3 changed files with 25 additions and 11 deletions

View File

@ -331,7 +331,14 @@ module VagrantPlugins
end end
if !prov if !prov
prov = VagrantConfigProvisioner.new(name, type.to_sym) if options.key?(:before)
before = options.delete(:before)
end
if options.key?(:after)
after = options.delete(:after)
end
prov = VagrantConfigProvisioner.new(name, type.to_sym, before, after)
@provisioners << prov @provisioners << prov
end end
@ -760,12 +767,10 @@ module VagrantPlugins
next next
end end
require 'pry' provisioner_errors = vm_provisioner.validate(machine)
binding.pry if provisioner_errors
#provisioner_errors = vm_provisioner.validate(machine) errors = Vagrant::Config::V2::Util.merge_errors(errors, provisioner_errors)
#if provisioner_errors end
# errors = Vagrant::Config::V2::Util.merge_errors(errors, provisioner_errors)
#end
if vm_provisioner.config if vm_provisioner.config
provisioner_errors = vm_provisioner.config.validate(machine) provisioner_errors = vm_provisioner.config.validate(machine)

View File

@ -105,23 +105,27 @@ module VagrantPlugins
@config.finalize! @config.finalize!
end end
# TODO: This isn't being called
#
# @return [Array] array of strings of error messages from config option validation # @return [Array] array of strings of error messages from config option validation
def validate(machine) def validate(machine)
errors = _detected_errors errors = _detected_errors
if @before if @before
if @before.is_a?(Symbol) && !VALID_BEFORE_AFTER_TYPES.include?(@before) if @before.is_a?(Symbol) && !VALID_BEFORE_AFTER_TYPES.include?(@before)
errors << "Before symbol is not a valid symbol" errors << I18n.t("vagrant.provisioners.base.invalid_alias_value", opt: "before", alias: VALID_BEFORE_AFTER_TYPES.join(", "))
elsif !@before.is_a?(String) && !VALID_BEFORE_AFTER_TYPES.include?(@before)
errors << I18n.t("vagrant.provisioners.base.wrong_type", opt: "before")
end end
end end
if @after if @after
if @after.is_a?(Symbol) && !VALID_BEFORE_AFTER_TYPES.include?(@after) if @after.is_a?(Symbol) && !VALID_BEFORE_AFTER_TYPES.include?(@after)
errors << "After symbol is not a valid symbol" errors << I18n.t("vagrant.provisioners.base.invalid_alias_value", opt: "after", alias: VALID_BEFORE_AFTER_TYPES.join(", "))
elsif !@after.is_a?(String) && !VALID_BEFORE_AFTER_TYPES.include?(@after)
errors << I18n.t("vagrant.provisioners.base.wrong_type", opt: "after")
end end
end end
{"provisioner" => errors}
end end
# Returns whether the provisioner used was invalid or not. A provisioner # Returns whether the provisioner used was invalid or not. A provisioner

View File

@ -2486,6 +2486,11 @@ en:
VirtualBox has successfully been installed! VirtualBox has successfully been installed!
provisioners: provisioners:
base:
invalid_alias_value: |-
Provisioner option `%{opt}` is not set as a valid type. Must be a string, or one of the alias shortcuts: %{alias}
wrong_type: |-
Provisioner option `%{opt}` is not set as a valid type. Must be a string.
chef: chef:
chef_not_detected: |- chef_not_detected: |-
The chef binary (either `chef-solo` or `chef-client`) was not found on The chef binary (either `chef-solo` or `chef-client`) was not found on