From df207d2637eba8fd5dc63a0f120425494e46b95a Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 19 Nov 2015 15:52:16 -0800 Subject: [PATCH 1/2] Require nodes_path for Chef Zero provisioning Fixes GH-6110 --- plugins/provisioners/chef/config/chef_zero.rb | 4 ++ templates/locales/en.yml | 5 ++- .../chef/config/chef_zero_test.rb | 44 ++++++++++++++----- .../source/v2/provisioning/chef_zero.html.md | 6 ++- 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/plugins/provisioners/chef/config/chef_zero.rb b/plugins/provisioners/chef/config/chef_zero.rb index 9b1daf1a5..671c2690c 100644 --- a/plugins/provisioners/chef/config/chef_zero.rb +++ b/plugins/provisioners/chef/config/chef_zero.rb @@ -73,6 +73,10 @@ module VagrantPlugins errors << I18n.t("vagrant.config.chef.cookbooks_path_empty") end + if [nodes_path].flatten.compact.empty? + errors << I18n.t("vagrant.config.chef.nodes_path_empty") + end + if environment && environments_path.empty? errors << I18n.t("vagrant.config.chef.environment_path_required") end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 05f9f4b0d..10fee4f09 100755 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1402,7 +1402,10 @@ en: common: bad_field: "The following settings shouldn't exist: %{fields}" chef: - cookbooks_path_empty: "Must specify a cookbooks path for chef solo." + cookbooks_path_empty: |- + Missing required value for `chef.cookbooks_path'. + nodes_path_empty: |- + Missing required value for `chef.nodes_path'. environment_path_missing: |- Environment path not found: %{path} environment_path_required: |- diff --git a/test/unit/plugins/provisioners/chef/config/chef_zero_test.rb b/test/unit/plugins/provisioners/chef/config/chef_zero_test.rb index 9a1f98cd6..1767da562 100644 --- a/test/unit/plugins/provisioners/chef/config/chef_zero_test.rb +++ b/test/unit/plugins/provisioners/chef/config/chef_zero_test.rb @@ -82,7 +82,7 @@ describe VagrantPlugins::Chef::Config::ChefZero do it "returns an error" do subject.cookbooks_path = nil subject.finalize! - expect(errors).to eq [I18n.t("vagrant.config.chef.cookbooks_path_empty")] + expect(errors).to include(I18n.t("vagrant.config.chef.cookbooks_path_empty")) end end @@ -90,7 +90,7 @@ describe VagrantPlugins::Chef::Config::ChefZero do it "returns an error" do subject.cookbooks_path = [] subject.finalize! - expect(errors).to eq [I18n.t("vagrant.config.chef.cookbooks_path_empty")] + expect(errors).to include(I18n.t("vagrant.config.chef.cookbooks_path_empty")) end end @@ -98,7 +98,31 @@ describe VagrantPlugins::Chef::Config::ChefZero do it "returns an error" do subject.cookbooks_path = [nil, nil] subject.finalize! - expect(errors).to eq [I18n.t("vagrant.config.chef.cookbooks_path_empty")] + expect(errors).to include(I18n.t("vagrant.config.chef.cookbooks_path_empty")) + end + end + + context "when the nodes_path is nil" do + it "returns an error" do + subject.nodes_path = nil + subject.finalize! + expect(errors).to include(I18n.t("vagrant.config.chef.nodes_path_empty")) + end + end + + context "when the nodes_path is an empty array" do + it "returns an error" do + subject.nodes_path = [] + subject.finalize! + expect(errors).to include(I18n.t("vagrant.config.chef.nodes_path_empty")) + end + end + + context "when the nodes_path is an array with nil" do + it "returns an error" do + subject.nodes_path = [nil, nil] + subject.finalize! + expect(errors).to include(I18n.t("vagrant.config.chef.nodes_path_empty")) end end @@ -111,7 +135,7 @@ describe VagrantPlugins::Chef::Config::ChefZero do it "returns an error" do subject.environments_path = nil subject.finalize! - expect(errors).to eq [I18n.t("vagrant.config.chef.environment_path_required")] + expect(errors).to include(I18n.t("vagrant.config.chef.environment_path_required")) end end @@ -119,7 +143,7 @@ describe VagrantPlugins::Chef::Config::ChefZero do it "returns an error" do subject.environments_path = [] subject.finalize! - expect(errors).to eq [I18n.t("vagrant.config.chef.environment_path_required")] + expect(errors).to include(I18n.t("vagrant.config.chef.environment_path_required")) end end @@ -127,7 +151,7 @@ describe VagrantPlugins::Chef::Config::ChefZero do it "returns an error" do subject.environments_path = [nil, nil] subject.finalize! - expect(errors).to eq [I18n.t("vagrant.config.chef.environment_path_required")] + expect(errors).to include(I18n.t("vagrant.config.chef.environment_path_required")) end end @@ -136,11 +160,9 @@ describe VagrantPlugins::Chef::Config::ChefZero do env_path = "/path/to/environments/that/will/never/exist" subject.environments_path = env_path subject.finalize! - expect(errors).to eq [ - I18n.t("vagrant.config.chef.environment_path_missing", - path: env_path - ) - ] + expect(errors).to include(I18n.t("vagrant.config.chef.environment_path_missing", + path: env_path, + )) end end end diff --git a/website/docs/source/v2/provisioning/chef_zero.html.md b/website/docs/source/v2/provisioning/chef_zero.html.md index bd2527fc9..48b691cf8 100644 --- a/website/docs/source/v2/provisioning/chef_zero.html.md +++ b/website/docs/source/v2/provisioning/chef_zero.html.md @@ -41,8 +41,9 @@ available below this section. * `environments_path` (string) - A path where environment definitions are located. By default, no environments folder is set. -* `nodes_path` (string or array) - A list of paths where node objects (in JSON format) are stored. By default, no - nodes path is set. +* `nodes_path` (string or array) - A list of paths where node objects + (in JSON format) are stored. By default, no nodes path is set. This value is + required. * `environment` (string) - The environment you want the Chef run to be a part of. This requires Chef 11.6.0 or later, and that `environments_path` @@ -75,6 +76,7 @@ Vagrant.configure("2") do |config| # Specify the local paths where Chef data is stored chef.cookbooks_path = "cookbooks" chef.data_bags_path = "data_bags" + chef.nodes_path = "nodes" chef.roles_path = "roles" # Add a recipe From 76f3dce5dba92afc2cf296464d8b8de90eddffcb Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 19 Nov 2015 15:52:21 -0800 Subject: [PATCH 2/2] Remove deprecated options --- plugins/provisioners/chef/config/chef_solo.rb | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/plugins/provisioners/chef/config/chef_solo.rb b/plugins/provisioners/chef/config/chef_solo.rb index a9630a7b8..f74146f52 100644 --- a/plugins/provisioners/chef/config/chef_solo.rb +++ b/plugins/provisioners/chef/config/chef_solo.rb @@ -49,31 +49,6 @@ module VagrantPlugins @synced_folder_type = UNSET_VALUE end - # @deprecated This is deprecated in Chef and will be removed in Chef 12. - def recipe_url=(value) - puts "DEPRECATION: The 'recipe_url' setting for the Chef Solo" - puts "provisioner is deprecated. This value will be removed in" - puts "Chef 12. It is recommended you use the Chef Apply provisioner" - puts "instead. The 'recipe_url' setting will be removed in the next" - puts "version of Vagrant." - - if value - @recipe_url = value - end - end - - def nfs=(value) - puts "DEPRECATION: The 'nfs' setting for the Chef Solo provisioner is" - puts "deprecated. Please use the 'synced_folder_type' setting instead." - puts "The 'nfs' setting will be removed in the next version of Vagrant." - - if value - @synced_folder_type = "nfs" - else - @synced_folder_type = nil - end - end - #------------------------------------------------------------ # Internal methods #------------------------------------------------------------