Ensure a dependency provisioner isnt configured to rely on another dependency provisioner

This commit is contained in:
Brian Cain 2019-08-28 15:52:38 -07:00
parent f608c324e5
commit fc8bf6aed4
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
3 changed files with 22 additions and 4 deletions

View File

@ -772,8 +772,7 @@ module VagrantPlugins
next
end
provisioner_names = @provisioners.map { |i| i.name if i.name != vm_provisioner.name }.reject(&:nil?)
provisioner_errors = vm_provisioner.validate(machine, provisioner_names)
provisioner_errors = vm_provisioner.validate(machine, @provisioners)
if provisioner_errors
errors = Vagrant::Config::V2::Util.merge_errors(errors, provisioner_errors)
end

View File

@ -108,11 +108,13 @@ module VagrantPlugins
# Validates the before/after options
#
# @param [Vagrant::Machine] machine - machine to validate against
# @param [Array<Symbol>] provisioner_names - Names of provisioners for a given machine
# @param [Array] provisioners - Array of defined provisioners for the guest machine
# @return [Array] array of strings of error messages from config option validation
def validate(machine, provisioner_names)
def validate(machine, provisioners)
errors = _detected_errors
provisioner_names = provisioners.map { |i| i.name if i.name != name }.reject(&:nil?)
if @before
if !VALID_BEFORE_AFTER_TYPES.include?(@before)
if @before.is_a?(Symbol) && !VALID_BEFORE_AFTER_TYPES.include?(@before)
@ -128,6 +130,14 @@ module VagrantPlugins
action: "before",
provisioner_name: @name)
end
dep_prov = provisioners.map { |i| i if i.name.to_s == @before && (i.before || i.after) }.reject(&:nil?)
if !dep_prov.empty?
errors << I18n.t("vagrant.provisioners.base.dependency_provisioner_dependency",
name: @name,
dep_name: dep_prov.first.name.to_s)
end
end
end
@ -146,6 +156,13 @@ module VagrantPlugins
action: "after",
provisioner_name: @name)
end
dep_prov = provisioners.map { |i| i if i.name.to_s == @after && (i.before || i.after) }.reject(&:nil?)
if !dep_prov.empty?
errors << I18n.t("vagrant.provisioners.base.dependency_provisioner_dependency",
name: @name,
dep_name: dep_prov.first.name.to_s)
end
end
end

View File

@ -2487,6 +2487,8 @@ en:
provisioners:
base:
dependency_provisioner_dependency: |-
Dependency provisioner "%{name}" relies on another dependency provisioner "%{dep_name}". This is currently not supported.
invalid_alias_value: |-
Provisioner option `%{opt}` is not set as a valid type. Must be a string, or one of the alias shortcuts: %{alias}
missing_provisioner_name: |-