Validate that before/after provisioner exists in machines config
This commit is contained in:
parent
8ecd32de53
commit
d15bac7fb7
|
@ -767,7 +767,8 @@ module VagrantPlugins
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
provisioner_errors = vm_provisioner.validate(machine)
|
provisioner_names = @provisioners.map { |i| i.name if i.name != vm_provisioner.name }.reject(&:blank?)
|
||||||
|
provisioner_errors = vm_provisioner.validate(machine, provisioner_names)
|
||||||
if provisioner_errors
|
if provisioner_errors
|
||||||
errors = Vagrant::Config::V2::Util.merge_errors(errors, provisioner_errors)
|
errors = Vagrant::Config::V2::Util.merge_errors(errors, provisioner_errors)
|
||||||
end
|
end
|
||||||
|
|
|
@ -105,24 +105,44 @@ module VagrantPlugins
|
||||||
@config.finalize!
|
@config.finalize!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @param [Vagrant::Machine] machine - machine to validate against
|
||||||
|
# @param [Array<Symbol>] provisioner_names - Names of provisioners for a given machine
|
||||||
# @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, provisioner_names)
|
||||||
errors = _detected_errors
|
errors = _detected_errors
|
||||||
|
|
||||||
if @before
|
if @before
|
||||||
|
if !VALID_BEFORE_AFTER_TYPES.include?(@before)
|
||||||
if @before.is_a?(Symbol) && !VALID_BEFORE_AFTER_TYPES.include?(@before)
|
if @before.is_a?(Symbol) && !VALID_BEFORE_AFTER_TYPES.include?(@before)
|
||||||
errors << I18n.t("vagrant.provisioners.base.invalid_alias_value", opt: "before", alias: VALID_BEFORE_AFTER_TYPES.join(", "))
|
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)
|
elsif !@before.is_a?(String) && !VALID_BEFORE_AFTER_TYPES.include?(@before)
|
||||||
errors << I18n.t("vagrant.provisioners.base.wrong_type", opt: "before")
|
errors << I18n.t("vagrant.provisioners.base.wrong_type", opt: "before")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if !provisioner_names.include?(@before.to_sym)
|
||||||
|
errors << I18n.t("vagrant.provisioners.base.missing_provisioner_name",
|
||||||
|
name: @before,
|
||||||
|
machine_name: machine.name,
|
||||||
|
action: "before")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if @after
|
if @after
|
||||||
if @after.is_a?(Symbol) && !VALID_BEFORE_AFTER_TYPES.include?(@after)
|
if !VALID_BEFORE_AFTER_TYPES.include?(@after)
|
||||||
|
if @after.is_a?(Symbol)
|
||||||
errors << I18n.t("vagrant.provisioners.base.invalid_alias_value", opt: "after", alias: VALID_BEFORE_AFTER_TYPES.join(", "))
|
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)
|
elsif !@after.is_a?(String)
|
||||||
errors << I18n.t("vagrant.provisioners.base.wrong_type", opt: "after")
|
errors << I18n.t("vagrant.provisioners.base.wrong_type", opt: "after")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if !provisioner_names.include?(@after.to_sym)
|
||||||
|
errors << I18n.t("vagrant.provisioners.base.missing_provisioner_name",
|
||||||
|
name: @after,
|
||||||
|
machine_name: machine.name,
|
||||||
|
action: "after")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
{"provisioner" => errors}
|
{"provisioner" => errors}
|
||||||
|
|
|
@ -2489,6 +2489,8 @@ en:
|
||||||
base:
|
base:
|
||||||
invalid_alias_value: |-
|
invalid_alias_value: |-
|
||||||
Provisioner option `%{opt}` is not set as a valid type. Must be a string, or one of the alias shortcuts: %{alias}
|
Provisioner option `%{opt}` is not set as a valid type. Must be a string, or one of the alias shortcuts: %{alias}
|
||||||
|
missing_provisioner_name: |-
|
||||||
|
Could not find provisioner name `%{name}` defined for machine `%{machine_name}` to run provisioner `%{action}`.
|
||||||
wrong_type: |-
|
wrong_type: |-
|
||||||
Provisioner option `%{opt}` is not set as a valid type. Must be a string.
|
Provisioner option `%{opt}` is not set as a valid type. Must be a string.
|
||||||
chef:
|
chef:
|
||||||
|
|
Loading…
Reference in New Issue