diff --git a/plugins/provisioners/salt/config.rb b/plugins/provisioners/salt/config.rb index 044a8c1cc..6ca014218 100644 --- a/plugins/provisioners/salt/config.rb +++ b/plugins/provisioners/salt/config.rb @@ -83,6 +83,13 @@ module VagrantPlugins def validate(machine) errors = _detected_errors + if @minion_config + expanded = Pathname.new(@minion_config).expand_path(machine.env.root_path) + if !expanded.file? + errors << I18n.t("vagrant.provisioners.salt.minion_config_nonexist") + end + end + if @minion_key || @minion_pub if !@minion_key || !@minion_pub errors << @minion_pub diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 273b7ba74..4bf3e69a3 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1548,6 +1548,8 @@ en: install_failed: "Docker installation failed." salt: + minion_config_nonexist: |- + The specified minion_config file could not be found. missing_key: |- You must include both public and private keys. must_accept_keys: |- diff --git a/test/unit/plugins/provisioners/salt/config_test.rb b/test/unit/plugins/provisioners/salt/config_test.rb new file mode 100644 index 000000000..299be65b0 --- /dev/null +++ b/test/unit/plugins/provisioners/salt/config_test.rb @@ -0,0 +1,46 @@ +require File.expand_path("../../../../base", __FILE__) + +require Vagrant.source_root.join("plugins/provisioners/salt/config") + +describe VagrantPlugins::Salt::Config do + include_context "unit" + + subject { described_class.new } + + let(:iso_env) do + # We have to create a Vagrantfile so there is a root path + env = isolated_environment + env.vagrantfile("") + env.create_vagrant_env + end + + let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) } + + describe "validate" do + let(:error_key) { "salt provisioner" } + + it "passes by default" do + subject.finalize! + result = subject.validate(machine) + expect(result[error_key]).to be_empty + end + + context "minion_config" do + it "fails if minion_config is set and missing" do + subject.minion_config = "/nope/nope/i/dont/exist" + subject.finalize! + + result = subject.validate(machine) + expect(result[error_key]).to_not be_empty + end + + it "is valid if is set and not missing" do + subject.minion_config = File.expand_path(__FILE__) + subject.finalize! + + result = subject.validate(machine) + expect(result[error_key]).to be_empty + end + end + end +end