From a4eb002750bbd3f0f51b213e51fd0b2024678627 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Fri, 1 Feb 2019 16:16:55 -0800 Subject: [PATCH 1/3] Use ld path of system libs with appimage libs suffixed --- lib/vagrant/util/subprocess.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/vagrant/util/subprocess.rb b/lib/vagrant/util/subprocess.rb index 789364b3b..9aa2358be 100644 --- a/lib/vagrant/util/subprocess.rb +++ b/lib/vagrant/util/subprocess.rb @@ -129,10 +129,10 @@ module Vagrant if ENV["VAGRANT_APPIMAGE"] embed_path = Pathname.new(Vagrant.installer_embedded_dir).expand_path.to_s exec_path = Pathname.new(@command[0]).expand_path.to_s - if !exec_path.start_with?(embed_path) && ENV["VAGRANT_APPIMAGE_LD_LIBRARY_PATH"] + if !exec_path.start_with?(embed_path) && ENV["VAGRANT_APPIMAGE_HOST_LD_LIBRARY_PATH"] @logger.info("Detected AppImage environment and request to external binary. Updating library path.") - @logger.debug("Setting LD_LIBRARY_PATH to #{ENV["VAGRANT_APPIMAGE_LD_LIBRARY_PATH"]}") - process.environment["LD_LIBRARY_PATH"] = ENV["VAGRANT_APPIMAGE_LD_LIBRARY_PATH"].to_s + @logger.debug("Setting LD_LIBRARY_PATH to #{ENV["VAGRANT_APPIMAGE_HOST_LD_LIBRARY_PATH"]}") + process.environment["LD_LIBRARY_PATH"] = ENV["VAGRANT_APPIMAGE_HOST_LD_LIBRARY_PATH"].to_s end end else From e165a5bc6e0718bdf36d4d463cedd671fc98ebf7 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 5 Feb 2019 07:16:40 -0800 Subject: [PATCH 2/3] Update test checking ld path modifications --- test/unit/vagrant/util/subprocess_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/vagrant/util/subprocess_test.rb b/test/unit/vagrant/util/subprocess_test.rb index 0fd69818b..81da0e635 100644 --- a/test/unit/vagrant/util/subprocess_test.rb +++ b/test/unit/vagrant/util/subprocess_test.rb @@ -69,7 +69,7 @@ describe Vagrant::Util::Subprocess do allow(process_env).to receive(:[]=) allow(ENV).to receive(:[]).with("VAGRANT_INSTALLER_ENV").and_return("1") allow(ENV).to receive(:[]).with("VAGRANT_APPIMAGE").and_return("1") - allow(ENV).to receive(:[]).with("VAGRANT_APPIMAGE_LD_LIBRARY_PATH").and_return(appimage_ld_path) + allow(ENV).to receive(:[]).with("VAGRANT_APPIMAGE_HOST_LD_LIBRARY_PATH").and_return(appimage_ld_path) allow(File).to receive(:file?).with(exec_path).and_return(true) allow(ChildProcess).to receive(:build).and_return(process) allow(Vagrant).to receive(:installer_embedded_dir).and_return(appimage_path) From 2e58e002d68e82c21a8159785179fe12d5aeb21a Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 11 Feb 2019 15:48:43 -0800 Subject: [PATCH 3/3] Fix format finalization of plugins in Vagrantfile --- plugins/kernel_v2/config/vagrant.rb | 55 ++++++++++++------- templates/locales/en.yml | 2 + .../plugins/kernel_v2/config/vagrant_test.rb | 50 +++++++++++++++++ 3 files changed, 88 insertions(+), 19 deletions(-) diff --git a/plugins/kernel_v2/config/vagrant.rb b/plugins/kernel_v2/config/vagrant.rb index 2e097d61b..0954d6a4a 100644 --- a/plugins/kernel_v2/config/vagrant.rb +++ b/plugins/kernel_v2/config/vagrant.rb @@ -7,7 +7,8 @@ module VagrantPlugins attr_accessor :sensitive attr_accessor :plugins - VALID_PLUGIN_KEYS = [:sources, :version, :entry_point].freeze + VALID_PLUGIN_KEYS = ["sources", "version", "entry_point"].map(&:freeze).freeze + INVALID_PLUGIN_FORMAT = :invalid_plugin_format def initialize @host = UNSET_VALUE @@ -43,13 +44,21 @@ module VagrantPlugins errors << I18n.t("vagrant.config.root.sensitive_bad_type") end - @plugins.each do |plugin_name, plugin_info| - invalid_keys = plugin_info.keys - VALID_PLUGIN_KEYS - if !invalid_keys.empty? - errors << I18n.t("vagrant.config.root.plugins_bad_key", - plugin_name: plugin_name, - plugin_key: invalid_keys.join(", ") - ) + if @plugins == INVALID_PLUGIN_FORMAT + errors << I18n.t("vagrant.config.root.plugins_invalid_format") + else + @plugins.each do |plugin_name, plugin_info| + if plugin_info.is_a?(Hash) + invalid_keys = plugin_info.keys - VALID_PLUGIN_KEYS + if !invalid_keys.empty? + errors << I18n.t("vagrant.config.root.plugins_bad_key", + plugin_name: plugin_name, + plugin_key: invalid_keys.join(", ") + ) + end + else + errors << I18n.t("vagrant.config.root.plugins_invalid_format") + end end end @@ -61,18 +70,26 @@ module VagrantPlugins end def format_plugins(val) - result = case val - when String - {val => {}} - when Array - Hash[val.map{|item| [item.to_s, {}]}] - else - val - end - result.keys.each do |key| - result[key] = Hash[result[key].map{|k,v| [k.to_sym, v]}] + case val + when String + {val => Vagrant::Util::HashWithIndifferentAccess.new} + when Array + val.inject(Vagrant::Util::HashWithIndifferentAccess.new) { |memo, item| + memo.merge(format_plugins(item)) + } + when Hash + Vagrant::Util::HashWithIndifferentAccess.new.tap { |h| + val.each_pair { |k, v| + if v.is_a?(Hash) + h[k] = Vagrant::Util::HashWithIndifferentAccess.new(v) + else + h[k] = v + end + } + } + else + INVALID_PLUGIN_FORMAT end - result end end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index fe2a80115..26daedf9a 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1813,6 +1813,8 @@ en: sensitive_bad_type: |- Invalid type provided for `sensitive`. The sensitive option expects a string or an array of strings. + plugins_invalid_format: |- + Invalid type provided for `plugins`. plugins_bad_key: |- Invalid plugin configuration detected for `%{plugin_name}` plugin. diff --git a/test/unit/plugins/kernel_v2/config/vagrant_test.rb b/test/unit/plugins/kernel_v2/config/vagrant_test.rb index ece682f51..d2f55be2f 100644 --- a/test/unit/plugins/kernel_v2/config/vagrant_test.rb +++ b/test/unit/plugins/kernel_v2/config/vagrant_test.rb @@ -56,4 +56,54 @@ describe VagrantPlugins::Kernel_V2::VagrantConfig do subject.finalize! end end + + describe "#plugins" do + it "converts string into hash of plugins" do + subject.plugins = "vagrant-plugin" + subject.finalize! + expect(subject.plugins).to be_a(Hash) + end + + it "converts array of strings into hash of plugins" do + subject.plugins = ["vagrant-plugin", "vagrant-other-plugin"] + subject.finalize! + expect(subject.plugins).to be_a(Hash) + expect(subject.plugins.keys).to eq(["vagrant-plugin", "vagrant-other-plugin"]) + end + + it "does not convert hash" do + plugins = {"vagrant-plugin" => {}} + subject.plugins = plugins + subject.finalize + expect(subject.plugins).to eq(plugins) + end + + it "converts array of mixed strings and hashes" do + subject.plugins = ["vagrant-plugin", {"vagrant-other-plugin" => {:version => "1"}}] + subject.finalize! + expect(subject.plugins["vagrant-plugin"]).to eq({}) + expect(subject.plugins["vagrant-other-plugin"]).to eq({"version" => "1"}) + end + + it "generates a validation error when incorrect type is provided" do + subject.plugins = 0 + subject.finalize! + result = subject.validate(machine) + expect(result.values).not_to be_empty + end + + it "generates a validation error when invalid option is provided" do + subject.plugins = {"vagrant-plugin" => {"badkey" => true}} + subject.finalize! + result = subject.validate(machine) + expect(result.values).not_to be_empty + end + + it "generates a validation error when options are incorrect type" do + subject.plugins = {"vagrant-plugin" => 1} + subject.finalize! + result = subject.validate(machine) + expect(result.values).not_to be_empty + end + end end