From 56861296fa69b7db9e59380005a44cde9185a3f9 Mon Sep 17 00:00:00 2001 From: Jonathan LaBroad Date: Thu, 5 Oct 2017 06:25:36 -0400 Subject: [PATCH] Added tests and validation for python_version parameter --- plugins/provisioners/salt/config.rb | 8 ++++ templates/locales/en.yml | 2 + .../plugins/provisioners/salt/config_test.rb | 43 +++++++++++++++++++ website/source/docs/provisioning/salt.html.md | 2 +- 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/plugins/provisioners/salt/config.rb b/plugins/provisioners/salt/config.rb index c10bdcbf0..c4af8933b 100644 --- a/plugins/provisioners/salt/config.rb +++ b/plugins/provisioners/salt/config.rb @@ -163,6 +163,14 @@ module VagrantPlugins errors << I18n.t("vagrant.provisioners.salt.args_array") end + if @python_version && @python_version.is_a?(String) && !@python_version.scan(/\D/).empty? + errors << I18n.t("vagrant.provisioners.salt.python_version") + end + + if @python_version && !(@python_version.is_a?(Integer) || @python_version.is_a?(String)) + errors << I18n.t("vagrant.provisioners.salt.python_version") + end + return {"salt provisioner" => errors} end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index a953478c8..98193171e 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -2444,6 +2444,8 @@ en: You must accept keys when running highstate with master! args_array: |- You must set this value as an array. + python_version: |- + You must set this as an integer or string that represents an integer. pushes: file: diff --git a/test/unit/plugins/provisioners/salt/config_test.rb b/test/unit/plugins/provisioners/salt/config_test.rb index 2571bdbb2..c3e0a0123 100644 --- a/test/unit/plugins/provisioners/salt/config_test.rb +++ b/test/unit/plugins/provisioners/salt/config_test.rb @@ -114,5 +114,48 @@ describe VagrantPlugins::Salt::Config do expect(result[error_key]).to be_empty end end + + context "python_version" do + it "is valid if is set and not missing" do + subject.python_version = "2" + subject.finalize! + + result = subject.validate(machine) + expect(result[error_key]).to be_empty + end + + it "can be a string" do + subject.python_version = "2" + subject.finalize! + + result = subject.validate(machine) + expect(result[error_key]).to be_empty + end + + it "can be an integer" do + subject.python_version = 2 + subject.finalize! + + result = subject.validate(machine) + expect(result[error_key]).to be_empty + end + + it "is not a number that is not an integer" do + subject.python_version = 2.7 + subject.finalize! + + result = subject.validate(machine) + expect(result[error_key]).to_not be_empty + end + + it "is not a string that does not parse to an integer" do + subject.python_version = '2.7' + subject.finalize! + + result = subject.validate(machine) + expect(result[error_key]).to_not be_empty + end + + end end end diff --git a/website/source/docs/provisioning/salt.html.md b/website/source/docs/provisioning/salt.html.md index 09cd71707..f84633305 100644 --- a/website/source/docs/provisioning/salt.html.md +++ b/website/source/docs/provisioning/salt.html.md @@ -77,7 +77,7 @@ distribution's stable package manager, git tree-ish, daily ppa, or testing repos * `version` (string, default: "2017.7.1") - Version of minion to be installed. Only supported on Windows guest machines. -* `python_version` (string, default: "2") - Python version of minion to be installed. Only valid for minion versions >= 2017.7.1. Only supported on Windows guest machines. +* `python_version` (string, default: "2") - Major Python version of minion to be installed. Only valid for minion versions >= 2017.7.0. Only supported on Windows guest machines. ## Minion Options These only make sense when `no_minion` is `false`.