Require nodes_path for Chef Zero provisioning

Fixes GH-6110
This commit is contained in:
Seth Vargo 2015-11-19 15:52:16 -08:00
parent 3fb9a1a1eb
commit df207d2637
4 changed files with 45 additions and 14 deletions

View File

@ -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

View File

@ -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: |-

View File

@ -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

View File

@ -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