From 66aac2347005a44b9239b44e68f03d889c441685 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Mon, 19 Aug 2019 11:23:06 -0700 Subject: [PATCH] Properly set and validate before/after keys for base provisioner class --- plugins/kernel_v2/config/vm.rb | 19 ++++++++++++------- plugins/kernel_v2/config/vm_provisioner.rb | 12 ++++++++---- templates/locales/en.yml | 5 +++++ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 2cf4a9c75..8379f09d8 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -331,7 +331,14 @@ module VagrantPlugins end 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 end @@ -760,12 +767,10 @@ module VagrantPlugins next end - require 'pry' - binding.pry - #provisioner_errors = vm_provisioner.validate(machine) - #if provisioner_errors - # errors = Vagrant::Config::V2::Util.merge_errors(errors, provisioner_errors) - #end + provisioner_errors = vm_provisioner.validate(machine) + if provisioner_errors + errors = Vagrant::Config::V2::Util.merge_errors(errors, provisioner_errors) + end if vm_provisioner.config provisioner_errors = vm_provisioner.config.validate(machine) diff --git a/plugins/kernel_v2/config/vm_provisioner.rb b/plugins/kernel_v2/config/vm_provisioner.rb index 4f49bed80..4c3c4a04f 100644 --- a/plugins/kernel_v2/config/vm_provisioner.rb +++ b/plugins/kernel_v2/config/vm_provisioner.rb @@ -105,23 +105,27 @@ module VagrantPlugins @config.finalize! end - # TODO: This isn't being called - # # @return [Array] array of strings of error messages from config option validation def validate(machine) errors = _detected_errors if @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 if @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 + + {"provisioner" => errors} end # Returns whether the provisioner used was invalid or not. A provisioner diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 2b63dd383..766f36984 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -2486,6 +2486,11 @@ en: VirtualBox has successfully been installed! 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_not_detected: |- The chef binary (either `chef-solo` or `chef-client`) was not found on