From c9b65bd129b17a2dae9b152c9b94e1ae89985695 Mon Sep 17 00:00:00 2001 From: Eugenio Marzo Date: Sat, 22 Jul 2017 11:00:05 +0200 Subject: [PATCH] produce error when node_path is defined but the directory does not exist on disk locally --- plugins/provisioners/chef/config/chef_zero.rb | 7 +++++++ templates/locales/en.yml | 2 ++ .../provisioners/chef/config/chef_zero_test.rb | 11 +++++++++++ 3 files changed, 20 insertions(+) diff --git a/plugins/provisioners/chef/config/chef_zero.rb b/plugins/provisioners/chef/config/chef_zero.rb index 93a036cd7..d02f78f6f 100644 --- a/plugins/provisioners/chef/config/chef_zero.rb +++ b/plugins/provisioners/chef/config/chef_zero.rb @@ -79,6 +79,13 @@ module VagrantPlugins if !present?(Array(nodes_path)) errors << I18n.t("vagrant.config.chef.nodes_path_empty") + else + missing_paths = Array.new + nodes_path.each { |dir| missing_paths << dir[1] if !File.exists? dir[1] } + # If it exists at least one path on disk it's ok for Chef provisioning + if missing_paths.size == nodes_path.size + errors << I18n.t("vagrant.config.chef.nodes_path_missing", path: missing_paths.to_s) + end end if environment && environments_path.empty? diff --git a/templates/locales/en.yml b/templates/locales/en.yml index deae43256..f6da5f97a 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1579,6 +1579,8 @@ en: Missing required value for `chef.nodes_path'. environment_path_missing: |- Environment path not found: %{path} + nodes_path_missing: |- + Path specified for `nodes_path` does not exist: %{path} environment_path_required: |- When 'environment' is specified, you must provide 'environments_path'. cookbooks_path_missing: |- 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 1767da562..c674a2767 100644 --- a/test/unit/plugins/provisioners/chef/config/chef_zero_test.rb +++ b/test/unit/plugins/provisioners/chef/config/chef_zero_test.rb @@ -110,6 +110,17 @@ describe VagrantPlugins::Chef::Config::ChefZero do end end + context "when an element of nodes_path does not exist on disk" do + it "returns an error" do + nodes_path = ["/path/to/nodes/that/will/never/exist"] + subject.nodes_path = nodes_path + subject.finalize! + expect(errors).to include(I18n.t("vagrant.config.chef.nodes_path_missing", + path: nodes_path + )) + end + end + context "when the nodes_path is an empty array" do it "returns an error" do subject.nodes_path = []